var http = create_request_object(); 

function create_request_object() { 
	if(window.XMLHttpRequest) {
		// client use Firefox, Opera etc - Non Microsoft product
		try {
			MyHttpRequest = new XMLHttpRequest();
		}
		catch(e) {
			MyHttpRequest = false;
		}
	}
	else if(window.ActiveXObject) {
		// client use Internet Explorer
		try {
			MyHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try{
				MyHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				MyHttpRequest = false;
			}
		}
	}
	else{
		MyHttpRequest = false;
	}
	if(!MyHttpRequest) {
		alert("cant create activex htttp request object");
	}
	return MyHttpRequest;
}

function get_jobs(job_id) {  
	http.open("get", "common/AJAX/jobs.php?id=" + job_id , true); 
	http.onreadystatechange = get_jobs_response; 
	http.send(null);
} 
function get_jobs_response() { 
	if(http.readyState == 4 && http.status == 200){ 
		var response = http.responseText;
		if(response) { 
			document.getElementById("jobs").innerHTML = response;
		}
	}
}

// JavaScript Document
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Search boxes
function submitsearch() {
	if ((document.searchform.query.value == "Search") || (document.searchform.query.value == "")) {
		alert("Please enter a search word before pressing 'GO'.");
		return false;
	}
	else {
		return true;
	}
}
function openwindow(path){
  	open(path,'windowname','width=800,height=600,scrollbars,resizable');
    //w.document.write("This is a new window");
	//w.document.write("<img src='" + document.getElementById('building_image').value + "'>");
	//w.document.write(document.getElementById('building_image').value);
}
function ccsubmitresize() {
	document.ccresizeform.submit();
	showccprocessing();
}

function showccprocessing() {
	//setTimeout(showsearchloading,1000); 
	if (! document.getElementById('spinnerdiv') || ! document.getElementById('searchimage')) {
		
		spinnerdiv = document.createElement('div');
		spinnerdiv.setAttribute('id', 'spinnerdiv');
		spinnerdiv.setAttribute('class', 'spinner');
		spinnerdiv.setAttribute('className', 'spinner');
		spinnerdiv.innerHTML = "<h1>Processing ...</h1>";
	
		document.body.appendChild(spinnerdiv);
	}
}
function clearsearch() {
	if (document.searchform.query.value == "Search") {
		window.document.searchform.query.value = "";
	}
}
function fillsearch() {
	if (document.searchform.query.value == "") {
		window.document.searchform.query.value = "Search";
	}
}

//Email newsletter boxes
function submit_email() {
	if ((document.email_form.email.value == "Email Address") || (document.email_form.email.value == "")) {
		alert("Please enter your email address before pressing 'Sign up'.");
		return false;
	}
	else {
		return true;
	}
}

function clear_email() {
	if (document.email_form.email.value == "Email address") {
		window.document.email_form.email.value = "";
	}
}
function fill_email() {
	if (document.email_form.email.value == "") {
		window.document.email_form.email.value = "Email address";
	}
}
function reloader(){
	document.getElementsByName('theform')[0].submit();
}
function feedback(feedbacktext){
	if ((feedbacktext != null) && (feedbacktext != "")) {
		alert(feedbacktext);
	}
}

function submitlogin() {
	if (document.loginform.name.value == "Username" || document.loginform.password.value == "Password") {
		alert("Please enter your Username and Password before logging in.");
	}
	else {
		document.loginform.submit();
	}
}

function clearfill_username() {
	if (document.loginform.name.value == "Username") {
		window.document.loginform.name.value = "";
	}
	else if (document.loginform.name.value == "") {
		window.document.loginform.name.value = "Username";
	}
}
function clearfill_password() {
	if (document.loginform.password.value == "Password") {
		window.document.loginform.password.value = "";
	}
	else if (document.loginform.password.value == "") {
		window.document.loginform.password.value = "Password";
	}
}

function submitlogin_home() {
	if (document.loginform_home.name.value == "Username" || document.loginform_home.password.value == "Password") {
		alert("Please enter your Username and Password before logging in.");
	}
	else {
		document.loginform_home.submit();
	}
}

function clearfill_username_home() {
	if (document.loginform_home.name.value == "Username") {
		window.document.loginform_home.name.value = "";
	}
	else if (document.loginform_home.name.value == "") {
		window.document.loginform_home.name.value = "Username";
	}
}
function clearfill_password_home() {
	if (document.loginform_home.password.value == "Password") {
		window.document.loginform_home.password.type = "password";
		window.document.loginform_home.password.value = "";
	}
	else if (document.loginform_home.password.value == "") {
		window.document.loginform_home.password.type = "text";
		window.document.loginform_home.password.value = "Password";
	}
}
function validate_knowledgehub_contact_form(comment_email, comment_text){
	if(!validate_email(comment_email, "You must enter a valid email address.")){
		return false;
	}
	if(!validate_required(comment_text, "You must enter a comment")){
		return false;
	}
}
function validate_email(field, alerttxt){
	with (field){
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		doubleQotPos = value.lastIndexOf("\"");
		singleQotPos = value.lastIndexOf("'");
		
		if (apos < 1 || dotpos-apos < 2 || value == null || value == "" || doubleQotPos >= 0 || singleQotPos >= 0){
			alert(alerttxt);
			return false;
		} else { return true; }
	}
}
function validate_required(field, alerttxt){
	with (field){
		doubleQotPos = value.lastIndexOf("\"");
		singleQotPos = value.lastIndexOf("'");
		if (value == null || value == "" || doubleQotPos >= 0 || singleQotPos >= 0){
			alert(alerttxt);
			return false;
		} else { return true; }
	}
}