// m42p.js
// Marina42 Public Site Javascript
// Copyright (c) 2006 TireSwing Systems, Inc.
// All Rights Reserved.

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,toolbar,status,titlebar" , false );
	newWindow.focus();
}

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

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

function PopUpFaq ( entry, dealer, width, height ) {
	var myURL = ( "/cgi-bin/p/m42p-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" , false );
	PreviewWindow.focus();
}

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


function VFGB() {
	var DF = document.guestbook;
	var Mesg = "";
	if( ! trim( DF.name.value ) ) {
		Mesg += "      + Please fill in the NAME field          \n";
	}
	if( DF.subscribe ) {
		if( DF.subscribe.checked ) {
			if( ! ValidEmail( trim( DF.email.value ) ) ) {
				Mesg += "      + You must supply email address to subscribe      \n";
			}
		}
	}
	if( Mesg ) {
		alert( "\n\n    The form cannot be submitted:          \n\n" + Mesg + "\n\n" );
		return false;
	} else {
		DF.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 {
		document.service.thing.value = "desmond";
		return true;
	}
}


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


function SetRfpEmail() {
	var myCookie = document.cookie;
	var Pos = myCookie.indexOf( "rfp=" );
	if( Pos != -1 ) {
		var start = Pos + 4;
		var endEmail = myCookie.indexOf( "%" , start );
		if( endEmail == -1 ) endEmail = myCookie.length;
		var Email = myCookie.substring( start , endEmail );
		var Address = myCookie.substring( endEmail + 1 , myCookie.length );
		document.rfp.email.value=Email;
		if( document.rfp.address ) {
			document.rfp.address.value=Address;
		}
	}
}


function VFRfp( AddrRequired, PhoneRequired ) {
	var Email = trim( document.rfp.email.value );
	var Address = "";
	var Mesg = "";

	if( ! trim( document.rfp.name.value ) ) {
		Mesg += "    Please let us know your name.      \n";
	}

	if( ! ValidEmail( Email ) ) {
		Mesg += "    Cannot submit without the email address.      \n";
	}

	if( document.rfp.address ) {
		Address = trim( document.rfp.address.value );
		if( AddrRequired && ! Address ) {
			Mesg += "    Please complete the address line.      \n";
		}
	}

	if( document.rfp.phone ) {
		Phone = trim( document.rfp.phone.value );
		if( PhoneRequired && ! Phone ) {
			Mesg += "    Please enter a phone number so we can reach you.      \n";
		}
	}

	if( Mesg ) {
		alert( Mesg );
		return false;
	} else {
		if( ! Address ) {
			var cookieAddress = "";
			var myCookie = document.cookie;
			var Pos = myCookie.indexOf( "rfp=" );
			if( Pos != -1 ) {
				var start = Pos + 4;
				var startAddress = myCookie.indexOf( "%" , start ) + 1;
				cookieAddress = myCookie.substring( startAddress , myCookie.length );
			}
			Address = cookieAddress;
		}
		document.cookie = "rfp=" + Email + "%" + Address + ";path=/; expires=Friday, 12-Dec-25 05:06:00;";
		return true;
	}
}


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


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


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


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;
}


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

