// put all java script in this file and make calls - see add_to_favorites_button.htm

// Opens new window in a new browser
function NewWindow(mypage, myname, w, h, scroll, tool, direct, stat, menub) 
{
	var winl = (screen.width - w)/2;
	var wint = (screen.height - h)/2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar='+tool+',directories='+direct+',status='+stat+',menubar='+menub+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function goTo( url ) {
	window.location.href = url;
}

// Creates new web page used to view pics
function create(this_photo, photo_comment, w, h) 
{ 
    var picStr = "images/"+this_photo+".jpg"
    var winl = (screen.width - w)/2;
    var wint = (screen.height - h)/2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',toolbar=no,directories=no,status=no,scrollbars=no,resize=no,menubar=no'
    pop_up = window.open(picStr,this_photo,winprops);
    with (pop_up.document) 
    {                 
		writeln ("<html>");
		writeln ("<TITLE>Big House Bordeaux</TITLE>");
		writeln ("<body bgcolor='#ffffff' text='#000000' link='#0000ff' vlink='#800080' alink='#ff0000' topmargin='5' marginheight='0' leftmargin='0'>");
		writeln ("<table border='0' cellpadding='0' cellspacing='0' align='center'>");

		writeln ("<tr><td><img src=" + picStr + " WIDTH='100%'></td></tr>");
		writeln ("<tr><td align='center' bgcolor='#000000'><b><font face='Arial' size='3' color='#ffffff'>" +photo_comment+ "</font></b></td></tr>");
		

		writeln ("<tr><form><td align='center' bgcolor='C5C5C5'><input type='button' value='Close' onclick='window.close()'></td></form></tr>");

		writeln ("</table>");
		writeln ("</body>");
		writeln ("</html>");
    }
}


function navBar( tableCellRef, hoverFlag, navStyle ) {
	if ( hoverFlag ) {
		switch ( navStyle ) {
			case 1:
				tableCellRef.style.backgroundColor = '#6c9';
				break;
			default:
//				tableCellRef.style.backgroundColor = '#ccc';
				if ( document.getElementsByTagName ) {
					tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#c00';
				}
		}
	} else {
		switch ( navStyle ) {
			case 1:
				tableCellRef.style.backgroundColor = '#063';
				break;
			default:
//				tableCellRef.style.backgroundColor = '#ddd';
				if ( document.getElementsByTagName ) {
					tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#000';
				}
		}
	}
}



function navBarClick( tableCellRef, navStyle, url ) {
	 navBar( tableCellRef, 0, navStyle );
	 goTo( url );
}




// Check for required fields in contact.htm for waitinglist
function check_parts(cfrm)
{
	var rtn=true
	if (rtn == true)
	{
		rtn = false
		var the_str
		the_str = cfrm.GENDER
		document.forms[0].GENDER[0].focus()
		for (i = 0; i < the_str.length; i++)
		{
			if( the_str[i].checked == true)
			{
				rtn = true
			}
		}
		if (rtn != true)
		{
			alert ("Please enter either Male, Female, or No preference")
		} 
	}

	if (rtn == true)
	{
		rtn = false
		var the_str
		the_str = cfrm.QUALITY
		document.forms[0].QUALITY[0].focus()
		for (i = 0; i < the_str.length; i++)
		{
			if( the_str[i].checked == true)
			{
				rtn = true
			}
		}
		if (rtn != true)
		{
			alert ("Please enter either Pet Quality, Breed able, or Undetermined")
		} 
	}

	if (rtn == true)
	{
		var txt
		txt = cfrm.name.value
		var rtn = false
		var onechar
		document.forms[0].name.focus()
		if (txt.length > 0)
		{
			for (var i=0; i < txt.length; i++)
			{
				onechar = txt.charAt(i)
				if (onechar != " ")
				{
					rtn = true
				}
			}
		}
		if (rtn != true)
		{
			alert ("Please enter in a Name")
		}
	}

	if (rtn == true)
	{
		var rtn = false
		var email_ad
		email_ad = cfrm.from.value
		document.forms[0].from.focus()
		if (email_ad.length >= 5)
		{
			if ( email_ad.search("[.@{1}.+\.{1}.]") != -1 )
			{
				rtn = true
			}
			if ( email_ad.search("[@]") == -1 )
			{
				rtn = false
			}
			if ( email_ad.search("[\.]") == -1 )
			{
				rtn = false
			}
		}
		if (rtn != true)
		{
			alert ("Please enter in a valid email address")
		}
	}
	if (rtn == true)
	{
		var rtn = false
		var acode
		acode = cfrm.AREACD.value
		document.forms[0].AREACD.focus()
		if (acode.length == 3)
		{
			if ( acode.search("[0-9][0-9][0-9]") != -1 )
			{
				rtn = true
			}
		}
		if (rtn != true)
		{
			alert ("Please enter in a 3-digit Area code")
		}
	}
	if (rtn == true)
	{
		var rtn = false
		var phonenbr
		phonenbr = cfrm.PNUMBER.value
		document.forms[0].PNUMBER.focus()
		if (phonenbr.length == 8)
		{
			if ( phonenbr.search("[0-9][0-9][0-9][ -.][0-9][0-9][0-9][0-9]") != -1 )
			{
				rtn = true
			}
		}
		if (rtn != true)
		{
			alert ("Please enter in a valid phone number")
		}
	}
	return rtn
}

// Reset form
function ResetForm()
{
	if (confirm("Please confirm reset."))
	{
		document.forms[0].reset()
	}
}

// Close Window
function go_back()
{
	window.close()
}

