// o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
// awtp.js
// copyright 2003-2009 tireswing systems, inc. all rights reserved. DO NOT REUSE.
// o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o


function ValidEmail( Email ) {
	Email = trim( Email );
	if( ( ! Email ) || ( ! Email.match( /^[\w\.\-\_]+@[^\.][\w\.\-\_]+$/ ) ) || ( ! Email.match( /\.[a-zA-Z]{2,}$/ ) ) ) {
		return false;
	} else {
		return true;
	}
}


//# o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o

function PopUp( URL , Name , X , Y , Xoff , Yoff ) {
	if( ! Xoff ) { Xoff = 25; }
	if( ! Yoff ) { Yoff = 25; }
	var newWindow = window.open( URL , Name , "screenX=" + Xoff + ",left=" + Xoff + ",screenY=" + Yoff + ",top=" + Yoff + ",width=" + X + ",height=" + Y + ",scrollbars=yes,resizable=yes" , false );
	newWindow.focus();
}


//# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #
//
// Function to pop up the bigger picture in a new window.


function PopUpStorePic( myPic ) {
	var myURL = ( "/cgi-bin/p/awtp-showpic.cgi?p=" + myPic );
	var PreviewWindow = window.open( myURL , "storepic" , "width=600,height=600,top=25,left=50,screenX=50,screenY=25,resizable,scrollbars" , false );
	PreviewWindow.focus();
}

function PopUpPic ( myPic ) {
	var myURL = ( "/cgi-bin/p/awtp-showpic.cgi?p=" + myPic );
	var PreviewWindow = window.open( myURL , "mypic" , "width=600,height=600,top=25,left=50,screenX=50,screenY=25,resizable,scrollbars" , false );
	PreviewWindow.focus();
}

function PopUpScrapbook ( myPic, width, height ) {
	var myURL = ( "/cgi-bin/p/awtp-showpic.cgi?p=" + myPic );
	var PreviewWindow = window.open( myURL , "mypic" , "width=" + width + ",height=" + height + ",top=25,left=50,screenX=50,screenY=25,resizable,scrollbars" , false );
	PreviewWindow.focus();
}

function PopUpFaq ( entry, dealer, width, height ) {
	var myURL = ( "/cgi-bin/p/awtp-faqentry.cgi?d=" + dealer + "&id=" + entry );
	var PreviewWindow = window.open( myURL , "faq" , "width=" + width + ",height=" + height + ",top=25,left=50,screenX=50,screenY=25,resizable,scrollbars" , false );
	PreviewWindow.focus();
}

function PopUpProductQueryForm ( dealer, product, width, height ) {
	var myURL = ( "/cgi-bin/p/awtp-product-query-form.cgi?d=" + dealer + "&id=" + product );
	var ProductQueryWindow = window.open( myURL , "faq" , "width=" + width + ",height=" + height + ",top=25,left=50,screenX=50,screenY=25,resizable,scrollbars" , false );
	ProductQueryWindow.focus();
}

function PopUpProductCategoryQueryForm ( dealer, category, width, height ) {
	var myURL = ( "/cgi-bin/p/awtp-product-category-query-form.cgi?d=" + dealer + "&id=" + category );
	var ProductQueryWindow = window.open( myURL , "faq" , "width=" + width + ",height=" + height + ",top=25,left=50,screenX=50,screenY=25,resizable,scrollbars" , false );
	ProductQueryWindow.focus();
}

//# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #



function VFGB() {
	var Mesg = "";
	if( ! document.guestbook.name.value ) {
		Mesg += "      Please fill in the NAME field.          \n";
	}
	if( ! ValidEmail( trim( document.guestbook.email.value ) ) ) {
		Mesg += "  Please complete the EMAIL field (it will never be visible to the public).      \n";
	}
	if( Mesg ) {
		alert( "\n\n    The form cannot be submitted:          \n\n" + Mesg + "\n\n" );
		return false;
	} else {
		document.guestbook.thing.value="desmond";
		return true;
	}
}


//# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #


function VFServicePublic() {
	var Mesg = "";
	var GoodEmail = 1;
	var GoodPhone = 1;

	// validate that there's a name.

	if( ! document.service.name.value ) {
		Mesg += "      Please fill in the NAME field.          \n";
	}

	// validate that there's a phone number.

	if( ! document.service.phone.value ) {
		GoodPhone = 0;
	}

	// validate that if there's an email entered that it looks valid...

	if( ( ! document.service.email.value ) || ( ! document.service.email.value.match( /^[\w\.-_]+@[^\.][\w\.]+$/ ) ) | ( ! document.service.email.value.match( /\.[a-zA-Z]{2,}$/ ) ) ) {
		GoodEmail = 0;
	}

	if( GoodPhone + GoodEmail == 0 ) {
		Mesg += "      Please fill in either the PHONE or EMAIL field.          \n";
	}

	if( ! document.service.service.value ) {
		Mesg += "      Please fill in the SERVICES NEEDED area.          \n";
	}

	if( Mesg ) {
		alert( "\n\n    The form cannot be submitted:          \n\n" + Mesg + "\n\n" );
		return false;
	} else {
		return true;
	}
}


//# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #


function VFForm() {
	var Mesg = "";
	if( ! document.contact.name.value ) {
		Mesg += "      + Name is empty          \n";
	}
	if( ! document.contact.comments.value ) {
		Mesg += "      + Comments field is empty          \n";
	}
	if( Mesg ) {
		alert( "\n    The form can't be submitted yet:          \n\n" + Mesg + "\n" );
		return false;
	} else {
		return true;
	}
}


//# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #

function VFSignin() {
	var Mesg = "";
	if( ! ValidEmail( trim( document.signin.email.value ) ) ) {
		Mesg += "  + Email is empty or invalid      \n";
	}
	if( ! trim( document.signin.password.value ) ) {
		Mesg += "  + Password is empty      \n";
	}
	if( Mesg ) {
		alert( "\n  The sign in form cannot be submitted:      \n\n" + Mesg + "\n" );
		return false;
	} else {
		return true;
	}
}

function VFMemberSignup( forumflag ) {
	var Mesg = "";
	var GoodEmail = false;
	var e1 = trim( document.signup.email.value );
	var e2 = trim( document.signup.emailv.value );

	if( ! trim( document.signup.name.value ) ) {
		Mesg += "    + Name field is empty        \n";
	}
	if( ValidEmail( e1 ) && ( e1 == e2 ) ) {
		GoodEmail = true;
	}
	if( ! GoodEmail ) {
		Mesg += "    + Email fields must be valid and match exactly      \n";
	}
	if( forumflag && ! trim( document.signup.alias.value ) ) {
		Mesg += "    + Alias field is empty      \n";
	}
	if( forumflag && ! document.signup.agree.checked ) {
		Mesg += "    + You must accept the membership terms      \n";
	}
	if( Mesg ) {
		alert( "\n  The form cannot be submitted yet:      \n\n" + Mesg + "\n" );
		return false;
	} else {
		document.signup.thing.value = "desmond";
		return true;
	}
}

function VFPublicMemberSettings() {
	var Mesg = "";
	var Email = trim( document.settings.email.value.toLowerCase() );
	var Emailv = trim( document.settings.emailv.value.toLowerCase() );
	var allowChangePw = trim( document.settings.allow_change_password.value );


	if( ! trim( document.settings.name.value ) ) {
		Mesg += "    + Name field is empty      \n";
	}

	if( ! trim( document.settings.password.value ) || ! trim( document.settings.passwordv.value ) ) {
		Mesg += "    + Invalid password      \n";
	}

	if( Email != Emailv ) {
		Mesg += "    + Both Email fields must match exactly      \n";
	} else {
		if( ! ValidEmail( Email ) ) {
			Mesg += "    + Email must be a valid email pattern      \n";
		}
	}

	if( allowChangePw == "1" ) {
		var subMesg = VFPublicMemberSettingsPW();
		if( subMesg != "" ) {
			Mesg += subMesg;
		}
	}

	if( Mesg ) {
		alert( "\n  The form cannot be submitted:      \n\n" + Mesg + "\n" );
		return false;
	} else {
		return true;
	}
}


function VFPublicMemberSettingsPW () {
	var Password = document.settings.password.value.toLowerCase();
	var Passwordv = document.settings.passwordv.value.toLowerCase();
	var Mesg = "";
	if( Password && Passwordv && ( Password == Passwordv ) ) {
		// Good!
	} else {
		Mesg += "    + Both Password forms must be valid and match exactly      \n";
	}
	return Mesg;
}

//# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #

function trim( myStr ) {
	myStr = myStr.replace( /^\s+/ , "" );
	myStr = myStr.replace( /\s+$/ , "" );
	return myStr;
}


//# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #


function HL( Row , Color ) {
	document.getElementById( Row ).bgColor=Color;
}


//# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #


function UHL( Row , Color ) {
	document.getElementById( Row ).bgColor=Color;
}


//# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #

function ValidPhone( Phone ) {
	var GoodSwitch = 0;
	if( Phone.match( /^[\d \-\(\)\.]+$/ ) ) {
		if( Phone.replace( /[^\d]/g , "" ).match( /^1?[23456789]\d{9}$/ ) ) {
			GoodSwitch++;
		}
	}
	return GoodSwitch;
}

//# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #

function UpdateShipping( Item ) {
	var ppform;
	var ppformname = "paypal" + Item;
	var selname = "shipsel" + Item;

	for ( var i = 0; i<document.forms.length; i++ ) {
		if( document.forms[i].name == ppformname ) {
			// Found the proper form.
			// Now grab the selector to find the new shipping cost

			var selector = document.all.item( selname );
			var si = selector.selectedIndex;
			var newshipid = selector.options[si].value;
			var shipmethod = selector.options[si].innerText;

			document.forms[i].shipid.value = newshipid;
		}
	}
}

//# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #


function ToggleCB( CB ) {
	var MYCB = eval( "document." + CB );
	if( MYCB.checked == true ) {
		MYCB.checked = false;
	} else {
		MYCB.checked = true;
	}
}


//# o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o


function ToggleRadio( RADIONAME , POSITION ) {
	eval( "document." + RADIONAME + "[" + POSITION + "].checked=true" );
}


//# o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o

