
function saveForm()
{

	var ts_firstname = document.getElementById('ts_firstname').value;
	
	if (ts_firstname=="") {
		document.getElementById('ts_firstname').value=""
		document.getElementById('required').innerHTML="<font color=red>Missing First Name..</font>";
		document.getElementById('ts_firstname').focus();
		
		return false;
	}
	var ts_lastname = document.getElementById('ts_lastname').value;
	if (ts_lastname=="") {
		document.getElementById('ts_lastname').value=""
		document.getElementById('required').innerHTML="<font color=red>Missing Last Name..</font>";
		document.getElementById('ts_lastname').focus();
		return false;
	}	
	
	var ts_phone = document.getElementById('ts_phone').value;
	if (ts_phone=="") {
		document.getElementById('ts_phone').value=""
		document.getElementById('required').innerHTML="<font color=red>Missing Phone..</font>";
		document.getElementById('ts_phone').focus();
		return false;
	}	
	
	var ts_email = document.getElementById('ts_email').value;
	
	if (echeck(ts_email)==false){
		document.getElementById('ts_email').value=""
		document.getElementById('ts_email').focus()
		return false
	}
	if (document.getElementById('checker').checked) {
		toMem();
	}
	return true;
	
	
}


function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		document.getElementById('required').innerHTML="<font color=red>Improper E-mail address..</font>";
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   document.getElementById('required').innerHTML="<font color=red>Improper E-mail address..</font>";
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail ID")
		document.getElementById('required').innerHTML="<font color=red>Improper E-mail address..</font>";
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		document.getElementById('required').innerHTML="<font color=red>Improper E-mail address..</font>";
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		document.getElementById('required').innerHTML="<font color=red>Improper E-mail address..</font>";
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		document.getElementById('required').innerHTML="<font color=red>Improper E-mail address..</font>";
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		document.getElementById('required').innerHTML="<font color=red>Improper E-mail address..</font>";
		return false
	 }

	 return true					
}



function newCookie(name,value,days) {
 var days = 10;   // the number at the left reflects the number of days for the cookie to last
                 // modify it according to your needs
 if (days) {
   var date = new Date();
   date.setTime(date.getTime()+(days*24*60*60*1000));
   var expires = "; expires="+date.toGMTString(); }
   else var expires = "";
   document.cookie = name+"="+value+expires+"; path=/"; }

function readCookie(name) {
   var nameSG = name + "=";
   var nuller = '';
  if (document.cookie.indexOf(nameSG) == -1)
    return nuller;

   var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
  if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length,c.length); }
    return null; }

function eraseCookie(name) {
  newCookie(name,"",1); }

function toMem(a) {
    newCookie('theFName', document.getElementById('ts_firstname').value);  
	newCookie('theLName', document.getElementById('ts_lastname').value);  
	newCookie('thePhone', document.getElementById('ts_phone').value);  
		 // add a new cookie as shown at left for every
    newCookie('theEmail', document.getElementById('ts_email').value);  
	    newCookie('theBroke', document.getElementById('ts_brokerage').value);  
		// field you wish to have the script remember
}

function delMem(a) {
  eraseCookie('theFName');   // make sure to add the eraseCookie function for every field
  eraseCookie('theLName');
 eraseCookie('thePhone');   // make sure to add the eraseCookie function for every field
  eraseCookie('theEmail');
    eraseCookie('theBroke');
 document.getElementById('ts_email').value=""   // add a line for every field
 document.getElementById('ts_firstname').value=""
 document.getElementById('ts_lastname').value=""
 document.getElementById('ts_phone').value=""
  document.getElementById('ts_brokerage').value=""
   
   }


function remCookie() {

 document.getElementById('ts_email').value=readCookie("theEmail");  // add a line for every field
 document.getElementById('ts_firstname').value=readCookie("theFName");
 document.getElementById('ts_lastname').value=readCookie("theLName");
 document.getElementById('ts_phone').value=readCookie("thePhone");
  document.getElementById('ts_brokerage').value=readCookie("theBroke");
}

// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  remCookie();
});
