<!--
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
function popup(a,width,height,menubar)	{
	if(typeof menubar == "undefined")
		window.open( a, "Humres","status=1,height="+ height +",width="+ width +",resizable=1,scrollbars=1");
	else
		window.open( a, "Humres","status=1,height="+ height +",width="+ width +",resizable=1,scrollbars=1,menubar=1");
}
function checkLoginForm()
{
	var required = {
	"txtUsername": "Username cannot be left blank",
	"txtPassword": "Password cannot be left blank"
	};
	for (var i in required) 
	{
		var el = document.getElementById(i);
		if (!el.value) 
		{
			alert(required[i]);
			//el.focus();	
			return false;
		}
	}
}
function checkJobForm()
{
	var required = {
	"title": "Job title cannot be left blank",
	"reference": "Reference number cannot be left blank",
	"location" : "Location cannot be left blank",
	"location2" : "Location cannot be left blank",
	"currency" : "Currency cannot be left blank",
	"salaryfrom" : "Salary(From) cannot be left blank",
	"salaryto" : "Salary(To) cannot be left blank",
	"period" : "Salary period cannot be left blank"
	};
	for (var i in required) 
	{
		var el = document.getElementById(i);
		if (!el.value) 
		{
			alert(required[i]);
			//el.focus();	
			return false;
		}
	}
}
function checkRSSForm()
{
	var required = {
	"title": "RSS title cannot be left blank",
	"url": "RSS url cannot be left blank"
	};
	for (var i in required) 
	{
		var el = document.getElementById(i);
		if (!el.value) 
		{
			alert(required[i]);
			//el.focus();	
			return false;
		}
	}
}
function checkNewsForm()
{
	var required = {
	"atitle": "Admin title cannot be left blank"
	};
	for (var i in required) 
	{
		var el = document.getElementById(i);
		if (!el.value) 
		{
			alert(required[i]);
			//el.focus();	
			return false;
		}
	}
}
function checkUserForm()
{
	var required = {
	"fname": "First name cannot be left blank",
	"email": "Email address cannot be left blank",
	"username": "Username cannot be left blank"
	};
	for (var i in required) 
	{
		var el = document.getElementById(i);
		if (!el.value) 
		{
			alert(required[i]);
			//el.focus();	
			return false;
		}
	}
	evalue=document.getElementById ('email').value;
    if(evalue.length &&(evalue.indexOf("@")==0||evalue.indexOf("@")==-1||evalue.indexOf(".")==-1||evalue.indexOf(".")==0))
    {
        alert("Invalid E-Mail address.\n"+"Valid Format: email@domainname.com");
        //document.getElementById('email').focus();
        return false;
    }
	if(document.getElementById('uid').value.trim() =='')
	{
		if(document.getElementById('password').value.trim() =='')
		{
			alert('Password cannot be left blank');
			return false;
		}
	}
}
function checkPageForm()
{
	var required = {
	"atitle": "Admin title cannot be left blank",
	"ptitle": "Page title cannot be left blank"
	};
	for (var i in required) 
	{
		var el = document.getElementById(i);
		if (!el.value) 
		{
			alert(required[i]);
			//el.focus();	
			return false;
		}
	}
}
function checkname(username)
{
	if(username=='')
	{
		alert('Please enter a username');
		return false;
	}
	else
		popup('check.php?un='+username,400,120);
}
function showRoles(sector)
{
	sector=sector.trim();
	if(sector=='')
		return;
	var ajax = getXMLHttpRequest();
	var randomnumber=Math.floor(Math.random()*1000);
	var url = "/getroles.php?t="+ randomnumber +"&id="+sector; 
	ajax.open("GET", url, false);
	ajax.send(null);
	//alert(url);
	var data='';
	var selectbox=document.getElementById("role");
	try
	{
		data = ajax.responseText;
		//alert(data);
		if(data != '')
		{
			removeOption(selectbox);
			fillOption(selectbox,data);
		}
		else
		{
			removeOption(selectbox);	
		}
			
	}
	catch (ex)
	{}
}
function showLocations(sector)
{
	sector=sector.trim();
	if(sector=='')
		return;
	var ajax = getXMLHttpRequest();
	var randomnumber=Math.floor(Math.random()*1000);
	var url = "/getlocations.php?t="+ randomnumber +"&id="+sector; 
	ajax.open("GET", url, false);
	ajax.send(null);
	//alert(url);
	var data='';
	var selectbox=document.getElementById("location2");
	try
	{
		data = ajax.responseText;
		//alert(data);
		if(data != '')
		{
			removeOption(selectbox);
			fillOption(selectbox,data);
		}
		else
		{
			removeOption(selectbox);	
		}
			
	}
	catch (ex)
	{}
}
function generateFeeds()
{
	if(confirm('Do you really want to re-generate RSS feeds?\nNOTE:\nThis may take a few minutes.'))
	{
		document.getElementById('generatefeeds').value='true';
		document.getElementById('form1').submit();
	}
	else
		return;
}
/////////////////////////////////////
//gets called from fillOption function
function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}
function removeOption(selectbox)
{
	//alert('removeOption');
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		if(selectbox.options[i].value != '')
			selectbox.remove(i);
	}
}
function fillOption(selectbox,data)
{
	//alert('fillOption');
	var data_arr=Array();
	data_arr = data.split(',');
	for (x in data_arr)
	{
		temp = data_arr[x];
		temp_arr = temp.split('^');
		addOption(selectbox,temp_arr[0],temp_arr[1]);
	}
}
///////////////////////////////////////
//#### Validate URL ####
function getValidURL(){
	setTitleFields('url', getValidURL_Do(document.getElementById('url').value, false).toLowerCase(), true);
}
function getValidURL_Do(sFormVal, isFile){
	var validChars 			= "abcdefghijklmnopqrstuvwxyz0123456789()[]"
	var validCharsExtended 	= "_-" + (isFile?".":"")
	var invalidReplacement 	= "_"
	
	//Replace non-valid characters
	var tmpURL = sFormVal.toLowerCase()
	var tmpNewURL = ''
	if(tmpURL!=''){
		for(var i=0;i<tmpURL.length;i++){
			if(validChars.indexOf(tmpURL.substring(i, i+1)) == -1 && validCharsExtended.indexOf(tmpURL.substring(i, i+1)) == -1){ tmpNewURL += invalidReplacement }
			else{ tmpNewURL += tmpURL.substring(i, i+1) }
		}
	}
	//trim extended characters
	var tmpURL = tmpNewURL
	var tmpNewURL = ''
	for(var i=0;i<tmpURL.length;i++){
		if(!(tmpURL.substring(i, i+1) == invalidReplacement && tmpURL.substring(i+1, i+2) == invalidReplacement)){ tmpNewURL += tmpURL.substring(i, i+1) }
	}
	for(var i=0;i<tmpNewURL.length;i++){
		if(validCharsExtended.indexOf(tmpNewURL.substring(i, i+1)) == -1){ tmpNewURL = tmpNewURL.substring(i); break; }
	}
	for(var i=tmpNewURL.length-1;i>=0;i--){
		if(validCharsExtended.indexOf(tmpNewURL.substring(i, i+1)) == -1){ tmpNewURL = tmpNewURL.substring(0, i+1); break; }
	}
	
	return tmpNewURL;
}
function setTitleFields(elem, elemTitle, elemOverwrite){
	if(document.getElementById(elem)){
		if(elemOverwrite == null){ elemOverwrite = false }
		if(document.getElementById(elem).value == '' || elemOverwrite){
			document.getElementById(elem).value = elemTitle;
		}
	}
}
//#### Change TabMenu options ####
function tabMenu_show(tabId){
	try {
		var iTab = 1
		while(document.getElementById('tabMenu_Div' + iTab) != null && document.getElementById('tabMenu_Tab' + iTab) != null){
			document.getElementById('tabMenu_Div' + iTab).style.display = 'none';
			document.getElementById('tabMenu_Tab' + iTab).className = 'tabMenu_Tab';
			iTab++
		}
		document.getElementById('tabMenu_Div' + tabId).style.display = 'block';
		document.getElementById('tabMenu_Tab' + tabId).className = 'tabMenu_TabClicked';
	}
	catch(e){}
}
//#### Copy URL to clipboard ####
function copyURLToClipboard(){
	var txtCopy = '';
		txtCopy += document.getElementById('spn_parentPath').innerHTML;
		txtCopy += document.getElementById('url').value;
		txtCopy += document.getElementById('spn_extensionPath').innerHTML;
		txtCopy = txtCopy.replace(/\/\//,"/");
	try
	{
		window.clipboardData.setData("Text", txtCopy);	
	}
	catch (err)
	{
		alert('This feature is only supported on Internet Explorer.');
	}
	
}
//-->