
/* ************************* */
// GENERAL AJAX FUNCTIONS
/* ************************* */
window.locale = {
	"language": "en",
	"locale": "en_GB",
	"currencyCode": "GBP",
	"currencySymbol": "\u00a3",
	"baseUrl": ""
}



function checkStrength(password){
	var pwscore = 0;
	var resp = new Array();
	resp[0] = "Very Weak Password";
	resp[1] = "Weak Password";
	resp[2] = "Ok Password";
	resp[3] = "Good Password";
	resp[4] = "Very Good Password";
	resp[5] = "Excellent Password";
 
		if (  password.length>5) pwscore++;
		if (( password.match(/[a-z]/)) && ( password.match(/[A-Z]/))) pwscore++;
		if (  password.match(/\d+/)) pwscore++;
		if (  password.match(/.[!,{,},@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) pwscore++;
		if (  password.length>11) pwscore++;
 	
 	document.getElementById("pwResponse").style.display = "block";
	document.getElementById("pwResponse").innerHTML = resp[pwscore];
}


checked="";
function checkedAll (chkbxs) {
	var aa = document.getElementById('chkbxs');
	 if(checked == false){
        checked = true
     }else{
        checked = false
     }

	for (i=0; i < aa.elements.length; i++){
		aa.elements[i].checked = checked
		if ( aa.elements[i] == i){
		 newArray =  aa.elements.splice(i,1);
		 document.getElementById('jcats').value = aa.elements;
		}
	}

	doJobFilter();
}



function pausecomp(millis){ //pause the script (milliseconds)
	var date = new Date();
	var curDate = null;
	do {curDate = new Date();} 
	while( curDate-date < millis );
} 	

function getHTTPObject() {
	var xhr = false;
		if(window.XMLHttpRequest) {
		//alert('window.XMLHttpRequest');			
		//detect to see if browser allows this method
			var xhr = new XMLHttpRequest();
		//set var the new request
		} else if(window.ActiveXObject) {
			//alert('window.ActiveXObject');
			//detect to see if browser allows this method
			try {
				var xhr = new ActiveXObject("Msxml2.XMLHTTP");
				//alert('Msxml2.XMLHTTP');
			} catch(e) {
				try {
					var xhr = new ActiveXObject("Microsoft.XMLHTTP");
					//alert('Microsoft.XMLHTTP');
				} catch(e) {
					xhr = false;
				}
			}
		}
		return xhr;
}

  
	function checkDisplayName(){
	     httpCodes = getHTTPObject();
				var code = document.getElementById('regusername').value;			 
		    if (httpCodes != null) {
					var queryString = "?action=check_username&username=" + code;
					httpCodes.open("GET", "ajax-functions.php" + queryString, true);
					httpCodes.send(null);
					httpCodes.onreadystatechange = setCodes;
		    }
	} var httpCodes = null;		
	
		function setCodes(){
			if(httpCodes.readyState == 2){
				document.getElementById('validateUsername').innerHTML = "<img src='img/ajax-loader.gif' height='16' width='16' /> checking availability...";
			}	
			if(httpCodes.readyState == 4){
				//document.getElementById('validateUsername').innerHTML = "<img src='img/ajax-loader.gif' height='16' width='16' /> checking availability...";
				document.getElementById('validateUsername').innerHTML = httpCodes.responseText;
			}
		} 
		
	function checkEmail(){
	     httpCodes2 = getHTTPObject();
				var code2 = document.getElementById('email_address').value;			 
		    if (httpCodes2 != null) {
					var queryString = "?action=check_email&email=" + code2;
					httpCodes2.open("GET", "ajax-functions.php" + queryString, true);
					httpCodes2.send(null);
					httpCodes2.onreadystatechange = setCodes2;
		    }
	} var httpCodes = null;		
	
		function setCodes2(){
			if(httpCodes2.readyState == 2){
				document.getElementById('validateEmail').innerHTML = "<img src='img/ajax-loader.gif' height='16' width='16' /> checking for duplicates...";
			}	
			if(httpCodes2.readyState == 4){
				//document.getElementById('validateEmail').innerHTML = "<img src='img/ajax-loader.gif' height='16' width='16' /> checking for duplicates...";
				document.getElementById('validateEmail').innerHTML = httpCodes2.responseText;
			}
		} 		


//show-hide elements
function displayDiv(element){
	elm = document.getElementById(element);
	elm.style.display='block';
}

function hideDiv(element){
	elm = document.getElementById(element);
	elm.style.display='none';
}

function confirm_edit(URL) {
	window.location = URL;
}

function makeSavedRecord(){
	document.getElementById('savetype').innerHTML = '<input type="hidden" name="saved" value="save"> ';
}

function makeDraftRecord(){
	document.getElementById('savetype').innerHTML = '<input type="hidden" name="saved" value="draft"> ';
}

function confirm_del_prompt(URL) {
	if (!confirm("Are you sure that you want to permanently delete this article? \nThe delete process is irreversible!")){	
		return false;
	}else{
		window.location = URL;
	}
}
function confirm_del_user(URL) {
	if (!confirm("Are you sure that you want to permanently delete yourself? \nThe delete process is irreversible and will also delete your feedback score!")){	
		return false;
	}else{
		window.location = URL;
	}
}


function removeStrings(what){
	//alert(what);
	var x = "";
    var tmp = document.getElementById(what).value;
	x = tmp.replace(/[^0-9a-zA-Z \.:,!()?\-\r\n'£]/igm, "");
	x = x.replace(/\http:/ig, "");
	x = x.replace(/\.com/ig, "");
	x = x.replace(/\.co.uk/ig, "");
	x = x.replace(/\.net/ig, "");
	x = x.replace(/www/ig, "");
	x = x.replace(/01/ig, "");
	x = x.replace(/02/ig, "");
	x = x.replace(/07/ig, "");
	x = x.replace(/08/ig, "");
    document.getElementById(what).value = x;
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height){
  if(popUpWin){
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

