
/** functions used for popup div - 'tempDiv' **/

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}	
	return [curleft,curtop];	
}

function openPopup(span,num) {
    var obj = document.getElementById('tempDiv');	
	if (obj.style.display == '' || obj.style.display == 'none') {	    	        
        var arr = findPos(span);
		obj.style.left = arr[0] -300+ 'px';
	//	obj.style.top = arr[1] + 17 + 'px';		
		obj.style.top = arr[1]-(num*26) + 'px'; 
	//	window.scrollTo(0,arr[1]+50);				
	    obj.style.display = 'block';	    
		tempData(num);		
	} 
}

function closePopup() {
    obj = document.getElementById('tempDiv');
	obj.style.display = 'none';		
	if((typeof(temp)!='undefined') && (temp != null))updateDateField(temp);	
}
/* added by maya for closing div on click outside******************************************/

//var	bodyClickFlag = false;
var	calFlag = false;


function bodyClick(){ 	    
	var dateObj	, dateObjStyle;
	if(document.getElementById('datepicker')) {		
	dateObj = document.getElementById('datepicker');
	dateObjStyle = dateObj.style;	   
//	alert(calFlag);
        if (!(BrowserDetect.browser=="Firefox") ){
	   if(dateObjStyle.display  == 'block' && dateObjStyle.visibility  == 'visible' && calFlag== false ) 	   		
	   		updateDateField();	
	}
	}
	
	//bodyClickFlag = false;
	calFlag = false;	
}


/**** other common validations **/
	
/* ---- To check for data entry in textbox ----- */
function isJustData(formField, event, type) { 
	//alert(formField);
	var alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var space=" ";
	var num="0123456789";
	if (type =="alpha") char_set=alpha+space;	
	if (type =="num") char_set=num;
	if (type =="alphanum") char_set=alpha+num+space;
	if (type =="email") char_set=alpha+num+"@._";
	if ((type=="tel") || (type=="fax"))char_set=num+"-"+space;
	//if (type=="loginid") char_set=num+"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	if (type=="loginid") char_set=alpha+num;
	if (type=="password") char_set=alpha+num+"@._-#$%&+=|";
	
	var key, keyChar;
	//var bool=false;
	//check how browser treats key events
	if(window.event){
		key = window.event.keyCode;
		}
	else if(event){ 
				key = event.which;
			}
//			else bool=true;					
			
	keyChar = String.fromCharCode(key);
	if((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)  ) {
	//	bool=true; 
		return true;
	}
	//make sure the key pressed was not a special key 
	if( (char_set).indexOf(keyChar) > -1){	
			return true;
		}
	else 	return false;  		
	
	//return bool;  
}	

// Function for validation of all numeric fields
function isJustDecimal(formField,event) {
	//regular expressions
	var reValidChars,ss=false;
	var reKeyboardChars = /[\x00\x08\x0D]/;
	//check how browser treats key events
	if(window.event){  key = window.event.keyCode;
					}
	else if(event){  key = event.which;
					}
	else bool=true;		
		
	keyChar = String.fromCharCode(key);	 	
	// check presence of '.' in entered value
	for(u=0;u<formField.value.length;u++) {
		if(".".indexOf(formField.value.charAt(u))!=-1) {
			ss=true;
		}
	} 
	if(ss==false) {	 reValidChars =/^[0-9\.]$/   // if '.' not typed
					}
	else {
		reValidChars = /^[0-9]$/ // if '.' already typed		
		s=formField.value.split(".");		
		if (s[1].length >= 2 || ( !reValidChars.test(keyChar) && !reKeyboardChars.test(keyChar))) return false;
		else return true;
		
	}
	
	if (!reValidChars.test(keyChar) && !reKeyboardChars.test(keyChar)) {
		//alert("Enter numerals only in this field.");
		return false;
	}
	return true;   					  
}	


/* ---- To check for entry of singlequotes in textbox ----- */
function isQuotes(formField, event)
 { 	singleQuote=!((window.event ? event.keyCode : event.which) == 39);	
	doubleQuote=!((window.event ? event.keyCode : event.which) == 34);		
	return (singleQuote && doubleQuote)
  }	


/* ---- To check for entry of singlequotes, double quotes and comma in textbox ----- */
function isComma_Quotes(formField, event)
 { 	singleQuote=!((window.event ? event.keyCode : event.which) == 39);
	doubleQuote=!((window.event ? event.keyCode : event.which) == 34);
	commaQuote=!((window.event ? event.keyCode : event.which) == 44);
	return (singleQuote && doubleQuote && commaQuote)
  }	


/* ---- To check if date entered is valid ----- */
function isValidDate(day,month,year){
	if (day=='' || month=='' || month=='0' || year=='' || year.length<4){
		return false;
	}
	else{
		//  create a date object
   		source_date = new Date(year,month-1,day);
   		//alert(source_date);
   		if(year != source_date.getFullYear())  {		     
		      return false;
		   }
		 if(month-1 != source_date.getMonth()) {
		      return false;
		   }
		 if(day != source_date.getDate())	{		   
		      return false;
		   }
   		return true;
	}
}


/* ---- To check if first date entry less than or equals to second date entry ----- */
function isFirstDateLess(day1,month1,year1,day2,month2,year2){
	if(isValidDate(day1,month1,year1) && isValidDate(day2,month2,year2)){
		var date1=new Date(year1,month1-1,day1); 	
		var date2=new Date(year2,month2-1,day2); 	
		if (date1<=date2)		{ 
			return true;	
		}
		else return false;			
	}else return false;	
}

/* ---- To check if first date entry less than second date entry (no equal condition)----- */
function isFirstDateLessOnly(day1,month1,year1,day2,month2,year2){
	if(isValidDate(day1,month1,year1) && isValidDate(day2,month2,year2)){
		var date1=new Date(year1,month1-1,day1); 	
		var date2=new Date(year2,month2-1,day2); 	
		if (date1<date2)		{ 
			return true;	
		}
		else return false;			
	}else return false;	
}

/* ---- Remove whitespace from the right & left sides of the values ----- */	
function trim(sString) 
{
  	while (sString.substring(0,1) == ' ')
	{ sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{ sString = sString.substring(0,sString.length-1);
	}
	return sString;
}



// To store type of valid image file extensions
fileTypes= ['gif', 'jpg', 'png', 'jpeg'];
// Function to check if uploaded file is image file
function TestFileType(fileName) 
{		
	dots = fileName.split(".");
	//get the part AFTER the LAST period.		
	if ((dots.length-1)>0)
	{	fileType = dots[dots.length-1];	
	//	alert(fileType);
		//alert("file :"+fileTypes.join(".").indexOf(fileType));
		if (fileTypes.join(".").indexOf(fileType) == -1)
		{	return false;
		}
		else return true; 
	}
	else return false; 
}


/* ---- To Select/Deselect the checkboxes ----- */	
function selectDeselectAll(obj){
//alert(obj.checked);	
		element_num=document.forms[0].length;
		if (obj.checked){			
			for (i=0;i<element_num ;i++) {
				fieldElem=document.forms[0].elements[i];	
				fieldType = document.forms[0].elements[i].type;			
				if (fieldType=="checkbox" && fieldElem.disabled!=true){	
					//	alert(fieldElem.disabled);			
					fieldElem.checked=true;
				}
			}
		}else{
			for (i=0;i<element_num ;i++) 	{
				fieldElem=document.forms[0].elements[i];	
				fieldType = document.forms[0].elements[i].type;	
				if (fieldType=="checkbox"){
					fieldElem.checked=false;
				}
			}
		}
	
}

function checkSelect(obj,mainobj){
//	alert(mainobj.name);
	//alert(obj.checked);
	setcheck=true
	if (!obj.checked){
		if(mainobj.checked)	mainobj.checked=false
	}else{
			element_num=document.forms[0].length;	
	 		for (i=0;i<element_num ;i++) {
				fieldElem=document.forms[0].elements[i];	
				fieldType = document.forms[0].elements[i].type;			
				if (fieldType=="checkbox" && !fieldElem.checked && fieldElem.name!=mainobj.name){	
					setcheck=false				
				}
			}
		//	alert(setcheck);
			if(setcheck) mainobj.checked=true
		}
}
function getIEVersion(){
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 		return new Number(RegExp.$1) // capture x.x portion and store as a number
	}
}
function renderErrorMsg(actionError){
	text=actionError.split("</span>");
	b=text[0].split(">");						
	return b[b.length-1];
}

/************ Added by sahoo on 17/04/2009 - Email configuration details ****************/ 
function displayAccDet(){
	//alert("account display");
	document.getElementById("accdet_err").innerHTML = "";
	document.getElementById("error").innerHTML = "";
	document.forms[0].myAcc_chk[0].checked = true;
	document.forms[0].account_Name.readOnly = true;
	document.forms[0].password.readOnly = true;
	new Ajax.Request('accDet!load.action',{
	onFailure: function(){ alert('Something went wrong...') },
	onSuccess: function(transport){ 
		if(transport.responseText=="Time_out"){
	   				//document.location.href ="<%=request.getContextPath()%>/loginForward.jsp?ajaxtout=1" 
	   				openWindow(contextPath+"/loginForward.jsp?ajaxtout=1","","",0);   
	   			//	alert("Time_out");  
	   			}else{
		      		response = transport.responseText || "no response text";
		      		//alert(response);
		      		var acc_det = response.evalJSON(true);
						
					document.forms[0].account_Name.value = defAccName = acc_det.account_Name;
					document.forms[0].domainName.value = acc_det.domainName;
					document.forms[0].password.value = defPassword = acc_det.password;					
					displayDiv('accountDetails',true);
				}
		}
	});
}
function validateAccDetail(){	
	var fld1 = document.forms[0].account_Name.value = trim(document.forms[0].account_Name.value);
	var fld2 = document.forms[0].domainName.value;
	var fld3 = document.forms[0].password.value = trim(document.forms[0].password.value);
	if(fld2 == "") {
		document.getElementById("accdet_err").innerHTML = "Email config is not set";
		return false;
	}
	if(fld1 =="" || fld3 ==""){
		document.getElementById("accdet_err").innerHTML = "Enter Mandatory Fields";
		return false;
	}
	if(!isValidEmail(fld1+fld2)) {
		document.getElementById("accdet_err").innerHTML = "E-mail ID not valid for From Email";
		return false;	
	}	
//	closePopup1('accountDetails');
	hideDiv('accountDetails');
	//alert(document.forms[0].name);
	if(document.forms[0].name =="fm"){
		document.forms[0].action="mailing.action";
		document.forms[0].submit();
	}else if(document.forms[0].name =="registerUser"){
		document.registerUser.action="userdetact!add.action";
		document.registerUser.submit();
	}else if(document.forms[0].name =="changePassword"){
		document.changePassword.action="chgpwd.action";
		document.changePassword.submit();
	}else if(document.forms[0].name =="userActivation"){
		document.userActivation.action="activate.action";
		document.userActivation.submit();
	}else {
		checUserkParam();
	}
	return true;
}

function enableAccDet(){
	if(document.forms[0].myAcc_chk[1].checked) {					
		document.forms[0].account_Name.readOnly = false;
		document.forms[0].password.readOnly = false;
		document.forms[0].account_Name.value = "";
		document.forms[0].password.value = "";		
	}else{
		document.forms[0].account_Name.value = defAccName;
		document.forms[0].password.value = defPassword;		
		document.forms[0].account_Name.readOnly = true;
		document.forms[0].password.readOnly = true;
	}
}

function dynamicDiv(paramArr){ // added by sahoo
	document.getElementById("param_error").innerHTML = "";
	var newtr;
	var newtd;
	var newtd1;
	var trlength;
	var tbody = document.getElementById("tbody");
	var trlen = tbody.getElementsByTagName('tr').length;
	if(trlen == 0) {
		var div= document.getElementById('tempDiv');          
		displayDiv('tempDiv',true);
		for(var i=0;i<paramArr.length;i++){	
			trlength = trlen+1;
			//alert(trlength);
			newtr = document.createElement('tr');
			newtr.className="alt_raw2";
			newtr.setAttribute('id','row'+trlength);
			newtd = document.createElement('td');
			newtd.setAttribute('height',30);
			newtd.style.paddingLeft = "2px";
			newtd.style.color = "red";
			newtd.innerHTML = paramArr[i];
			newtd1 = document.createElement('td');
			newtd1.setAttribute('height',30);
			newtd1.style.paddingLeft ="6px";
			newtd1.innerHTML ="<input type='text' class='textbox_01'  name='"+paramArr[i]+"' id='"+paramArr[i]+"'/>";
			if(paramArr[i] == "$interviewDate") {
				newtd1.innerHTML = ":<input type='text' class='textbox_01'  readonly='true' name='"+paramArr[i]+"' id='"+paramArr[i]+"'/>"+"<img src='homepage_images/cal.gif' alt='Calendar' width='22' height='19' align='absbottom'"+
				" onclick='displayDatePicker(&quot;$interviewDate&quot;, false, &quot;dmy&quot;, &quot;/&quot;);calFlag=true;' onmouseover='this.style.cursor=&quot;hand&quot;'/>";
			}

			newtr.appendChild(newtd);
			newtr.appendChild(newtd1);
			tbody.appendChild(newtr);
		}
		
		trlength = trlen+1;
			//alert(trlength);
			newtr = document.createElement('tr');
			newtr.className="alt_raw2";
			newtr.setAttribute('id','row'+trlength);
			newtd = document.createElement('td');
			newtd.setAttribute('height',30);			
			newtd.setAttribute('width',130);
			newtd.setAttribute('align','right');
			newtd.innerHTML = '<input type="button" value="click to send mail" class="button_01" onclick="doSendMail()"/>'
			newtr.appendChild(newtd);
			
			// added on 12-jun-2009 by juliet
			newtd1 = document.createElement('td');
			newtd1.setAttribute('height',30);
			newtd1.setAttribute('width',180);
			newtd1.setAttribute('align','right');
			newtd1.style.paddingLeft ="0px";
			newtd1.innerHTML ='<input type="button" value="Cancel" class="button_01" onclick="hideDiv(\'tempDiv\')"/>';
			newtr.appendChild(newtd1);
				
			tbody.appendChild(newtr);		
	}
	else {     
		 while (tbody.firstChild) {	 
			tbody.removeChild(tbody.firstChild);
	     }
		 dynamicDiv(paramArr);
		}
}

function closePopup1(id) {
	//alert(id);
    obj = document.getElementById(id);
	obj.style.display = 'none';	
	
}

//for limiting the text area length
 function textLimit(field, maxlen) {
	if (field.value.length > maxlen)
		field.value = field.value.substring(0, maxlen);
	} 



/************************************************/


/************* Main Screen & Popup functionality - Start ************************/
 var childWin = null;// global variable for child window
// to check for existing popups when opening another
// if   popupName!="" , flg is 1 for reloading the popup (processinglist/filterlist), or flg is 0 not for reload
// else , flg is 1 when conrifmation msg is required to close popup, 
//		or flg is 0 when closing all popup without confirmation msg at timeout or logout 
function openWindow(popupUrl,popupName,popupOption,flg){
	//alert(popupUrl);
 	//popfilter="";
	var openChild = false;
	var openMain = false;
	//alert(openChild);
	if (popupName!=""){ // for poups
		if (childWin == null || childWin.closed){ 
			// if no popup is open 
			openChild = true;
		} 
		else { 
			// if same popup is open 
			if (childWin.name==popupName) {
				if (flg==1) {	
					childWin.location.reload();		
					childWin.focus();		
					//return;	
				}
				childWin.close();	
				openChild = true;
			}
			else { // if different popup is open 
				if (confirm("This will close other opened pop-ups. Is it Ok?")) {
					childWin.close();	
					openChild = true;
				}else {
					childWin.focus();				
				}
			}
		}	
		//alert(openChild);
		if(openChild){								
				childWin=window.open(popupUrl,popupName,popupOption);
				// explicity used only for search screen
				if (popupName=="filterList" || popupName=="CandidateReg" || popupName=="CandidateUpdate" 
					|| popupName=="CompanyUserReg" || popupName=="CorporateUserReg" || popupName=="CompanyUserEdit"
					|| popupName=="CorporateUserEdit" || popupName=="UserPassword" || popupName=="UserActivation") {
					popfilter=popupName;
					checkFilterPopUp(); //to check if filter screen has been openned
				}
		}
	}
	if (popupName==""){ // for main screens			
		if(childWin == null || childWin.closed){
			openMain = true;
		}else{
			if (flg==1) { // ask confimation msg
				if (confirm("Before leaving the page all the popups will be closed. Is it ok?")){
					childWin.close();
					openMain = true;
				}else childWin.focus();					
			}else { // no confimation msg at logout or timeout
				childWin.close();	
				openMain = true;
			}	
		}
		if(openMain){
				window.location.href=popupUrl;	
		}
	} 	
}


/************* Main Screen & Popup functionality - End ************************/
	
	
	
/******************Progress Bar for Canddiate Profile - Start********************************/

var grade = new Array();
var barimage= new Array();
var len;

function startProgressBar(profile) {
	len=document.getElementById("bar"+profile+"num").value;
	for (i=0;i<len;i++){
		//alert(i);
		rate=document.getElementById("rate"+profile+i).value;
		//alert(rate);
		srcValue=document.getElementById("color"+rate).src;
		//alert(srcValue);
		document.getElementById("barColor"+profile+i).style.background='url(homepage_images'+srcValue.substring(srcValue.lastIndexOf('/'),srcValue.length)+')';
	}

}

function reset(type,no) {	
		str=no+type;
	//	alert(i+"          "+document.getElementById("mask"+(i)+str));
		document.getElementById("mask"+str).style.left = "0px";
	//alert(document.getElementById("mContainer"+(i+1)).offsetWidth);
		document.getElementById("mask"+str).style.width = document.getElementById("mContainer"+str).offsetWidth + "px";
		document.getElementById("progressIndicator"+str).style.zIndex  = 10;
		document.getElementById("mask"+str).style.display = "block";
	//document.getElementById("progressIndicator").innerHTML = "0%";
}

function doProgress(type,no) {
	str=no+type;
	document.getElementById("gradient"+str).style.background = barimage[no];
	//document.getElementById("mask"+str).style.zIndex=10;
	document.getElementById("mask"+str).style.left = ((grade[no]*2)+6)+ "px";
	//alert("mask left ..."+document.getElementById("mask"+str).style.left);
 // 6 for the sides (6*2)+24 = 36
 	wid=document.getElementById("mask"+str).offsetWidth-((grade[no]*2)+12);
 	if(wid<0) wid=0;
 	//alert("mask width ..."+wid);
	document.getElementById("mask"+str).style.width=wid+"px";
}
/******************Progress Bar for Canddiate Profile - End ********************************/

/****************** Div display  - Start ********************************/
var lockWin;
var g_PopupIFrameOverLay;
function displayDiv(divid,overlayOption,fixedOption){	

	/* iframe to blackout the main body page */
	if (overlayOption){
		var wdth=document.body.offsetWidth-2;
		var hght=document.body.offsetHeight+15;
	  	var iFrameOverLay = document.createElement("IFRAME");
		iFrameOverLay.setAttribute("src", "blank.html");	
		iFrameOverLay.style.width =wdth+'px';
		iFrameOverLay.style.height =hght+'px';
		iFrameOverLay.className="overlayBG";
		document.body.appendChild(iFrameOverLay);		
	 	g_PopupIFrameOverLay=iFrameOverLay;		 	
	 	var x = (document.body.offsetWidth / 2) - (document.getElementById(divid).offsetWidth / 2);	 
 		document.getElementById(divid).style.top = '20px';
  		document.getElementById(divid).style.left = x+'px';	 	 
  		if (!fixedOption) {
  			if (getIEVersion()==6) lockWin=setInterval("window.scrollTo(0,0)",10);  		
			else document.getElementById(divid).style.position="fixed";
		}
	}
	document.getElementById(divid).style.visibility = 'visible';		
	document.getElementById(divid).style.zIndex =15;

}

function hideDiv(divid){	
	if(lockWin) clearInterval(lockWin);
//	alert(divid);
	if(g_PopupIFrameOverLay){
		document.body.removeChild(g_PopupIFrameOverLay);
		g_PopupIFrameOverLay=null;
	}
	document.getElementById(divid).style.visibility = 'hidden';	
}

/****************** Div display  - END ********************************/


//for checking the length of text area
function chkLength(field,len){
  var fieldval = field.value;
  len = len-1;
  if(fieldval.length>=len){
  	field.value = fieldval.substring(0,len);
  }
}


/************* Timer for test - start *************************/
	
var timer=null;

 function pad(number) //pads the mins/secs with a 0 if its less than 10
 {
    if(number<10)
       number=0+""+number;
    return number;
 }

function formatDate(mnth,dt,yr,hr,mn,sec){
	dtf=(mnth)+"/"+dt+"/"+yr;
	//dtf=yr+"-"+pad(mnth)+"-"+pad(dt);
	dtf=dtf+" "+pad(hr)+":"+pad(mn)+":"+pad(sec);
	return dtf;
}

function getStartTime(){
	nowTime = new Date();
	var strTrime=formatDate((nowTime.getMonth()+1),nowTime.getDate(),nowTime.getFullYear(),nowTime.getHours(),nowTime.getMinutes(),nowTime.getSeconds());
	//alert(month+"/"+day+"/"+year+" "+hours+":"+minutes+":"+secs+" "+str);
	return strTrime;
}

function setTestTimer(path){
	nowTime = new Date();	
	/*
	if((document.getElementById('qno').value)==1){
		strTrime=formatDate((nowTime.getMonth()+1),nowTime.getDate(),nowTime.getFullYear(),nowTime.getHours(),nowTime.getMinutes(),nowTime.getSeconds());
		//alert(month+"/"+day+"/"+year+" "+hours+":"+minutes+":"+secs+" "+str);
		document.getElementById("startTime").value=strTrime;
	}*/
	contentarr=findPos(document.getElementById('quest_top'));	
	document.getElementById("timeusedimg").style.left=contentarr[0]+440+"px";
	setDuration(path);

}


function setDuration(path){
	var timespent;	
	nowTime = new Date();	
	timespent=nowTime.getTime()-Date.parse(document.getElementById("startTime").value);
	var sec = Math.floor(timespent/1000);
	timespent = timespent % 1000
	var min = Math.floor(sec/60)
	sec = sec % 60
	var hr = Math.floor(min/60)
	min = min % 60
	timerdisplay=pad(hr)+":"+pad(min)+":"+pad(sec);
	imgDisplay="";

	for (i=0;i<timerdisplay.length;i++){
		if (timerdisplay.charAt(i)!=":")
			imgDisplay=imgDisplay+"<img src='"+path+"/homepage_images/t"+timerdisplay.charAt(i)+".gif'/>";
		else 
			imgDisplay=imgDisplay+"<img src='"+path+"/homepage_images/tcolon.gif'/>";
	}
	document.getElementById("duration").value=timerdisplay;
	document.getElementById("timeusedimg").innerHTML=imgDisplay;
	timer=setTimeout("setDuration('"+path+"')",1000);
}


var actualTime;
function setTechTestTimer(path,dur){
//	alert("setTechTestTimer");
	nowTime = new Date();	
	/*
	if((document.getElementById('qno').value)==1){
		strTrime=formatDate((nowTime.getMonth()+1),nowTime.getDate(),nowTime.getFullYear(),nowTime.getHours(),nowTime.getMinutes(),nowTime.getSeconds());
	//	alert(month+"/"+day+"/"+year+" "+hours+":"+minutes+":"+secs+" "+str);
		document.getElementById("startTime").value=strTrime;
	}*/
	
	actualTime = new Date();
	var spdur;
	if((document.getElementById('qno').value)==1){
		spdur=dur.split(':');	
		actualTime = new Date();// taken from db	
		actualTime.setMinutes ( actualTime.getMinutes() + parseFloat(spdur[1]) + (parseFloat(spdur[0])*60) );  		
	}
	else {		
		spdur=document.getElementById("duration").value.split(':');
		actualTime.setSeconds(actualTime.getSeconds() + parseFloat(spdur[2]));
		actualTime.setMinutes ( actualTime.getMinutes() + parseFloat(spdur[1]) + (parseFloat(spdur[0])*60) );  
	}
	
	contentarr=findPos(document.getElementById('quest_top'));	
	document.getElementById("timeusedimg").style.left=contentarr[0]+440+"px";	
	
	setTechDuration(path);
}


function setTechDuration(path){

	nowTime = new Date();	
	var timespent=actualTime-nowTime;	
	if(timespent>0) {
		var sec = Math.floor(timespent/1000);
		timespent = timespent % 1000
		var min = Math.floor(sec/60)
		sec = sec % 60
		var hr = Math.floor(min/60)
		min = min % 60
		timerdisplay=pad(hr)+":"+pad(min)+":"+pad(sec);
		imgDisplay="";

		for (i=0;i<timerdisplay.length;i++){
			if (timerdisplay.charAt(i)!=":")
				imgDisplay=imgDisplay+"<img src='"+path+"/homepage_images/t"+timerdisplay.charAt(i)+".gif'/>";
			else 
				imgDisplay=imgDisplay+"<img src='"+path+"/homepage_images/tcolon.gif'/>";
		}
		document.getElementById("duration").value=timerdisplay;
		document.getElementById("timeusedimg").innerHTML=imgDisplay;
		timer=setTimeout("setTechDuration('"+path+"')",1000);
	}else {
		alert("Sorry! Timeout. You will be logged out of the system.");
		document.getElementById("quitflag").value='4';
		document.forms[0].action = "commontestQuit.action";
		document.forms[0].submit();
	}
}
/********************************************added by maya for changing images on mouseover***/
function changeImage(obj){
	var child =obj.childNodes[0];
	if(child.nodeName == 'IMG')	{		
	   var orgfil = child.src.substring( child.src.lastIndexOf("."));
	   var modtype = "1"+orgfil;
	   child.src =child.src.replace(orgfil,modtype);
	   //alert(filtype+"    "+filtype1+"    "+child.src);
	}
}
function originalImage(obj){
	var child =obj.childNodes[0];
	if(child.nodeName == 'IMG'){
	   var orgfil = child.src.substring( child.src.lastIndexOf("1."));
	   var modtype =orgfil.replace("1.",".");	  
	   child.src =child.src.replace(orgfil,modtype);
	}
}
function chg(path,obj,img){	
	obj.style.backgroundImage="url("+path+"/homepage_images/"+img+")";
	obj.style.color='#FF4E5C';
}

function unchg(path,obj,img){   
	obj.style.backgroundImage="url("+path+"/homepage_images/"+img+")";
	obj.style.color='#577184';
}

function onHover(obj){
	var img = obj.getElementsByTagName('img')[0].src;
	var orgfil = img.substring( img.lastIndexOf("."));
	var modtype = "1"+orgfil;	
	obj.getElementsByTagName('img')[0].src= img.replace(orgfil,modtype);	
	obj.getElementsByTagName('span')[0].style.color='#000000';
	var r =(BrowserDetect.browser=="Explorer" )?0:1;
	obj.childNodes[r].style.backgroundColor ='#E2CFCF'// '#C1C6DF';	
}

function onHoverout(obj){
	var img = obj.getElementsByTagName('img')[0].src;
	var orgfil = img.substring( img.lastIndexOf("1."));
	var modtype =orgfil.replace("1.",".")
    obj.getElementsByTagName('img')[0].src = img.replace(orgfil,modtype);	
	obj.getElementsByTagName('span')[0].style.fontWeight='bold';
	obj.getElementsByTagName('span')[0].style.color='#407d9e';
	var r =(BrowserDetect.browser=="Explorer" )?0:1;
	obj.childNodes[r].style.backgroundColor = '#F9F8F7';	
}
/***added by may aon 24-sept-2009
start: code for fading effect in actions div... taken from http://www.switchonthecode.com/tutorials/javascript-tutorial-simple-fade-animation **/
var TimeToFade = 1000.0;
function animateFade(lastTick, eid)
{ 
  //alert(typeof(lastTick))  ;
  //var element = new Object(ele);
  //alert(element.id);
  var curTick = new Date().getTime();  
  var elapsedTicks = curTick - lastTick; 
  if(element.FadeTimeLeft <= elapsedTicks) {    
    element.style.filter = 'alpha(opacity = '+ (100)+')';   
    return;
  } 
  element.FadeTimeLeft -= elapsedTicks;  
  var newOpVal = element.FadeTimeLeft/TimeToFade;  
  newOpVal = 1 - newOpVal;
  element.style.opacity = newOpVal;  
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')'; 
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}
/*****End: codes for fading*********/


/*********** javascript for menu display in site - maya  - start ***************/
// JavaScript Document
//Drop Down Tabs Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)
//http://www.dynamicdrive.com/dynamicindex1/droptabmenu.htm
//Created: May 16th, 07'

var tabdropdown={
	disappeardelay: 100, //set delay in miliseconds before menu disappears onmouseout
	disablemenuclick: false, //when user clicks on a menu item with a drop down menu, disable menu item's link?	
	TimeToFade:1000,

	//No need to edit beyond here////////////////////////
	dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, previousmenuitem:null,

	getposOffset:function(what, offsettype){		
		var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
		var parentEl=what.offsetParent;			
			while (parentEl!=null){
				totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;				
				parentEl=parentEl.offsetParent;
			}
		return totaloffset;
	},

	showhide:function(obj, e, obj2){ 
		if (this.ie || this.firefox)
			this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
		if (e.type=="click" && obj.style.visibility==hidden || e.type=="mouseover"){
			obj2.style.color="#a8f5ff";
			obj.style.visibility="visible";
			obj.style.filter = 'alpha(opacity = ' + (100) + ')'; /*for ie*/
	        obj.style.opacity = 1;  /*for non-ie browser*/
	       // obj.FadeTimeLeft = tabdropdown.TimeToFade;			
		//	setTimeout("tabdropdown.animateFade(" + new Date().getTime() + ",'" + obj.id + "')", 33);
				
			}
		else if (e.type=="click")
			obj.visibility="hidden";
	},
	
	dropit:function(obj, e, dropmenuID){	/*here obj refers to main menu items*/
		if (this.dropmenuobj!=null){ //hide previous menu	
			this.dropmenuobj.style.visibility="hidden" //hide menu				
			this.previousmenuitem.style.color="#ffffff";
		}		
		this.clearhidemenu()
		if (this.ie||this.firefox){
			obj.onmouseout=function(){tabdropdown.delayhidemenu(obj)}
			obj.onclick=function(){return !tabdropdown.disablemenuclick} //disable main menu item link onclick?
			this.dropmenuobj=document.getElementById(dropmenuID)			
			this.dropmenuobj.onmouseover=function(){tabdropdown.clearhidemenu()}
			this.dropmenuobj.onmouseout=function(e){tabdropdown.dynamichide(e, obj)}
			this.dropmenuobj.onclick=function(){tabdropdown.delayhidemenu(obj)}			
			this.showhide(this.dropmenuobj, e, obj)
			this.dropmenuobj.x=this.getposOffset(obj, "left")			
			this.dropmenuobj.y=this.getposOffset(obj, "top")
			this.dropmenuobj.style.left=this.dropmenuobj.x-2+"px";	
			this.dropmenuobj.style.top=this.dropmenuobj.y+obj.offsetHeight+8+"px";
			this.previousmenuitem=obj //remember main menu item mouse moved out from (and into current menu item)
		}
	},

	contains_firefox:function(a, b) {		 
		while (b.parentNode){		
		if ((b = b.parentNode) == a)
			return true;
		return false;}
	},

	dynamichide:function(e, obj2){ //obj2 refers to tab menu item mouse is currently over	   
		var evtobj=window.event? window.event : e
		if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
			this.delayhidemenu(obj2)
		else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget)){			
			this.delayhidemenu(obj2)}
	},

	delayhidemenu:function(obj2){		    
		this.delayhide=setTimeout(function(){obj2.style.color="#ffffff";tabdropdown.dropmenuobj.style.visibility='hidden';},this.disappeardelay) //hide menu
	},

	clearhidemenu:function(){	
		if (this.delayhide!="undefined")
			clearTimeout(this.delayhide)
	},	
	
	init:function(menuid, dselected){		
		var menuitems=document.getElementById(menuid).getElementsByTagName("a")		
		for (var i=0; i<menuitems.length; i++){
			if (menuitems[i].getAttribute("rel")){
				var relvalue=menuitems[i].getAttribute("rel")					
				document.getElementById(relvalue).firstlink=document.getElementById(relvalue).getElementsByTagName("a")[0]
				menuitems[i].onmouseover=function(e){					
					var event=typeof e!="undefined"? e : window.event					
					tabdropdown.dropit(this, event, this.getAttribute("rel"))
				}
			}
		}
	},

    animateFade:function(lastTick, eid)/*this fn is for fading effect while displaying menuitems*/
		{ 		  
		  var element = document.getElementById(eid);
		  var curTick = new Date().getTime();  
		  var elapsedTicks = curTick - lastTick; 
		  if(element.FadeTimeLeft <= elapsedTicks) {    
			element.style.filter = 'alpha(opacity = '+ (100)+')';   
			return;
		  } 		 
		  element.FadeTimeLeft -= elapsedTicks;  
		  var newOpVal = element.FadeTimeLeft/(tabdropdown.TimeToFade);  
		  newOpVal = 1 - newOpVal;
		  element.style.opacity = newOpVal; 		  
		  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')'; 
		  setTimeout("tabdropdown.animateFade(" + curTick + ",'" + eid + "')", 33);
		}	
}

/*********** javascript for menu display in site - maya  - end ***************/
	
/***  script for browser detection - start *********************/
	
	var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
if (!((BrowserDetect.browser=="Explorer" ) && (BrowserDetect.version==6 || BrowserDetect.version==7))) {
	//alert("This site is best viewed in IE 6/7");
}
/******* script for browser detection - end *********************/
/******* script for right click - start *********************/
document.onselectstart = function () { return false; } // ie

document.oncontextmenu=new Function("return false");
function right(e) {	
  if ((BrowserDetect.browser=="Firefox" ||BrowserDetect.browser=="Chrome" ) && (e.which == 3)) {   
    return false;
  }
  else if (BrowserDetect.browser=="Explorer" && (event.button == 2 )) {    
    return false;
  }

  return true;
}

if (document.layers) window.captureEvents(Event.MOUSEDOWN);
document.onmousedown=right;

/******* script for right click - end *********************/
	
/*** common code to load country, state, city ****/
function getCombo(field1,field2,field3,option){
//alert('field1 '+field1);
/*
option is 'ICS_cand' or 'CCS_cand' or 'CCS_corp' to identify the field names in the corresponsing pages:
'ICS_cand' has field 'temp_stateID'
'CCS_cand'/'CCS_corp' has field 'state'
in ics new candidate registration also field name is 'state' hence the option is set there as 'CCS_cand',even if it is of ICS
*/
//alert(field3);
  if(field1 != ''){
    var url="ajaxLoadCombo.action";
	var params = "";
	if(field3 != 'designation' && field3!= 'role') {
		params = 'countryCode='+field1;
    	params +='&stateCode='+field2;
	}else if(field3 == 'designation' || field3 == 'role') {
		params = 'jobCategory='+field1;
	}

   // alert(params);
    new Ajax.Updater(field3,url,{method: 'post', parameters: params,asynchronous: false});
    if (option=='ICS_cand' && field3=='temp_stateID') {
    	document.forms[0].temp_cityID.length=0;
    }
    if ((option=='CCS_cand' || option=='CCS_corp') && field3=='state') {
    	document.forms[0].city.length=0;
    }
	if(field3 == 'designation' && field3 == 'role') {
		detectOthers(this.value,'desg_others');
	}

	//alert(document.getElementById(field3).innerHTML);
  } // end of outer if
  else{
  	if(field3 != 'designation' && field3 != 'role') {
  		if (option=='ICS_cand' && field3=='temp_stateID') {
			if(document.forms[0].temp_stateID.length>0){
			  document.forms[0].temp_stateID.options[0].selected=true;
			}
			if(document.forms[0].temp_cityID.length>0){
			  document.forms[0].temp_cityID.options[0].selected=true;
			}
		}
		if ( (option=='CCS_cand' || option=='CCS_corp') && field3=='state') {
			if(document.forms[0].state.length>0){
			  document.forms[0].state.options[0].selected=true;
			}
			if(document.forms[0].city.length>0){
			  document.forms[0].city.options[0].selected=true;
			}
		}
	} // end if if
	else if(field3 == 'designation') {
		if(document.forms[0].designation.length>0){
		  //document.forms[0].designation.options[0].selected=true;
		  var myselect=document.forms[0].designation;
			for(var i=myselect.length-1; i>0; i--) {
				myselect.remove(i); // remove all previous options except blank
				}
		}
	}// end of else
	else if(field3 == 'role') {
		if(document.regCand.role.length>0){
		   var myselect=document.forms[0].role;
			for(var i=myselect.length-1; i>0; i--) {
				myselect.remove(i); // remove all previous options except blank
				}
			detectOthers(this.value,'desg_others');
		}
	}// end of else
  } // end of outer else
}// end of function


function unpredictListLoad(divname){	
	new Ajax.Updater(divname, 'unpredictabilityLoad.action',{method: 'post',asynchronous: false});
	//alert("loding over");
}

/* ---- To read terms and conditions when registering  ----- */	
function displayTerms(){
	//alert("displayTerms");
	var ni = document.getElementById('footer');
	var newdiv = document.createElement('div');
  var divIdName = 'termDiv';
  newdiv.setAttribute('id',divIdName);
  newdiv.style.backgroundColor ='white';
  newdiv.style.visibility ='hidden';
  newdiv.style.position ='absolute';
   newdiv.style.top ='10px';
    newdiv.style.left ='10px';
  newdiv.innerHTML = '<table width="650" height="500"><tr><td align="right"><a href="javascript:hideDiv(\'termDiv\');" style="color:black"><strong>Close</strong></a></td></tr><tr><td><iframe id="frame" src="terms_use.jsp?view=all" width="650" height="450" scrolling="yes"  frameborder="0"></iframe> </td></tr></table>';
 // alert(newdiv.innerHTML);
  ni.appendChild(newdiv);
  displayDiv('termDiv',true);

}

/*************************************************************************************************************************/
/* ---- To validate email entry ----- */	
function isValidEmail(fieldValue) {
	var val = trim(fieldValue);
	// verify the syntax of email
	var	re= /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
 	if (val!='' && (val.match(re)==null)) {			
			return false;
			}  
	else return true;				
}

/********** added on 27-jul-2010 for menu display in main html pages ***********/

function loadMenu(src,menuid){
	
	var len =0;
	var pptid ='';
	// define menu lenth and pptid based on screenid passed
	// HomepageHTML.jsp
	if (src == 'HTML1') {
		len = 8;
		pptid = 'PPT1';
	}
	// CCS_Homepage.jsp
	if (src == 'HTML2') {
		len = 6;
		pptid = 'PPT2';
	}
	// Inst_Homepage.jsp
	if (src == 'HTML3') {
		len = 4;
		pptid = 'PPT3';
	}
	// HR_Homepage.jsp
	if (src == 'HTML4') {
		len = 3;
		pptid = 'PPT4';
	}
	// ICS_Homepage.jsp
	if (src == 'HTML5') {
		len = 6;
		pptid = 'PPT5';
	}
	// CRG_Homepage.jsp
	if (src == 'HTML6') {
		len = 4;
		pptid = 'PPT6';
	}


	// deactivate all others
	for (i=0;i<len;i++){		
		document.getElementById('menu'+i).className='inactive';	
		document.getElementById('menu'+i+'detail').style.display='none';
				

		if(document.getElementById(pptid) && i==(len-1)) {
			document.getElementById('generaltbl').style.display='block';
			document.getElementById(pptid).style.display='none';
		}
	}
	document.getElementById(menuid).className='active';
	document.getElementById(menuid+'detail').style.display='block';		

	if(document.getElementById(pptid) && menuid==('menu'+(len-1)) ) {
		document.getElementById('generaltbl').style.display='none';
		document.getElementById(pptid).style.display='block';	
	}
	
}

function loadmouseover(menuid){
// deactivate all others
	if (document.getElementById(menuid).className=='inactive') 
	document.getElementById(menuid).className='view';
}

function loadmouseout(menuid){
// deactivate all others
	if (document.getElementById(menuid).className=='view') 
	document.getElementById(menuid).className='inactive';
}



function downIcsManual(path){
	openWindow(path+"/ics_candPages/manualDoc.jsp","Operation_Manual","left=0,top=0,screenX=0,screenY=0,resizable=yes,scrollbars=yes,status=yes,toolbar=no,location=no,menu=no,width=800,height=600",0);	
}

function checkImgError(){
//	alert("errorr");
	document.getElementById("corpLogoImg").src="homepage_images/cir_transparent.gif";
	document.getElementById("corpLogoImg").className="noImg";
//alert();
}
