var sHostName = window.location.hostname;
var sCountry;
var sZip;

if (sHostName.indexOf('dev') >= 0)
//Modified by saty090 for etemplate conversion on June 14th 2007
    //sEnvironment = 'devwww.web.ppg.com';
    //sEnvironment = 'sgofetemdev1.edev.nac.ppg.com';           //commented by saty161 for Etem conversion from 1.0 to 2.0
      sEnvironment = 'sdrsedev2web1.edev.nac.ppg.com';          //added by saty161 for ETem conversion from 1.0 to 2.0 on July 3rd 2008
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=' + sZip,'736','600','yes','no','no','no');
    //added by saty161 on 20 June 2008 for #217830(PAFPaintTool Etemplate Conversion from 1.0 to 2.0)                                  //comment line added by saty161     
    var paintToolUrl;                                                                                                                  //new line added by saty161
    paintToolUrl = 'http:\/\/' + sEnvironment + '\/pafpainttools\/dealerSearch\/where_to_buy.htm?Zip=' + sZip + '&Brand=22,23,24'      //new line added by saty161
    openWindow(paintToolUrl,'736','600','yes','no','no','no')                                                                          //new line added by saty161
    //commented by saty161 on 20 June 2008 for #217830(PAFPaintTool Etemplate Conversion from 1.0 to 2.0)                              //comment line added by saty161                                                              
    //openWindow('/where_to_buy.htm?Zip=' + sZip + '=' +sCountry,'736','600','yes','no','no','no');                                    //existing line commented by saty161
}

function locatorPopup2() {
    //openWindow('/where_to_buy.htm','736','600','yes','no','no','no');                                                 //commented by saty161 on 9th july, 2008 for PAFPaintTool app conversion from Etem 1.0 to 2.0
      var paintToolUrl;                                                                                                 //added by saty161 on 9th july, 2008 for PAFPaintTool app conversion from Etem 1.0 to 2.0
      paintToolUrl = 'http:\/\/' + sEnvironment + '\/pafpainttools\/dealerSearch\/where_to_buy.htm?Brand=22,23,24'      //added by saty161 on 9th july, 2008 for PAFPaintTool app conversion from Etem 1.0 to 2.0
      openWindow(paintToolUrl ,'736','600','yes','no','no','no');                                                 //added by saty161 on 9th july, 2008 for PAFPaintTool app conversion from Etem 1.0 to 2.0
}

/*
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 msdsPopup() {
    openWindow('/msds.htm','636','450','yes','no','no','no');
}

function contactPopup() {
    openWindow('/contact_us.htm','636','600','yes','no','no','no');
}

function offersPopup() {
    openWindow('http:\/\/tools.olympic.com\/olympic_updates.htm','636','700','yes','no','no','no');
}

function addPageLocation(pageLocation){
	var theAnchor = document.getElementById('email_this_page');
	var thePageRef = theAnchor.href;
	thePageRef = '';
	var theOutput = 'mailto:?subject=Products%20you%20need%20to%20see%20from%20Olympic&body=Found%20these%20great%20products%20at%20Olympic.com.%20You%20definitely%20should%20check%20them%20out:%20' + pageLocation;
	theAnchor.href = theOutput;
}

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('/legal.htm','636','600','yes','no','no','no');
}

function calculatorPopup() {
openWindow('http:\/\/tools.olympic.com\/calculator.htm','636','600','yes','no','no','no');
}


function validateZip(e) {

var usZipPattern = /\d{5}/
var canZipPattern = /^[a-zA-Z][0-9][a-zA-Z].[0-9][a-zA-Z][0-9]$/
var inputValue = document.forms[0].Zip.value;
sZip = inputValue
var altCanZipPattern = /^[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]$/
	//Modified by saty119 on 12/11/2007 for the change Request  214538 – ProjectChangeRequest 02 - PAF Olympic HTML Web
	if	(inputValue == 'ZIP/Postal Code') 	sZip ='';	
	if ((inputValue.length) != 0)	{
	
		if	(inputValue != 'ZIP/Postal Code')
		 {			if (inputValue != inputValue.match(canZipPattern) && inputValue != inputValue.match(usZipPattern) && inputValue != inputValue.match(altCanZipPattern)) 				{
				alert("Please enter a valid ZIP/Postal code.");
				inputValue = "";
				document.forms[0].Zip.focus();
			     }
			else {					if ((inputValue.length) > 5)
						sCountry = '2';
					else
						sCountry = '1';
					    locatorPopup();
			      }	
	    }
	    else
	    {
			 //commented by saty161 on 10th July,2008 to fix issue no. 6[#217830 PAFPainttool app conversion from Etem 1.0 to 2.0]		     //locatorPopup();  		     /* added by saty161 on 10th July,2008 to fix issue no. 6[#217830 PAFPainttool app conversion from Etem 1.0 to 2.0] */                             		     alert("Please enter a valid ZIP/Postal code.");		     inputValue = "";
		     document.forms[0].Zip.focus();		     /* End of code added by saty161 on 10 July, 2008 */
	    }    	}	else	{	     //commented by saty161 on 10th July,2008 to fix issue no. 6[#217830 PAFPainttool app conversion from Etem 1.0 to 2.0]		 //locatorPopup();  		 /* added by saty161 on 10th July,2008 to fix issue no. 6[#217830 PAFPainttool app conversion from Etem 1.0 to 2.0] */                             		 alert("Please enter a valid ZIP/Postal code.");		 inputValue = "";
		 document.forms[0].Zip.focus();		 /* End of code added by saty161 on 10 July, 2008 */	}
		
}
function stopDefault(e) {
  	if (!e) {e = window.event;}
	if (!e.preventDefault) {
       	e.preventDefault = function() { this.returnValue = false; }
   	}
  	e.preventDefault();
   	return false;
  }

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) {
		validateZip();
		return false;
	}

}

function checkEnterKeyPress(e) {
 
     var charCode;
     
     if(e && e.which) {
           e = e;
           charCode = e.which;
     }
     else {
     e = event;
     charCode = e.keyCode;
     }
     
     if(charCode == 13) {
		validateZip();
		return false;
     }
}
