


	
function ShowPopup(hoveritem, title, helpText)
{
 var hp = document.getElementById("hoverpopup");
 var title = document.getElementById("popUpTitle");
 var body = document.getElementById("popUpDescript");
 
 if(hp == null) return;
 if(title == null) return;
 if(body == null) return;
 title.innderHTML = title;
 body.innerHTML = helpText;
 
// Set position of hover-over popup
// Set popup to visible
hp.style.visibility = "Visible";
}

function HidePopup()
{
hp = document.getElementById("hoverpopup");
hp.style.visibility = "Hidden";
}



function getNumOfJobsProcessed(){
	
	var xmlHttp = new Ajax.Request(getSite(document.URL)+"/logic/numOfJobs.php",{
		method: "post",
		parameters: "",
		evalScripts: true,
		onComplete: function(){
			
			if(xmlHttp.responseIsFailure()){
				alert("Error: status = " + xmlHttp.transport.status);
			}else{
			//alert(xmlHttp.transport.responseText);
			$('njCount').innerHTML = "More than "+ xmlHttp.transport.responseText +" Opportunities Found Since May 1st 2009!";
				
			}
		}});
}



function findSelectedCity(){
	
 var x=$('selectCity');
	city = x.options[x.selectedIndex].value;
	
	$('scrollingCity').innerHTML = " ";
	$('spinner').innerHTML = "<img src='http://www.natsjobs.com/images/spinning-wait-icons/wait30trans.gif' width='30' height='30'>";

	var xmlHttp = new Ajax.Request(getSite(document.URL)+"/logic/getjobsbycity.php?city="+city,{
		method: "post",
		parameters: Form.serialize($('cityForm')),
		evalScripts: true,
		onComplete: function(){
			
			if(xmlHttp.responseIsFailure()){
				alert("Error: status = " + xmlHttp.transport.status);
			}else{
			//alert(xmlHttp.transport.responseText);
				var text = xmlHttp.transport.responseText;
				//$('jobsbycity').innerHTML = "<marquee behavior='scroll' direction='up' scrolldelay='300'>"+text+"</marquee>";
				$('spinner').innerHTML = "";
				$('scrollingCity').innerHTML = text;
			}
		}});
	}


function changeAllCities(){

		var city = $('selectedCity1').options[$('selectedCity1').selectedIndex].value;
		$('selectedCity2').value = city;
		$('selectedCity3').value = city;
}	

var citiesNames = 0;

function getSite(url){

	var off;
	off = url.indexOf("//");
	if(off > 0){
		off+=2;
		off = url.indexOf("/", off);
		if(off > 0){
		var str = url.substring(1,off);		
			return url.substring(0,off);
		}
	}
	return "http://natsnewjobs.com";
}

function createCityDropDownList(feedNum){
	

	var divTag = "cityListDiv" + feedNum;
	var onSelect = "";
	if(feedNum == 1){
		onSelect = ' onchange="changeAllCities();" ';
	}
	if(citiesNames == 0){
		var xmlHttp = new Ajax.Request(getSite(document.URL)+"/logic/getCitys.php",{
			method: "post",
			parameters: "",
			evalScripts: true,
			onComplete: function(){
				
				if(xmlHttp.responseIsFailure()){
					alert("Error: status = " + xmlHttp.transport.status);
				}else{
			//	alert(document.URL + " " +xmlHttp.transport.responseText);
					var text = xmlHttp.transport.responseText;
					citiesNames = text; 
					$(divTag).innerHTML = "<b>Select city #" + feedNum + ": </b><select  id='selectedCity" + feedNum+"' name='city' style='width: 135px' "+onSelect+"><option value='0'>Select City</option>" + text + "</select>";
					

				}
			}});
		}else{
			var text = citiesNames;
			$(divTag).innerHTML = "<b>Select city #" + feedNum + ": </b><select  id='selectedCity" + feedNum+"' name='city' style='width: 135px' "+onSelect+"><option value='0'>Select City</option>" + text + "</select>";		
		}
		
	}

	function goToNatsJobCenter(url, jobID, email){
		addJobIdToFavourite(jobID, email);
		parent.location.href=url;
	}
	
	function addJobIdToFavourite(jobID, email){
			var xmlHttp = new Ajax.Request(getSite(document.URL)+"/logic/natHelper.php",{
			method: "post",
			parameters: "jobID="+jobID+"email="+email,
			evalScripts: true,
			onComplete: function(){
				
				if(xmlHttp.responseIsFailure()){
					alert("Error: status = " + xmlHttp.transport.status);
				}else{
			//	alert(document.URL + " " +xmlHttp.transport.responseText);
					var text = xmlHttp.transport.responseText;
					citiesNames = text; 
			//		$(divTag).innerHTML = "<b>Select city #" + feedNum + ": </b><select  id='selectedCity" + feedNum+"' name='city' style='width: 135px' "+onSelect+"><option value='0'>Select City</option>" + text + "</select>";
					

				}
			}});		
	}
	
	
				
	function downloadOutlook(){
			var date = getValue("FollowupDate");
			var xmlHttp = new Ajax.Request(getSite(document.URL)+"/logic/outlook.php",{
				method: "post",
			parameters: Form.serialize($('jobHistoryForm')),
			evalScripts: true,
			onComplete: function(){
				
				if(xmlHttp.responseIsFailure()){
					alert("Error: status = " + xmlHttp.transport.status);
				}else{
					updateHistory("Added Followup meeting in Outlook ("+  date + ")");
				}
				window.location=xmlHttp.transport.responseText;
				storeJobHistory();
				
			}});			
	}
	
function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }

		
	function isInteger (s)
   {
      var i;

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);
		 if(c == '-') 
		 	continue;
         if (!isDigit(c)) return false;
      }

      return true;
   }
   

	function storeJobHistory(){
			var xmlHttp = new Ajax.Request(getSite(document.URL)+"/logic/storeJobHistory.php",{
			method: "post",
			parameters: Form.serialize($('jobHistoryForm')),
			evalScripts: true,
			onComplete: function(){
				
				if(xmlHttp.responseIsFailure()){
					alert("Error: status = " + xmlHttp.transport.status);
				}else{
					var str = "" + xmlHttp.transport.responseText;
//alert(str);					
					str = str.replace(/^\s+|\s+$/g, '');
								
					if(isInteger(str)){
//alert("action -> set actionID " + str);					
						setValue('actionID', str);
					}
				}
			}});		
	}
	

	
	function changeCity(){
	
		changeTheCity(false);
	}
	var paid = "trial";
	function doCities(){
		paid = "paid";
		changeTrialCity();
	}
	function changeTrialCity(){
			
		var friendEmail = $('optionb').value;
		var friend2Email = $('optionc').value;
		var msg = "";
		var trial = "natsjobs";
		var email = $('email').value;
		if(!checkEmail(email)){
			$('email').focus();
			return;
		}
		
		if((friendEmail.length > 4) || (friend2Email.length > 4)){
			if((friendEmail==friend2Email) ||
				(email==friend2Email) ||
				(email==friendEmail)) {
				alert("Two E-mail address are the same. Please specify different E-mail address");
				 return;
			}
		}
		
		if((friendEmail.length > 3) || (friend2Email.length > 3)){
			if(friendEmail.length > 3){
				if(!checkEmail(friendEmail)){
					$('optionb').focus();
					return;
				}
			}else{
				friendEmail = "";
			}
			
			if(friend2Email.length > 3){
				if(!checkEmail(friend2Email)){
					$('optionc').focus();
					return;
				}
			}else{
				friend2Email = "";
			}
			// make sure that if one is blank it is friend2
			if(friend2Email.length > friendEmail.length){
				//swap them
				var tmp = friendEmail;
				friendEmail = friend2Email;
				friend2Email = tmp;
			}
			trial = "tellafriend";
			msg = "<p>I'm using a new service that e-mails me a list of jobs every a day.<br>";
			msg += "The service searches over 7,000 job sites so I don't have to.<br><br>";
			msg += "It took 1 minute to signup and it's free to try. I encourage you to try it by clicking on: <a href='http://www.natsNewJobs.com'>http://www.natsNewJobs.com</a> <br><br>";		
			msg += "<p>Your friend,<br>";
			msg +=$('firstName').value+" "+$('lastName').value;
			msg += "<br>A member of Nats Jobs.com</p><p><br><br>Jobs. Sent to you. Every day. Simple!</p>";
			
		}else{
			friendEmail = "";
			msg = "";
		}
		dochangeTrialCity(msg, friendEmail, friend2Email, trial);
	}

	function changeWQSBTrialCity(){
		dochangeTrialCity($('program').value,$('gradDate').value,$('attendance').value, "WQSB");
	}
	
	
	
	function dochangeTrialCity(optiona, optionb, optionc, promo){
		// make sure all cities are unique
		var email = $('email').value;
		if(!checkEmail(email)){
			$('email').focus();
		
		
		}
		var script = "updateFeeds.php";

		var city = new Array(3); 
		 city[0] = $('selectedCity1').options[$('selectedCity1').selectedIndex].value;
		 city[1] = $('selectedCity2').options[$('selectedCity2').selectedIndex].value;
		 city[2] = $('selectedCity3').options[$('selectedCity3').selectedIndex].value;
		var area = new Array(3);
		area[0] = $('area1').options[$('area1').selectedIndex].value;
		area[1] = $('area2').options[$('area2').selectedIndex].value;
		area[2] = $('area3').options[$('area3').selectedIndex].value;
		
		if((city[0] == 0) && (city[1] == 0) && (city[2] ==0) &&
			(area[0] == 0) && (area[1] == 0)  && (area[2] == 0)) {
			alert("Please select the cities that you are interested in receiving e-mails alerts from.");
			$('selectedCity1').focus=true;
			return; 
		}
		
		if(((area[0] != 0) && (city[0] == 0))||
		   ((area[1] != 0) && (city[1] == 0))||
		   ((area[2] != 0) && (city[2] == 0)))
		{
			alert("You have selected a filter for a city, but you have not selected a city. Please select the city and then any filters for that city.");
			return; 
		}
	/*	if(city[0] == city[1]){
			city[1] = 0;
		}
		if(city[0] == city[2]){
			city[2] = 0;
		}
		if(city[1] == city[2]){
			city[2] =0;
		} going to allow multiple cities so they can have different areas from each city*/
	
	// should have 3 unique feeds
		//add them for this user. 
		
			
			script = "updatetrial.php";

			
			var params = "&first="+$('firstName').value+"&last="+$('lastName').value+"&area1="+area[0]+"&area2="+area[1]+"&area3="+area[2]+"&paid="+paid;
			var params2 = "?jobID="+$('jobID').value+"&optiona="+optiona+"&optionb="+optionb+"&optionc="+optionc+"&promo="+promo+"&email="+email+"&city1="+city[0]+"&city2="+city[1]+"&city3="+city[2]+params;
		
//alert(getSite(document.URL)+"/logic/"+script+params2+params);
			var xmlHttp = new Ajax.Request(getSite(document.URL)+"/logic/"+script+params2+params,{
			method: "post",
			parameters: "",
			evalScripts: true,
			onComplete: function(){
			
				if(xmlHttp.responseIsFailure()){
					alert("Error: status = " + xmlHttp.transport.status);
				}else{
				//alert(xmlHttp.transport.responseText);
					var text = xmlHttp.transport.responseText;
				//	alert(text);
				}
			}});
			if($('jobID').value.length > 1)
				alert("An e-mail has been sent to you - It will contain contain a link to the job you requested.");
			else
				alert("An e-mail has been sent to you.\nYou need to click on a link in that email to complete your registration");
			window.location.href="http://tinyurl.com/free-Jobs-Tips-CD"; 

	}
	function changeTheCity(trial){
		// make sure all cities are unique
		var email = $('email').value;
		var script = "updateFeeds.php";
		if(!checkEmail(email)){
			return;
		}
		var city = new Array(3); 
		 city[0] = $('selectedCity1').options[$('selectedCity1').selectedIndex].value;
		 city[1] = $('selectedCity2').options[$('selectedCity2').selectedIndex].value;
		 city[2] = $('selectedCity3').options[$('selectedCity3').selectedIndex].value;
		 
		var area = new Array(3);
		area[0] = $('area1').options[$('area1').selectedIndex].value;
		area[1] = $('area2').options[$('area2').selectedIndex].value;
		area[2] = $('area3').options[$('area3').selectedIndex].value;
		if(((area[0] != 0) && (city[0] == 0))||
		   ((area[1] != 0) && (city[1] == 0))||
		   ((area[2] != 0) && (city[2] == 0)))
		{
			alert("You have selected a filter for a city, but you have not selected a city. Please select the city and then any filters for that city.");
			reutrn 
		}
		 
		/*if(city[0] == city[1]){ // now can have multiple feeds from the same city. 
			city[1] = 0;
		}
		if(city[0] == city[2]){
			city[2] = 0;
		}
		if(city[1] == city[2]){
			city[2] =0;
		} */
		// should have 3 unique feeds
		//add them for this user. 
		
			if(trial){
				script = "updatetrial.php";
			}
			var params = "&area1="+area[0]+"&area2="+area[1]+"&area3="+area[2];
		
			var xmlHttp = new Ajax.Request(getSite(document.URL)+"/logic/"+script+"?email="+email+"&city1="+city[0]+"&city2="+city[1]+"&city3="+city[2]+params,{
			method: "post",
			parameters: "",
			evalScripts: true,
			onComplete: function(){
			
				if(xmlHttp.responseIsFailure()){
					alert("Error: status = " + xmlHttp.transport.status);
				}else{
				//alert(xmlHttp.transport.responseText);
					var text = xmlHttp.transport.responseText;
				//	alert(text);
				}
			}});
			s = $('state').options[$('state').selectedIndex].value;
			a = $('area').options[$('area').selectedIndex].value;
			var params = "origEmail="+origEmail+"&city="+ $('city').value+"&first="+$('firstName').value+"&last="+$('lastName').value+"&email="+$('email').value+"&address="+$('address').value+"&city="+$('city').value+"&state="+s+"&zip="+$('zip').value+"&area="+a;

			var xmlHttp = new Ajax.Request(getSite(document.URL)+"/logic/updateInfo.php?"+params,{
			method: "post",
			parameters: "",
			evalScripts: true,
			onComplete: function(){
				if(xmlHttp.responseIsFailure()){
					alert("Error: status = " + xmlHttp.transport.status);
				}else{
				//alert(xmlHttp.transport.responseText);
					var text = xmlHttp.transport.responseText;

				}
			}});
			alert("Your cities have been entered into Nat's Job Engine");
			window.location.href="http://tinyurl.com/free-Jobs-Tips-CD"; 

	
	}

	function checkEmail(str) {

		var at="@";
		var dot=".";
	
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address");
		   return false;
		}

		if (str.indexOf("..")!=-1){
		   alert("Invalid E-mail Address");
		   return false;
		}

		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address");
		    return false;
		 }

 		 return true;
	}




