var sHostName = window.location.hostname;

if (sHostName.indexOf('dev') >= 0)
//Modified by saty090 for etemplate conversion on June 14th 2007
    //sEnvironment = 'devwww.web.ppg.com';
    sEnvironment = 'sgofetemdev1';
else if (sHostName.indexOf('stg') >= 0)
//Modified by saty090 for etemplate conversion on June 14th 2007
    //sEnvironment = 'wwwtest.web.ppg.com';
    sEnvironment = 'stgbuyat.ppg.com';
else
//Modified by saty090 for etemplate conversion on June 14th 2007
    //sEnvironment = 'www.ppg.com';
    sEnvironment = 'buyat.ppg.com';

if (sHostName.indexOf('enlighten') >= 0)
    sToolEnvironment = 'olympic.enlighten.com';
else
    sToolEnvironment = 'tools.olympic.com';

function openWindow(mypage, w, h, scroll, resizable, menubar, toolbar) {
    var winl = 30;  //(screen.width - w) / 2;
    var wint = 30;  //(screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resizable+',menubar='+menubar+',toolbar='+toolbar
    win = window.open(mypage,'',winprops)
}

function locatorPopup() {
    openWindow('where_to_buy.htm?Zip=' + document.forms[0].Zip.value,'736','600','yes','no','no','no');
}

function locatorPopup2() {
    openWindow('http://stores.lowes.com/lowes/cgi/index?design=default?=en&mapid=US&svv=true&fname=&snum=&sname=&ci=&zip=&zipid=','736','600','yes','no','no','no');
}

/*
function runLocator() {
	document.forms[0].action = "http:\/\/" + sEnvironment + "\/pafpainttools\/dealerSearch\/frmFindDistribResult.asp?country=1&brand=22,23,24&Zip=48224";
	document.forms[0].submit();		
}
*/


function offersPopup() {
    openWindow('http:\/\/tools.olympic.com\/olympic_updates.htm','636','700','yes','no','no','no');
}

function updatesPopup() {
    openWindow('http:\/\/tools.olympic.com\/olympic_updates.htm','636','700','yes','no','yes','yes');
}

function videoPlayer() {
	//window.open('/tv_spot.htm','_blank','width=402,height=415,top=0,left=0,resizable=no,status=no,toolbar=no,directories=no,menubar=no,scrollbars=no,location=0');
}

function legalPopup() {
    openWindow('/lowes/legal.htm','636','600','yes','no','no','no');
}

function calculatorPopup() {
openWindow('http:\/\/tools.olympic.com\/lowes\/calculator.htm','636','600','yes','no','no','no');
}

function validateZip() {

var usZipPattern = /\d{5}/
var canZipPattern = /^[A-Z][0-9][A-Z].[0-9][A-Z][0-9]$/
var altCanZipPattern = /^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/
	if (document.forms[0].Zip.value != document.forms[0].Zip.value.match(canZipPattern) && document.forms[0].Zip.value != document.forms[0].Zip.value.match(usZipPattern) && document.forms[0].Zip.value != document.forms[0].Zip.value.match(altCanZipPattern)) {
		alert("Please enter a valid ZIP/Postal code.");
		document.forms[0].zip.value = "";
		document.forms[0].zip.focus();
	}
    else {
        locatorPopup();
	}

}


function isNumeric(strText)
{
	var ValidChars = "0123456789";  // valid characters
	var IsNumber = true;
	var Char;

	for (i = 0; i < strText.length && IsNumber == true; i++) { 
		Char = strText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
			}
	}
	return IsNumber;
}

// DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
function eCheck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	
	if (str.indexOf(at)==-1)
    	return false

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		return false

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		return false

	if (str.indexOf(at,(lat+1))!=-1)
		return false

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		return false

	if (str.indexOf(dot,(lat+2))==-1)
		return false
    
	if (str.indexOf(" ")!=-1)
		return false

 	return true				
}

function validateEmail() {
    if (!eCheck(document.forms[0].emailadd.value)) {
		alert("Please enter a valid email address.");
		document.forms[0].emailadd.focus();
		return false;
	}
    else
	    document.forms[0].submit();
}

function checkEnterKeyPressHP(e) { 
	var charCode;
	
	if(e && e.which) {
		e = e;
		charCode = e.which;
	}
	else
	{
		e = event;
		charCode = e.keyCode;
	}
	
	if(charCode == 13)
	{
		return validateZip();
	}
}

function checkEnterKeyPress(e)
{
	var charCode;

	if(e && e.which)
	{
		e = e;
		charCode = e.which;
	}
	else
	{
		e = event;
		charCode = e.keyCode;
	}

	if(charCode == 13)
	{
		return validateZip();
	}
}
