
function formrule(field)
{
	if (field.defaultValue == field.value) field.value = "";
}

function formrule2(field) {
  if (field.value == "") {
    field.value = field.defaultValue;
  }
}

var newWin = null; 
function popUp(strURL, strType, strHeight, strWidth) { 
 if (newWin != null && !newWin.closed) 
   newWin.close(); 
 var strOptions=""; 
 if (strType=="console") 
   strOptions="resizable,height="+ 
     strHeight+",width="+strWidth; 
 if (strType=="fixed") 
   strOptions="status,height="+ 
     strHeight+",width="+strWidth; 
 if (strType=="elastic") 
   strOptions="toolbar,menubar,scrollbars,"+ 
     "resizable,location,height="+ 
     strHeight+",width="+strWidth; 
 newWin = window.open(strURL, 'newWin', strOptions); 
 newWin.focus(); 
}

function addBookmark(title,url) { 
 if (window.sidebar) { 
 window.sidebar.addPanel(title, url,""); 
 } else if( document.all ) { 
 window.external.AddFavorite( url, title); 
 } else if( window.opera && window.print ) { 
 return true; 
} 
}


function FormSubmit(frm) {		// validate form1
	if (document.form1.name.value==' name') {
		alert('Please enter name');
		document.form1.name.focus()
		return false;
	}
	if (document.form1.phone.value==' phone') {
		alert('Please enter phone number');
		document.form1.phone.focus()
		return false;
	}
	// check to see if email address field is of valid syntax
	substremail = document.form1.email.value.split("@")
	if (substremail.length > 1)
	{
		index = substremail[1].indexOf(".")
		if (index == -1)
 		{
		alert("Please enter a valid e-mail address")
		document.form1.email.focus()
		return false
		}
	}
	else {
		alert("Please enter a valid e-mail address")
		document.form1.email.focus()
		return false
	}
	
//	document.form1.name.value = document.form1.fname.value + ' ' + document.form1.name.value
	return true;
}



function vgen() {		// validate fgen form
	f = document.fgen;
	if (f.nfirst.value=='') {
		alert('Please enter first name');
		f.nfirst.focus();
		return false;
	}
	if (f.nlast.value=='') {
		alert('Please enter last name');
		f.nlast.focus();
		return false;
	}
	// check to see if email address field is of valid syntax
	if (!IsValidEmailSyntax(f.email.value)) {
		alert("Please enter a valid e-mail address")
		f.email.focus();
		return false;
	}
	if (f.email.value != f.cemail.value) {
		alert('Email and confirmation email are not the same');
		f.cemail.focus();
		return false;
	}
	return true;
}
function IsValidEmailSyntax (sEmail) {
	//var myRegExp = /^(\w+(\.|\_|-)?\w+)*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}$/;
	var myRegExp = /^([_A-Za-z0-9.-]+)@(([A-Za-z0-9.-]|\[|\])+)$/;
	return myRegExp.test(sEmail);
}

function vaddr() {		// validate fgen form
	f = document.fgen;
	if (f.nfirst.value=='') {
		alert('Please enter first name');
		f.nfirst.focus();
		return false;
	}
	if (f.nlast.value=='') {
		alert('Please enter last name');
		f.nlast.focus();
		return false;
	}
	// check to see if email address field is of valid syntax
	if (!IsValidEmailSyntax(f.email.value)) {
		alert("Please enter a valid e-mail address")
		f.email.focus()
		return false;
	}
	if (f.email.value != f.cemail.value) {
		alert('Email and confirmation email are not the same');
		f.cemail.focus();
		return false;
	}
	// ---- extra required fields
	if (f.adcity.value=='') {
		alert('Please enter City');
		f.adcity.focus();
		return false;
	}
	if (f.adstate.value=='') {
		alert('Please enter State');
		f.adstate.focus();
		return false;
	}
	if (!f.Disclaimer.checked) {
		alert('Please read and check the disclaimer');
		f.Disclaimer.focus();
		return false;
	}		
	return true;
}

function vcust(rqrd) {	
	// validate fgen form w. custom required flds
	f = document.fgen;
	if (f.nfirst.value=='') {
		alert('Please enter first name');
		f.nfirst.focus();
		return false;
	}
	if (f.nlast.value=='') {
		alert('Please enter last name');
		f.nlast.focus();
		return false;
	}
	// check to see if email address field is of valid syntax
	if (!check_email(f.email.value)) {
		alert("Please enter a valid e-mail address")
		f.email.focus()
		return false;
	}
	if (f.email.value != f.cemail.value) {
		alert('Email and confirmation email are not the same');
		f.cemail.focus();
		return false;
	}

	// ---- check custom required fields
	var fn = '';
	var cfarr = rqrd.split(',');
	for (var k=0; k < cfarr.length; k++) {
		fn = eval('f.'+cfarr[k]);
		if (fn.value=='') {
			alert('Please enter all required fields');
			fn.focus();
			return false;
		}
	}
	return true;
}

function vrqrd(flist) {
	// validate fgen form required flds from list 'f1,f2,..'
	f = document.fgen;
	// f.all.length+f.adrstate.selectedIndex+f.adrstate.type+eval(f.adrstate.value==''))

	if (!check_email(f.email.value)) {
		alert("Please enter a valid e-mail address")
		f.email.focus()
		return false;
	}

	var fn = '';
	var cfarr = flist.split(',');
	for (var k=0; k <= cfarr.length; k++) {
		fn = eval('f.'+cfarr[k]);
		if (fn.value=='') {
			alert('Please enter all required fields');
			fn.focus();
			return false;
		}
	}
	return true;
}
//---------------
/* Email Check */
// Copyright DJ Wice webdesign www.professional-webmaster.com
// For more information email me at admin@professional-webmaster.com

function check_email(x)
// This function checks if  x  is an emailaddress
{
  var b = /[\._\-@]{2}/;	// an emailadress may not contain two of these next to eachother
  var c = /^[\._\-]/;		// an emailadress may not start with these

  var m = /(^[A-Za-z0-9_\.\-]{2,})@([A-Za-z0-9\.\-\[\]]{6,})$/;
  var p = x.match(m);

  if (p!=null)
  {
    var d = /[\._\-]$/;		// an username may not end with these

    if ((!(b.test(x)))    &&
        (!(c.test(x)))    &&
        (!(d.test(p[1]))) &&
        ( check_subdomain(p[2]) ||
          check_domain(p[2])    ||
          check_IP(p[2])        )
       )
       { return true; }
  }

  return false;
}



