
var objRegDate ; // global Date object for Calendar control
var strRegDate="";
function CheckNumeric()
{
	if(document.all)
	{
		ss=window.event.keyCode	
			
		if (ss !=46)
		{ 
			if (ss < 48 || ss > 57)
			{
				window.event.keyCode=0;  
			}
		}	
	}	
}

function CheckKeyCode(e)
{
	if (document.all)
	{
		if(e.keyCode==13)
		{
			e.keyCode = 0;
			return CallSearch();
		}
	}
	if (document.layers)
	{
		if(e.which==13)
		{
			return CallSearch();
		}
	}
}	

function CheckKeyCode1(e)
{
	if (document.all)
	{
		if(e.keyCode==13)
		{
			e.keyCode = 0;
			return CallSearch1();
		}
	}
	if (document.layers)
	{
		if(e.which==13)
		{
			return CallSearch1();
		}
	}
}	

function FillCombo()
{	
	PopulateYearCombo(shopper_new.cmbYear1);	
	PopulateMonthCombo(shopper_new.cmbMnth1);
	PopulateYearCombo(shopper_new.cmbYear2);	
	PopulateMonthCombo(shopper_new.cmbMnth2);		
	//shopper_new.txtfname.focus();
}

function PopulateYearCombo(objYear)
{
	
		// Populate Year
		CurrentYear = new Date();
		for (intCounter=CurrentYear.getYear(); intCounter <= CurrentYear.getYear() + 5; intCounter++) 
		{		
			str=new String(intCounter);
			var s1=str.slice(2,4);			
			objOption = new Option(intCounter,s1);			
			objYear.add(objOption);
		}
	
}

// function to populate the objMonth month combo
function PopulateMonthCombo(objMonth)
{
		var intCounter;
		var strCounter

		for (var intCounter=1; intCounter <= 12; intCounter++) 
		{
			
			if (intCounter < 10)
			{
				strCounter="0"+ intCounter;
			}
			else
			{
				strCounter=intCounter;
			}
			objOption = new Option(strCounter, strCounter);
			objMonth.add(objOption);
		}

}


function trim(strInput)
{
// for trimLeft
	var strTemp = new  String(strInput)
	while(strTemp.charAt(0)==" ")
	{
		strTemp = strTemp.slice(1);
	}
// for TrimRight
	var iLength = strTemp.length;
	iLength--;// accounts for zero based index
	while(strTemp.charAt(iLength)==" ")
	{
		strTemp = strTemp.slice(0,iLength--);
	}
	return strTemp;
}

//This function is called when clicked on Calender Lookup
//obj is the target text field control
function SelectFromCalendar(obj)
{
	

	if (document.all)
	{
		var iW = 171; // Width
		var iH = 198; // Height
	}
	
	if (document.layers)
	{
		var iW = 170; // Width
		var iH = 198; // Height	
	}
	var iX = CalculateWindowTop(iH);
	var iY = CalculateWindowLeft(iW);
	var bResize = 0;
	var bHelp = 0;
	var bStatus = 0;
	var args = obj.value; //The Value of the control
	if(obj.value!="")
	{
		strRegDate=obj.value;
	}
	var strOptions = "dialogHeight: " + iH + "px; dialogWidth: " + iW + "px; dialogTop: " + iY + "px; dialogLeft: " + iX + "px; resizable: " + bResize + "; help: " + bHelp + "; status: " + bStatus + ";";
	//var retval = window.showModalDialog("Calendar.htm", args, strOptions);	
	var objCalendar=window.open("./include/Calendar.htm","Calendar", "width=" +  iW + ",height=" + iH +",left=" + iY +",top=" + iX +",screenX=" +iY +",screenY=" +iX);
	objCalendar.focus();
	/*if (retval != null)
	{
		obj.value = retval;
	}*/
	objRegDate=obj;
	
	return false;
	
}

function Validate()
{
	if(trim(shopper_new.shopper_email)=="")
	{		
		alert("Email cannot be empty!");
		return;
	}
	if(trim(shopper_new.shopper_dob)=="")		
	{		
		alert("Date Of Birth cannot be empty!");
		return;
	}	
	
	
	if(trim(shopper_new.shopper_login)=="")		
	{		
		alert("Logon Name cannot be empty!");
		return;
	}
	if(trim(shopper_new.shopper_ccard)=="")		
	{		
		alert("Credit Card Number cannot be empty!");
		return;
	}
	if(trim(shopper_new.shopper_ccname)=="")		
	{		
		alert("Credit Card Name cannot be empty!");
		return;
	}
	if(trim(shopper_new.shopper_ccdate)=="")		
	{		
		alert("Credit Card Exp Date cannot be empty!");
		return;
	}
	
}

function Validate_Bid()
{
	
	BidPrice=filterNum(document.frmBid.hBPrice.value)	
	MinPrice=new Number(document.frmBid.hMin.value)
	AskPrice=new Number(document.frmBid.hAsk.value)	
	if (BidPrice < MinPrice)
	{
		document.frmBid.hPage.value="Rejected";				
	}
	if (BidPrice < AskPrice && BidPrice >=MinPrice)
	{
		document.frmBid.hPage.value="Posted";				
	}
	if (BidPrice >= AskPrice)
	{
		document.frmBid.hPage.value="Accepted";		
	}
	document.frmBid.submit();
}



function CheckData(objform)
{
	
	setMake()
	msg=new String();
	if(trim(objform.txtName.value)=="")
		msg=msg+"Please enter a HeadLiner\n";		
	
	if(trim(objform.txtDesc.value)=="")	
		msg=msg+"Please enter a Description\n";	
	
	if(trim(objform.cmbDept.value)=="")	
		msg=msg+"Please select a Department\n";	
	
	if(trim(objform.cmbProd.value)=="")	
		msg=msg+"Please select a Product\n";		

	if(trim(objform.txtManuf.value)=="")	
		msg=msg+"Please enter a Manufacturer\n";	
	
	if(trim(objform.txtModel.value)=="")	
		msg=msg+"Please enter a Model\n";
	if (document.frmPostAd.optGauge[0].checked==true)
	{
		if (document.frmPostAd.txtCaliber.value=="")
			msg=msg+"Please enter a value for Caliber\n";
	}
	if (document.frmPostAd.optGauge[1].checked==true)
	{
		if (document.frmPostAd.txtGuage.value=="")
			msg=msg+"Please enter a value for Gauge\n";
	}
	if(trim(objform.txtqty.value)=="")
	{
		msg=msg+"Please enter a Quantity greater than 0\n";
	}
	else
	{
		if(parseInt(objform.txtqty.value) <= 0)
		{
			msg=msg+"Please enter a Quantity greater than 0\n";
		}
	}
		
	if(msg!="")
	{
		alert(msg)
		return false;
	}		
	desc=new String(objform.txtDesc.value)	
	if(desc.length>5000)
	{		
		alert("Description cannot exceed 5000 characters.")
		return false
	}	
	aprice=filterNum(objform.txtAsk.value)
	aprice=parseFloat(aprice)
	mprice=filterNum(objform.txtMin.value)
	mprice=parseFloat(mprice)	
	
	
	if(isNaN(aprice) || isNaN(mprice) || aprice > 99999999999999.9999 || mprice>99999999999999.9999 || mprice==0 || aprice==0)					
	{
		alert('Enter a valid value for Minimum Price /Ask Price.')
		return false
	}			
	if(aprice<mprice)
	{
		alert('Minimum Price should be less than Ask Price.')
		return false
	}
	return true
	
}	


function InvalidUser()
{
	alert('You have to Login before posting a bid.');
	return;
}


function setMake()
{
	if(document.frmPostAd.optGauge[0].checked==true)
	{
		document.frmPostAd.make.value="on"
		if (document.frmPostAd.txtCaliber.disabled == true)
		{
			document.frmPostAd.txtGuage.value=""
			document.frmPostAd.txtCaliber.disabled=false
		}
		document.frmPostAd.txtGuage.disabled=true
	}
	else	
	{
		if (document.frmPostAd.txtGuage.disabled == true)
		{
			document.frmPostAd.txtCaliber.value=""
			document.frmPostAd.txtGuage.disabled=false
		}
		document.frmPostAd.txtCaliber.disabled=true
		document.frmPostAd.make.value="off"
	}
		
}


function ClearFields(objForm)
{	
	for(i=0; i<objForm.length; i++)
	{
		if (objForm.elements[i].type=="text" || objForm.elements[i].type=="textarea" || objForm.elements[i].type=="password")					
			objForm.elements[i].value="";				
		if(objForm.elements[i].type=="select-one")
			objForm.elements[i].selectedIndex=0
	}	
}


function PostAd(objform)
{
		MakeFullYear()
		exp=new Date(objform.txtExp.value)
		tday=new Date()		
		if(exp<tday || isNaN(exp))
		{
			alert("Expiry date should be greater than Current date.")
			return;
		}	
		objform.hValidate.value='2';
		
		objform.submit();
}


function ShowConfirm()
{
	msg=new String();

	BidPrice = filterNum(document.frmBid.txtNewPrice.value)
	
	if(BidPrice==0 || isNaN(BidPrice) || BidPrice>99999999999999.9999)
	{
		alert("Valid Bid price should be entered")
		document.frmBid.hValidate.value='';
		return
	}

	BidQty = filterNum(document.frmBid.txtBidCount.value)
	
	if(BidQty==0 || isNaN(BidQty) || BidQty>9999)
	{
		alert("Bid quantity must be at least 1")
		document.frmBid.hValidate.value='';
		return
	}

	if(msg!="")
	{
		alert('	\n'+msg)
		return;
	}
	else
	{
		document.frmBid.hValidate.value='1';
		document.frmBid.hPage.value="";
		document.frmBid.submit();			
	}	
}


function ShowConfirm2()
{
	msg=new String();

	if(document.frmBid.CCSelect.value == "new")
	{
		if(trim(document.frmBid.txtCCard.value)=="")
			msg=msg+"\tCredit Card No.\n";

		if(trim(document.frmBid.txtCardHolder.value)=="")
			msg=msg+"\tCard Holder Name\n";		

		if(trim(document.frmBid.txtCreditYear.options[document.frmBid.txtCreditYear.selectedIndex].text)=="")
			msg=msg+"\tCredit Card Expiry Date\n";

		if(trim(document.frmBid.txtBAStreet.value)=="")
			msg=msg+"\tBilling Address Street\n";		

		if(trim(document.frmBid.txtBACity.value)=="")
			msg=msg+"\tBilling Address City\n";		

		if(trim(document.frmBid.txtBAZip.value)=="")
			msg=msg+"\tBilling Address Zip Code\n";		

		if(trim(document.frmBid.cmbBAState.value)=="")
			msg=msg+"\tBilling Address State\n";
	}

	if(msg!="")
	{
		alert('	\n'+msg)
				return;
	}
	else
	{
		if(document.frmBid.CCSelect.value == "new")
		{
			if (MakeDataFullYear() == false)
			    return;

			document.frmBid.hdnCardType.value = document.frmBid.cmbCardType.options[document.frmBid.cmbCardType.selectedIndex].value
			document.frmBid.hdnCCard.value = document.frmBid.txtCCard.value
			document.frmBid.hdnCardHolder.value = document.frmBid.txtCardHolder.value
			document.frmBid.hdnBAStreet.value = document.frmBid.txtBAStreet.value
			document.frmBid.hdnBACity.value = document.frmBid.txtBACity.value
			document.frmBid.hdnBAZip.value = document.frmBid.txtBAZip.value
			document.frmBid.hdnBAState.value = document.frmBid.cmbBAState.options[document.frmBid.cmbBAState.selectedIndex].value
		}
		document.frmBid.hValidate.value='2';
		document.frmBid.hPage.value="";
		document.frmBid.submit();			
	}		
}


/*
function CallSearchOld()
{
	
	var make = ""
	var model = ""
	var keyword = ""
	var SearchText = ""
	SearchText = trim(document.frmSearch.txtSearch.value)
	Shopper_id = document.frmSearch.hdnShopperid.value
	Category = document.frmSearch.hdnCategory.value
	Classifieds = document.frmSearch.hdnAdCategory.value
	if (SearchText == "")
	{
		alert("A Search text should be given to perform the Search Operation")
		return false;
	}
	if ((document.frmSearch.cmbSearch.options[document.frmSearch.cmbSearch.selectedIndex].value) == "Keyword")
		keyword = "1"
	if ((document.frmSearch.cmbSearch.options[document.frmSearch.cmbSearch.selectedIndex].value) == "Make")
		make = "1"
	if ((document.frmSearch.cmbSearch.options[document.frmSearch.cmbSearch.selectedIndex].value) == "Model")
		model = "1"
	document.frmSearch.action = "SearchResults.php?SearchText=" + SearchText + "&Keyword=" + keyword + "&Make=" + make  + "&Model=" + model + "&mscssid="+Shopper_id + "&mscssCategory=" + Category + "&mscssAdCategory=" + Classifieds
	document.frmSearch.submit()
	return false;
}
*/

	
function CallSearch()
{
	var make = "";
	var model = "";
	var keyword = "";
	var AdId = "";
	var SearchText = "";
	SearchText = trim(document.frmSearch.txtSearch.value);
	Shopper_id = document.frmSearch.hdnShopperid.value;
	Category = document.frmSearch.hdnCategory.value;
	Classifieds = document.frmSearch.hdnAdCategory.value;
	if (SearchText == "")
	{
		alert("A Search text should be given to perform the Search Non-Guns Operation");
		return false;
	}
	if ((document.frmSearch.cmbSearch.options[document.frmSearch.cmbSearch.selectedIndex].value) == "Keyword")
		keyword = "1";
	if ((document.frmSearch.cmbSearch.options[document.frmSearch.cmbSearch.selectedIndex].value) == "Make")
		make = "1";
	if ((document.frmSearch.cmbSearch.options[document.frmSearch.cmbSearch.selectedIndex].value) == "Model")
		model = "1";
	if ((document.frmSearch.cmbSearch.options[document.frmSearch.cmbSearch.selectedIndex].value) == "AdId")
		AdId = "1";
	document.frmSearch.AdCategory.value = "1";
	document.frmSearch.SearchText.value = SearchText;
	document.frmSearch.Keyword.value = keyword;
	document.frmSearch.Make.value = make;
	document.frmSearch.Model.value = model;
	document.frmSearch.AdIdNum.value = AdId;
	document.frmSearch.Page.value = "<? echo $Page; ?>";
	document.frmSearch.action = "adlisting1.php";

//	?AdCategory=1&SearchText=" + SearchText +
//				     "&Keyword=" + keyword + "&Make=" + make  + "&Model=" + model +
//				     "&AdIdNum=" + AdId + "&Page=Products.php";
	document.frmSearch.submit();
	return false;
}
	

function CallSearch1()
{
	var make = "";
	var model = "";
	var keyword = "";
	var AdId = "";
	var SearchText = "";
	SearchText = trim(document.frmSearch1.txtSearch.value);
	Shopper_id = document.frmSearch1.hdnShopperid.value;
	Category = document.frmSearch1.hdnCategory.value;
	Classifieds = document.frmSearch1.hdnAdCategory.value;
	if (SearchText == "")
	{
		alert("A Search text should be given to perform the Search Guns Operation");
		return false;
	}
	if ((document.frmSearch1.cmbSearch.options[document.frmSearch1.cmbSearch.selectedIndex].value) == "Keyword")
		keyword = "1";
	if ((document.frmSearch1.cmbSearch.options[document.frmSearch1.cmbSearch.selectedIndex].value) == "Make")
		make = "1";
	if ((document.frmSearch1.cmbSearch.options[document.frmSearch1.cmbSearch.selectedIndex].value) == "Model")
		model = "1";
	if ((document.frmSearch1.cmbSearch.options[document.frmSearch1.cmbSearch.selectedIndex].value) == "AdId")
		AdId = "1";
	document.frmSearch1.AdCategory.value = "0";
	document.frmSearch1.SearchText.value = SearchText;
	document.frmSearch1.Keyword.value = keyword;
	document.frmSearch1.Make.value = make;
	document.frmSearch1.Model.value = model;
	document.frmSearch1.AdIdNum.value = AdId;
	document.frmSearch1.Page.value = "<? echo $Page; ?>";
	document.frmSearch1.action = "adlisting1.php";
//	?AdCategory=0&SearchText=" + SearchText +
//				    "&Keyword=" + keyword + "&Make=" + make  + "&Model=" + model +
//				     "&AdIdNum=" + AdId + "&Page=Products.php";
	document.frmSearch1.submit();
	return false;
}


// Used to Format the Currency Value.
function formatCurrency(num) 
{

	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	/*cents = Math.floor((num*100+0.5)%100);
	
	num = Math.floor((num*100+0.5)/100).toString();
	
	if(cents < 10) cents = "0" + cents;*/
	num = num.toString().replace(/\$|\,/g,'');

	if(isNaN(num)) num = "0";
	if(num.indexOf(".")==-1)	
	{
		cents="00"		
	}		
	else
	{
		tmp=num.split(".")
		cents=tmp[1]		
		num=tmp[0]
		if (cents.length == 1)
			cents = cents + "0";
	}
	if(num=="") 
		num="0"
		
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
		return ('$' + num + '.' + cents);
}


// Removes the $ and , from the Text Box
function filterNum(str) 
{
	str1=new String(str)
	re = /^\$/g;
	str1=str1.replace(re, "");
	re = /\,/g;
	return str1.replace(re, "");
}


function CalculateWindowTop(iWindowHeight)
{
	if (document.layers)
	{
		var iWindowTop= (window.outerHeight - iWindowHeight)/2;
	
	}
	
	if (document.all)
	{
		var iWindowTop= (window.screen.height - iWindowHeight)/2
	}
		return iWindowTop;
	
}


function CalculateWindowLeft(iWindowWidth)
{
	if(document.layers)
	{
		var iWindowLeft= (window.outerWidth - iWindowWidth)/2;
	}
	
	if (document.all)
	{
		var iWindowLeft = (window.screen.width - iWindowWidth)/2
	}
	
	return iWindowLeft;

}

function CallLogin()
{
	document.frmLogin.method="post"
	document.frmLogin.action=document.frmLogin.secURL.value + "/Shopper_lookup.php"
	document.frmLogin.submit()
}

// Function for Calling MyGuntopia page.
function CallMyGuntopia()
{
		Shopper_id = document.frmSearch.hdnShopperid.value
		Category = document.frmSearch.hdnCategory.value
		Classifieds = document.frmSearch.hdnAdCategory.value
		sURL = "MyClassified.php"
		win1 = window.open(sURL,'MyGuntopia','width=800,height=600,resizable=yes,scrollbars=yes,top=0,left=0,screenX=0,screenY=0');
		if (win1.opener == null) win1.opener = self;
}

function CallMyAccount(Flag)
{
	Shopper_id = document.frmSearch.hdnShopperid.value;
	Category = document.frmSearch.hdnCategory.value;
	Classifieds = document.frmSearch.hdnAdCategory.value;
	sURL = "MyAccount.php?Popup=1";
	if (Flag == '1')
	    sURL = sURL + "&Close=1";
	win2 = window.open(sURL,'MyAccount','width=800,height=600,resizable=yes,scrollbars=yes,top=0,left=0,screenX=0,screenY=0');
	if (win2.opener == null) win2.opener = self;
}

// Function for Password Assist
function CallPassword()
{
		sURL = "Password_Assist1.php"
		win1 = window.open(sURL,'PasswordAssist','width=425,height=275,resizable=no,scrollbars=no,top=0,left=0,screenX=0,screenY=0');
		if (win1.opener == null) win1.opener = self;
}

// Function to set the combo box value
// el -- combo box name,,  val - value to be set
function setComboValue(el,val)
{
	if (document.all)
	{
		el.value = val
		return;
	}
	else
	{
		var numOptions = el.options.length
		var pos = 0
		var found = false
		var index = el.selectedIndex
		while ((!found) && (pos < numOptions) ) 
		{
			el.selectedIndex = pos
			if (el.options[pos].value == val) 
			{
				index = el.selectedIndex
				found = true
				
			}
			else
			{
				pos = pos + 1
			}
		}
		el.selectedIndex = index
		return;
	}
}


function ValidateTime(obj)
{
	if (!isEmpty(trim(obj.value)))
	{
		if (isValidTime(obj.value) == false)
		{
			alert("Enter a Valid Time \n(For example 04:00AM or 12:30PM)\n"); 
			obj.value= '';
			obj.focus();
			return false;
		}
	}
}


function MandatoryCheck(objform)
{
	msg=new String();

	if(trim(objform.txtOwnerName.value)=="")
			msg=msg+'\tOwner Name\n';

	if(trim(objform.txtLicName.value)=="")
			msg=msg+'\tLicense Name\n';
	
	if(trim(objform.txtStreet.value)=="")
			msg=msg+'\tStreet\n';
	
	if(trim(objform.txtCity.value)=="")
			msg=msg+'\tCity\n';
	
	if(objform.cmbState.selectedIndex==0)
			msg=msg+'\tState\n';
	
	if(trim(objform.txtZip.value)=="")
			msg=msg+'\tZip\n';
	
	if(trim(objform.txtExpireDate.value)=="")
			msg=msg+'\tExpiration Date Of FFL\n';

	if(CheckExpDate(objform.txtExpireDate.value,'1')==false)
			msg=msg+'\tExpiration Date Should be a Future Date \n';

	if(trim(objform.txtFFLType.value)=="")
			msg=msg+'\tFFL Type\n';
	
	if(trim(objform.txtFFLNum.value)=="")
			msg=msg+'\tFFL #\n';
	
	if(trim(objform.txtFedId.value)=="")
			msg=msg+'\tFe	d Id\n';

	if(trim(objform.txtPhone.value)=="")
			msg=msg+'\tPhone\n';
	
	if(trim(objform.txtBusinessStartDate.value)=="")
			msg=msg+'\tBusiness Start Date\n';
	
	if(CheckExpDate(objform.txtBusinessStartDate.value,'2')==false)
			msg=msg+'\tBusiness Start Date Should be a Valid date \n';
	
	if(trim(objform.txtStoreSize.value)=="")
			msg=msg+'\tStore Size\n';
	/*
	if(trim(objform.txtMonOpen.value)=="")
			msg=msg+'\tOpenTime for Monday\n';

	if(trim(objform.txtMonClose.value)=="")
			msg=msg+'\tCloseTime for Monday\n';

	if(trim(objform.txtTuesOpen.value)=="")
			msg=msg+'\tOpenTime for Tuesday\n';

	if(trim(objform.txtTuesClose.value)=="")
			msg=msg+'\tCloseTime for Tuesday\n';

	if(trim(objform.txtWednesOpen.value)=="")
			msg=msg+'\tOpenTime for Wednesday\n';
		
	if(trim(objform.txtWednesClose.value)=="")
			msg=msg+'\tCloseTime for Wednesday\n';
			
	if(trim(objform.txtThursOpen.value)=="")
			msg=msg+'\tOpenTime for Thursday\n';
			
	if(trim(objform.txtThursClose.value)=="")
			msg=msg+'\tCloseTime for Thursday\n'		
		
	if(trim(objform.txtFriOpen.value)=="")
			msg=msg+'\tOpenTime for Friday\n'

	if(trim(objform.txtFriClose.value)=="")
			msg=msg+'\tCloseTime for Friday\n'
	*/
	if(msg!="")
	{
		alert('The following are Mandatory\n'+msg)
		return false;
	}	
	else
		return true;
}


function CheckExpDate(FFLDate,chkType)
{
	var CurrDate = new Date();
	var GivenDate = new Date(FFLDate);
	if (chkType == 1)
	{
		if (CurrDate.getFullYear() > GivenDate.getFullYear())
		{
			return false;
		}
		if ((CurrDate.getFullYear() == GivenDate.getFullYear()) && ((CurrDate.getMonth() + 1) > GivenDate.getMonth() + 1))
		{
			return false;
		}
		if ((CurrDate.getFullYear() == GivenDate.getFullYear()) && (CurrDate.getMonth() + 1 == GivenDate.getMonth() + 1) && (CurrDate.getDate() > GivenDate.getDate()))
		{
			return false;
		}
	}
	else
	{
		if (CurrDate.getFullYear() < GivenDate.getFullYear())
		{
			return false;
		}
		if ((CurrDate.getFullYear() == GivenDate.getFullYear()) && ((CurrDate.getMonth() + 1) < GivenDate.getMonth() + 1))
		{
			return false;
		}
		if ((CurrDate.getFullYear() == GivenDate.getFullYear()) && (CurrDate.getMonth() + 1 == GivenDate.getMonth() + 1) && (CurrDate.getDate() > GivenDate.getDate()))
		{
			return false;
			
		}
	}
	return true;
}

//--------------------------------------------------------------------------------------------

// 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();
}
//--------------------------------------------------------------------------------------------

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();
		}
	}
}
//--------------------------------------------------------------------------------------------
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;
}
//----------------------------------------------------------------------------------------
function MakeDataFullYear()
{
	var dob="";
	if (eval(document.frmBid.cmbCreditMonth.options[document.frmBid.cmbCreditMonth.selectedIndex].text != ""))
			dob +=  document.frmBid.cmbCreditMonth.options[document.frmBid.cmbCreditMonth.selectedIndex].text
		if (eval(document.frmBid.txtCreditYear.options[document.frmBid.txtCreditYear.selectedIndex].text !=""))
			dob += "/" + document.frmBid.txtCreditYear.options[document.frmBid.txtCreditYear.selectedIndex].text

		document.frmBid.txtCardExpDate.value = dob;
		if (document.frmBid.txtCreditYear.value != "")
		{
			if(CheckCardNumber() == false)
				return false
		}
		return true;
}

