

// THIS variable is for policies tabs

var isfirstmetho=true;


/////////////////// menu codes ////////////////
var mytimeout;
var lastdivshown="";
function showmenu(divname,e)
{
	
	var myEvent = window.event ? window.event : e;
	//document.getElementById(divname).style.left=myEvent.clientX+"px";
	
	//$("#"+divname).fadeIn("slow");
	document.getElementById(divname).style.display="block";
	
	if((lastdivshown!="")&&(lastdivshown!=divname))
	{
	 if(document.getElementById(lastdivshown).style.display!="none")
	 {//$("#"+lastdivshown).fadeOut("fast");
	 document.getElementById(lastdivshown).style.display="none";
	 }
	}
	lastdivshown=divname;
	clearTimeout(mytimeout);
	
}


function hidemenu()

{

//alert(lastdivshown);

$("#"+lastdivshown).fadeOut("slow");
//document.getElementById(lastdivshown).style.display="none";
}



function overmenu(divname,obj)

{

//obj.style.backgroundColor="#ffffff";

obj.style.color="#ffffff";

clearTimeout(mytimeout);



}



function outmenu(divname,obj)

{

//obj.style.backgroundColor="#C50102";

obj.style.color="#000000";

mytimeout=setTimeout("hidemenu();",500);



}



function outmenu1(divname)

{

mytimeout=setTimeout("hidemenu();",500);

}



function overlink(obj)

{

obj.style.color="#dddddd";

}



function outlink(obj)

{

obj.style.color="#ffffff";

}

		//////// function to swap images randomly
 	
	document.onload=startevrything();
	
	var blue=2;
	var flag=true;
    
	
	function swapman()
	{
	var graysrc="img/man-gray.jpg";
	var bluesrc="img/man-blue.jpg";
		
			// lets generate 2 rondom numbers 
			var num1=Math.floor(Math.random()*6);
			//alert(num1);
			if(num1==blue)
			{
				num1=Math.floor(Math.random()*6);
			}
			var imgid="img"+num1;
			$("#"+imgid).fadeOut("slow",function (){$("#"+imgid).attr("src",bluesrc).fadeIn();});
			
			
	
		var imgid1="img"+blue;
		//alert(imgid);
		
		
		$("#"+imgid1).fadeOut("slow",function (){$("#"+imgid1).attr("src",graysrc).fadeIn();});
		//logoimg.src="img/"+imgs[0];
		//$("#"+imgid).fadeIn();
		//alert(logoimg.src);

	blue=num1;
	
	setTimeout("swapman();",1500);
	}
	
	//document.onload=swapman();
	
var current_link="homelink";
var krmtime="";
var istimerset=false;

	function overlink(obj)
	{
		document.getElementById(current_link).style.backgroundImage="";
		obj.style.backgroundImage="url(img/menu-bg.gif)";
		//current_link=obj.id;
		//playSound(0);
		if(istimerset)
		{clearTimeout(krmtime);istimerset=false;}
	}
	
	function outlink(obj)
	{
		obj.style.backgroundImage="";
		//stopSound(0);
		{
			krmtime=setTimeout("revertbutton();",1000);
			istimerset=true;
		}
		
	}
	
	function revertbutton()
	{
		document.getElementById(current_link).style.backgroundImage="url(img/menu-bg.gif)";	
	}
	
	
	
		
		////////////////////// AJAX ENGINE ////////////////////
	
	function fetchdata(str,box)
	{
	isfirstmetho=true;	
	clearTimeout(swaptimer);
	
	 var obj=GetXmlHttpObject();
	 
	 str = "http://www.krmglobal.com/"+str;
	 
	 obj.open("GET",str,true);
	 obj.onreadystatechange=function f1()
	  {
	  if(obj.readyState==4)
	   {
		var x=obj.responseText;
		   //alert(x);
		   //document.getElementById(box).innerHTML=x;
		   //document.getElementById("loading").style.display="none";
		   document.getElementById(box).innerHTML=x;
		obj=null;
	   }
	   else
	   {
		//document.getElementById("loading").style.display="block";
		document.getElementById(box).innerHTML="<center><br><br><br><br><br><br><br><br><br><br><br><br><span style='color:#aaaaaa;'>Loading Page...</span></center>";
	   }
	  }
	 obj.send(null);
	}
		
	
			function GetXmlHttpObject()
			{
			  var xmlHttp=null;
			  try
				{
				// Firefox, Opera 8.0+, Safari
				xmlHttp=new XMLHttpRequest();
				}
			  catch (e)
				{
				// Internet Explorer
				try
				  {
				  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				  }
				catch (e)
				  {
				  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				  }
				}
			  return xmlHttp;
			}
	
		////////////////////////FUNCTION FOR CLIENTS IMAGES SWAPPING ////////////////
	
		var imgs=new Array();
		
		imgs[0]="client0.jpg";
		imgs[1]="client1.jpg";
		imgs[2]="client2.jpg";
		imgs[3]="client3.jpg";
		imgs[4]="client4.jpg";
		imgs[5]="client5.jpg";
		imgs[6]="client6.jpg";
		imgs[7]="client7.jpg";
		imgs[8]="client8.jpg";
		imgs[9]="client9.jpg";
		
		//////// function to swap images randomly
    
    var swaptimer="";
	
/*	function swapimg()
	{
	 // lets generate 2 rondom numbers 
	 var num1=Math.floor(Math.random()*9);
//alert(num1);
	if(num1==0)
	{
		num1=4;
	
	}
	var imgid="logo"+num1;
	
	var logoimg=document.getElementById(imgid);
	var x=logoimg.src;
	var tmpimgs=x.split("/");
	var tmpimg=tmpimgs[tmpimgs.length-1];
	
	//alert(imgid);
	var newsrc="img/"+imgs[0];
	$("#"+imgid).fadeOut("slow",function (){$("#"+imgid).attr("src",newsrc).fadeIn();});
	//logoimg.src="img/"+imgs[0];
	//$("#"+imgid).fadeIn();
	//alert(logoimg.src);
	imgs[0]=tmpimg;
	
	swaptimer=setTimeout("swapimg();",2000);
	}
*/	
	//document.onload=swapimg();
	
/*	
	var bluee=2;
	var flagg=true;
	
	function swapman1()
	{
	var graysrc="img/man-gray.jpg";
	var bluesrc="img/man-blue.jpg";
		
			// lets generate 2 rondom numbers 
			var num1=Math.floor(Math.random()*6);
			//alert(num1);
			if(num1==bluee)
			{
				num1=Math.floor(Math.random()*6);
			}
			var imgid="imgr"+num1;
			$("#"+imgid).fadeOut("slow",function (){$("#"+imgid).attr("src",bluesrc).fadeIn();});
			
			
	
		var imgid1="imgr"+bluee;
		//alert(imgid);
		
		
		$("#"+imgid1).fadeOut("slow",function (){$("#"+imgid1).attr("src",graysrc).fadeIn();});
		//logoimg.src="img/"+imgs[0];
		//$("#"+imgid).fadeIn();
		//alert(logoimg.src);

	bluee=num1;
	
	setTimeout("swapman1();",1500);
	}
	
*/	//document.onload=swapman1();

	///// CADIDATES PAGE SCRIPTS 
	
	function showindex()
	{
			var url="home.php?sid="+Math.random();
			//alert(url);
			fetchdata(url,"contentbox");
			document.getElementById(current_link).style.backgroundImage="";
			current_link="homelink";
			revertbutton();
			
			//setTimeout("swapimg();",2000);
			//$("#contentbox").load(url);
	}

	function showvision()
	{
			var url="vision-mission.php?sid="+Math.random();
			//alert(url);
			fetchdata(url,"contentbox");
			document.getElementById(current_link).style.backgroundImage="";
			current_link="homelink";
			revertbutton();
			
			//setTimeout("swapimg();",2000);
			//$("#contentbox").load(url);
	}//document.onload=showindex();

	function showoverview()
	{
			var url="overview.php?sid="+Math.random();
			//alert(url);
			fetchdata(url,"contentbox");
			document.getElementById(current_link).style.backgroundImage="";
			current_link="homelink";
			revertbutton();
			
			//setTimeout("swapimg();",2000);
			//$("#contentbox").load(url);
	}//document.onload=showindex();


	function showinfra()
	{
			var url="infra.php?sid="+Math.random();
			//alert(url);
			fetchdata(url,"contentbox");
			document.getElementById(current_link).style.backgroundImage="";
			current_link="homelink";
			revertbutton();
			setTimeout("setlightbox();",1000);
			//setTimeout("swapimg();",2000);
			//$("#contentbox").load(url);
	}//document.onload=showindex();

	function setlightbox()
	{
		$("a[rel=group123]").fancybox({});
		//$("a.fancybox").attr('rel', 'gallery').fancybox();
			
	}


	function showadv()
	{
			var url="adv.php?sid="+Math.random();
			//alert(url);
			fetchdata(url,"contentbox");
			document.getElementById(current_link).style.backgroundImage="";
			current_link="homelink";
			revertbutton();
			
			//setTimeout("swapimg();",2000);
			//$("#contentbox").load(url);
	}//document.onload=showindex();



	function showcandidates()
	{
			var url="candidates.php?sid="+Math.random();
			fetchdata(url,"contentbox");
			
			current_link="candidlink";
			revertbutton();
			
			//$("#contentbox").load(url);
	}
	
		function overjob(obj)
		 {
			obj.style.backgroundColor="#DFF4FF";
			obj.style.color="#666666";
		 }
		 
		 function outjob(obj)
		 {
			obj.style.backgroundColor="";
			obj.style.color="#cccccc";
		 }
		
	///// clients page scritps 
	
		function showclients()
		{
			var url="client.php?sid="+Math.random();
			aaas="Engi";
			isfirst=true;
			//$("#contentbox").load(url,"","swapimg()");
	       //imgs[0]="client0.jpg";
 			fetchdata(url,"contentbox");
			current_link="clientlink";
			revertbutton();

			//setTimeout("swapimg();",2000);
			//alert("asdasd");
		
		}
		
		//// values scripts 
		
		function showvalues()
		{
			var url="values.php?sid="+Math.random();
			//$("#contentbox").load(url,"","swapimg()");
	       //imgs[0]="client0.jpg";
 			fetchdata(url,"contentbox");
			current_link="valueslink";
			revertbutton();

			//setTimeout("swapimg();",2000);
			//alert("asdasd");
		
		}		
		
		
		 var aaas="Engi";
		 var isfirst=true;
		 
		 function toggle(obj)
		 {
			if(isfirst)
			{
				$("#spacer4").slideUp();
				$("#spacer1").slideUp();
				$("#spacer2").slideUp();
				$("#spacer3").slideUp();
				isfirst=false;
			}
			
			$("#"+aaas).slideUp();
			aaas=obj;
			$("#"+aaas).slideDown();
			
		 }
	
	////////contact page script
	
			
	function contact()
	{
			var url="contact.php?sid="+Math.random();
			fetchdata(url,"contentbox");
			document.getElementById(current_link).style.backgroundImage="";
			current_link="contactlink";
			revertbutton();

			//$("#contentbox").load(url);
	}		
				
		
			function getRequestBody(oForm) 
			{
				var aParams = new Array();
				for (var i=0 ; i < oForm.elements.length; i++) 
				{
					var sParam = encodeURIComponent(oForm.elements[i].name);
					sParam += "=";
					sParam += encodeURIComponent(oForm.elements[i].value);
					aParams.push(sParam);
				}
				return aParams.join("&");
			}
			
			
			function sendRequest()
			{
				//alert("sending your message");
				var oForm = document.forms[0];
				var sBody = getRequestBody(oForm);
				var oXmlHttp = GetXmlHttpObject();
				oXmlHttp.open("post", oForm.action, true);
				oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				oXmlHttp.onreadystatechange=function f2()
				{
					if (oXmlHttp.readyState == 4) 
					{
						   document.getElementById("smilebox").innerHTML=oXmlHttp.responseText;
							//if(oForm.fname.value=="dataforom")
							{
							 //oForm.reset();
							 //document.getElementById("subbutt").value="Sent Sucessfully";
							 //document.getElementById("contactbox").style.display="none";
							 //document.getElementById("smilebox").style.display="block";
							// getobj('#updateform').slideUp('slow');
							 //showcurrupdates();
							 //document.getElementById("subbutt").disabled=false;
							 oXmlHttp=null;
							 return;
							}
				   }
				   else
				   {
					//document.getElementById("subbutt").style.backgroundImage="";
					document.getElementById("subbutt").value="Sending...";
					document.getElementById("subbutt").disabled=true;
				   }
				}
				oXmlHttp.send(sBody);
			}




			
			
			
		/////////team page script
	
	
		
		function mycarousel_initCallback(carousel)
		{
			// Disable autoscrolling if the user clicks the prev or next button.
			carousel.buttonNext.bind('click', function() {
				carousel.startAuto(0);
			});
		
			carousel.buttonPrev.bind('click', function() {
				carousel.startAuto(0);
			});
		
			// Pause autoscrolling if the user moves with the cursor over the clip.
			carousel.clip.hover(function() {
				carousel.stopAuto();
			}, function() {
				carousel.startAuto();
			});  
			
			jQuery('#mycarousel-next').bind('click', function() {
				carousel.next();
				return false;
			});
		
		
			jQuery('#next1').bind('click', function() {
				carousel.next();
				return false;
			});
		
			jQuery('#mycarousel-prev').bind('click', function() {
				carousel.prev();
				return false;
			});
		
			jQuery('#back1').bind('click', function() {
				carousel.prev();
				return false;
			});
		
		
		}
		
		
	   function team()
		{
			var url="team.php?sid="+Math.random();
			fetchdata(url,"contentbox");
			//$().load(url);
			current_link="homelink";
			revertbutton();
			setTimeout("startslider();",2000);
		}
 		
		function quality_policy()
		{
			var url="quality_policy.php?sid="+Math.random();
			fetchdata(url,"contentbox");
			//$().load(url);
			current_link="homelink";
			revertbutton();
			setTimeout("startslider();",2000);
		}		
		
	   function showservices()
		{
			var url="services.php?sid="+Math.random();
			//$("#contentbox").load(url);
			fetchdata(url,"contentbox");
			current_link="servicelink";
			revertbutton();
			//setTimeout("startservices();",1000);
		}		

		
		function startslider()
		{
			document.getElementById("mycarousel").style.display="block";
			
			jQuery('#mycarousel').jcarousel({
				auto: 0,
				wrap: 'last',
				start: 2,
				initCallback: mycarousel_initCallback
			});
		}


// methods calling block 


	   function methods()
		{
			var url="methods.php?sid="+Math.random();
			//$("#contentbox").load(url);
			fetchdata(url,"contentbox");
			current_link="methodslink";
			revertbutton();
			//setTimeout("startmetho();",1500);
		}


	   function showprocesses()
		{
			var url="process.php?sid="+Math.random();
			//$("#contentbox").load(url);
			fetchdata(url,"contentbox");
			current_link="methodslink";
			revertbutton();
			//setTimeout("startmetho();",1500);
			
		}

/*		function startmetho()
		{
				a=document.getElementById('li0');
				alert("a is in memory now");
		}
*/
// methods calling block 

	   function policies()
		{
			var url="policies1.php?sid="+Math.random();
			//$("#contentbox").load(url);
			fetchdata(url,"contentbox");
			current_link="policieslink";
			revertbutton();
			//setTimeout("startservices();",1000);
		}
		 
		 function metho(obj)
		 {
			if(isfirstmetho)
			{a=document.getElementById('li0');isfirstmetho=false;}
			
			a.style.display="none";
			a=document.getElementById(obj);
			//document.getElementById(obj).style.display="block";
			$("#"+obj).fadeIn();
		 }
 
 ///// APPLY FOR JOBS SCRIPTDS 
 
  var a="Engi";
 
/* function toggle(obj)
 {
 	
	$("#"+a).slideUp();
	a=obj;
	$("#"+a).slideDown();
	
 }*/
 
 function overjob(obj)
 {
 	obj.style.backgroundColor="#555555";
	obj.style.color="#666666";
 }
 
  function outjob(obj)
 {
 	obj.style.backgroundColor="";
	obj.style.color="#cccccc";
 }

 function applynow(ur)
 {
	//alert(ur);
	fetchdata(ur,"contentbox");
		current_link="candidlink";
		revertbutton();

//$("#loginbox").fadeIn("slow");

//$("#blocker").fadeIn("fast");

 }
function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.getElementById('et').value;
   if(reg.test(address) == false) {
      alert('Invalid Email Address');
      return false;
   }else{
	   return true;
	   }
} 

/*function notEmpty(obj){

	var myTextField1= document.getElementById('nt');
	if(myTextField1.value == ""||myTextField1.value==null)
	{
		alert("Please enter name ?");
		return false;
	}
		//javascript for mobile
	var myTextField5= document.getElementById('ct');
	if(myTextField5.value == ""||myTextField5.value==null)
	{
		alert("Please enter mobile number of 10 digit?");
		return false;
	}
	//javascript for email
	var myTextField4= document.getElementById('et');
	if(myTextField4.value == ""||myTextField4.value==null)
	{
		alert("Please enter your email");
		return false;
	}
	if(myTextField4.value != ''){
		validate(myTextField4.value);
 		}
	
    //javascript for qualification
	var myTextField = document.getElementById('qt');
 	if(myTextField.value == ""||myTextField.value==null)
	{
		alert("Please enter your qualification");
		return false;
	}

	
	//javascript for Total Work Experience 
	var myTextField2= document.getElementById('expt');
	if(myTextField2.value == ""||myTextField2.value==null)
	{
		alert("Please enter your Total Work Experience");
		return false;
	}
	//javascript for present company name
	var myTextField3= document.getElementById('comt');
	if(myTextField3.value == ""||myTextField3.value==null)
	{
		alert("Please enter Present Company name");
		return false;
	}
	//javascript for designation
	var myTextField6= document.getElementById('dest');
	if(myTextField6.value == ""||myTextField6.value==null)
	{
		alert("Please enter your designation");
		return false;
	}
	//javascript for function area
	var myTextField7= document.getElementById('farea');
	if(myTextField7.value == ""||myTextField7.value==null)
	{
		alert("Please select your function area");
		return false;
	}
	//javascript for industry type
	var myTextField8= document.getElementById('industry');
	if(myTextField8.value == ""||myTextField8.value==null)
	{
		alert("Please select any type of indutry");
		return false;
	}
	
	//javascript for present location
	var myTextField9= document.getElementById('loct');
	if(myTextField9.value == ""||myTextField9.value==null)
	{
		alert("Please enter present location");
		return false;
	}
	//javascript for uploading a resume
	 
	///////////////////for doc or pdf file////////
 
 				
}*/

function validatePhone(fld) {
    var error = "";
    var stripped = fld.replace(/[\(\)\.\-\ ]/g, '');    
        if (isNaN(parseInt(stripped))) {
        alert("The phone number contains illegal characters.");
		return false;
     } else if (!(stripped.length == 10)) {
       alert("The phone number is the wrong length.");
	   return false;
     }else{
		 return true;
		 }
     
}

//////////////function for apply using post method resume start here ///////////////////////////////////

 var http_request = false;
   function makePOSTRequest(url, parameters) {
       http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
           document.getElementById('contentbox').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function getApply(obj) {
     var nt =document.getElementById("nt").value;
	if(nt == ''){
		alert("Please enter name ?");
		return false;
		}
	var ct =document.getElementById("ct").value;
	if(ct == ''){
		alert("Please enter mobile number of 10 digit?");
		return false;
		}
	if(ct !=''){
	var chknum = validatePhone(ct);
		if(chknum == false){
 		return false;
		} 
		}
    var et =document.getElementById("et").value;
	if(et == ''){
		alert('please enter email-id');
		return false;
		}
	if(et != ''){
		var chkmail = validate(et);
		if(chkmail == false){
 		return false;
 		}
	}
	var qt =document.getElementById("qt").value;
/*	if(qt == ''){
		alert("Please enter your qualification");
		return false;
		}*/
	var expt =document.getElementById("expt").value;
	var expt = expt +"."+document.getElementById("expm").value;
	/*if(expt == ''){
		alert("Please enter your Total Work Experience");
		return false;
		}*/
	var comt =document.getElementById("comt").value;
	/*if(comt == ''){
		alert('please enter present company');
		return false;
		}*/
	var dest =document.getElementById("dest").value;
	/*if(dest == ''){
		alert("Please enter your designation");
		return false;
		}*/
	var farea =document.getElementById("farea").value;
	/*if(farea == '' || farea == -1 ){
		alert("Please select your function area");
		return false;
		}*/
   var industry =document.getElementById("industry").value;
	/*if(industry == '' || industry == -1 ){
		alert("Please select any type of indutry");
		return false;
		}*/
	 var loct =document.getElementById("loct").value;
	/*	if(loct == ''){
		alert("Please enter present location");
		return false;
		}*/
	 var resume =document.getElementById("file_name").value;
		/*if(resume == ''){
		alert("Please uplode your resume");
		return false;
		}*/
 	var jobId =document.getElementById("jobId").value;
	var filename =document.getElementById("file_name").value;
	document.getElementById("applyform").style.display ='none';
     var poststr ="name="+nt+"&mobNum="+ct
			+"&email="+et+"&quali="+qt+"&exp="+expt+"&pcomp="+comt+"&desi="+dest+"&farea="+farea+"&inds="+industry+"&loc="+loct+"&filename="+filename+"&jobId="+jobId;
	//alert(poststr);
makePOSTRequest('submitresume.php', poststr);
 
   }   
 //////////////function for apply using post method resume end here /////////////////////////////////// 
