// JavaScript Document

var xmlhttp;

function setback(tab)
{
	var backimage='url(./images/'+tab+')';
	//alert(backimage);
	//document.getElementById('head_navigation').backgroundImage=ssss;
	document.getElementById('tab').style.backgroundImage= backimage; 
	setCookie('top_nav',tab,1);
}


function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookie()
{
username=getCookie('top_nav');
if (username!=null && username!="")
  {
  //alert('Welcome again '+username+'!');
  var backimage='url(./images/'+username+')';	
  document.getElementById('tab').style.backgroundImage= backimage;   
  }
}





function saveAll(theForm)
{
	
	if((theForm.name.value=="Full Name")|| (theForm.email.value=="E-Mail"))
	{
	  alert("Please Enter Your Full Name and E-Mail");
	}
	else
	{
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	  
	var url = 'job_db.php';
	
    var param = theForm.name.name + "=" + encodeURIComponent( theForm.name.value );	
	param += "&" + theForm.email.name + "=" + encodeURIComponent( theForm.email.value );
	param += "&" + theForm.addres.name + "=" + encodeURIComponent( theForm.addres.value );
	param += "&" + theForm.city.name + "=" + encodeURIComponent( theForm.city.value );
	param += "&" + theForm.state.name + "=" + encodeURIComponent( theForm.state.value );
	param += "&" + theForm.zip.name + "=" + encodeURIComponent( theForm.zip.value );
	param += "&" + theForm.phone.name + "=" + encodeURIComponent( theForm.phone.value );
	param += "&" + theForm.age.name + "=" + encodeURIComponent( theForm.age.checked );     //check box
	
	param += "&" + theForm.ref_name1.name + "=" + encodeURIComponent( theForm.ref_name1.value );
	param += "&" + theForm.ref_relationship1.name + "=" + encodeURIComponent( theForm.ref_relationship1.value );
	param += "&" + theForm.ref_company1.name + "=" + encodeURIComponent( theForm.ref_company1.value );
	param += "&" + theForm.ref_phoneEmail1.name + "=" + encodeURIComponent( theForm.ref_phoneEmail1.value );
	
	param += "&" + theForm.ref_name2.name + "=" + encodeURIComponent( theForm.ref_name2.value );
	param += "&" + theForm.ref_relationship2.name + "=" + encodeURIComponent( theForm.ref_relationship2.value );
	param += "&" + theForm.ref_company2.name + "=" + encodeURIComponent( theForm.ref_company2.value );
	param += "&" + theForm.ref_phoneEmail2.name + "=" + encodeURIComponent( theForm.ref_phoneEmail2.value );
	
	param += "&" + theForm.where_work.name + "=" + encodeURIComponent( theForm.where_work.value );
	param += "&" + theForm.pre_employer.name + "=" + encodeURIComponent( theForm.pre_employer.value );
	param += "&" + theForm.comments.name + "=" + encodeURIComponent( theForm.comments.value );
	
	param += "&" + theForm.Monday.name + "=" + encodeURIComponent( theForm.Monday.checked );
	param += "&" + theForm.avail_monday.name + "=" + encodeURIComponent( theForm.avail_monday.value );
	param += "&" + theForm.Tuesday.name + "=" + encodeURIComponent( theForm.Tuesday.checked );
	param += "&" + theForm.avail_tuesday.name + "=" + encodeURIComponent( theForm.avail_tuesday.value );
	param += "&" + theForm.Wednesday.name + "=" + encodeURIComponent( theForm.Wednesday.checked );
	param += "&" + theForm.avail_wednesday.name + "=" + encodeURIComponent( theForm.avail_wednesday.value );
	param += "&" + theForm.Thursday.name + "=" + encodeURIComponent( theForm.Thursday.checked );
	param += "&" + theForm.avail_thursday.name + "=" + encodeURIComponent( theForm.avail_thursday.value );
	param += "&" + theForm.Friday.name + "=" + encodeURIComponent( theForm.Friday.checked );
	param += "&" + theForm.avail_friday.name + "=" + encodeURIComponent( theForm.avail_friday.value );
	param += "&" + theForm.Saturday.name + "=" + encodeURIComponent( theForm.Saturday.checked );
	param += "&" + theForm.avail_saturday.name + "=" + encodeURIComponent( theForm.avail_saturday.value );
	param += "&" + theForm.Sunday.name + "=" + encodeURIComponent( theForm.Sunday.checked );
	param += "&" + theForm.avail_sunday.name + "=" + encodeURIComponent( theForm.avail_sunday.value );
	
	param += "&" + theForm.whenstart.name + "=" + encodeURIComponent( theForm.whenstart.value );
	param += "&" + theForm.item_image.name + "=" + encodeURIComponent( theForm.item_image.value );
	
	
	
	xmlhttp.open("POST",url,true);
	
	xmlhttp.onreadystatechange=stateChanged2;
	
	
   xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlhttp.setRequestHeader("Content-length", param.length);
   xmlhttp.setRequestHeader("Connection", "close");

   //Make the request
   xmlhttp.send(param);
	}
}


function stateChanged2()
{
	if (xmlhttp.readyState==4)
	{	
	alert("Insertion Successful");
	document.getElementById('display').innerHTML = xmlhttp.responseText;   
	}
}


function setId(id)
{
	document.getElementById("ifram").style.display='block';
	document.getElementById("id_no").value=id;		
}


   function set_Datet(t)
   {
    // alert('Selected='+t);
	 document.getElementById('whenstart').value=t;
	
	  document.getElementById('display_calender').style.display='none';
   }
   
   function goPrevious(currentYear)
   {
    xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	  
var month=parseInt(document.getElementById('month').value)-1; 
var year=parseInt(document.getElementById('year').value);

if(month < 1)
{
  year=year-1;
}
	
if(year >= currentYear)
  { 
  	
	if(month<1)
	  {
	  month=12;
	  document.getElementById('year').value=year; 
	  }
	  
  
	document.getElementById('month').value=month;
	
	url="calendar.php";							
	url=url+"?year="+document.getElementById('year').value;	
	url=url+"&month="+month; 	
	url=url+"&sid="+Math.random();		
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
  }
}
   
 
 function Go(tr)
 {
    xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	
	url="calendar.php";		
						
	url=url+"?year="+document.getElementById('year').value;
	url=url+"&month="+document.getElementById('month').value; 		
	url=url+"&sid="+Math.random();		
	
	
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
 } 
 
 function goNext()
   {
 
   xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	
	url="calendar.php";		
						
	url=url+"?year="+document.getElementById('year').value;
	
	var month=(parseInt(document.getElementById('month').value)+1); 
	if(month>12)
	  {
	  month=1;
	  document.getElementById('year').value=(parseInt(document.getElementById('year').value)+1); 
	  }
	  
	document.getElementById('month').value=month;
	
	url=url+"&month="+month; 	
	url=url+"&month="+document.getElementById('month').value; 		
	url=url+"&sid="+Math.random();		
	
	
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	  }
   
	
function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
	   document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
	}
}

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	  {
	      // code for IE7+, Firefox, Chrome, Opera, Safari
	       return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
	       // code for IE6, IE5
	       return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
}
