window.addEvent('domready', function() {


	
	var btnmore = $('btn-more');
	var btnless = $('btn-less');
	var advanced = $('advanced');
	var categories = $('categories');
	var joblist = $('joblist');
	
	
	if($('webdescription')) {
		
		$('webdescription').fade('hide');
		
		if($('fieldexpand')) {
			$('fieldexpand').addEvents({
										 
				"click": function(event) {
					event.stop();		
					$('webdescription').setStyle("display","block");
					$('webdescription').fade('in');
					$('fieldexpand').fade('out');
				}
	
			});
		}
		
	}
	
	
	if($('jobtoolcontainer')) {
		$('pagination').setStyle("display","none");
	}
		//id="pagination" 	
	
	
	if (categories) {
		//categories.fade(0);
	}
	if(btnless) {
		btnless.fade(0);
	}
	/*if(joblist) {
		joblist.fade(0);
	}*/
	
	if($('keyword')) {
	$('keyword').addEvent('keydown', function(event) {
      if(event.key != "enter") {
         updateSearch();
      }
   });
	}


	if($('btn-results')) {
	
		
		
		$('jobsearchform').addEvents({
									 
						
			"keydown": function(event) {
				if(event.key == "enter") {
					 event.stop();
					 listJobs();
				};
			},
			
			"submit": function(e) {
				e.stop();
				listJobs();
			}

			
			
		});


	
	}
	
	var morph = new Fx.Morph('advanced');
	
	if ($('joblist')) {
	var scroll = new Fx.Scroll('joblist', {
		wait: false,
		duration: 2500,
		offset: {'x': -200, 'y': -50},
		transition: Fx.Transitions.Quad.easeInOut
	});
	}


	if (document.getElementById("cattotal")) {
		windowHeight = document.getElementById("cattotal").value;
	} else {
		windowHeight = 0;
	}
	
	if (btnmore) {
		btnmore.addEvent('click', function(e) {
			
			var fx = new Fx.Tween(advanced,{
				duration: 500,
				link: 'cancel',
				onComplete: function(){
					/*categories.fade(1); // fade in the sub menu
					btnmore.fade(0);
					btnless.fade(1)*/
				}
			});
			e.stop();
			
			fx.cancel();
			fx.start('height', windowHeight + 'px'); //change the width of the menu holder	
		
		
		});
	}
	
	/*if (btnless) {
		btnless.addEvent('click', function(e) {
			
			var fx = new Fx.Tween(advanced,{
				duration: 500,
				link: 'cancel',
				onComplete: function(){
					btnmore.fade(1);
					btnless.fade(0);
					
					for(i=0; i<document.jobsearch.elements.length; i++)
					{
						
						var fieldname = document.jobsearch.elements[i].name;
						if(fieldname.indexOf("categoryid") != -1)
						{
							document.getElementById(fieldname).checked = false;
						}
						
					}
					updateArray();
					updateSearch("clicked");
					
					 // fade in the sub menu
				}
			});
			e.stop();
			
			categories.fade(0);
			fx.cancel();
			fx.start('height','0px'); //change the width of the menu holder	
		
		
		});
	}
	*/
	/*if ($('catarray')) {
		if (document.getElementById("catarray").value != "") {
			
			
			
			var fx = new Fx.Tween(advanced,{
				duration: 500,
				link: 'cancel',
				onComplete: function(){
					
				}
			});
			
			
			
			fx.cancel();
			fx.start('height', windowHeight + 'px'); //change the width of the menu holder	
		}
	}*/
	
	if ($('listsent')) {
			if(document.getElementById("listsent").value == 1) {
				
				updateSearch();
				listJobs();
			}
	}	
	
	
	
	myCal = new Calendar({ startDate: 'm/d/Y' });
	myCal = new Calendar({ applicationDeadline: 'm/d/Y' });
	
	
	
	
}); //domready//
	
	
	function updateArray(x) {
		
		catset = 0;
		
		var catarray = "";
		
		for(i=0; i<document.jobsearch.elements.length; i++)
		{
			
			var fieldname = document.jobsearch.elements[i].name;
			
			if(fieldname.indexOf("categoryid") != -1)
			{
				if (document.getElementById(fieldname).checked == true)
				{
					catset = 1;
					catarray = catarray + document.jobsearch.elements[i].value + ",";
				}
			}
			
		}
		
		if (catset == 1) {
			catarray = "," + catarray;
		}
		
		
		document.getElementById("catarray").value = catarray;
		if($('jobnumber')) {
			
		updateSearch();
		}
		
	}
	
	function updateSearch(x){
		
		var http = false;				
		
		if ($('listsent')) {
		document.getElementById("listsent").value = 0;
		}
		
		if (x != "clicked") {
		$('joblist').fade(.2);
		}
		
		if(navigator.appName == "Microsoft Internet Explorer") {
		  http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
		  http = new XMLHttpRequest();
		}
		
		keyword = document.getElementById("keyword").value;
		province = document.getElementById("province").value;
		catarray = document.getElementById("catarray").value;
		
		
		http.open("GET", "/_classes/apps/jobcount.cfm?name=" + keyword + "&province=" + province + "&catarray=" + catarray);
		http.onreadystatechange=function() {
		  if(http.readyState == 4) {
			myobj = document.getElementById("jobnumber");
			myobj.innerHTML = http.responseText;	
			
			if (http.responseText == "Done"){
				//clearInterval(xx);
			}
		  }
		}
		http.send(null);
		
	}

	function listJobs() {
		
		
		
		$('joblist').fade(1);
		
		
		var myFx = new Fx.Scroll(window).toElement('joblist');
		
		if ($('listsent')) {
		document.getElementById("listsent").value = 1;
		}
		
		var http = false;				
		
		if(navigator.appName == "Microsoft Internet Explorer") {
		  http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
		  http = new XMLHttpRequest();
		}
		
		keyword = document.getElementById("keyword").value;
		province = document.getElementById("province").value;
		catarray = document.getElementById("catarray").value;
		
		http.open("GET", "/_classes/apps/joblist.cfm?name=" + keyword + "&province=" + province + "&catarray=" + catarray);
	
		http.onreadystatechange=function() {
		  if(http.readyState == 4) {
			
			myobj = document.getElementById("joblist");
			myobj.innerHTML = http.responseText;	
			//document.location.href='#joba';
			
			
			

		
			if (http.responseText == "Done"){
				//clearInterval(xx);
			}
		  }
		}
		http.send(null);
		
	}
	
	disablecopy = 0;
	
function limitText(limitField, limitCount, limitNum, newjob) {
	
	
	
	fieldvalue = limitField.value.replace("  ", "~");
	totalspaces = (fieldvalue.split(" ").length);
	
	
	var lastPos = limitField.value.length-1;
	//alert(limitField.value.charAt(lastPos));
	
	
	if(fieldvalue.charAt(fieldvalue.length-1) == " ") {
		totalspaces = totalspaces - 1;
	}
	//console.log(limitNum);
	
	
	
	if (totalspaces > limitNum) {
		$(''+limitCount+'').setStyle("color","#a9ae2e");
		$(''+limitCount+'').setStyle("font-weight","bold");
		$(''+limitCount+'').value = Math.abs(limitNum - totalspaces) + " extra words @ $1/word";
	} else {
		$(''+limitCount+'').setStyle("color","#000000");
		$(''+limitCount+'').setStyle("font-weight","normal");
		$(''+limitCount+'').value = (limitNum - totalspaces) + " available words remaining";
	}
	if(limitNum == 120) {
		$('wordcount_print').value = totalspaces;
		if(newjob == 1 && disablecopy != 1) {
			document.getElementById("jobDescription").value = document.getElementById("jobDescription_print").value;
			$('wordcount_online').value = totalspaces;
			
		}
	} 
	
	if(limitNum == 240) {
		$('wordcount_online').value = totalspaces;
	} 
	
	//console.log($('wordcount_online').value + "/" + $('wordcount_print').value);
	
	if(newjob == 1 && disablecopy != 1) {
		document.getElementById("jobDescription").value = document.getElementById("jobDescription_print").value;
	}
	
	if(newjob == 2) {
		disablecopy = 1;
	}
	
}


function confirmDelete(delUrl) {
  if (confirm("Are you sure you want to delete this?")) {
    document.location = delUrl;
  }
}

function showform()
{
	document.getElementById("myreg").style.display = 'none';	
	document.getElementById("passwordscreen").style.display = 'none';
	document.getElementById("error").style.display = 'none';	
	document.getElementById("confirmation").style.display = 'none';	
	document.getElementById("mylogin").style.display = '';
}

function showregistration()
{	
	document.getElementById("mylogin").style.display = 'none';
	document.getElementById("passwordscreen").style.display = 'none';
	document.getElementById("error").style.display = 'none';	
	document.getElementById("confirmation").style.display = 'none';	
	document.getElementById("myreg").style.display = '';
}

function showpassword()
{
	document.getElementById("myreg").style.display = 'none';
	document.getElementById("mylogin").style.display = 'none';	
	document.getElementById("error").style.display = 'none';	
	document.getElementById("confirmation").style.display = 'none';
	document.getElementById("passwordscreen").style.display = '';
}

function showconfirmation()
{
	document.getElementById("myreg").style.display = 'none';
	document.getElementById("mylogin").style.display = 'none';
	document.getElementById("passwordscreen").style.display = 'none';
	document.getElementById("error").style.display = 'none';	
	document.getElementById("confirmation").style.display = '';
}

function showerror()
{
	document.getElementById("myreg").style.display = 'none';
	document.getElementById("mylogin").style.display = 'none';
	document.getElementById("passwordscreen").style.display = 'none';
	document.getElementById("confirmation").style.display = 'none';
	document.getElementById("error").style.display = '';
}

function showconfirmation()
{
	document.getElementById("myreg").style.display = 'none';
	document.getElementById("mylogin").style.display = 'none';
	document.getElementById("passwordscreen").style.display = 'none';	
	document.getElementById("error").style.display = 'none';
	document.getElementById("confirmation").style.display = '';
}



