
function  isStandardDomain(domainIn )
{
	var  isStandardReturn = false;
	var  last4chars  =  domainIn.substring( domainIn.length-4, domainIn.length );
	var  last3chars  =  domainIn.substring( domainIn.length-3, domainIn.length );

	last4chars = last4chars.toUpperCase();
	var  countryCodePattern = /\.[a-zA-Z][a-zA-Z]/;
	if      ( last4chars == ".COM" ) isStandardReturn = true;
	else if ( last4chars == ".EDU" ) isStandardReturn = true;
	else if ( last4chars == ".GOV" ) isStandardReturn = true;
	else if ( last4chars == ".NET" ) isStandardReturn = true;
	else if ( last4chars == ".MIL" ) isStandardReturn = true;
	else if ( last4chars == ".ORG" ) isStandardReturn = true;

	else if ( last3chars.search( countryCodePattern )   !=  -1 )
		isStandardReturn = true;
	return  isStandardReturn;
} 

function  SearchAT( fldemailIn )  
{
	if(fldemailIn.value!=''){
		var	 emailIn = remSpaces(fldemailIn.value)
		var  numAtChars;
		var  userNameIn;
		var  domainNameIn;
		var  addressFields = new Array();
		var  alertString = "";
		addressFields = emailIn.split( '@' );
		numAtChars = addressFields.length - 1;
	
		if (( numAtChars  ==  0 )||( numAtChars  >  1 )|| ( addressFields[0] == "" )||( addressFields[1] == "" ))
			alertString = "Enter a Valid Email(xxxx@xx.xx)";
		else
			{
			userNameIn   = addressFields[0];
			domainNameIn = addressFields[1];

			if ( userNameIn.indexOf(" ") != -1 )
				alertString = "Enter a Valid Email(xxxx@xx.xxx)";
			else if (domainNameIn.indexOf(" ") != -1 )
				alertString = "Enter a Valid Email(xxxx@xx.xxx)";

			else if (isStandardDomain( domainNameIn ) == false )
				alertString = "Enter a Valid Email(xxxx@xx.xxx)";

			else
				return true;

			}
		if(alertString!='')
		{
		alert(alertString);
		fldemailIn.value="";
		fldemailIn.focus();
		}
	}
}

/*-----------------------------------------------------------------------------------------*/

//To check for numbers 
function IsNumberonly(objField)
{
if(objField.value != "")
	 {
		if(isNaN(objField.value)){
			alert("Enter a valid Number");
			objField.value="";
			objField.focus();

			}
		if(objField.value < 0){
			alert("Field cannot have negative values.");
			objField.value="";
			objField.focus();

			}
	}
}

//**************************************************************************************

// Add a function called as a method of the prototype 
// object of the String constructor.
String.prototype.trim = function()
{
 // Use a regular expression to replace leading and trailing 
 // spaces with the empty string
 return this.replace(/(^\s*)|(\s*$)/g, "");
}
	
function remSpaces(strValue)
{
 var strFldValue;
 strFldValue = strValue;
 return strFldValue.trim();
}

//**************************************************************************************

//Check for phone field
function FormatPhone(objPhone,objName)
{
	var sPhone=objPhone.value;
	var sValidPhone="";
	var sFormatPhone="";
	var sRegExp="";
	sRegExp=/\(|\)|-/g
	sValidPhone=remSpaces(sPhone.replace(sRegExp,""));
	
	if(sValidPhone!="")
	{
		if (isNaN(sValidPhone))
		{	
			if (objName == "Phone")
			{	
				alert("Please enter a valid Phone number(10 digits)")
				objPhone.focus();
				objPhone.value="";
				return false;
			}
			else if (objName == "Fax")
			{
				alert("Please enter a valid Fax number(10 digits)")
				objPhone.focus()
				objPhone.value="";
				return false;
			}
			
		}
		if (sValidPhone.length==10)
		{
			sFormatPhone="(" + sValidPhone.substring(0,3) + ")"
			sFormatPhone=sFormatPhone + sValidPhone.substring(3,6) + "-" + sValidPhone.substring(6)
			
		}
		else 
		{
			//sFormatPhone=sPhone
		if (objName == "Phone"  )
			{	
				alert("Please enter a valid Phone number(10 digits)")
				objPhone.focus();
				objPhone.value="";
				return false;
			}
			else if (objName == "Fax")
			{
				alert("Please enter a valid Fax number(10 digits)")
				objPhone.focus();
				objPhone.value="";
				return false;
			}
		}
		objPhone.value=sFormatPhone;
	}
	return true;
}

//**************************************************************************************

//Check for special characters in the field
function SpecialCharcheck(obj,objName)
{
if(obj.value !=''){
	var mikExp;
	if(objName != 'UserName')
		mikExp = /[\#\"\']/;
	else
		mikExp = /[$\\@\\\#%\^\&\*\(\)\[\]\+\,\.\<\>\?\:\;\"\'\/\{\}\`\~\=\|\!\%]/;
		
	if(obj.value.search(mikExp) == -1) 
			return true;
	else 
		{
		if(objName != 'UserName')
			alert("Please enter valid data without special characters.");
			//alert("Please enter valid data without the following characters: \n\r\n\r \" \#  \' \n");
		else
			alert("Sorry, but the following characters\n\r\n\r@ $ % ^ ! ? : < > , . / & * # ( ) [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!\n");
		obj.focus();
		obj.value="";
		return false;
		}
	}
}


//**************************************************************************************

//The function set the value from the DB in the combo for a single selection.

function setComboVal(obj,objval,objLen)
{
	var itmCount
	
	// Get the number of items in the combo.
	itmCount = objLen;
	
		for(i=0;i<itmCount;i++)
		{
			if(obj.options[i].value==remSpaces(objval))
			{
				obj.options[i].selected=true;
				break;
			}
		}
}

//**************************************************************************************

//function to select all the checkboxes in a form
function SelectAll(frmName)
{
	for(i=0; i<frmName.length; i++){
		if(frmName.elements[i].type=='checkbox')
			frmName.elements[i].checked=true
		}
}

//**************************************************************************************

//function to deselect all the checkboxes in a form	
function ClearAll(frmName)
{
	for(i=0; i<frmName.length; i++){
		if(frmName.elements[i].type=='checkbox')
			frmName.elements[i].checked=false;
		}
}

//**************************************************************************************
//function to Restrict the TextArea length
function TextAreaMaxChk(txtfield,maxlimit)
{
	if (txtfield.value.length > maxlimit){
		txtfield.value = txtfield.value.substring(0,maxlimit);
		alert("The field has exceeded the maximum limit. Only "+maxlimit+" characters will be saved.")	
	}
	else
		maxlimit = maxlimit - txtfield.value.length;
	
}
//**************************************************************************************

//funtion to prevent decimal point and alphabets
function CheckInteger()
{
	if (window.event.keyCode < 48 || window.event.keyCode > 57)
	window.event.keyCode=0;  
}

//**************************************************************************************

//funtion to prevent alphabets
function CheckNumeric()
{
	var KCode=window.event.keyCode;
	if(KCode!=46){ 
		if(KCode< 48 || KCode > 57)
			window.event.keyCode=0;  
	}	
}

//**************************************************************************************
/*
//function to validate Zip field
function ZipValidate(ObjField)
{
if (remSpaces(ObjField.value) != "") 
		{
			var valid = "0123456789-";
			var hyphencount = 0;
					
			if (ObjField.value.length!=5 && ObjField.value.length!=10)
			{alert("1")
				alert("Please enter your 5 digit or 5 digit+4 zip code.\n");
				ObjField.value= '';
				ObjField.focus();
				return false;
			}
			else
				return true;
				
			for (var i=0; i < ObjField.value.length; i++) 
			{
				temp = "" + ObjField.value.substring(i, i+1);
				if (temp == "-") hyphencount++;
				if (valid.indexOf(temp) == "-1") 
				{alert("2")
					alert("Invalid characters in your zip code.  Please try again.\n");
					ObjField.value= '';
					ObjField.focus();
					return false;
				}
				else
					return true;
				
				if ((hyphencount > 1) || ((ObjField.value.length==10) && ""+ObjField.value.charAt(5)!="-")) 
				{alert("3")
					alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.\n");
					ObjField.value= '';
					ObjField.focus();
					return false;
				}
				else
					return true;
			}
		}	
	}
*/
//**************************************************************************************

/* *** Function to display the message/tooltip in the status bar *** */
function DisplayStatusMessage(sMessage)
{		
	window.status=unescape(sMessage);
 	return true;
}
//**************************************************************************************

//Function to pop up the locator in shopper site

function openWindow(url, name) {
  popupWin = window.open(url, name, 'dependent,width=600,height=512,left=25,top=25')
}
function openbbWindow(url, name) {
  popupWin = window.open(url, name, 'dependent,width=700,height=512,left=10,top=10')
}

function openLocator(url, name) {
  popupWin = window.open(url, name, 'dependent,width=639,height=448,left=10,top=10')
}

//**************************************************************************************
function swapLocatorImage(frmobj, onOut)
{
	if(onOut=='1')
	{
		frmobj.src="shopperImages/findit_over.gif";
	}
	if(onOut=='2')
	{
		frmobj.src="shopperImages/findit.gif";
	}
}
//**************************************************************************************