//===show and hide rollover effects on side menus
function fShowEffect(vID) {
	var obj = document.getElementById(vID)
	obj.style.background = '#FFCC66'
	obj.style.margin = '0px'
	obj.style.borderTop = 'black 1px ridge'
	obj.style.borderRight = 'black 1px ridge'
	obj.style.borderBottom = 'black 1px ridge'
	obj.style.borderLeft = 'black 1px ridge'
	obj.style.paddingTop = '0px'
	obj.style.paddingRight = '0px'
	obj.style.paddingBottom = '0px'
	obj.style.paddingLeft = '0px'
}
function fHideEffect(vID) {
	var obj = document.getElementById(vID)
	obj.style.background = ''
	obj.style.margin = ''
	obj.style.borderTop = ''
	obj.style.borderRight = ''
	obj.style.borderBottom = ''
	obj.style.borderLeft = ''
	obj.style.paddingTop = ''
	obj.style.paddingRight = ''
	obj.style.paddingBottom = ''
	obj.style.paddingLeft = ''
}

function openwindow(adid)
{
	vadid = adid
	window.open("http://restmart.com/EmailResponseForm.asp?adid=" + vadid ,"mywindow","menubar=1,resizable=1,width=350,height=250");
}

function PhReq() {
	window.open('Photorequirements.htm','PhotoRequirements','location=no,status=yes,scrollbars=no,resizable=yes,width=520,height=250')
}

//===make sure shopping cart is not empty
function fCheckCartItems(vThisForm) {
	if (document[vThisForm].emptycart) {
		alert("There are no items in your shopping cart at this time.")
		return(false)
	}
	if (document[vThisForm].shipping.selectedIndex < 1) {
		alert("The field -shipping- cannot be left blank.")
		return(false)
	}
}



//===make sure shopping cart is not empty
function fCheckCartQuantities(vItemCount) {
	for (i = 1; i < vItemCount + 1; i++) {
		var vThisField = "quantity" +vItemCount
		var vThisNumber = document.shoppingcart[vThisField].value
		if (isNaN(vThisNumber)) {
			alert("The field -quantity- must be numeric.")
			return (false)
		} else if (!(isNaN(vThisNumber))) {
			if (document.shoppingcart[vThisField].value < 1) {
				alert("The field -quantity- must be a whole number (ie. 1 or greater).")
				return (false)
			} else if (document.shoppingcart[vThisField].value > 1) {
				var vOldNumber = document.shoppingcart[vThisField].value
				var vNewNumber = parseInt(vOldNumber).toString()
				if (vOldNumber.length == vNewNumber.length && vNewNumber != "NaN") {
					return (true)
				} else {
					alert("The field -quantity- must be a whole number (ie. 1 or greater).")
					return (false)
				}
			}
		}
	}
}




//===validate forms before submission
function fValidate(vThisForm)
{	
	if (vThisForm == "frmAdSearch") 
	{
		//alert("search")
		if (document[vThisForm].ADID.value == "") {
			alert("The field - AD # - cannot be left blank.")
			document[vThisForm].ADID.focus()
			return(false)
		}	
	}
	//--validate email listing form
	if (vThisForm == "frmEmailListing") 
	{
		if (document[vThisForm].name.value == "") {
			alert("The field - Your Name - cannot be left blank.")
			document[vThisForm].name.focus()
			return(false)
		}	
		var vThisEmail = new String(document[vThisForm].email.value)
		if (document[vThisForm].email.value == "" || vThisEmail.search("@") == -1) {
			alert("The field -email- cannot be left blank and must be properly formatted.")
			document[vThisForm].email.focus()
			return(false)
		}
	}
	
	//--validate update ad form
	if (vThisForm == "frmUpdateAd") 
	{
		if(document[vThisForm].border.checked = true ) 
			{
			if (document[vThisForm].bordercolor.selectedIndex < 1) {
			alert("The field -Border Color- cannot be left blank.")
			document[vThisForm].bordercolor.focus()
			return(false)
			}	
		else
			{
			}		
		}
		if(document[vThisForm].cclipart.checked = true ) {
			if (document[vThisForm].clipart.selectedIndex < 1) {
			alert("The field -Animated Clip Art- cannot be left blank.")
			document[vThisForm].clipart.focus()
			return(false)
			}		
			else
			{
			}		
		}
		if(document[vThisForm].link.checked = true ) {
			if (document[vThisForm].websitelink.value == "") {
			alert("The field - Link to your website - cannot be left blank.")
			document[vThisForm].websitelink.focus()
			return(false)
			else
			{
			}	
		}			
		}
		if (document[vThisForm].username.value == "") {
			alert("The field - Username - cannot be left blank.")
			document[vThisForm].username.focus()
			return(false)
		}		
		if (document[vThisForm].password.value == "") {
			alert("The field - Password - cannot be left blank.")
			document[vThisForm].password.focus()
			return(false)
		}	
		if (document[vThisForm].contactname.value == "") {
			alert("The field - Contact Name - cannot be left blank.")
			document[vThisForm].contactname.focus()
			return(false)
		}	
		if (document[vThisForm].phone.value == "") {
			alert("The field - Phone - cannot be left blank.")
			document[vThisForm].phone.focus()
			return(false)
		}	
		var thisChar = document[vThisForm].phone.value
		if (isNaN(thisChar)) {
			alert("The field -Phone- must be numeric.")
			document[vThisForm].phone.focus()
			return(false)
		}
		var vThisEmail = new String(document[vThisForm].email.value)
		if (document[vThisForm].email.value == "" || vThisEmail.search("@") == -1) {
			alert("The field -email- cannot be left blank and must be properly formatted.")
			document[vThisForm].email.focus()
			return(false)
		}
		if (document[vThisForm].billing.selectedIndex < 1) {
			alert("The field -Billing Options- cannot be left blank.")
			document[vThisForm].billing.focus()
			return(false)
		}
		if (document[vThisForm].cardtype.selectedIndex < 1) {
			alert("The field -Payment Method- cannot be left blank.")
			document[vThisForm].cardtype.focus()
			return(false)
		}
		if (document[vThisForm].cardholder.value == "") {
			alert("The field - Cardholder Name - cannot be left blank.")
			document[vThisForm].cardholder.focus()
			return(false)
		}	
		if (document[vThisForm].cardno1.value == "") {
			alert("The field - Credit Card Number - cannot be left blank.")
			document[vThisForm].cardno1.focus()
			return(false)
		}	
		var thisChar = document[vThisForm].cardno1.value
		if (isNaN(thisChar)) {
			alert("The field -Credit Card Number- must be numeric.")
			document[vThisForm].cardno1.focus()
			return(false)
		}
		if (document[vThisForm].cardno2.value == "") {
			alert("The field - Credit Card Number - cannot be left blank.")
			document[vThisForm].cardno2.focus()
			return(false)
		}	
		var thisChar = document[vThisForm].cardno2.value
		if (isNaN(thisChar)) {
			alert("The field -Credit Card Number- must be numeric.")
			document[vThisForm].cardno2.focus()
			return(false)
		}
		if (document[vThisForm].cardno3.value == "") {
			alert("The field - Credit Card Number - cannot be left blank.")
			document[vThisForm].cardno3.focus()
			return(false)
		}	
		var thisChar = document[vThisForm].cardno3.value
		if (isNaN(thisChar)) {
			alert("The field -Credit Card Number- must be numeric.")
			document[vThisForm].cardno3.focus()
			return(false)
		}
		if (document[vThisForm].cardno4.value == "") {
			alert("The field - Credit Card Number - cannot be left blank.")
			document[vThisForm].cardno4.focus()
			return(false)
		}	
		var thisChar = document[vThisForm].cardno4.value
		if (isNaN(thisChar)) {
			alert("The field -Credit Card Number- must be numeric.")
			document[vThisForm].cardno4.focus()
			return(false)
		}
		//validate expiration date		
		var today = new Date();
		var TempDate = new Date(document[vThisForm].expYear.value,document[vThisForm].expMonth.value - 1 , 01 );		
		var EnteredDate = new Date(document[vThisForm].expYear.value,document[vThisForm].expMonth.value - 1 ,getDaysInMonth(TempDate)  );  
		
		if(EnteredDate < today)
		{ 
			alert("Please select a valid Expiration Date.");
			document[vThisForm].expMonth.focus()
			return(false);				
		}
		if (document[vThisForm].baddress.value == "") {
			alert("The field - Billing Address - cannot be left blank.")
			document[vThisForm].baddress.focus()
			return(false)
		}	
		if (document[vThisForm].bcity.value == "") {
			alert("The field - Billing City - cannot be left blank.")
			document[vThisForm].bcity.focus()
			return(false)
		}	
		if (document[vThisForm].bstate.value == "") {
			alert("The field - Billing State - cannot be left blank.")
			document[vThisForm].bstate.focus()
			return(false)
		}	
		if (document[vThisForm].bzip.value == "") {
			alert("The field - Billing Zip - cannot be left blank.")
			document[vThisForm].bzip.focus()
			return(false)
		}	
		if(document[vThisForm].agree.checked != true ) {	
			alert("The field - Agreement - cannot be left unchecked.")
			return(false)
		}
	}
	
	//--validate subscriber login form
	if (vThisForm == "frmLogin") 
	{
		if (document[vThisForm].username.value == "") {
			alert("The field - UserName - cannot be left blank.")
			document[vThisForm].username.focus()
			return(false)
		}	
		if (document[vThisForm].password.value == "") {
			alert("The field - Password - cannot be left blank.")
			document[vThisForm].password.focus()
			return(false)
		}	
	}
	
	//--post additional ad for sale
	if (vThisForm == "frmPostAdAdditional") 
	{
		if (document[vThisForm].adcity.value == "") {
			alert("The field - Ad City - cannot be left blank.")
			document[vThisForm].adcity.focus()
			return(false)
		}
		var vThisNumber = document[vThisForm].adcity.value
		if (isNaN(vThisNumber)) 
		{
		
		}
		else
		{
			alert("The field -Ad City- must be text only.")
			return (false)
		} 	
		if (document[vThisForm].username.value == "") {
			alert("The field - Username - cannot be left blank.")
			document[vThisForm].username.focus()
			return(false)
		}		
		if (document[vThisForm].password.value == "") {
			alert("The field - Password - cannot be left blank.")
			document[vThisForm].password.focus()
			return(false)
		}	
		if (document[vThisForm].contactname.value == "") {
			alert("The field - Contact Name - cannot be left blank.")
			document[vThisForm].contactname.focus()
			return(false)
		}	
		if (document[vThisForm].phone.value == "") {
			alert("The field - Phone - cannot be left blank.")
			document[vThisForm].phone.focus()
			return(false)
		}	
		var thisChar = document[vThisForm].phone.value
		if (isNaN(thisChar)) {
			alert("The field -Phone- must be numeric.")
			document[vThisForm].phone.focus()
			return(false)
		}
		var vThisEmail = new String(document[vThisForm].email.value)
		if (document[vThisForm].email.value == "" || vThisEmail.search("@") == -1) {
			alert("The field -email- cannot be left blank and must be properly formatted.")
			document[vThisForm].email.focus()
			return(false)
		}
		if (document[vThisForm].agencyname.value == "") {
			alert("The field - Agency Name - cannot be left blank.")
			document[vThisForm].agencyname.focus()
			return(false)
		}	
		if (document[vThisForm].billing.selectedIndex < 1) {
			alert("The field -Billing Options- cannot be left blank.")
			document[vThisForm].billing.focus()
			return(false)
		}
		if (document[vThisForm].cardholder.value == "") {
			alert("The field - Cardholder Name - cannot be left blank.")
			document[vThisForm].cardholder.focus()
			return(false)
		}	
	}
		
		
		
	//--update billing information
	if (vThisForm == "frmUpdateBilling") 
	{
		if (document[vThisForm].username.value == "") {
			alert("The field - UserName - cannot be left blank.")
			document[vThisForm].username.focus()
			return(false)
		}	
		if (document[vThisForm].password.value == "") {
			alert("The field - Password - cannot be left blank.")
			document[vThisForm].password.focus()
			return(false)
		}	
		if (document[vThisForm].cardholder.value == "") {
			alert("The field - Current Billing Name - cannot be left blank.")
			document[vThisForm].cardholder.focus()
			return(false)
		}	
		var vThisEmail = new String(document[vThisForm].email.value)
		if (document[vThisForm].email.value == "" || vThisEmail.search("@") == -1) {
			alert("The field -email- cannot be left blank and must be properly formatted.")
			document[vThisForm].email.focus()
			return(false)
		}
		if (document[vThisForm].location.value == "") {
			alert("The field - Restaurant Location - cannot be left blank.")
			document[vThisForm].location.focus()
			return(false)
		}	
		if (document[vThisForm].phone.value == "") {
			alert("The field - Phone - cannot be left blank.")
			document[vThisForm].phone.focus()
			return(false)
		}	
		var thisChar = document[vThisForm].phone.value
		if (isNaN(thisChar)) {
			alert("The field -Phone- must be numeric.")
			document[vThisForm].phone.focus()
			return(false)
		}
		if (document[vThisForm].cardtype.selectedIndex < 1) {
			alert("The field -New Payment Method- cannot be left blank.")
			document[vThisForm].cardtype.focus()
			return(false)
		}
		if (document[vThisForm].cardholdernew.value == "") {
		alert("The field - Card Holder Name - cannot be left blank.")
		document[vThisForm].cardholdernew.focus()
		return(false)
		}	
		if (document[vThisForm].cardno1.value == "") {
			alert("The field - Credit Card Number - cannot be left blank.")
			document[vThisForm].cardno1.focus()
			return(false)
		}	
		var thisChar = document[vThisForm].cardno1.value
		if (isNaN(thisChar)) {
			alert("The field -Credit Card Number- must be numeric.")
			document[vThisForm].cardno1.focus()
			return(false)
		}
		if (document[vThisForm].cardno2.value == "") {
			alert("The field - Credit Card Number - cannot be left blank.")
			document[vThisForm].cardno2.focus()
			return(false)
		}	
		var thisChar = document[vThisForm].cardno2.value
		if (isNaN(thisChar)) {
			alert("The field -Credit Card Number- must be numeric.")
			document[vThisForm].cardno2.focus()
			return(false)
		}
		if (document[vThisForm].cardno3.value == "") {
			alert("The field - Credit Card Number - cannot be left blank.")
			document[vThisForm].cardno3.focus()
			return(false)
		}	
		var thisChar = document[vThisForm].cardno3.value
		if (isNaN(thisChar)) {
			alert("The field -Credit Card Number- must be numeric.")
			document[vThisForm].cardno3.focus()
			return(false)
		}
		if (document[vThisForm].cardno4.value == "") {
			alert("The field - Credit Card Number - cannot be left blank.")
			document[vThisForm].cardno4.focus()
			return(false)
		}	
		var thisChar = document[vThisForm].cardno4.value
		if (isNaN(thisChar)) {
			alert("The field -Credit Card Number- must be numeric.")
			document[vThisForm].cardno4.focus()
			return(false)
		}
		//validate expiration date		
		var today = new Date();
		var TempDate = new Date(document[vThisForm].expYear.value,document[vThisForm].expMonth.value - 1 , 01 );		
		var EnteredDate = new Date(document[vThisForm].expYear.value,document[vThisForm].expMonth.value - 1 ,getDaysInMonth(TempDate)  );  
		
		if(EnteredDate < today)
		{ 
			alert("Please select a valid Expiration Date.");
			document[vThisForm].expMonth.focus()
			return(false);				
		}
	}
	
	//--update account
	if (vThisForm == "frmUpdateAccount") 
	{
		if (document[vThisForm].username.value == "") {
			alert("The field - UserName - cannot be left blank.")
			document[vThisForm].username.focus()
			return(false)
		}	
		if (document[vThisForm].password.value == "") {
			alert("The field - Password - cannot be left blank.")
			document[vThisForm].password.focus()
			return(false)
		}	
		if (document[vThisForm].contactname.value == "") {
			alert("The field - Contact Name - cannot be left blank.")
			document[vThisForm].contactname.focus()
			return(false)
		}	
		var vThisEmail = new String(document[vThisForm].email.value)
		if (document[vThisForm].email.value == "" || vThisEmail.search("@") == -1) {
			alert("The field -email- cannot be left blank and must be properly formatted.")
			document[vThisForm].email.focus()
			return(false)
		}
		if(document[vThisForm].modify.checked != true )
			{
				if(document[vThisForm].remove.checked != true )
					{
						if(document[vThisForm].ccolor.checked != true )
							{
								if(document[vThisForm].cclipart.checked != true )
									{
										if(document[vThisForm].clink.checked != true )
										{
											if(document[vThisForm].cphoto.checked != true )
												{
													if(document[vThisForm].cmassemail.checked != true )
													{
														alert("Please select atleast one modify options.")
														return(false)
													}
												}
										}
									}
							}
					
					}
			
			}
		
		
		if(document[vThisForm].modify.checked != true ) 
			{
			}
			else
			{	
			if (document[vThisForm].modifyoptions.selectedIndex < 1) {
			alert("The field -Modify your existing Ad - cannot be left blank.")
			document[vThisForm].modifyoptions.focus()
			return(false)
			}
			if (document[vThisForm].changes.value == "") {
			alert("The field - Indicate Changes - cannot be left blank.")
			document[vThisForm].changes.focus()
			return(false)
			}				
		}
		if(document[vThisForm].remove.checked != true ) 
			{
			}
			else
			{
			if (document[vThisForm].adcity.value == "") {
			alert("The field - City - cannot be left blank.")
			document[vThisForm].adcity.focus()
			return(false)
			}		
			if (document[vThisForm].adstate.selectedIndex < 1) {
			alert("The field -State - cannot be left blank.")
			document[vThisForm].adstate.focus()
			return(false)
			}
			if (document[vThisForm].adcopy.value == "") {
			alert("The field - Informative Ad Copy - cannot be left blank.")
			document[vThisForm].adcopy.focus()
			return(false)
			}	
						
		}
		if(document[vThisForm].ccolor.checked != true ) 
			{
			}
			else
			{
			if (document[vThisForm].color.selectedIndex < 1) {
			alert("The field -Make your Ad full color - cannot be left blank.")
			document[vThisForm].color.focus()
			return(false)
			}
		}	
		if(document[vThisForm].cclipart.checked != true ) 
			{
			}
			else
			{
			if (document[vThisForm].clipart.selectedIndex < 1) {
			alert("The field -Add a clipart graphic - cannot be left blank.")
			document[vThisForm].clipart.focus()
			return(false)
			}
		}	
		if(document[vThisForm].clink.checked != true ) 
			{
			}
			else
			{
			if (document[vThisForm].link.selectedIndex < 1) {
			alert("The field -Link to your web address - cannot be left blank.")
			document[vThisForm].link.focus()
			return(false)
			}
		}	
	}
	
	
}	

function textLimit(field, maxlen) 
{
	if (field.value.length > maxlen + 1)
		alert("your input has been truncated!");
	if (field.value.length > maxlen)
		field.value = field.value.substring(0, maxlen);
}
function getDaysInMonth(aDate){
   // returns the last day of a given month
    var m = new Number(aDate.getMonth());
    var y = new Number(aDate.getYear());

    var tmpDate = new Date(y, m, 28);
    var checkMonth = tmpDate.getMonth();
    var lastDay = 27;

    while(lastDay <= 31){
        temp = tmpDate.setDate(lastDay + 1);
        if(checkMonth != tmpDate.getMonth())
            break;
        lastDay++
    }
    return lastDay;
}
