
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// -----------------------------------------------------------------------------



// JavaScript Document
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
	object="";
}

function hightLightBg(Obj,L){
	if(L==1){
		oldCname=document.getElementById(Obj).className
		document.getElementById(Obj).className="homeRoll";	
	}
	else{
		document.getElementById(Obj).className=oldCname;	
		}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	countryA= new Array();
	
	countryA[0]="us";
	countryA[1]="fra";
	countryA[2]="sp";
	countryA[3]="ger";
	countryA[4]="uae";
	countryA[5]="uk";
	countryA[6]="ukr";

	
	for(i=6;i<countryA.length;i++){
			changeOpac(30,countryA[i])
		}
	
}


function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


////text resize

// JavaScript Document
//Specify affected tags. Add or remove from list:
var tgs = new Array('div','td','tr','p','table','small');

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;

function ChangeFontSize(trgt,inc,clicked) {
	var fontSize = checkCookieForFont('txtImageSize',11)
	var txtImageMap = document.getElementById('TxtSizeImage');

	if (inc != fontSize && fontSize!=null)
	{

		if (clicked == 1) // this value is changed from click
		{
			inc = fontSize;
		}	

	if(inc==10){
			txtImageMap.src="images/Text_size1.jpg"
			setCookie('txtImageSize',inc,1);
		}
	else if(inc==11){
			txtImageMap.src="images/Text_size2.jpg"
			setCookie('txtImageSize',inc,1);
		}
	else if(inc==12){
			txtImageMap.src="images/Text_size3.jpg"
			setCookie('txtImageSize',inc,1);
		}
	else {
		alert("last else ?? nothing to do")
		}
	}else{
		// cookie is nulll
		txtImageMap.src="images/Text_size2.jpg"
		setCookie('txtImageSize',11,1);
	}

	
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
	//sz += inc;
	//if ( sz < 0 ) sz = 0;
	//if ( sz > 6 ) sz = 3;
	//startSz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ){ 
			if(cTags[ j ].className=="footer"){
					cTags[ j ].style.fontSize = inc-1
				}
			else{
				cTags[ j ].style.fontSize = inc
			}
		}
	}
}


// Cookie functions for font change
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookieForFont(c_name,default_value)
{
cookieName=getCookie(c_name);
if (cookieName!=null && cookieName!="")
  {
//  alert('Cookie Exists '+cookieName+'!');
  return cookieName;
  }
  else 
  {
//  alert('Seting default value');
  cookieName=default_value;
  if (cookieName!=null && cookieName!="")
    {
    setCookie(c_name,cookieName,1);
	return cookieName;
    }
  }
}

function hideSelects(visibility){
		selects = document.getElementsByTagName('select');
		for(i = 0; i < selects.length; i++) {
			selects[i].style.visibility = visibility;
		}
	}


/*******************AJAX CALL*////////////


function SearchbyKey(SearchTerm){
		if(SearchTerm==""){
				document.getElementById('searchResultDIV').style.display="none";
				hideSelects("visible");
			}
		else{
				document.getElementById('searchResultDIV').style.display="block";
				showSearchResult(SearchTerm);
				hideSelects("hidden");
			}
	}
	

var xmlHttp

function showSearchResult(str)
{ 
	document.getElementById("indicator").style.display="block"
	var url="../search.asp?Rid="+ Math.random() +"&searchTerm=" + str;
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-Length", "0");
	xmlHttp.send(null)
} 



function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
	document.getElementById("indicator").style.display="none"
	document.getElementById("results").innerHTML=xmlHttp.responseText 
	window:scroll(0,280);
	if(document.getElementById('ULSearchResult')){
		countHowMuchResult('ULSearchResult')
		document.getElementById('searchResultDIV').style.height="";
		
		current=Searchrows;//reseting from first Paging 
		balance=0;
	}
	else{
		document.getElementById('searchResultDIV').style.height="320px";
		}
} 
} 


///HTTP REQUEST
function GetXmlHttpObject(handler)
{ 
	var objXmlHttp=null

/*	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This example doesn't work in Opera") 
		return 
	}
*/	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP"
		} 
		try
		{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0 || navigator.userAgent.indexOf("Opera")>=0)
	{
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
} 


Searchrows=5;///how many at one page

var SearchRowUL;
current=Searchrows;
function countHowMuchResult(Obj){
	
		SearchRowUL=document.getElementById(Obj).getElementsByTagName('li');//getting all LI
		
		for(i=0;i<SearchRowUL.length;i++){//hiding all Li
			SearchRowUL[i].style.display="none";
		}
		
		if(SearchRowUL.length>Searchrows){//checking for LI lengths if it is greater Searchrows print first 5(Searchrows). disable prev btn
			for(i=0;i<Searchrows;i++){
				SearchRowUL[i].style.display="block";
				}
				document.getElementById('SearchPrevBtn').disabled=true;
				document.getElementById('SearchPrevBtn').style.cursor="default";
				changeOpac(20,'SearchPrevBtn')
				
				document.getElementById('searchResultDIV').style.height="";
				
				document.getElementById('paging').innerHTML="<b>1 - " + Searchrows+" of "+SearchRowUL.length +"</b>"
				
				
		}
		else{//if total is low print that much only./disbale both buttons
			for(i=0;i<SearchRowUL.length;i++){
				SearchRowUL[i].style.display="block";
				}
				
				document.getElementById('SearchPrevBtn').disabled=true;
				document.getElementById('SearchNextBtn').disabled=true;
				
				document.getElementById('SearchPrevBtn').style.cursor="default";
				document.getElementById('SearchNextBtn').style.cursor="default";
				
				changeOpac(20,'SearchPrevBtn')
				changeOpac(20,'SearchNextBtn')
				
				document.getElementById('searchResultDIV').style.height="320px";

				
				///paging
				document.getElementById('paging').innerHTML="<b>1 - " + SearchRowUL.length+" of "+SearchRowUL.length +"</b>"
			}
			
			
	}
balance=0;
function SearchShowNP(To){
	
		for(i=0;i<SearchRowUL.length;i++){
			SearchRowUL[i].style.display="none";
		}
		
		if(To=="Prev"){
			
			for(j=CurrentStaring-1;j>=CurrentStaring-Searchrows;j--){
					current=j;
					SearchRowUL[j].style.display="block";
				}
				
				document.getElementById('SearchNextBtn').disabled=false;
				document.getElementById('SearchNextBtn').style.cursor="pointer";
				changeOpac(100,'SearchNextBtn')
				
				//printing pages number
				document.getElementById('paging').innerHTML="<b>"+current +" - " + CurrentStaring +" of "+SearchRowUL.length +"</b>" 
				
			CurrentStaring=	current	
			
			
			if(current==0){
						document.getElementById('SearchPrevBtn').disabled=true;
						document.getElementById('SearchPrevBtn').style.cursor="default";
						changeOpac(20,'SearchPrevBtn');
						
						//printing pages number
						document.getElementById('paging').innerHTML="<b>"+current+1 +" - " + Searchrows +" of "+SearchRowUL.length +"</b>" 
						
						balance=0;
						current=Searchrows;
				}
		}
		else if(To=="Next"){
			if(balance<=Searchrows && balance!=0){///balance for defining first avoiding undefined error
				for(i=current;i<current+balance;i++){///adding balance to current
					SearchRowUL[i].style.display="block";
					}

				document.getElementById('SearchNextBtn').disabled=true;
				document.getElementById('SearchNextBtn').style.cursor="default";
				balance=parseInt(SearchRowUL.length)-current;
				changeOpac(20,'SearchNextBtn')
				CurrentStaring=current;
				
				//printing pages number
				document.getElementById('paging').innerHTML="<b>"+CurrentStaring +" - " + (current+balance) +" of "+SearchRowUL.length +"</b>" 
				}
			else{
						
					if(parseInt(SearchRowUL.length)-current>Searchrows){
						for(i=current;i<current+Searchrows;i++){
							SearchRowUL[i].style.display="block";
						}
					}
					else{
						for(i=current;i<current+(parseInt(SearchRowUL.length)-current);i++){
							SearchRowUL[i].style.display="block";
						}
						document.getElementById('SearchNextBtn').disabled=true;
						document.getElementById('SearchNextBtn').style.cursor="default";
						changeOpac(20,'SearchNextBtn')
					}
						
				CurrentStaring=current;
				current=current+Searchrows;
						
	
				document.getElementById('SearchPrevBtn').disabled=false;
									
				
				document.getElementById('SearchPrevBtn').style.cursor="pointer";
				changeOpac(100,'SearchPrevBtn')	
				
				
				balance=parseInt(SearchRowUL.length)-current;
				
									
				///printing pages number
				document.getElementById('paging').innerHTML="<b>"+CurrentStaring +" - " + current+" of "+SearchRowUL.length +"</b>"
			}//if

		}//end of NEXT

}///end of function searchShowNP()


/********lighbox settings pos *///

/**Light Box pos**/
function ChangeLBPosSize(type,obj){
	
		if(type==1){
			document.getElementById('lightbox').style.width='750px'
			document.getElementById('lightbox').style.height='510px'
			if(window.screen.width<=1024){
				document.getElementById('lightbox').style.left='38%'
				document.getElementById('lightbox').style.top='40%'
			}
			else if(window.screen.width>1024){
				document.getElementById('lightbox').style.left='40%'
				document.getElementById('lightbox').style.top='28%'
				}
			}
		else if(type==2){
			document.getElementById('lightbox').style.width='780px'
			document.getElementById('lightbox').style.height='500px'
			document.getElementById('lightbox').style.left='35%'
			document.getElementById('lightbox').style.top='45%'
			}
	}
	
/*************/

/********Highlight Page*///////////

function HightLightPage(Obj,classN){
	if(classN){
		document.getElementById(Obj).className=classN
		}
	else{
		document.getElementById(Obj).className="textHighlight"
	}
}

/********end of highlight page*****************/

/****Search*****/



	/***************Ajax function calling using Prototype Class*////////////////
	var ResponsWritePlace;
	var LoadedContent;
	function CreateAJAXRequest(url,rPlace,pars,lContent){
		
		ResponsWritePlace=rPlace;
		LoadedContent=lContent;
		LightBoxURL=url;
		pars=pars+"&killCache="+new Date().getTime();
			
		//Element.show("loadingDIV")

		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onSuccess: CallSucess,
				onFailure:CallError,
				onComplete: showResponse
			}
		);
	}

	function showResponse(originalRequest){
		
		//this checking it is normal MASTER PAGES Request or lightbox submition? 
		//First one is normal MASTER PAGES AJAX Request
		if(ResponsWritePlace!="noPrintRequired" || LoadedContent!="NoContent"){
			
			///remove already available(prevoius loaded) element
			if($(LoadedContent)){Element.remove($(LoadedContent));}
			
				//put returned XML in the Container
				info = "<div id="+LoadedContent+">" + originalRequest.responseText + "</div>";
				
				new Insertion.Before($(ResponsWritePlace), info);//this enable javascript in loaded page
				
				if(LoadedContent=="lbContent"){//problem for FireFox 
					$('lightbox').className = "done";
				}
				
				Element.hide("loadingDIV")
		}	
	}
	
	function CallSucess(){
		//alert('success')
	}
	
	function CallError(){
		alert('Your Request Failed.. \n ----------------------')
	}
	
	
	
	   var elem = "td";
   var rClick=false;
   var c=0
   var Hlength=0;
   addSArrayBool=false;
function createHighLight(Obj,td){
		if(document.getElementsByTagName){
			if(td=='tr'){
				elem='tr';
				}
			else{
				elem='td';
			}
			
			var el = document.getElementById(Obj).getElementsByTagName(elem);
			if(td=='tr'){Hlength=el.length;	}else{Hlength=el.length;}

			
			for(var i=0; i<Hlength; i++){
			
			 el[i].onmouseover = function(){
				this.oldClassName=this.className
				if(Obj=='caseStudiesSelector' ){
					if(this.className=="selectedItem"){
						this.className = "selectedItem";
					}
					else{
						this.className = "selectedItem";	
					}
				}
			 }
			 el[i].onmouseout = function(){
					if(rClick==false || this.className!="selectedItem"){
						this.className =this.oldClassName;
			 		}
			  }
			  
			  

			}
		}
}

caseStudiesArray= new Array();
caseStudiesArray[0]="../casestudies/microsoft.html~~~#29";
caseStudiesArray[1]="../casestudies/sap.html~~~#30";
caseStudiesArray[2]="../casestudies/xora.html~~~#31";
caseStudiesArray[3]="../casestudies/tidaldata.html~~~#32";
caseStudiesArray[4]="../casestudies/yahoo.html~~~#33";
caseStudiesArray[5]="../casestudies/flex.html~~~#34";
caseStudiesArray[6]="../casestudies/twb.html~~~#35";
caseStudiesArray[7]="../casestudies/pos.html~~~#36";
caseStudiesArray[8]="../casestudies/akamai.html~~~#37";
caseStudiesArray[9]="../casestudies/siri.html~~~#38";
caseStudiesArray[10]="../casestudies/carpediem.html~~~#39";
caseStudiesArray[11]="../casestudies/sasken.html~~~#40";
caseStudiesArray[12]="../casestudies/ona.html~~~#41";
caseStudiesArray[13]="../casestudies/printo.html~~~#42";

function loadCaseStudies(num){
		createHighLight("caseStudiesSelector")
		getTdTags=$("caseStudiesSelector").getElementsByTagName("td");
		for(i=0;i<getTdTags.length;i++){
			getTdTags[i].className="";	
		}
		
		getTdTags[num].className="selectedItem";
		getTdTags[num].onmouseout=function(){
		//	alert(true)		
		}
		
		cutCasestudiesArray=caseStudiesArray[num].split("~~~");
		changeSNumber(cutCasestudiesArray[1])
		CreateAJAXRequest(cutCasestudiesArray[0],'holder1','','LoadedContent1')
}

function changeSNumber(num){
	showCaseNumber.innerHTML=num;	
}

function showHideTR(idx,vis,tableObj) {
	
  var tbl,row;
  if(document.getElementById && document.getElementsByTagName) {
    tbl = document.getElementById(tableObj);
    if(!tbl || (idx >= tbl.getElementsByTagName('tr').length)) return;
    row = tbl.getElementsByTagName('tr')[idx];
  } else if(document.all && document.all.tags) { // IE4 support 
    tbl = document.all.table1;
    if(!tbl || (idx >= tbl.all.tags('tr').length)) return;
    row = tbl.all.tags('tr')[idx];
  }
  if(row) {
    if(!vis) {
      row.style.display = 'none';
    } else {
      // conditional compilation to hide the try-catch blocks from IE4
      /*@cc_on @if(!@_jscript || (@_jscript_version >= 5)) @*/
        try {
          row.style.display = 'table-row';
        } catch(e) {
          row.style.display = 'block';
        }
      /*@elif(@_jscript_version < 5)
        row.style.display = 'block'; // for IE4
      @end @*/
    }
  }
}

function ValidateForm(formObj){
			error=0;
			errorMessages="";
			if($('Fname').value=="" ){
				alert("Enter your First Name");
				$('Fname').focus();
			}
			else if($('Lname').value==""){
				alert("Enter your Last Name");
				$('Lname').focus();
			}
			else if($('Email').value=="" ){
				alert("Enter Email Address");
				$('Email').focus();
			}
			else if(!isValidEmail($('Email').value)){
				alert("Enter a valid Email Address");
				$('Email').focus();
			}
			else if($('file1').value==""){
				alert("Browse your CV");
				$('file1').focus();
			}
			else{
				$(formObj).submit();	
			}
	
	}
	
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  //strEmail = document.forms[0].email.value;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      //alert('A valid e-mail address is required.\nPlease amend and retry');
      return false;
    } 
    return true; 
}


