// JavaScript Document

/////////////////////////////////////////////////
function sendMail()
{
	if(Form1.txtFirstName.value==""){alert("First Name is a required field");return false;}
	if(Form1.txtLastName.value==""){alert("Last Name is a required field");return false;}
	if(Form1.txtEMail.value==""){alert("Email is a required field");return false;}
	if(Form1.State.value==""){alert("State is a required field");return false;}
	if(Form1.txtZip.value==""){alert("Zip is a required field");return false;}
	if(Form1.Country.value==""){alert("Country is a required field");return false;}
	if(Form1.txtPhone1.value=="" || Form1.txtPhone2.value=="" || Form1.txtPhone3.value==""){alert("Phone is a required field");return false;}
	
	var bodyText="";
	var mailId= Form1.hdnMailId.value;
	var subject= "Information required..";
	bodyText += "Hi " + Form1.hdnOwner.value + "%0D%0A%0D%0A";
	bodyText += "I am " + Form1.txtFirstName.value + " " + Form1.txtLastName.value + ".";
	bodyText += " I want to know about '" + Form1.optService.value + "'" + "%0D%0A";
	bodyText += "My details are given below: " + "%0D%0A%0D%0A";
	bodyText += "Email: " + Form1.txtEMail.value + "%0D%0A";
	bodyText += "Business Name: " + Form1.txtBusinessName.value + "%0D%0A";
	bodyText += "Address: " + Form1.txtAddress1.value + ", " + Form1.txtAddress2.value + "%0D%0A";
	bodyText += Form1.txtCity.value + ", " + Form1.State.value + "%0D%0A";
	bodyText += Form1.Country.value + "%0D%0A";
	bodyText += "Zip/Postal Code: " + Form1.txtZip.value + "%0D%0A";
	bodyText += "Phone: " + Form1.txtPhone1.value + Form1.txtPhone2.value + Form1.txtPhone3.value + ", " + Form1.txtAltphone1.value + Form1.txtAltphone2.value + Form1.txtAltphone3.value + "%0D%0A%0D%0A";
	bodyText += "I learned of Paul Davis through '" + Form1.optReferral.value + "'" + "%0D%0A%0D%0A";
	//bodyText += "Note: " + Form1.txtComments.value + "%0D%0A%0D%0A";
	bodyText += "Thanks" + "%0D%0A";
	bodyText += Form1.txtFirstName.value + " " + Form1.txtLastName.value ;
	
	location.href = "mailto:" + mailId + "?subject=" + subject + "&body=" + bodyText;
	return false;
}

/////////////////////////////////////////////////
var newwindow = '';
function popitup(url,webset)
{
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open(url,"",webset);
		if (!newwindow.opener) newwindow.opener = self;
	}				
	newwindow.moveTo(10,10);
	newwindow.focus();				
}
/////////////////////////////////////////////////
function to_old_win(url)
{				
	if(opener.closed == false)													
		opener.location.href = url + "?UseTemplate=yes";
							
	window.close();				
}
/////////////////////////////////////////////////

function onKeyPress_MakeCapital()
{			  
	if (window.event.keyCode>=97 && window.event.keyCode<123)
		window.event.keyCode =  window.event.keyCode - 32 ;
}
function onKeyPress_ValidateForInteger()
{			  
	if(window.event.keyCode != 8)
	{
	if (window.event.keyCode <48 || window.event.keyCode>57)
		window.event.keyCode =  0;
	}
}

////////////////////////////////////////////////
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) 
{
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) 
	{
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}

function containsElement(arr, ele) 
{
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
		found = true;
	else
		index++;
return found;
}

function getIndex(input) 
{
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
}
return true;
}

////////////////////////////////////////////////
function onLostFocus(param,val)
{				
	var paramvalue = param.value;
	if( parseFloat(paramvalue) != paramvalue ) 
	{
		alert(paramvalue + " is invalid entry ! ");
		param.value = val ;
	}
								
}	

function showTemplate(pageName,wd,ht)
{
	var retval="";
	var param="";
	param="width=" + wd + ",";
	param+="height=" + ht + "," + "status=no";
		//retval=window.open(pageName,"Template","width=450,height=325,status=no");
		retval=window.open(pageName,"Template",param);
		retval.focus();
		/*retval.location.replace(retval.location);*/
		retval.moveTo(10,10);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// Main function, called when the page loads
function alternateRows() {
	var i, j;
	
	if (!document.getElementById) return
	
		var tables = document.getElementsByTagName("table");	  
		//search through tables in document
		for (i=0; i<tables.length; i++) {
			// If table has the right classname
			if (tables[i].className == "alternateRows") {
				rows = tables[i].getElementsByTagName("tr");
				applyClasstoRows(rows);
			}
		}
}

// Function, which is passed a table reference, applies the class 'even' to each even row, <tr> tag
function applyClasstoRows(myRows) {
	// search through rows
	for (j=0; j<rows.length; j++) {
	
	   // Set class for even rows (odd doesn't need to be set)
	   if (j%2 == 0) { 
		  rows[j].setAttribute("className", "shaded");
		  rows[j].setAttribute("class", "shaded");
	   } 
	}
}


// Piggy-back fucntion onto onLoad event ............................................
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(alternateRows);
