var oktosubmit = 0;


function submitter(currpage, param1, param2, param3, param4, param5, param6, param7, param8){
var oktosubmit = 1;
var frm = eval('document.form1');

if(oktosubmit == 1){
url = "index.php?page="+currpage;
if(param1) url = url+"&"+param1;
if(param2) url = url+"&"+param2;
if(param3) url = url+"&"+param3;
if(param4) url = url+"&"+param4;
if(param5) url = url+"&"+param5;
if(param6) url = url+"&"+param6;
if(param7) url = url+"&"+param7;
if(param8) url = url+"&"+param8;
frm.action = url;
frm.submit();
}
}

function submitsearch(currpage, param1, param2, param3, param4, param5, param6, param7, param8){
var oktosubmit = 1;
var frm = eval('document.searchform');

if(oktosubmit == 1){
url = "index.php?page="+currpage;
if(param1) url = url+"&"+param1;
if(param2) url = url+"&"+param2;
if(param3) url = url+"&"+param3;
if(param4) url = url+"&"+param4;
if(param5) url = url+"&"+param5;
if(param6) url = url+"&"+param6;
if(param7) url = url+"&"+param7;
if(param8) url = url+"&"+param8;
frm.action = url;
frm.submit();
}
}



function confirmdelete(objtodelete) {
var b = confirm('Do you want to delete '+objtodelete+'?\nClick \'OK\' to confirm');

if(b)
return 1;
else 
return 0;
}


// add/remove option from using two select boxes

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
{
var newOpt = new Option(theText, theValue);
var selLength = theSel.length;
theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
var selLength = theSel.length;
if(selLength>0)
{
theSel.options[theIndex] = null;
}
}

function moveOptions(theSelFrom, theSelTo, mode)
{

var selLength = theSelFrom.length;
var selectedText = new Array();
var selectedValues = new Array();
var selectedCount = 0;
var i;


// Find the selected Options in reverse order
// and delete them from the 'from' Select.
for(i=selLength-1; i>=0; i--)
{
if(theSelFrom.options[i].selected)
{
selectedText[selectedCount] = theSelFrom.options[i].text;
selectedValues[selectedCount] = theSelFrom.options[i].value;
if(mode==1){
deleteOption(theSelFrom, i);
}
selectedCount++;
}
}


if(mode==0){
// Add the selected text/values in reverse order.
// This will add the Options to the 'to' Select
// in the same order as they were in the 'from' Select.
for(i=selectedCount-1; i>=0; i--)
{
addOption(theSelTo, selectedText[i], selectedValues[i]);
}
}

if(NS4) history.go(0);
}

function transfertohidden(mainsel, hiddentemp){
var mainLength = mainsel.length;

hiddentemp.value = '';
for(i=mainLength-1; i>=0; i--)
{
if(i == mainLength-1){
hiddentemp.value = mainsel.options[i].value;
}
else{
hiddentemp.value = hiddentemp.value +','+ mainsel.options[i].value;
}
}
}


function expandcollapse(elem){

if(document.getElementById(elem).className   == "minimize")
document.getElementById(elem).className = "maximize";
else
document.getElementById(elem).className = "minimize";
}


function expand(elem, elem2){
document.getElementById(elem).className = "maximize";
document.getElementById(elem2).className = "minimize";
}



function checkIfEmpty(fld, req){
error = sEmpty(fld, req);
}

function showprintablepage() {
var WinOpen = window.open('', '', 'left=0, top=0, width=0, height=0, visible=false, toolbar=0, scrollbars=1, status=0');
var css = '<style type="text/css">@import url("themes/hrms/stylesheets/reports.css");</style>';
var hdr = document.getElementById('head');
var printer = document.getElementById('report');
var content = hdr.innerHTML+printer.innerHTML;

WinOpen.document.write(css+'<br /><table border=0><tr><td>'+content+'</td></tr></table>');
WinOpen.document.close();
WinOpen.print();
}


function isNumeric(elem, helperMsg){
	var error = "";
	var numericExpression = /^[0-9]+$/;
	
	if(elem.value.length == 0) {
		elem.style.background = 'Yellow';
		error = 'Please Provide a Contact Number';
		elem.focus();
	}
	else if(!elem.value.match(numericExpression)){
		elem.style.background = 'Yellow';
		error = elem.value+' is not a number';
		elem.focus();
	} else {
		elem.style.background = 'White';
	}
return error;
}


function EnableSaveIfFilled(elem, btnelem){
	if(elem.value != '') 
		document.getElementById(btnelem).disabled=false; 
	else 
		document.getElementById(btnelem).disabled=true;
}


function CheckIfEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg+' has not been filled in');
		elem.focus();
		return false;
	
	}else{
		return true;
	}

}


function trim(s)
{
	return s.replace(/^\s+|\s+$/, '');
}


function validateEmail(fld, req) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = req + " has not been filled in.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
	fld.focus();
    return error;
}


function validateEmpty(fld, req) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow';
		fld.focus();
        error = req + " has not been filled in.\n"
    } 
	
	else {
        fld.style.background = 'white';
    }
    return error;  
}
		
		
function validateContactUsForm(theForm) {
var reason = "";

	if(reason == "") reason += validateEmpty(theForm.name, 'Name');
	if(reason == "") reason += validateEmpty(theForm.company, 'Company');
	if(reason == "") reason += validateEmail(theForm.email, 'Email Address');
	if(reason == "") reason += validateEmpty(theForm.message, 'Message');
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}


function validateInquiryForm(theForm) {
var reason = "";

	if(reason == "") reason += validateEmpty(theForm.contact_person, 'Contact Person');
	if(reason == "") reason += validateEmpty(theForm.company, 'Company');
	if(reason == "") reason += validateEmpty(theForm.tel_country_code, 'Telephone Country Code');
	if(reason == "") reason += validateEmpty(theForm.tel_area_code, 'Telephone Area Code');
	if(reason == "") reason += validateEmpty(theForm.tel_no, 'Telephone Number');
	if(reason == "") reason += validateEmail(theForm.email, 'Email Address');
	if(reason == "") reason += validateEmpty(theForm.message, 'Message');
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateForm(theForm) {
var reason = "";

	if(reason == "") reason += validateEmpty(theForm.category, 'Job Category');
	if(reason == "") reason += validateEmpty(theForm.lname, 'Last Name');
	if(reason == "") reason += validateEmpty(theForm.fname, 'First Name');
	if(reason == "") reason += validateEmail(theForm.email, 'Email Address');
	if(reason == "") reason += validateEmpty(theForm.cityadd, 'City Address');
	if(reason == "") reason += isNumeric(theForm.ctnum, '');
	if(reason == "") reason += validateEmpty(theForm.skills, 'Skills');
	if(reason == "") reason += validateEmpty(theForm.resume, 'Resume');
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}
