// JavaScript Document
//***********************************************************
// Function:	addZero
// Description :	places a leading "0" infront of any single digit number
// Parameters :		the number that may require a leading zero
//***********************************************************
function addZero(num)
{
	if(num < 10)
	return '0' + num;
	return num;
	 
}
function isMail(elem)
{
	var str = elem.value;
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if(!str.match(re))
	{
		return false;		
	}
	return true;
}
function isNum(elem)
{
	var str = elem.value;
	var re = /^[-]?\d*\.?\d*$/;
	str = str.toString();
	if(!str.match(re))
	{
		return false;
	}
	return true;
}
function isNotEmpty(elem)
{
	var str = elem.value;
	var re = /.+/;
	if(!str.match(re))
	{
		return false;
	}
	return true;
}

function validMail(obj)
{
	var invalidChars =" /:,;";
	var email = obj.value;
	var i = 0;
	var Valid = true;
	if (email != "")
	{
		Valid = isMail(obj);
		if (! Valid)
		{
			alert("EMail Address is not valid Please Check");
			obj.select();
		}
	}
}

function validTxt(obj)
{
	return;
}
function validPhone(obj)
{
	var validChars =" ()+1234567890";
	var phoneNum = obj.value;
	var i = 0;
	var Valid = true;
	var theChar = "";
	if (phoneNum != "")
	{
		for (i=0;i<phoneNum.length;i++)
		{   theChar = phoneNum.charAt(i);
			if (validChars.indexOf(theChar,0) == -1)
			{
				Valid = false;
			}
			
		}		
		if (! Valid)
		{
			alert("Phone Number is not valid Please Check");
			obj.select();
		}
	}
}

function validNum(obj)
{
	var valid = true;
	if(obj.value != "")
	{
		valid = isNum(obj);
		if(!valid)
		{
			alert("Value must be Numeric");
			obj.value = "";
			obj.focus();
		}
	}
}
function showInvalid(obj,txt)
{
	document.getElementById("Err"+obj.id).innerHTML = txt;
}

function checkField(obj,objType)
{	var txt = '';
var valid = true;
	switch(objType)
	{
		case "email": if(!isNotEmpty(obj))
					  {
					  	txt = '*'; valid = false;	
					  }					  
					  break;
		case "text": if(!isNotEmpty(obj))
					  {
					  	txt = '*'; valid = false;	
					  }
					  break;
		case "numeric": if(!isNotEmpty(obj) || !isNumber(obj))
					  {
					  	txt = '*'; valid = false;	
					  }
					  break;
		case "select": if(obj.options[obj.selectedIndex].value == "")
					   {
					  	txt = '*'; valid = false;	
					   }
					   break;
	}
	showInvalid(obj,txt);
	return valid;
	
}

function getEventCoords( e )
{
   var docX, docY;
   if( e )
   {
      if( typeof( e.pageX ) == 'number' )
      {
         docX = e.pageX;
         docY = e.pageY;
      }
      else
      {
         docX = e.clientX;
         docY = e.clientY;
      }
   }
   else
   {
      e = window.event;
      docX = e.clientX;
      docY = e.clientY;
      if( document.documentElement
        && ( document.documentElement.scrollTop
            || document.documentElement.scrollLeft ) )
      {
         docX += document.documentElement.scrollLeft;
         docY += document.documentElement.scrollTop;
      } 
      else if( document.body
         && ( document.body.scrollTop
             || document.body.scrollLeft ) )
      {
         docX += document.body.scrollLeft;
         docY += document.body.scrollTop;
      }
   }
   return [ docX, docY ];

}
// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() 
{
		return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 
function pageHeight() 
{
		return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 
function posLeft() 
{
		return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
} 
function posTop() 
{
		return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
} 
function posRight() 
{
		return posLeft()+pageWidth();
} 
function posBottom() 
{
		return posTop()+pageHeight();
}
                    

function mouseCoords(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	return [posx,posy];
}

function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX; //+ (document.documentElement.scrollLeft ?
   //document.documentElement.scrollLeft :
   //document.body.scrollLeft);
else return null;
}
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY; // + (document.documentElement.scrollTop ?
   //document.documentElement.scrollTop :
   //document.body.scrollTop);
else return null;
}

//################### AJAX CODE #######################################################
function InitAjax()
{
	 var iAjax=false;
	 try 
	 {
	 	iAjax = new ActiveXObject("Msxml2.XMLHTTP");
	 }  catch (e) 
	 {
		  try 
		  {
		   iAjax = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) 
		  {
		   iAjax = false;
		  }
	 }
	 if(!iAjax && typeof XMLHttpRequest!='undefined') 
	 {
		iAjax = new XMLHttpRequest();
	 }
	 return iAjax;
}

function getParam(inpName)
{
	if(document.getElementById(inpName))
	{
		return document.getElementById(inpName).value;
	}
	else
	{
		return '';
	}
}
           




