// JavaScript Document
function PopupPic(sPicURL) { 
		 window.open( "viewimage.html?"+sPicURL, "ViewImage",  
		 "resizable=1"); 
}

function clearForms()
{
	if (document.shipform) {
		document.shipform.shipfname.value = '';
		document.shipform.shiplname.value = '';
		//document.shipform.shipcomp.value = '';
		document.shipform.shipaddress.value = '';
		document.shipform.shipaddress2.value = '';
		document.shipform.shipapt.value = '';
		document.shipform.shipcity.value = '';
		document.shipform.shipstate.value = '';
		document.shipform.shipprov.value = '';
		
		if (document.shipform.shipcountry.value != 'United States') {
			document.shipform.shipcountry.value = '';
		}else{
			
			document.shipform.shipcounty.value = '';
		}
		
		document.shipform.shipzip.value = '';
		document.shipform.shipphone.value = '';
		document.shipform.shipemail.value = '';
	}
	if (document.billform) {
		document.billform.billfname.value = '';
		document.billform.billlname.value = '';
		//document.billform.billcomp.value = '';
		document.billform.billaddress.value = '';
		document.billform.billaddress2.value = '';
		document.billform.billapt.value = '';
		document.billform.billcity.value = '';
		document.billform.billstate.value = '';
		document.billform.billprov.value = '';
		document.billform.billcounty.value = '';
		document.billform.billcountry.value = '';
		document.billform.billzip.value = '';
		document.billform.billphone.value = '';
		document.billform.billemail.value = '';
	}	
}

function openpopup(){
var popurl="http://www.snowlionpub.com/xmas03popup.html"
winpops=window.open(popurl,"","width=320,height=220,")
}
function openpopupB(){
var popurl="backorders_pop.php"
winpops=window.open(popurl,"","scrollbars=yes,width=320,height=220,")
}
function openpopupC(){
var popurl="shipping_domestic_pop.php"
winpops=window.open(popurl,"pop", "scrollbars=yes,width=450,height=300,")
}
function openpopupD(){
var popurl="security_pop.php"
winpops=window.open(popurl,"pop", "scrollbars=yes,width=450,height=300,")
}
function openpopupE(){
var popurl="shipping_foreign_pop.php"
winpops=window.open(popurl,"pop", "scrollbars=yes,width=450,height=300,")
}

function validateForm(theForm)
{
	var checkemail = document.form1.email.value;
	
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat="/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/";
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=checkemail.match(emailPat)
	if (matchArray==null) 
		{
			alert("Email address seems incorrect (check @ and .'s)")
			return false
		}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) 
		{
			alert("The username in the E-mail doesn't seem to be valid.")
			return false
		}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
		{
		  for (var i=1;i<=4;i++) 
			{
				if (IPArray[i]>255) 
					{
						alert("Destination IP address in the E-mail address is invalid!")
						return false
					}
			}
			return true
		}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) 
		{
			alert("The domain name in the E-mail address doesn't seem to be valid.")
			return false
		}
		
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
		{
			alert("The E-mail address must end in a three-letter or two letter domain. (i.e. .com or .uk)")
			return false
		}

	if (len<2) 
		{
			var errStr="This E-mail address is missing a hostname!"
			alert(errStr)
			return false
		}	
		return true;
}
