// JavaScript Document

function empty(divId){
	window.document.getElementById(divId).value = '';
	}

function changeMenu(divId){
	if(divId == 'home'){
	   window.document.getElementById(divId).innerHTML = 'emoh';
	   window.document.getElementById(divId).style.color = '#ee9c01';
	   window.document.getElementById(divId).style.cursor = 'pointer';
	}else if(divId == 'about_us'){
	   window.document.getElementById(divId).innerHTML = 'su tuoba';
	   window.document.getElementById(divId).style.color = '#ee9c01';
	   window.document.getElementById(divId).style.cursor = 'pointer';
	}else if(divId == 'contact_us'){
	   window.document.getElementById(divId).innerHTML = 'su tcatnoc';
	   window.document.getElementById(divId).style.color = '#ee9c01';
	   window.document.getElementById(divId).style.cursor = 'pointer';
	}
}

function restoreMenu(divId){
	if(divId == 'home'){
	   window.document.getElementById(divId).innerHTML = 'home';
	   window.document.getElementById(divId).style.color = '#333333';
	}else if(divId == 'about_us'){
	   window.document.getElementById(divId).innerHTML = 'about us';
	   window.document.getElementById(divId).style.color = '#333333';
   }else if(divId == 'contact_us'){
	   window.document.getElementById(divId).innerHTML = 'contact us';
	   window.document.getElementById(divId).style.color = '#333333';
	}
}

function getPage(divId){
if(divId == 'home'){
	   window.location = 'index.php';
	}else if(divId == 'about_us'){
	   window.location = 'about.php';
   }else if(divId == 'contact_us'){
	  window.location = 'contact.php';
	}
}

function checkFields(){
    if(document.contactform.name.value == ''){
	  alert('you must specify your name');
	  return false;
	}else if(document.contactform.email.value == ''){
	  alert('you must specify your email address');
	  return false;
	}else if(document.contactform.query.value == ''){
	  alert('you must specify your query');
	  return false;
	}
}

function checkName(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (document.getElementById(fld).value == "") {
        document.getElementById(fld).style.background = '#ccc';
		document.contactform.submit.enabled = false;
        error = "You didn't enter a username.\n";
    } else if ((document.getElementById(fld).value.length < 3) || (document.getElementById(fld).value.length > 15)) {
       document.getElementById(fld).style.background = '#ccc'; 
        error = "The username is the wrong length.\n";
    } else if (illegalChars.test(document.getElementById(fld).value)) {
        document.getElementById(fld).style.background = '#ccc'; 
        error = "The username contains illegal characters.\n";
    } else {
        document.getElementById(fld).style.background = 'White';
    } 
    if(error!="")
	alert(error);
}

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

function checkEmail(fld) {
    var error="";
    var tfld = trim(document.getElementById(fld).value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (document.getElementById(fld).value == "") {
        document.getElementById(fld).style.background = '#ccc';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        document.getElementById(fld).style.background = '#ccc';
        error = "Please enter a valid email address.\n";
    } else if (document.getElementById(fld).value.match(illegalChars)) {
        document.getElementById(fld).style.background = '#ccc';
        error = "The email address contains illegal characters.\n";
    } else {
        document.getElementById(fld).style.background = 'White';
    }
    if(error!="")
	alert(error);
}

function checkQuery(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (document.getElementById(fld).value == "") {
        document.getElementById(fld).style.background = '#ccc'; 
        error = "You didn't enter any word.\n";
    } else if (illegalChars.test(document.getElementById(fld).value)) {
        document.getElementById(fld).style.background = '#ccc'; 
        error = "The query contains illegal characters.\n";
    } else {
        document.getElementById(fld).style.background = 'White';
    } 
    if(error!="")
	alert(error);
}

function fixContact(){
    if(navigator.appName=="Microsoft Internet Explorer")
	        document.getElementById('contact_button').style.top = '180px';
}