var curfield;

function openWindow(url, width, height) {
	if (width==null) {
		width=600;
	}
	if (height==null) {
		height=400;
	}
	window.open(url,'','left=10,top=0,scrollbars=yes,width='+width+',height='+height+',toolbar=no,status=yes');
}

function submitZyoinForm(form, url) {
	form.action=url;
	form.submit();
}

var x = 20;
var y = 70;
function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}
function placeIt(obj)
{
	obj = document.getElementById(obj);
	if (document.documentElement)
	{
		theLeft = document.documentElement.scrollLeft;
		theTop = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		theLeft = document.body.scrollLeft;
		theTop = document.body.scrollTop;
	}
	theLeft += x;
	theTop += y;
	obj.style.left = theLeft + 'px';
	obj.style.top = theTop + 'px';
	setTimeout("placeIt(obj)",500);
}

 function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1){
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
			curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1){
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function getThisValue(value) {
	curfield.value=value;
}

function hideautocomplete(whocalled){
	var autocompdiv = document.getElementById("autocomp");
	if(whocalled==0) {
		setTimeout("hideautocomplete(1)",300);
	} else {
		autocompdiv.style.display = "none";
		autocompdiv.innerHTML = "";
	}
}

function autocomplete(field,entity){
    var city = field.value;
    qstr = 'city=' + city;
	curfield = field;
	autocompdiv = document.getElementById("autocomp");
	//Prepare list of auto-complete values
    var xmlHttpReq = false;
    var self = this;
    var strURL = "/zyoin-portlet/autocomp";
    if (window.XMLHttpRequest) { // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
        	str=self.xmlHttpReq.responseText;
			//Add new city

			loc = str.split(",");
			cities = "<TABLE width='100%' style='cursor:pointer;'>";
			for(stNo=1;stNo<loc.length;stNo++) {
				cities += "<TR onmouseOver='this.style.background=\"#94C0CA\";' onmouseout='this.style.background=\"#E2E1E6\";' onclick=\"getThisValue('"+loc[stNo]+"');\"><TD>"+loc[stNo]+"</TD></TR>";
			}
			cities += "</TABLE>";
			autocompdiv.style.left = findPosX(field);
			autocompdiv.style.top = findPosY(field) + field.offsetHeight;
			autocompdiv.innerHTML = cities;
			autocompdiv.style.display = "inline";
        }
    }
    self.xmlHttpReq.send(qstr);
	//Show auto-complete division
}

function autocompleteKey(field,entity){
    var key = field.value;
    qstr = 'key=' + key;
	curfield = field;
	autocompdiv = document.getElementById("autocomp");
	//Prepare list of auto-complete values
    var xmlHttpReq = false;
    var self = this;
    var strURL = "/zyoin-portlet/autocompkey";
    if (window.XMLHttpRequest) { // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
        	str=self.xmlHttpReq.responseText;
			//Add new city
			loc = str.split(",");
			keys = "<TABLE width='100%' style='cursor:pointer;'>";
			for(stNo=0;stNo<loc.length;stNo++) {
				keys += "<TR onmouseOver='this.style.background=\"#94C0CA\";' onmouseout='this.style.background=\"#E2E1E6\";' onclick=\"getThisValue('"+loc[stNo]+"');\"><TD>"+loc[stNo]+"</TD></TR>";
			}
			keys += "</TABLE>";
			autocompdiv.style.left = findPosX(field);
			autocompdiv.style.top = findPosY(field) + field.offsetHeight;
			autocompdiv.innerHTML = keys;
			autocompdiv.style.display = "inline";
        }
    }
    self.xmlHttpReq.send(qstr);
	//Show auto-complete division
 }
 
 function loginValidate(formName){
    var xmlHttpReq = false;
    var self = this;
    var strURL = "/zyoin-portlet/validLogin";
    if (window.XMLHttpRequest) { // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
        	result=self.xmlHttpReq.responseText;
        	if(result=='')
	        	formName.submit();
	        else
	        	errMsg.innerHTML ="<font color='red' face='arial'><B>Error:</B> "+result+"</font>";
        }
    }
    qstr = 'loginId=' + formName.loginId.value+'&&password=' +formName.password.value;
    self.xmlHttpReq.send(qstr);
}

 //candidate details
function getCandidateDetails(formName)
{  
   var email=formName.value;
   strEmail= 'email=' + email;
	var xmlHttpReq = false;
    var self = this;
    var strURL = "/zyoin-portlet/candidatedetail";
    if (window.XMLHttpRequest) { // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() { 
        if (self.xmlHttpReq.readyState == 4) {
        	str=self.xmlHttpReq.responseText;
        	CandiDetails = str.split(",");
        	//if(CandiDetails.length>1) document.getElementById("email").value=CandiDetails[1];
        	if(CandiDetails.length>0 && !myTrim(CandiDetails[0])=="")
        	    document.getElementById("name").value=CandiDetails[0]; 
        	if(CandiDetails.length>2 && !myTrim(CandiDetails[2])=="")
        		document.getElementById("mobile").value=CandiDetails[2];
        	
        	if(CandiDetails.length>3 && !myTrim(CandiDetails[3])=="")
        		document.getElementById("currentCompany").value=CandiDetails[3];
        	
        	if(CandiDetails.length>4 && !myTrim(CandiDetails[4])=="")
        		document.getElementById("expyear").value=CandiDetails[4];
        	
        	if(CandiDetails.length>5 && !myTrim(CandiDetails[5])=="")
        		document.getElementById("expmonth").value=CandiDetails[5];
        	
        	if(CandiDetails.length>6 && !myTrim(CandiDetails[6])=="") document.getElementById("qualification").value=CandiDetails[6];
        	if(CandiDetails.length>7 && !myTrim(CandiDetails[7])=="") document.getElementById("lakh").value=CandiDetails[7];
        	if(CandiDetails.length>8 && !myTrim(CandiDetails[8])=="") document.getElementById("thousand").value=CandiDetails[8];
            if(CandiDetails.length>9 && !myTrim(CandiDetails[9])=="") document.getElementById("location").value=CandiDetails[9];
        	if(CandiDetails.length>10 && !myTrim(CandiDetails[10])=="") document.getElementById("skillset").value=CandiDetails[10];
	    }
    }
  self.xmlHttpReq.send(strEmail);
}
	 
function resumeAction(url)
{ 
	
	var remark;
	if(confirm("Are you sure you want to change this candidate status?"))
	{
		remark = prompt("Remark.", "");
	}
	document.location.href=url+"&remark="+remark;
}
