// JavaScript Document
var current1 = "1";
function pageSwitch1 (id)
{
	if(!document.getElementById) return false;
	var div = document.getElementById("t"+id);
	var curDiv = document.getElementById("t"+current1);
	curDiv.style.display = "none";
	div.style.display = "block";
	current1 = id;
}

function Hide(){
	document.getElementById('r_form').style.display = 'block';
}

var current2 = "1";
function pageSwitch2 (id)
{
	if(!document.getElementById) return false;
	var div = document.getElementById("a"+id);
	var curDiv = document.getElementById("a"+current2);
	curDiv.style.display = "none";
	div.style.display = "block";
	current2 = id;
}

function validateFormOnSubmit(theForm) {
var reason = "";
	 reason += validateName(theForm.Name);
	  if (reason != ""){
    	 alert("Some fields need correction:\n" + reason);
   		 return false;
 	 }
	 else
	 reason += validateCity(theForm.City);
	 if (reason != ""){
    	 alert("Some fields need correction:\n" + reason);
   		 return false;
 	 }
	 else
	 reason += validateEmail(theForm.Email);
	 if (reason != ""){
    	 alert("Some fields need correction:\n" + reason);
   		 return false;
 	 }
	 else
	 reason += validatePhone(theForm.phone);
	 if (reason != ""){
    	 alert("Some fields need correction:\n" + reason);
   		 return false;
 	 }
	else
 	 return true;
}

function validateName(fld){
    var error = "";
     if (fld.value.length == 0)	 {
        fld.style.background = 'Yellow'; 
        error = "Name field has not been filled in.\n"
		fld.focus();
	}
	 else 
	 fld.style.background = 'White';
	 return error;  
}
function validateCity(fld){
    var error = "";
     if (fld.value.length == 0)	 {
        fld.style.background = 'Yellow'; 
        error = "City has not been entered.\n"
		fld.focus();
     }
	 else 
	 fld.style.background = 'White';
     return error;  
}
function validateEmail(fld) {
    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 = "You didn't enter an email address.\n";
		fld.focus();
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
		fld.focus();
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
		fld.focus();
    } else
        fld.style.background = 'White';
    return error;
}
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    
   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = 'Yellow';
		fld.focus();
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
		fld.focus();
    } else if (!(stripped.length == 10)) {
        error = "The phone number should be of 10 digit.\n";
        fld.style.background = 'Yellow';
		fld.focus();
    }
	else
        fld.style.background = 'White';
		return error;
}
function trim(s){
  return s.replace(/^\s+|\s+$/, '');
  document.getElementById('r_form').style.display = 'none';
	document.getElementById('r_tab1').style.display = 'block';
}

function cancel()
{
	document.getElementById('r_form').style.display = 'none';
}
	







