/*********************************************************************
 * Description : Global Variables                                    *
 *********************************************************************/
var tipCnt=0,tipX=0,tipY=0;
var dirCLoc = "..";

    var xmlHttp; 
    var RefEmailId;
    var requestURL = '../AjaxLookup.aspx'; 
    var reqURL = '../clientdb/getRefEmail.aspx';
    var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
    var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
    var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
    //netscape, safari, mozilla behave the same??? 
    var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;     
    var reportURL = '../emp/emp_ajax.aspx';
    var jsUrl = '../JS/js_ajax.aspx';
    var frwdUrl = '../clientdb/forwadPageMail.aspx';

/*********************************************************************
 * Function    : WriteTips(tipText,[tipPos])                         *
 * Description : Writes the Tip of a Field in Form                   *
 * Arguments   : tipText = The text that should be shown in Tip      *
 *               tipPos  = (Optional) Provides the position of Tip   *
 *               Refer ShowTips() for tipPos descriptions            *
 *********************************************************************/
function WriteTips(tipText)
{
    document.write(" <img id='imgTips" + tipCnt + "' src='" + dirCLoc + "/corpcorp2.0/images/icoHelp.gif' border=0 width=16 height=16 onMouseMove='ShowTips(" + tipCnt + ",event);' onMouseOut='HideTips(" + tipCnt + ");' style={cursor:help;}>");
	document.write("<div id='divTips"+tipCnt+"' value='"+((arguments.length>1)?arguments[1]:0)+"' class=txtTips style={position:absolute;left:0px;top:0px;width:200px;display:none;z-index:20;}>"+tipText+"</div>");
	tipCnt++;
}

/*********************************************************************
 * Function    : ShowTips(tipID,myEvt)                               *
 * Description : Shows the Tip of a Field in Form                    *
 * Arguments   : tipID = Unique ID for showing the related Tip       *
 *               myEvt = The Event Object that fired this Event      *
 *********************************************************************/
function ShowTips(tipID,myEvt)
{
	var curX,curY,objDiv,objImg;
	
	objDiv=document.getElementById("divTips"+tipID)
	curX=document.body.scrollLeft+myEvt.clientX;
	curY=document.body.scrollTop+myEvt.clientY;
	switch(parseInt(objDiv.value))
	{
		case 0: // Bottom-Right of the Cursor
			curY+=18;
			break;
		case 1: // Bottom-Center of the Cursor
			curY+=18;
			curX-=90;
			break;
		case 2:	// Bottom-Left of the Cursor
			curX-=200;
			curY+=18;
			break;
		case 3: // Middle-Left of the Cursor
			curY-=2;
			curX-=210;
			break;
		case 4: // Middle-Left-Center of the Cursor
			curY-=20;
			curX-=210;
			break;
		case 5: // Top-Left of the Cursor
			curY-=60;
			curX-=200;
			break;
		case 6: // Top-Center of the Cursor
			curY-=60;
			curX-=90;
			break;
		case 7: // Top-Right of the Cursor
			curY-=60;
			curX+=20;
			break;
		case 8: // Middle-Right-Center of the Cursor
			curY-=20;
			curX+=20;
			break;
		case 9: // Middle-Right of the Cursor
			curY-=2;
			curX+=20;
			break;
		default:
			curY+=18;
	}
	objDiv.style.left=curX+"px";
	objDiv.style.top=curY+"px";
	if(objDiv.style.display=="none")
		objDiv.style.display="";
}

/*********************************************************************
 * Function    : HideTips(tipID)                                     *
 * Description : Hides the Tip of a Field in Form                    *
 * Arguments   : tipID = Unique ID for hiding the related Tip        *
 *********************************************************************/
function HideTips(tipID)
{
	var objDiv;
	
	objDiv=document.getElementById("divTips"+tipID)
	if(objDiv.style.display!="none")
		objDiv.style.display="none";
}


 //----------------->> Function To Trim String <<-----------------------------------------------
    function trimString (str) 
    {
       str = this != window? this : str; // Using Regular Expression
       return str.replace(/^\s+/g, '').replace(/\s+$/g, ''); 
    }

    function show_city(){ 
        //Append the name to search for to the requestURL 
        var url = requestURL+'?ZipCode='+document.getElementById('txtZip').value;
      	if(document.getElementById('txtZip').value.length != 5)
		{
		return;
		}
        //Create the xmlHttp object to use in the request 
        //stateChangeHandler will fire when the state has changed, i.e. data is received back 
        // This is non-blocking (asynchronous) 
        xmlHttp = GetXmlHttpObject(stateChangeHandlerZIP); 

        //Send the xmlHttp get to the specified url 
        xmlHttp_Get(xmlHttp, url); 
    } 

	function check_emp_Refemail(txtEmail){ 
        //Append the name to search for to the requestURL 
        RefEmailId=txtEmail;
              
       var url = reqURL+'?EMPEmail='+document.getElementById(txtEmail).value;
            
        
        if(document.getElementById(txtEmail).value.length == 0)
		{ 
		return;
		}
        //Create the xmlHttp object to use in the request 
        //stateChangeHandler will fire when the state has changed, i.e. data is received back 
        // This is non-blocking (asynchronous) 
        xmlHttp = GetXmlHttpObject(stateChangeHandlerEMPEmail); 

        //Send the xmlHttp get to the specified url 
        xmlHttp_Get(xmlHttp, url); 
    }
    
    function check_js_email(){ 
        //Append the name to search for to the requestURL 
        var now = new Date();
		now = now.getSeconds();
        var url = requestURL+'?JSEmail='+document.getElementById('txtEmailID').value+'&uid='+now;
        var email = document.getElementById('txtEmailID').value;
		if(email.length == 0 || email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
		{
		document.getElementById('lblEmailValid').innerHTML = "";
		return;
		}
        //Create the xmlHttp object to use in the request 
        //stateChangeHandler will fire when the state has changed, i.e. data is received back 
        // This is non-blocking (asynchronous) 
        xmlHttp = GetXmlHttpObject(stateChangeHandlerJSEmail); 

        //Send the xmlHttp get to the specified url 
        xmlHttp_Get(xmlHttp, url); 
    } 

    function StoreSPNotes(spID, strNotes, strId) {    
        //Append the name to search for to the requestURL 
        var url = requestURL+'?spid='+spID+'&spnotes='+strNotes;
        //Create the xmlHttp object to use in the request 
        //stateChangeHandler will fire when the state has changed, i.e. data is received back 
        // This is non-blocking (asynchronous)        
        xmlHttp = GetXmlHttpObject(stateChangeHandlerNone); 

        //Send the xmlHttp get to the specified url 
        xmlHttp_Get(xmlHttp, url); 

		// Display status (w/o waiting for callback - caching source is complex)
        var strResponseId = strId.substring(0,strId.indexOf('txtNotes'))+ 'lblResult';
        document.getElementById(strResponseId).innerHTML = 'Saved';        
    } 
    
    function stateChangeHandlerNone()
    {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
        { 
            //Gather the results from the callback 
            var str = xmlHttp.responseText;                               
        }
        // do nothing for now
    }
    //stateChangeHandler will fire when the state has changed, i.e. data is received back 
    // This is non-blocking (asynchronous) 
    function stateChangeHandlerZIP() 
    { 
        //readyState of 4 or 'complete' represents that data has been returned 
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){ 
            //Gather the results from the callback 
            var str = xmlHttp.responseText;
            if(str.length == 0)
            {
              str = ",";
            }
            var arrValues = str.split(",");

            //Populate result
            if(arrValues[0] == "OK")
            {
            document.getElementById('txtCity').value = arrValues[1]; 
            document.getElementById('ddsState').value = arrValues[2] + ' (' + arrValues[3] + ')';
            document.getElementById('ddsCountry').value = 'United States of America';
            populate_jsphonearea();
            }
        } 
    } 

    //stateChangeHandler will fire when the state has changed, i.e. data is received back 
    // This is non-blocking (asynchronous) 
    function stateChangeHandlerJSEmail() 
    { 
        //readyState of 4 or 'complete' represents that data has been returned 
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){ 
            //Gather the results from the callback 
            var str = xmlHttp.responseText;
            if(str.length == 0)
            {
              str = ",";
            }
			
            var arrValues = str.split(",");

            //Populate result
            if(arrValues[0] == "OK")
            {	
                document.getElementById('txtEmailValid').value = arrValues[1];
				if(document.getElementById('txtEmailValid').value.length == 0)
				{
                document.getElementById('lblEmailValid').innerHTML = "<- EMail ID already exists. Please login";
                document.getElementById("lblEmailValid").style.fontWeight = "bold";
                document.getElementById('lblEmailValid').style.whiteSpace = "nowrap";
                document.getElementById('txtEmailID').select();
                }
                else if(document.getElementById('txtEmailValid').value == "FAIL")
                {
                document.getElementById('lblEmailValid').innerHTML = "<- Please enter valid EMail ID";
                document.getElementById("lblEmailValid").style.fontWeight = "bold";
                document.getElementById('lblEmailValid').style.whiteSpace = "nowrap";
                document.getElementById('txtEmailID').select();
                }
                 else if(document.getElementById('txtEmailValid').value == "LOGIN")
                {
                document.getElementById('lblEmailValid').innerHTML = "<- Recruiters/Companies - Post Resumes through Employer Login (If you are a Job Seeker, please use personal email id)";
                document.getElementById("lblEmailValid").style.fontWeight = "bold";
                document.getElementById('lblEmailValid').style.whiteSpace = "nowrap";
                document.getElementById('txtEmailID').select();
                }
                else
                {
                document.getElementById('lblEmailValid').innerHTML = "";
                }
            }
            else
            {
                document.getElementById('txtEmailValid').value = "";
            }
        } 
    } 

function stateChangeHandlerEMPEmail() 
    { 
        //readyState of 4 or 'complete' represents that data has been returned 
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){ 
            //Gather the results from the callback 
            var str = xmlHttp.responseText;
           //Populate result
            var temp=trimString(str.substring(0,str.indexOf("<!DOCTYPE")));  
           
           if(temp == "FAIL")
            {  
                document.getElementById('Label1').innerHTML = "EMail ID already exists. Refer someone";
                document.getElementById(RefEmailId).select();
                return false; 
            }
            else 
            {
               document.getElementById('Label1').innerHTML = "";
            }
            
        } 
    } 

	function HandleMasterDegree()
	{
	    var radDegree = document.forms[0].radDegree[2].checked | document.forms[0].radDegree[3].checked;
	    if(radDegree)
	    {
  	        document.forms[0].radUSDegree[0].disabled = false;
  	        document.forms[0].radUSDegree[1].disabled = false;
	    }
	    else
	    {
  	        document.forms[0].radUSDegree[1].checked = true;
  	        document.forms[0].radUSDegree[0].disabled = true;
  	        document.forms[0].radUSDegree[1].disabled = true;
	    }
	}

function downloadCount(emailid)
{
	var act = 3;
	var now = new Date();
	now = now.getSeconds();
	var url = reportURL+'?empEmailId='+encodeURIComponent(emailid)+'&action='+act+'&uid='+now;
	xmlHttp = GetXmlHttpObject(stateChangeHandlerNone);	
	xmlHttp_Get(xmlHttp,url);		
}
	
function storeJSReportNotes(note,resId,action)
{		
	var now = new Date();
	now = now.getSeconds();
	var str = 'notes='+note+'&rId='+resId+'&act='+action+'&uid='+now;		
	xmlHttp = GetXmlHttpObject(saveJSReportNotesHandler);
	xmlHttp_Post(xmlHttp,jsUrl,str);	
}

function saveJSReportNotesHandler()
{
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		if(str == 'success')
		{
			var sres = trimString(document.getElementById("txtNotes").value);
			if(sres.length > 0)
			{
				document.getElementById("txtBkup").value = sres;
				document.getElementById('lblNotes').innerHTML = "<dl><dt><b>Notes :</b></dt><dd>&nbsp;&nbsp;&nbsp;"+sres.replace(/\r\n/g,"<br />")+"</dd></dl>";
				document.getElementById("notes").innerHTML = "<img src='/corpcorp2.0/images/plus.gif' alt='' border='0' />&nbsp;Would you like to edit your previous notes?";
				document.getElementById('NotesOptions').style.display = 'none';				
			}
			else
			{
				document.getElementById("txtBkup").value = "";
				document.getElementById('lblNotes').innerHTML = "";
				document.getElementById("notes").innerHTML = "<img src='/corpcorp2.0/images/plus.gif' alt='' border='0' />&nbsp;Would you like to add your notes to report?";
				document.getElementById('NotesOptions').style.display = 'none';
			}
		}
		else if(str == 'fail')
		{
			document.getElementById('lblNotes').innerHTML = "";
			return false;
		}
	}
}

function deleteJSRepNotes(resId,action)
{		
	var now = new Date();
	now = now.getSeconds();
	var str = "rId="+resId+"&act="+action+'&uid='+now;		
	xmlHttp = GetXmlHttpObject(deleteJSReportNotesHandler);
	xmlHttp_Post(xmlHttp,jsUrl,str);		
}

function deleteJSReportNotesHandler()
{
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
			var str = xmlHttp.responseText;
			if(str == 'success')
			{
				document.getElementById("txtNotes").value = "";
				document.getElementById("txtBkup").value = "";
				document.getElementById('lblNotes').innerHTML = "";
				document.getElementById("notes").innerHTML = "<img src='/corpcorp2.0/images/plus.gif' alt='' border='0' />&nbsp;Would you like to add your notes to report?";
				document.getElementById('NotesOptions').style.display = 'none';			
			}
			else if(str == 'fail')
			{
				return false;
			}
	}	
}
function sendInquiryMail(fromid, toid, toName, ccid, bccId, replyToId, sub, body, orgMailbdyCnt, hdskid, connUrl) {
    document.getElementById("resMail").style.color = "#333333";
    document.getElementById("resMail").innerHTML = "<img src='/corpcorp2.0/Images/wait.gif' alt='' border='0' />&nbsp; please wait...";
    var str = "fromId=" + fromid + "&toId=" + toid + "&toName=" + toName + "&ccId=" + ccid + "&bccId=" + bccId + "&replyToId=" + replyToId + "&subject=" + encodeURIComponent(sub) +
        "&bdy=" + encodeURIComponent(body) + "&orgMailbdyCnt=" + encodeURIComponent(orgMailbdyCnt) + "&uid=" + (new Date()).getSeconds() + "&hdskid=" + hdskid;
    xmlHttp = GetXmlHttpObject(InquiryHandler);
    xmlHttp_Post(xmlHttp, connUrl, str);
}
function sendAppliedJobsReport(fromid,toid,ccid,sub,body) {   
	var now = new Date();
	now = now.getSeconds();
	var str = "fromId="+fromid+"&toId="+toid+"&ccId="+ccid+"&subject="+encodeURIComponent(sub)+"&bdy="+encodeURIComponent(body)+"&uid="+now;
	xmlHttp = GetXmlHttpObject(sendAppliedJobsReportHandler);
	xmlHttp_Post(xmlHttp,jsUrl,str);
}
function InquiryHandler() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
        var str = xmlHttp.responseText;
        if (str == 'success') {
            document.getElementById("resMail").style.color = "green";
            document.getElementById("resMail").innerHTML = "<img src='/corpcorp2.0/Images/tick-icon.png' alt='' border='0' />&nbsp;Mail has been sent";
            makeRequest('../../reminderlookup.aspx?discard=false&popupname=inquiry&replymsg=' + encodeURIComponent(document.getElementById('_ctl0_msgtxt').value) + '&replyMailId=' + document.getElementById('_ctl0_totxt').value + '&inqmailid=' + document.getElementById('inqmail_id').value + '&hdname=' + document.getElementById('_ctl0_ContentPlaceHolder1_loginId').value + '&ti=' + (new Date).getTime(), function(text) { /*showModalLayerCenter(to, sub, msg, document.getElementById('inqmail_id').value);*/ }, '');
        }
        else if (str == 'fail') {
            document.getElementById("resMail").style.color = "red";
            document.getElementById("resMail").innerHTML = "<img src='/corpcorp2.0/Images/error-icon.png' alt='' border='0' />&nbsp;Oops Error Occured";
            return false;
        }
    }
}   
function sendAppliedJobsReportHandler()
{
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		if(str == 'success')
		{
			document.getElementById("resMail").style.color = "green";
			document.getElementById("resMail").innerHTML = "<img src='/corpcorp2.0/Images/tick-icon.png' alt='' border='0' />&nbsp;Report has been sent";
			
		}
		else if(str == 'fail')
		{
		    document.getElementById("resMail").innerHTML = "<img src='/corpcorp2.0/Images/error-icon.png' alt='' border='0' />&nbsp;Oops Error Occured";
			return false;
		}
	}
}


 // XMLHttp send POST request
    
function xmlHttp_Post(xmlhttp,url,parameters)
{
	xmlhttp.open('POST', url, true);
	xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xmlhttp.send(parameters);		
}

// XMLHttp send GET request 
function xmlHttp_Get(xmlhttp, url) {
        xmlhttp.open('GET', url, true); 
    xmlhttp.send(null); 
    
} 

function GetXmlHttpObject(handler) { 
    var objXmlHttp = null;    //Holds the local xmlHTTP object instance 

    //Depending on the browser, try to create the xmlHttp object 
    if (is_ie){ 
        //The object to create depends on version of IE 
        //If it isn't ie5, then default to the Msxml2.XMLHTTP object 
        var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; 
            
        //Attempt to create the object 
        try{ 
            objXmlHttp = new ActiveXObject(strObjName); 
            objXmlHttp.onreadystatechange = handler; 
            
        } 
        catch(e){ 
        //Object creation errored 
            alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled'); 
            return; 
        } 
    } 
    else if (is_opera){ 
        //Opera has some issues with xmlHttp object functionality 
        alert('Opera detected. The page may not behave as expected.'); 
        return; 
    } 
    else{ 
        // Mozilla | Netscape | Safari 
        objXmlHttp = new XMLHttpRequest(); 
        objXmlHttp.onload = handler; 
        objXmlHttp.onerror = handler; 
    } 
        
    //Return the instantiated object 
    return objXmlHttp; 
} 

	function populate_jsphonearea() {
		var varWArea = document.getElementById('txtPhoneWArea');
		var varHArea = document.getElementById('txtPhoneHArea');
		var varMArea = document.getElementById('txtPhoneMArea');
		var varArea = document.getElementById('ddsCountryPhoneArea');
		var varCountry = document.getElementById('ddsCountry').selectedIndex;
		varWArea.value = varArea.options[varCountry].value;
		varMArea.value = varArea.options[varCountry].value;
		varHArea.value = varArea.options[varCountry].value;
	}
	
	function storeReportNotes(empid,jobid,strNote,act)
	{
		
		var url = reportURL+'?eid='+empid+'&jid='+jobid+'&txt='+strNote+'&action='+act;
		//Create the xmlHttp object to use in the request 
        //saveReportNotesHandler will fire when the state has changed, i.e. data is received back 
        // This is non-blocking (asynchronous) 
		xmlHttp = GetXmlHttpObject(saveReportNotesHandler);
		//Send the xmlHttp get to the specified url
		xmlHttp_Get(xmlHttp,url);		
	}
	
	function saveReportNotesHandler()
	{
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
		{
			var str = xmlHttp.responseText;
			if(str == 'success')
			{
				var sres = document.getElementById("txtNotes").value;
				document.getElementById("txtBkup").value = sres;
				document.getElementById('lblNotes').innerHTML = "<dl><dt><b>Notes :</b></dt><dd>&nbsp;&nbsp;&nbsp;"+sres+"</dd></dl>";
				document.getElementById("notes").innerHTML = "<img src='/corpcorp2.0/images/plus.gif' alt='' border='0' />&nbsp;Would you like to edit your previous notes?";
				document.getElementById('NotesOptions').style.display = 'none';				
			}
			else if(str == 'fail')
			{
				document.getElementById('lblNotes').innerHTML = "";
				return false;
			}
		}
	}
	
	function deleteEmpRepNotes(jobid,act)
	{
		
		var url = reportURL+'?jid='+jobid+'&action='+act;
		//Create the xmlHttp object to use in the request 
        //saveReportNotesHandler will fire when the state has changed, i.e. data is received back 
        // This is non-blocking (asynchronous) 
		xmlHttp = GetXmlHttpObject(deleteEmpReportNotesHandler);
		//Send the xmlHttp get to the specified url
		xmlHttp_Get(xmlHttp,url);		
	}
	
	function deleteEmpReportNotesHandler()
	{
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
		{
			var str = xmlHttp.responseText;
			if(str == 'success')
			{
				document.getElementById("txtNotes").value = "";
				document.getElementById("txtBkup").value = "";
				document.getElementById('lblNotes').innerHTML = "";
				document.getElementById("notes").innerHTML = "<img src='/corpcorp2.0/images/plus.gif' alt='' border='0' />&nbsp;Would you like to add your notes for report?";
				document.getElementById('NotesOptions').style.display = 'none';
			}
			else if(str == 'fail')
			{
				return false;
			}
		}
	}
	
function sendEmpEffortReport(frm,toIds,ccIds,subject,bodyCnt)
{
	var now = new Date();
	now = now.getSeconds();
	var str = 'fromId='+frm+'&toId='+toIds+'&ccId='+ccIds+'&sub='+encodeURIComponent(subject)+'&bdy='+encodeURIComponent(bodyCnt)+ '&action=2&uid='+now;		
	xmlHttp = GetXmlHttpObject(sendEmpEffortReportHandler);		
	xmlHttp_Post(xmlHttp,reportURL,str);
}
	
function sendEmpEffortReportHandler()
{
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		if(str == 'success')
		{
			document.getElementById("resMail").style.color = "green";
			document.getElementById("resMail").innerHTML = "<img src='/corpcorp2.0/Images/tick-icon.png' alt='' border='0' />&nbsp;Report has been sent";
			
		}
		else if(str == 'fail')
		{
		    document.getElementById("resMail").innerHTML = "<img src='/corpcorp2.0/Images/error-icon.png' alt='' border='0' />&nbsp;Oops Error Occured";
			return false;
		}
	}
}
	
function OptSelect()
{
  var objSource = document.getElementById('lbPriorityList');
  var objTarget = document.getElementById('lbSelectedPriority');
  if(objSource.selectedIndex >= 0)
  {
    var newOpt = new Option(objSource.options[objSource.selectedIndex].text, objSource.options[objSource.selectedIndex].value, false, false)
    objTarget.options.add(newOpt);
   // objSource.options.remove(objSource.selectedIndex);
   objSource.remove(objSource.selectedIndex);
  }
  StoreSelected();
  sortSelect(objSource);
}

function OptUnSelect()
{
  var objSource = document.getElementById('lbSelectedPriority');
  var objTarget = document.getElementById('lbPriorityList');
  if(objSource.selectedIndex >= 0)
  {
    var newOpt = new Option(objSource.options[objSource.selectedIndex].text, objSource.options[objSource.selectedIndex].value, false, false)
    objTarget.options.add(newOpt);
   // objSource.options.remove(objSource.selectedIndex);
   objSource.remove(objSource.selectedIndex);
   sortSelect(objTarget);
  }
  StoreSelected();
  sortSelect(objSource);  
}

function StoreSelected()
{
  var objSelected = document.getElementById('lbSelectedPriority');
  var objHidden = document.getElementById('txtSelectedStates');
  objHidden.value = '';
  for(i=0; i < objSelected.options.length; i++)
  {
    objHidden.value = objHidden.value + objSelected.options[i].value + ',';   
  }
}

function SROptSelect()
{
  var objSource = document.getElementById('lbStates');
  var objTarget = document.getElementById('lbStatesSelected');
  if (objSource.selectedIndex >= 0) {
      var newOpt = new Option(objSource.options[objSource.selectedIndex].text, objSource.options[objSource.selectedIndex].value, false, false)
      objTarget.options.add(newOpt);
      //objSource.options.remove(objSource.selectedIndex);
      objSource.remove(objSource.selectedIndex);
      document.getElementById('RadioButton2').checked = true;
      document.getElementById('RadioButton1').checked = false;
  }
  SRStoreSelected();
  sortSelect(objSource);
}

function SROptUnSelect()
{
  var objSource = document.getElementById('lbStatesSelected');
  var objTarget = document.getElementById('lbStates');
 if (objSource.selectedIndex >= 0) {
      var newOpt = new Option(objSource.options[objSource.selectedIndex].text, objSource.options[objSource.selectedIndex].value, false, false)
      objTarget.options.add(newOpt);
      //objSource.options.remove(objSource.selectedIndex);
      objSource.remove(objSource.selectedIndex);
      sortSelect(objTarget);
      document.getElementById('RadioButton2').checked = false;
      document.getElementById('RadioButton1').checked = true;
  }
  SRStoreSelected();
  sortSelect(objSource);
}

function SROptSelectAll()
{
  var objSource = document.getElementById('lbStates');
  var objTarget = document.getElementById('lbStatesSelected');
  for(i=objSource.options.length-1; i>=0; i--)
  {
    var newOpt = new Option(objSource.options[i].text, objSource.options[i].value, false, false)
    objTarget.options.add(newOpt);
    //objSource.options.remove(i);
    objSource.remove(i);
  }
  sortSelect(objTarget);
  SRStoreSelected();
}

function SRStoreSelected()
{
  var objSelected = document.getElementById('lbStatesSelected');
  var objHidden = document.getElementById('txtSelectedStates');
  objHidden.value = '';
  for(i=0; i < objSelected.options.length; i++)
  {
    objHidden.value = objHidden.value + objSelected.options[i].value + ',';
  }
}

function compareText (option1, option2) {
  return option1.text < option2.text ? -1 :
    option1.text > option2.text ? 1 : 0;
}

function sortSelect (select, compareFunction) {
  if (!compareFunction)
    compareFunction = compareText;

  var options = new Array (select.options.length);

  for (var i = 0; i < options.length; i++)
    options[i] = 
      new Option (
        select.options[i].text,
        select.options[i].value,
        select.options[i].defaultSelected,
        select.options[i].selected
      );
  options.sort(compareText);
  select.options.length = 0;
  for (var i = 0; i < options.length; i++)
    select.options[i] = options[i];
}

function PopulateSkills()
{
  var varSAreaValue = document.getElementById('ddlSpecializedArea').value;
  var varSSkill = document.getElementById('ddlSpecializedSkill');

  for(i=varSSkill.length-1; i>=0; i--)
  {
    varSSkill.remove(i);
  }
 
//  var newOpt1 = new Option("Select Specialized Skill", "0", false, false);
//  varSSkill.options.add(newOpt1);

  if(varSAreaValue == "0" || varSAreaValue == '')
  {
     return;
  }

  var arrValue = eval('arrSubCat' + varSAreaValue);
  //alert(arrValue);
  if(arrValue != null)
  {
	for(i=0; i < arrValue.length; i++)
	{
	var newOpt = new Option(arrValue[i][0], arrValue[i][1], false, false)
	varSSkill.options.add(newOpt);
	}
  }
}

function StoreSkill()
{
  var varSSkill = document.getElementById('ddlSpecializedSkill');
  var varHiddenSkill = document.getElementById('txtSelectedSkill');
  varHiddenSkill.value = varSSkill.value;
}

function insertAtCursor(myField, myValue)
{
	//IE support
	if (document.selection)
	{
		myField.focus();

		sel = document.selection.createRange();
		sel.text = myValue;
	}	
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0')
	{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		
		myField.value = myField.value.substring( 0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	}
	else
	{
		myField.value += myValue;
	}
}

function AddScratchPad(strResumeID)
{
	var objForm =  document.Form1;
	var strVarName = '';

	for(i=0;i<objForm.elements.length;i++)
	{
		var element = objForm.elements[i];
		if(element.name.indexOf('chkAddScratchPad_'+strResumeID) >= 0)
		{
			if(element.checked)
			{ 
				strVarName = element.name;
				//Append the name to search for to the requestURL 
				var url = '../emp/Emp_add_scratchpad.aspx?JSID='+strResumeID;
				
				
				xmlHttp = GetXmlHttpObject(stateChangeHandlerAddScratchPad);

				xmlHttp_Get(xmlHttp, url); 
				
				
				blnAdded = true;
			}
		}
	}

	if(strVarName.length > 0)
	{
	    strVarName = strVarName.replace('chkAddScratchPad_', 'lblAddToScratchPad_').replace(':', '_');
	    var lblElement = document.getElementById(strVarName);
	    if(lblElement != null)
	    {
	       lblElement.innerHTML = 'Added to Scratch Pad';
	    }
	}
}
function stateChangeHandlerAddScratchPad() 
{ 
    //readyState of 4 or 'complete' represents that data has been returned 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{ 
         //var str = xmlHttp.responseText;
         //alert('Added to scratch pad');
    } 
} 

function storeEmpRecommNotes(empDomain, resumeId, notes) {
    var now = new Date();
    now = now.getSeconds();
    var str = 'domain=' + encodeURIComponent(empDomain) + '&resId=' + resumeId + '&note=' + encodeURIComponent(notes)+ '&action=4&uid=' + now;
    xmlHttp = GetXmlHttpObject(storeEmpRecommNotesHandler);
    xmlHttp_Post(xmlHttp, reportURL, str);

}

function storeEmpRecommNotesHandler() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
        var str = xmlHttp.responseText;
        if (str == 'success') {             
            document.getElementById('lblResult').innerHTML = "Saved ...";
            document.getElementById('lblResult').style.color = "#347C17";
            if(trimString(document.getElementById('txtRecBkup').value).length > 0)
                document.getElementById('txtRecBkup').value += '\r' + document.getElementById('txtRecomm').value + '  - entered by [' + document.getElementById('empEmailId').value + ']';             
            else
                document.getElementById('txtRecBkup').value += document.getElementById('txtRecomm').value + '  - entered by [' + document.getElementById('empEmailId').value + ']';             
        }
        else if (str == 'fail') {
            document.getElementById('lblResult').innerHTML = "Oops error occured ...";
            document.getElementById('lblResult').style.color = "#E41B17";          
        } 
        if(document.getElementById('txtRecBkup') && document.getElementById('txtRecBkup').style.display == "none") {
            document.getElementById('txtRecBkup').style.display = "block"; 
		    document.getElementById('prevHeadText').style.display = "block";     
		}
    }
}
function forwardPage(fromid,toid,sub,filepath) {
    document.getElementById("resMail").style.color = "#333333";
    document.getElementById("resMail").innerHTML = "<img src='/corpcorp2.0/Images/wait.gif' alt='' border='0' />&nbsp;please wait ...";
    var now = new Date();
    now = now.getSeconds();
    var str = "filePath="+ encodeURIComponent(filepath) +"&fromId=" + encodeURIComponent(fromid) + "&toId=" + encodeURIComponent(toid) + "&subject=" + encodeURIComponent(sub) + "&uid=" + now;
    xmlHttp = GetXmlHttpObject(forwardPageHandler);
    xmlHttp_Post(xmlHttp, frwdUrl, str);
}

function forwardPageHandler() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
        var str = xmlHttp.responseText;
        if (str == 'OK') {
            document.getElementById("resMail").style.color = "green";
            document.getElementById("resMail").innerHTML = "<img src='/corpcorp2.0/Images/tick-icon.png' alt='' border='0' />&nbsp;Page has been forwaded";

        }
        else if (str == 'FAIL') {
            document.getElementById("resMail").style.color = "red";
            document.getElementById("resMail").innerHTML = "<img src='/corpcorp2.0/Images/error-icon.png' alt='' border='0' />&nbsp;Oops Error Occured";
            return false;
        }
    }
}
