var sHostName = window.location.hostname;
var sEBillingEnvironment; 

if (sHostName.indexOf('dev') >= 0)
{
    //sEnvironment = 'sgofetemdev1.edev.nac.ppg.com';  //commented by saty161 for Etemplate conversion from 1.0 to 2.0
    sEnvironment = 'devwww.pittsburghpaints.com';  //added by saty161 for Etemplate conversion from 1.0 to 2.0
    sEBillingEnvironment = 'sdrsedev2web1.edev.nac.ppg.com';
}
else if (sHostName.indexOf('stg') >= 0)
{
    sEnvironment = 'stgwww.pittsburghpaints.com';
    sEBillingEnvironment = 'stgbuyat.ppg.com';
 }
else
{
    sEnvironment = 'www.pittsburghpaints.com';
     sEBillingEnvironment = 'buyat.ppg.com';
}
if (sHostName.indexOf('enlighten') >= 0)
    sToolEnvironment = 'pittsburgh-tools.enlighten.com';
else
    sToolEnvironment = 'tools.pittsburghpaints.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 openCenteredWindow(mypage, w, h, scroll, resizable, menubar, toolbar) {
    var winl = (screen.width - w) / 2;
    var wint = (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 flashManorHallTimelessInt() {
    openCenteredWindow('/flash/Timeless%20Interior/mhi_flash_page.html','600','400','no','no','no','no');
}

function flashManorHallTimelessExt() {
    openCenteredWindow('/flash/timeless/main.htm','600','440','no','no','no','no');
}

function flashSealGrip() {
    openCenteredWindow('/flash/sealgrip/seal_grip_flash.html','610','436','no','no','no','no');
}

function flashSunProof() {
    openCenteredWindow('/flash/sunproof/main.htm','600','400','no','no','no','no');
}

function virtualPainterWindow() {
    openCenteredWindow('http://www.eisoftwareapps.com/PPGv2.0/main.asp','780','560','no','yes','no','no');
}

function updatesWindow() {
    openWindow('\/updates.aspx', '632', '700', 'yes', 'no', 'no', 'yes');
}

function specialOffersWindow() {
  openWindow('\/javascript:updatesWindow()','632','700','yes','no','no','no');
}

function paintCalcWindow() {
  openWindow('http://' + sToolEnvironment + '/calculator.asp', '632','700','yes','no','no','no' );
}

function locatorPopup2() {
    //openWindow('\/where_to_buy.htm?Zip=' + document.forms[0].Zip.value,'736','600','yes','no','no','no');
    window.open('\/Store_locator\/Store_locator.aspx', target = '_self')
}

function locatorPopup2() {
    //openWindow('\/where_to_buy.htm','736','600','yes','no','no','no');
    window.open('\/Store_locator\/Store_locator.aspx', target = '_self')
}

/*
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() {
    //openCenteredWindow("http:\/\/" + sEnvironment + "\/pafpainttools\/default.asp?intBrand=1&amp;startPage=msds", '636', '450', 'yes', 'no', 'no', 'no');
    window.open('\/MSDS\/MSDS.aspx?intBrand=1', target = '_self')    
}

function OpeneBilling()
 {
    openWindow('http:\/\/' + sEBillingEnvironment + '\/ContractorMaintenance/eBilling/Enrollment.aspx?Brand=PGH','1200','930','yes','yes','yes','yes');
}
function OpeneBillingSite()
 {
    openWindow('https://ebill.ppg.com/OA_HTML/AppsLocalLogin.jsp','1200','930','yes','yes','yes','yes');
}
function OpenContractorLocator()
 {
    openWindow('http:\/\/' + sEBillingEnvironment + '\/PAFContractorLoc/ContractorSearch/ContractorSearch.aspx?Brand=PGH','1200','930','yes','yes','yes','yes');
}
function contactPopup() {
    openWindow('\/contact_us.htm','636','600','yes','no','no','no');
}

function legalPopup() {
    openWindow('\/legal_notices_and_privacy_policies.htm','636','600','yes','no','no','no');
}

/*function calculatorPopup() {
    openWindow('http:\/\/' + sToolEnvironment + '\/calculator.htm','636','600','yes','no','no','no');
}*/
function calculatorPopup() {
    openWindow('http://tools.pittsburghpaints.com/calculator.asp','636','600','yes','no','no','no');
}
function virtualPainterPopup() {
    openCenteredWindow('http:\/\/www.eisoftwareapps.com\/PPGv2.0\/main.asp','780','570','yes','no','no','no');
}


function validateZip() {

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;

var altCanZipPattern = /^[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]$/
	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 {
        locatorPopup();
	}

}

function openLocate() { //comented    hcvahv
    //openWindow('http://www.ppg.com/ppgaf/pittsburgh/poplocater.htm?Brand=1','620','430','yes','no','no','no');
    //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 + '\/Store_locator\/Store_locator.aspx?Brand=1';   //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');
    window.open('\/Store_locator\/Store_locator.aspx?Brand=1', target = '_self')                                      //added by saty161 on 9th july, 2008 for PAFPaintTool app conversion from Etem 1.0 to 2.0
}

function locatorPopup() { 
    
    //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 + '\/Store_locator\/Store_locator.aspx?Zip=' + document.forms[0].Zip.value + '&Brand=1';                      //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=' + document.forms[0].Zip.value,'736','600','yes','no','no','no');
    window.open('\/Store_locator\/Store_locator.aspx?Zip=' + document.forms[0].Zip.value + '&Brand=1', target = '_self')                                                           //existing line commented by saty161
}

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 show(what)
{
	if (!document.getElementById) return null;
	var s = "_h";
	var s2 = what.concat(s);
	hide1 = document.getElementById("search_locations");
	hide1.className = "hidden";
//	hide2 = document.getElementById("search_msds");
//	hide2.className = "hidden";	
	hide3 = document.getElementById("search_site");
	hide3.className = "hidden";
	hide4 = document.getElementById("search_locations_h");
	hide4.className = "";
//	hide5 = document.getElementById("search_msds_h");
//	hide5.className = "";	
	hide6 = document.getElementById("search_site_h");
	hide6.className = "";	
	showWhat = document.getElementById(what);
	showWhat.className = "";
	headingOn = document.getElementById(s2);
	headingOn.className = "active";	
}

function gotoPage()
{
     var x=document.getElementById("selectedPage");
	window.location.href = x.value;
}
function gotoPageProfessional()
{
	var x=document.getElementById("selectedPageProfessional");
	window.location.href = x.value;
}
function brandflashNav(gotowhere) {
  		window.location.href = "http://pittsburgh.enlighten.com/" + gotowhere;
}

function checkEnterKeyPress(e) { 
	var charCode;
	
	if(e && e.which) {
		e = e;
		charCode = e.which;
	}
	else {
	e = event;
	charCode = e.keyCode;
	}
	
	if(charCode == 13) {
	validateZip();
	}
}

function writehomelink() {
	current_page = new String(document.location);
    var first_split = current_page.split("//");
    var second_split = first_split[1].split("/");
    if (second_split[1] != "index.htm")
    {
    	document.write("<a href='/index.htm'>Home<\/a>");
	}
	else
		document.write("<img src='/images/common/homeicon_small.gif' alt='Home' class='home_plain' />");
}
