RE_NUMBER           = new RegExp(/^[0-9]+$/);
var httpCheckUser          = getHTTPObject();
//onClick="if(addInquiry()){saveInquiry();return true;}else{ return false;}
var httpSaveInquiry      = getHTTPObject();

function getHTTPObject()
{

  var xmlhttp;
  if (!xmlhttp )
  {

    if(window.XMLHttpRequest) 

    {

    	try {

			      xmlhttp = new XMLHttpRequest();

          } 

          catch(e) {

			               xmlhttp = false;

                   }

     }

     else if(window.ActiveXObject)

     {

       	try {

        	    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

      	    }

            catch(E) {

        	             try {

          		               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

        	                 } catch(e) {

          		                          xmlhttp = false;

        	                            }

				             }

     }

  }  

  return xmlhttp;

}

// ============== Start all function of Application class ===============

//=========== Withdraw Application =========

function withdrawApplication(job_seeker_id)
{
	var j=1;
	var check = 0;
	var advertisement_idStr="";
	for(j; j<=chk_total_fields; j++)
	{					
		if(document.getElementById('CHK'+j).checked==1)
		{
			advertisement_idStr += document.getElementById('CHK'+j).value+',';
			check=1;
		}
	}
	advertisement_idStr = advertisement_idStr.substr(0,advertisement_idStr.length-1);	
	if(check==0)
	{
		alert("Please at list select one Application");
	}
	else
	{
		//alert(appStr);		
		if(doConfirm(PROMPT_DELETE_CONFIRM)){
		 var url_loc = "index.php?app=application&cmd=withdraw&advStr="+advertisement_idStr+"&job_seeker_id="+job_seeker_id;
   		 window.location = url_loc;
		}
	}
}

//============= End Withdraw Application========================



//=============== Start Delete Save Job ==============

function deleteSavejob(job_seeker_id)
{

	var j=1;

	var check = 0;

	var advertisement_idStr="";

	for(j; j<=chk_total_fields; j++)
	{					
		if(document.getElementById('CHK'+j).checked==1)
		{
			advertisement_idStr += document.getElementById('CHK'+j).value+',';
			check=1;
		}

	}
	advertisement_idStr = advertisement_idStr.substr(0,advertisement_idStr.length-1);	
	if(check==0)
	{
		alert("Please at list select one Application");
	}
	else
	{
		 //alert(advertisement_idStr);		
		if(doConfirm(PROMPT_DELETE_CONFIRM)){
		 var url_loc = "index.php?app=job_alert&cmd=delete_save_job&advStr="+advertisement_idStr+"&job_seeker_id="+job_seeker_id;
   		 window.location = url_loc;
		}
	}

}

//=============== End Delete Save Job ==============

//=============== View Application ==============

function viewApplication(id)
{
	var url_loc = "index.php?app=application&cmd=online_application&status="+id;
	//alert(id);
	window.location = url_loc;
}

//============= End View Application ============

function saveJob()
{
	var textToWrite="";
	var primary_email = document.getElementById('loginid').value;
	var password  = document.getElementById('password').value;
	var advertisement_id  = document.getElementById('advertisement_id').value;

	if(primary_email!="" && password!="")
	{

		var str = primary_email+'COLSEP'+password; 
	  	httpCheckUser.open("GET", 'index.php?app=job_opening&cmd=savejob&aid='+advertisement_id+'&strdata='+str, true);
		httpCheckUser.onreadystatechange = handleUserResponse;  	
  	  	httpCheckUser.send(null);  	
		return true;
	}
	else
	{
		 if(primary_email=="" && password=="")
		 {
			 textToWrite = "Please Enter Your MyJobsbd Login ID and Password!!!";
		 }
		 else if(primary_email=="")
		 {
			 textToWrite = "Please Enter Your MyJobsbd Login ID!!!";
		 }
		 else if(password=="")
		 {
			 	textToWrite = "Please Enter Your MyJobsbd Password!!!";
		 }
		 document.getElementById('status_msg').style.display = "block";
         document.getElementById('status_msg').innerHTML = textToWrite;
		 return false;
	}

}

function handleUserResponse()
{
    var textToWrite = "";

    if(httpCheckUser.readyState == 4)
    {  	
	  var res = trim(httpCheckUser.responseText);			
      if(res == "Success Save")
      {     
         textToWrite = ""; 
		 document.getElementById('frmbody').style.display = "none";
		 document.getElementById('success_msg').style.display = "block";		 
      }
      else if(trim(httpCheckUser.responseText)=="Not Save")
      {          	  	 
         textToWrite = "Already you saved this job !!!";
		 document.getElementById('frmbody').style.display = "block";		 
		 document.getElementById('success_msg').style.display = "none";	
        }
      else if(trim(httpCheckUser.responseText)=="Invalid")
      {          	  	 
        textToWrite = "Invalid User ID and Password. plz tray again !!!";
        document.getElementById('loginid').value="";
	    document.getElementById('password').value=""; 
		document.getElementById('frmbody').style.display = "block";
		document.getElementById('success_msg').style.display = "none";	

      }
	  if(textToWrite!="")
	  {
		  document.getElementById('status_msg').style.display = "block";
		  document.getElementById('status_msg').innerHTML = textToWrite;
	  }
	  else
	  {	  document.getElementById('status_msg').style.display = "none";
		  document.getElementById('frmbody').style.display = "none";
		  document.getElementById('success_msg').style.display = "block";	
		  document.getElementById('status_msg').innerHTML = textToWrite;
	  }
		  //var advertisement_id  = document.getElementById('advertisement_id').value;
		  //window.location = "index.php?app=job_opening&cmd=savejob&aid="+advertisement_id;
    }

    else 
    {
    	document.getElementById('status_msg').innerHTML = "Checking Existence. Please Wait...";
    }

}

//=====Start all function of Application class======

// ======== View Jobs=========
function viewJob(aid)
{
	newWindow = window.open("index.php?app=job_opening&cmd=show_advertisement&aid="+aid,"myWindow","width=700, height=705, left=150, top=25, menubar=no,directories=no, scrollbars,resizable=no");
}
// ======= end =======

// ======== View Jobs=========
function viewAllJobs(empid)
{
	newWindow = window.open("?app=advertisement&cmd=view_alljobs_from_com&employer_id="+empid,"myWindow","width=700, height=705, left=150, top=25, menubar=no,directories=no, scrollbars,resizable=no");
}
// ======= end =======

//===== Start getJobsWithoutSpecialization ======

function getJobsWithoutSpecialization()
{		
	var key = document.getElementById('key1').value;
	var type_of_industry = document.getElementById('type_of_industry').value;	
	var location = document.getElementById('location').value;
	var url_loc = "index.php?app=job_opening&key="+key+"&type_of_industry="+type_of_industry+"&location="+location+"&id=1";	
	window.location = url_loc;		
	//alert(5);

}

//====== end getJobsWithoutSpecialization =======

function doFormSubmit()
{
   requiredFields.length = 0;
   var errCnt = 0;
   var frm = document.frm;
   // Setup required fields
   setupForm(frm);
   // Validate form for required fields
   errCnt = validateForm(frm);
   if (errCnt)
   {
      alert(MISSING_REQUIRED_FIELDS);
      return false;
   }
   else
   {
      if(validateFields(frm))
      {
         return true;
      }
      else
         return false;
   }

}

function setupForm(frm)
{
   with(frm)
   {  
   	  setRequiredField(policy,             	 'checkbox',   'policy');			
   }
}

function validateFields(frm)
{
   with(frm)
   {    
   }
   return true;
}

function checkfrm()
{    
  if(!doFormSubmit())
  {
	   return false;
  } else {	
     return true;
  }
}

//======================ViewPersonalInfoCountryCodeTips===================

function ViewAppInterviewPolicyTips()
{	
	newWindow = window.open("index.php?app=job_opening&cmd=app_interview_policy_tips","myWindow","width=590, height=464, left=260, top=30, menubar=no,directories=no, scrollbars,resizable=no");
}

//=========================End ViewPersonalInfoCountryCodeTips=====================================

function Trim(TRIM_VALUE){

if(TRIM_VALUE.length < 1){

return"";

}

TRIM_VALUE = RTrim(TRIM_VALUE);

TRIM_VALUE = LTrim(TRIM_VALUE);

if(TRIM_VALUE==""){
return "";

}

else{
return TRIM_VALUE;
}

} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}

var iTemp = v_length -1;
while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;
} //End While

return strTemp;

} //End Function
function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";
var iTemp = 0;
while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;

} //End While

return strTemp;

} //End Function

