//Selects all the checkboxes in the form

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function featureJob(job_id, status) 
{	
    var url = '';
    job_id = job_id;
    var queryString = '';
    
    if(status)
    {    	
    	type1 = true;    	
    	url = '/admin/featureJob/' + job_id;
    	
    }
    else
    {    	
    	type1 = false;
    	url = '/admin/unFeatureJob/' + job_id;;
    }
     new Ajax.Request(url,
                    { 
                        method: 'get', 
                        onComplete: changefeaturedJobImage(job_id)                         
	                }); 
 
} 
function changefeaturedJobImage(id)
{ 
 	 
 	 var div = document.getElementById('featureJob'+id);  
 	
 	 if(type1 == true)
 	 {
 	 	 div.innerHTML ='<img src="/images/icons/checked.gif" align="absmiddle" width="28" height="28" />' + 
                        '<a href="#" onclick="featureJob(' + id + ', 0); return false;"><strong>Unfeature Job</strong></a>';
 	 }
 	 else
 	 {
 	 	 div.innerHTML ='<img src="/images/icons/unchecked.gif" align="absmiddle" width="28" height="28" />' + 
                        '<a href="#" onclick="featureJob(' + id + ', 1); return false;"><strong>feature Job</strong></a>';
 	 }    
}

function preview1(url) 
{	
		$("txtJobDescription").value = tinyMCE.getContent('txtJobDescription');
		$("txtRequirements").value = tinyMCE.getContent('txtRequirements');
    	var param = Form.serialize('form1');

    	new Ajax.Request(url + '?prv=1',
                    { 
                        method: 'post', 
                        parameters: param,
                        onComplete: showPopUp                      
	                }); 
  
} 
function resPreview(url) 
{	

    	var param = Form.serialize('form1');
   		
    	new Ajax.Request(url + '?prv=1',
                    { 
                        method: 'post', 
                        parameters: param,
                        onComplete: showResPopUp                      
	                }); 
  
} 
function showResPopUp(originalRequest)
{
		
	var mantra = strrev((strrev(escape(originalRequest.responseText))).substr(0,5));
	
    if(mantra == "Super")
    {
	    var url = window.location.href;
		var nohttp = url.split('//')[1];
		
		var hostPort = nohttp.split('/')[0]
		var host = "http://" + hostPort; 
		
		url = host + '/home/create-resume/pop';
		window.open(url, "_blank", "scrollbars");
	} 
    else 
    {    	
    	alert(originalRequest.responseText);
    }
    
}

function showPopUp(originalRequest)
{
	
	
    if(originalRequest.responseText == "Super")
    {
	    var url = window.location.href;
		var nohttp = url.split('//')[1];
		
		var hostPort = nohttp.split('/')[0]
		var host = "http://" + hostPort; 
		
		url = host + '/employer/post-jobs/pop';
		window.open(url, "_blank", "scrollbars");
	}
    else
    {
    	
    	alert(originalRequest.responseText);
    }
}

function copyContact()
{
	if((document.getElementById('copyCat')).checked)
	{
	
		var address1 = (document.getElementById('txtCompanyAddress1')).value;
		var address2 = (document.getElementById('txtCompanyAddress2')).value;
		var city     = (document.getElementById('txtCompanyCity')).value;
		var state    = (document.getElementById('cmbConpanyState')).value;
		var zip      = (document.getElementById('txtCompanyZip')).value; 
		var phone1   = (document.getElementById('txtCompanyPhone1')).value;
		var phone2   = (document.getElementById('txtCompanyPhone2')).value;
		var phone3   = (document.getElementById('txtCompanyPhone3')).value;
		var fax1	 = (document.getElementById('txtCompanyFax1')).value;	
		var fax2	 = (document.getElementById('txtCompanyFax2')).value;	
		var fax3	 = (document.getElementById('txtCompanyFax3')).value;	
		
		(document.getElementById('txtAddress1')).value = address1;
		(document.getElementById('txtAddress2')).value = address2;
		(document.getElementById('txtCity')).value = city;
		(document.getElementById('cmbState')).value = state;
		(document.getElementById('txtZip')).value = zip;
		(document.getElementById('txtPhone1')).value = phone1;
		(document.getElementById('txtPhone2')).value = phone2;
		(document.getElementById('txtPhone3')).value = phone3;
		(document.getElementById('txtFax1')).value = fax1;
		(document.getElementById('txtFax2')).value = fax2;
		(document.getElementById('txtFax3')).value = fax3;
	}
	else
	{
		(document.getElementById('txtAddress1')).value = "";
		(document.getElementById('txtAddress2')).value = "";
		(document.getElementById('txtCity')).value = "";
		(document.getElementById('cmbState')).value = "";
		(document.getElementById('txtZip')).value = "";
		(document.getElementById('txtPhone1')).value = "";
		(document.getElementById('txtPhone2')).value = "";
		(document.getElementById('txtPhone3')).value = "";
		(document.getElementById('txtFax1')).value = "";
		(document.getElementById('txtFax2')).value = "";
		(document.getElementById('txtFax3')).value = "";
	}
}
function strrev(str) {
	   if (!str) return '';
	   var revstr='';
	   for (i = str.length-1; i>=0; i--)
	       revstr+=str.charAt(i)
	   return revstr;
	}
