// JavaScript Document
var showaddtocart= false;
function isEmail(str) {
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
    return (!r1.test(str) && r2.test(str));
}

function checkForm() { 
document.orderForm.sendersemail.value=trim(document.orderForm.sendersemail.value);
	if(isEmail(document.orderForm.sendersemail.value) == "") {
		alert("Invalid E-mail\nPlease Re-enter");
		document.orderForm.sendersemail.focus();
		return false;
	} else{
		document.orderForm.action = "http://site.penplace.com/solidcactus/mapprice.php?price=" + document.getElementById("mappriceval").value + "&ogprice=" + document.getElementById("ogprice").value;
		document.orderForm.target = "newWin";
		return openWin("newWin", 300, 250, true)
	}
}

function trim(value) {
 	startpos=0;
	while((value.charAt(startpos)==" ")&&(startpos<value.length))
   		startpos++;
	if(startpos==value.length)
   		value="";
 	else{
		value=value.substring(startpos,value.length);
		endpos=(value.length)-1;
		while(value.charAt(endpos)==" ")
		 endpos--;
		value=value.substring(0,endpos+1);
 	}
 return(value);
}

function openWin(wName, wWidth, wHeight, wResize){
	features = 'left=0,top=0,scrollbars=0,status=0,resizable=' + ((wResize) ? 0 : 0) + ((wWidth) ? ',width=' + wWidth : '') + ((wHeight) ? ',height=' + wHeight : '');
	popWin = window.open('', wName, features);
	if(popWin.focus) { popWin.focus(); }
	return true;
}

function revealOrderBtn(){
readMapPriceCookie();
	var cururl = location.search;
	var orderhtml = "<center><input type=image src=/lib/yhst-97367470559681/add-to-cart.gif border=0 width=201 height=29></center>";
	if(cururl == "?showaddtocart=true" || showaddtocart){		
		document.getElementById("orderbtn").innerHTML = orderhtml;
		document.getElementById("mapsaleprice").innerHTML = document.getElementById("mappriceval").value;
		theCookie = "showMapPrice=showaddtocart:true; path=/";
		document.cookie = theCookie;
	}
}

function readMapPriceCookie(){
	var the_cookie = unescape(document.cookie);
	if(the_cookie.length > 0){
		var cookieArray = the_cookie.split(";");
		for(i=0;i<cookieArray.length;i++){
			if(cookieArray[i].indexOf("showMapPrice") > -1)
				showaddtocart = true;
		}
	}
}
