var uploader = '';
// VALIDATION FUNCTION BY FAHEEM FOR VALIDATING CarSelect.php ENDS HERE
function createXMLHttpRequest() 
{

    var ua;
	try { 
		ua = new XMLHttpRequest(); 
	} 
	catch (trymicrosoft) { 
		try { 
			ua = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch (failed) { 
			ua = false; 
		} 
	} 
    return ua;
}

var req = createXMLHttpRequest();
function handleResponse() {
    if(req.readyState == 1){
	   if(document.getElementById("hdnComboOptions").value==1)
	   {
			//alert(document.getElementById("hdnTdName").value);
		    var arr3 = new Object();
			arr3[0]="Wait .....";
			AddComboOptions(document.getElementById(document.getElementById("hdnTdName").value), arr3, 0);	   	
	   }
	   else
		   document.getElementById(document.getElementById("hdnTdName").value).innerHTML = "<div align='left'>Wait .....</div>";
	}
	else if(req.readyState == 4){
		//alert("here");	
        var response = req.responseText;
        var update = new Array();
        if(response.indexOf('||' != -1)) 
		{
           update = response.split('||');
		   strResponse=update[0];
		   //alert(strResponse);
		   if(document.getElementById("hdnComboOptions").value==1)
		   {
			   var arr= new Array();
			   var arr1 = new Array();
			   var arr3 = new Object();
			   arrResponse = strResponse.split('**');
			  // alert(arrResponse[0]);
			 //  alert(arrResponse[1]);
			   arr = arrResponse[1].split('*');
			   // assign values
			   if(arr.length>0)
			   {
				   for(i=0;i<arr.length;i++)
				   {
					   arr1 = arr[i].split('^');
					   if(arr1.length>1)
						 arr3[arr1[0]]=arr1[1];
				   }
			   }
			   //alert(document.getElementById("hdnTdName").value);	
			   //alert(document.getElementById(document.getElementById("hdnTdName").value));
			   AddComboOptions(document.getElementById(document.getElementById("hdnTdName").value), arr3, 0);   
		   }
		   else
		   {
			   //alert(strResponse);
		   	   document.getElementById(document.getElementById("hdnTdName").value).innerHTML = update[0];
		   }
        }
    }
}

function getRecords(nCaseID, strCriteria, strDivName, strControlName,strOnChange)
{
	
	strOnChange=strOnChange.replace("'","\'");
	//alert(strOnChange);
	
	//alert(strDivName);
	//alert(strControlName);
	
	if(strDivName!='')
	{
		document.getElementById("hdnTdName").value	= strDivName;
		document.getElementById("hdnComboOptions").value=0;
	}
	else
	{
		document.getElementById("hdnComboOptions").value=1;
		document.getElementById("hdnTdName").value	= strControlName;
	}

	strURL="Includes/GetRecords.php"; 
	
	strQryStr =	'nCaseID='+nCaseID+'&strCriteria='+strCriteria+'&strControlName='+strControlName+'&strOnChange='+strOnChange+'&nComboOptions='+document.getElementById("hdnComboOptions").value;
//	alert(strQryStr);
	strFolder=location.href;
	//alert(strFolder); 
	if(strFolder.indexOf("AdminArea")!=-1 || strFolder.indexOf("adminarea")!=-1 || strFolder.indexOf("Adminarea")!=-1)
		strURL="../Includes/GetRecords.php";
	else if(strFolder.indexOf("Includes")!=-1)
		strURL="GetRecords.php";
	//alert(strURL+'?'+strQryStr);
	
	req.open('get', strURL+'?'+strQryStr);
	//alert(strURL+'?'+strQryStr);	
	
	req.onreadystatechange = handleResponse;
	req.send(null);
	
}
function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	//alert(value);
	selectbox.options.add(optn);
}

function removeAllOptions(selectbox, nFromOption)
{
	var i;
	for(i=selectbox.options.length-1;i>=nFromOption;i--)
	{
		selectbox.remove(i);
	}
}

function AddComboOptions(selectbox, arr, nFromOption)
{
	//alert(selectbox+"___"+nFromOption);
	removeAllOptions(selectbox, nFromOption);
	for( var arrMaker in arr ) 
	{	
		addOption(selectbox,arr[arrMaker],arrMaker);
	}
}

function numbersonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
	if(unicode==8 || unicode==9 ||  unicode==13 || unicode==46 ||  unicode==37 || unicode==39)
	{
	}
	else
	{ 
		if (unicode<48||unicode>57) //if not a number
			return false //disable key press
	}
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  	if ((obj=MM_findObj(args[i]))!=null) 
	{ 
		v=args[i+2];
    	if (obj.style) 
		{ 
			obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
  		}
    	obj.visibility=v;
	 }
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  
  if(!d) 
  	d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) 
  	x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) 
  	x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
  	x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) 
  	x=d.getElementById(n); 
  return x;
}
function switchMenu(obj, nCheckDisplay) {
	var el = document.getElementById(obj);
	//alert(obj);
	if (nCheckDisplay == false ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

///////////////////////////// Page layout functions ///////////////////////////////////

function PopulateLayout()
{
	nFrameID=document.getElementById("hdnFrameID").value;
	if(opener.frames && opener.frames[nFrameID]) //IE 5 (Win/Mac), Konqueror, Safari
	  cWindow = opener.frames[nFrameID];
	else if(opener.document.getElementById(nFrameID).contentWindow) //IE 5.5+, Mozilla 0.9+, Opera
	  cWindow = opener.document.getElementById(nFrameID).contentWindow;
	else //Moz < 0.9 (Netscape 6.0)
	  cWindow = opener.document.getElementById(nFrameID);
	cDocument = cWindow.document;
	//alert(cDocument);
	cDocument.open();
	cDocument.write(window.document.getElementById('lstLayout').value);
	cDocument.close();
	window.close();
	return true;
}
function PreviewLayout()
{
	if(window.frames && window.frames['frmLayout']) //IE 5 (Win/Mac), Konqueror, Safari
	  cWindow = window.frames['frmLayout'];
	else if(window.document.getElementById('frmLayout').contentWindow) //IE 5.5+, Mozilla 0.9+, Opera
	  cWindow = window.document.getElementById('frmLayout').contentWindow;
	else //Moz < 0.9 (Netscape 6.0)
	  cWindow = window.document.getElementById('frmLayout');
	
	cDocument = cWindow.document;
	cDocument.open();
	//alert('xcvxcv');
	cDocument.write(window.document.getElementById('lstLayout').value);
	cDocument.close();
}

/////////////////////////// Image Layout functions ////////////////////////////////////
function SelectLayout(hdnFrameName, hdnHiddenName, hdnDivName)
{
	hdlWindow=window.open('SelectPictureLayout.php?hdnHiddenName='+hdnHiddenName+'&hdnFrameName='+hdnFrameName+'&hdnDivName='+hdnDivName,'Layout','width=450,height=330,left=300,top=300,screenX=300,screenY=300,scrollbars=1');
	hdlWindow.moveTo(100,20);
	return true;
}
function transfer()
{
	if(opener.frames && opener.frames[document.getElementById("hdnFrameName").value]) //IE 5 (Win/Mac), Konqueror, Safari
	  cWindow = opener.frames[document.getElementById("hdnFrameName").value];
	else if(opener.document.getElementById(document.getElementById("hdnFrameName").value).contentWindow) //IE 5.5+, Mozilla 0.9+, Opera
	  cWindow = opener.document.getElementById(document.getElementById("hdnFrameName").value).contentWindow;
	else //Moz < 0.9 (Netscape 6.0)
	  cWindow = opener.document.getElementById(document.getElementById("hdnFrameName").value);
	cDocument = cWindow.document;
	cDocument.open();
	opener.document.getElementById(document.getElementById("hdnDivName").value).style.display='';
	cDocument.write(window.document.getElementById('hdnDetail'+window.document.getElementById('lstLayout').value).value);
	//alert("here");
	//alert(document.getElementById("hdnHiddenName").value);
	//alert(opener.document.getElementById(document.getElementById("hdnHiddenName").value).value);
	opener.document.getElementById(document.getElementById("hdnHiddenName").value).value=window.document.getElementById('lstLayout').value;
	cDocument.close();
	//alert("here");
	window.close();
	return true;
}
function PreviewImageLayout()
{
	if(window.frames && window.frames['frmLayout']) //IE 5 (Win/Mac), Konqueror, Safari
	  cWindow = window.frames['frmLayout'];
	else if(window.document.getElementById('frmLayout').contentWindow) //IE 5.5+, Mozilla 0.9+, Opera
	  cWindow = window.document.getElementById('frmLayout').contentWindow;
	else //Moz < 0.9 (Netscape 6.0)
	  cWindow = window.document.getElementById('frmLayout');
	cDocument = cWindow.document;
	cDocument.open();
	//alert(window.document.getElementById('hdnDetail1'));  
	cDocument.write(window.document.getElementById('hdnDetail'+window.document.getElementById('lstLayout').value).value);
	cDocument.close();
}
function populateWYSWIG(strWYSWIGName,strContents)
{
	if(window.frames && window.frames[strWYSWIGName]) //IE 5 (Win/Mac), Konqueror, Safari
	  cWindow = window.frames[strWYSWIGName];
	else if(window.document.getElementById(strWYSWIGName).contentWindow) //IE 5.5+, Mozilla 0.9+, Opera
	  cWindow = window.document.getElementById(strWYSWIGName).contentWindow;
	else //Moz < 0.9 (Netscape 6.0)
	  cWindow = window.document.getElementById(strWYSWIGName);
	cDocument = cWindow.document;
	cDocument.open();
	cDocument.write(strContents);
	cDocument.close();
}
function ChangeLeftRight(d)
{
	var Left = document.getElementById("Left_"+d);
	var Right = document.getElementById("Right_"+d);
	Left.src = "images/mouseove_menu_tab_left.jpg";
	Right.src = "images/mouseove_menu_tab_right.jpg";
	
}
function REChangeLeftRight(d)
{
	var Left = document.getElementById("Left_"+d);
	var Right = document.getElementById("Right_"+d);
	
	
	Left.src = "images/menu_tab_left.jpg";
	Right.src = "images/menu_tab_right.jpg";
	
}
function switch_divs(show_div,hide_div){
	
	$('#'+hide_div).hide();
	$('#'+show_div).fadeIn();

}
var message="Function Disabled!";
function clickIE4(){
    if (event.button==2){
    alert(message);
    return false;
    }
}
function clickNS4(e){
    if (document.layers||document.getElementById&&!document.all){
        if (e.which==2||e.which==3){
        alert(message);
        return false;
        }
    }
}
if (document.layers){
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
    document.onmousedown=clickIE4;
}
//document.oncontextmenu=new Function("return false;");
function __in(divID){
	$(divID).fadeIn();
}

function __out(divID){
	$(divID).fadeOut();
	
}
							
function yourTurn(form,_url){	
	$("#msg").hide();
	$("#buttons").hide();
	$("#loading_ani").show(); 

	$.ajax({
		type: "POST",
		url: _url,
		data : $("#"+form).serialize(),
		success: function(html){
			var r = html.split("|");
			$("#buttons").show();
			$("#loading_ani").hide(); 
			
			if(r[0] == 1){
				$("#name").val('');
				$("#email").val('');
				$("#message").val('');	
				$("#phone").val('');
				$("#countryID").val('');
                
               window.location = $("#thankyou_url").val();
			}
			$("#security_code").val('');	
			jumpTo('#id_yourturn'); 
			$("#msg").show();
			$("#msg").html(r[1]);
			$("#q").html(r[2]);
		}
	});
}

function subscribe_foot(form,_url){	
	$("#newsletter_msg").hide();


	if($("#foot_name").val() == "Name" || $.trim($("#foot_name").val()) == ""){
		$("#newsletter_msg").show();
		$("#newsletter_msg").html("<p style='color:red;'>Name required</p>");
		return;
	}
	
	if($("#foot_email").val() == "E-mail" || $.trim($("#foot_email").val()) == ""){
		$("#newsletter_msg").show();
		$("#newsletter_msg").html("<p style='color:red;'>Email required</p>");
		return;
	}
	
	$("#newsletter_msg").hide();
	$.ajax({
		type: "POST",
		url: _url,
		data : $("#"+form).serialize(),
		success: function(html){
			var r = html.split("|");
			if(r[1] == 1){
				$("#div_get_yourself_posted").hide();
			}
			$("#newsletter_msg").show();
			$("#newsletter_msg").html(r[2]);
		}
	});
}

var current_div_section = '';
function mToggle(divID){
	if(current_div_section != divID){
		$(".toggle_section").slideUp();
	}
	$(divID).slideToggle('slow');
	current_div_section = divID;
}

function jumpTo(divID){
	var target = $(divID);
	target = target.length && target
	var targetOffset = target.offset().top;
	$("html,body").animate({scrollTop: targetOffset}, 1000);
}

function showImage(_url,imageID,portfolioid){
	_data = "imageID="+imageID + "&portfolioid="+portfolioid;
	$.ajax({
		type: "POST",
		url: _url,
		data: 	_data ,
		success: function(html){

			var r = html.split("|");
			var status = parseInt(r[0]);
			var img = r[1];
			var portfolioID = parseInt(r[2]);  
	
			if(status == 1){
				$("#desc_"+portfolioID).css("visibility", "hidden");
				$("#img_display_"+portfolioID).hide();
				$("#img_display_"+portfolioID).html(img);
				$("#img_display_"+portfolioID).show('slow');
			}
		}
	});
}

function _visible(divID){
	$(divID).css("visibility", "visible");
}

function _invisible(divID){
	$(divID).css("visibility", "hidden");
}

function _hint(obj,target_value,onblur){
	if(obj.value == target_value){
		obj.value = '';	
	}
	
	if(onblur == 1 && $.trim(obj.value) == ''){
		obj.value = target_value;
	}
}

function redirect(_url){
	window.location = _url;
}

function validate_rfp_form(form){
	var is_error = false;
	if($.trim(form.name.value) == ''){
		$("#em_name").show();
		is_error = true;
	}
	
	if($.trim(form.email.value) == ''){
		$("#em_email").show();
		is_error = true;
	}else if(!validate_email(form.email.value)){
		$("#em_email").show();
		("#em_email").html("Invalid email address");
		is_error = true;
	}
	
	if($.trim(form.phone.value) == ''){
		$("#em_phone").show();
		is_error = true;
	}
	
	
	if($.trim(form.countryID.value) == ''){
		$("#em_countryID").show();
		is_error = true;
	}
	
	if(is_error){
		$("#jmp_rfp_form").show();
		jumpTo('#rfp_jump');
		return false;
	}
	$("#jmp_rfp_form").hide();
	return true;
}
$(document).ready(function() {
	
	$(".main_what_we_do	.item").hover(function() { //On hover...
		
		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
		
		$(this).find("div.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		//Fade the image to 0 
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		}); 
	} , function() { //on hover out...
		//Fade the image to 1 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});
    
    try
    {
        $("#main_work").scrollable({circular: true, mousewheel: false}).navigator();
        $("#main_news").scrollable({circular: true, mousewheel: false}).navigator();
        $("#main_products").scrollable({circular: true, mousewheel: false}).navigator();
    }catch(err){}
    
    $(".main_work a").hover(function(){
        $(this).children("span").fadeOut();
    },function(){
        $(this).children("span").fadeIn();
    });
    
    try
        {
        $('.slideshow').cycle({
            fx: 'fade',
            timeout: 2500,
            speed: 1000,
            next:'#next',
            prev:'#prev'
        });
    }catch(err){} 

});
$(document).ready(function() {
$('#games').coinslider({ 
	width: 982, // width of slider panel
	height: 169, // height of slider panel
	spw: 7, // squares per width
	sph: 6, // squares per height
	delay: 4000, // delay between images in ms
	sDelay: 3, // delay beetwen squares in ms
	opacity: 0.7, // opacity of title and navigation
	titleSpeed: 500, // speed of title appereance in ms
	effect: 'random', // random, swirl, rain, straight
	navigation: true, // prev next and buttons
	links : false, // show images as links
	hoverPause: true // pause on hover
});
	
$('#portfolio').fader({ 'speed': 600, 'timeout':3000, 'containerHeight':203, 'pauseOnHover': true, });
$('#cs-buttons-games').hide();	
});
$(function(){
	$('#main_work').slides({
		preload: true,
		generatePagination: false,
		generateNextPrev: true
	});
	
	$('#main_news').slides({
		preload: true,
		generatePagination: false,
		generateNextPrev: true
	});
	
	$('#main_work .slide div').mouseover(function() {
    	var id = $(this).attr('id');
		$("#main_work #"+id+" .labelContainer").css('display','block');
		$("#main_work #"+id+" .imgContainer").css('display','none');
	 }).mouseout(function(){
		 var id = $(this).attr('id');
		$("#main_work #"+id+" .labelContainer").css('display','none');
		$("#main_work #"+id+" .imgContainer").css('display','block');
  	});

	//$("#main_news .slide .item:last").css('margin-right','0');
});
$("a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'normal',slideshow:3000, autoplay_slideshow: false});

	$("#pagination li:first").css({'color' : '#dddddd'}).css({'border' : 'solid #0063DC 1px'});
	//Pagination Click
	$("#pagination li").click(function(){
	$("#pagination li")
		.css({'border' : 'solid #dddddd 1px'})
		.css({'color' : '#0063DC'});
		
		$(this)
		.css({'color' : '#dddddd'})
		.css({'border' : 'solid #0063DC 1px'});

		//Loading Data
		var pageNum = $(this).attr('num');
		var ModuleId = $(this).attr('ModuleId');
		var CatId = $(this).attr('CatId');
		var TypeId = $(this).attr('TypeId');
		
		$(".work_listing_1").load("AllOurWork_data.php?page=" + pageNum + "&ModuleId="+ ModuleId + "&CatId="+ CatId + "&TypeId="+ TypeId,'',function(){$("a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'normal',slideshow:3000, autoplay_slideshow: false});});
	});

