var sHostName = window.location.hostname;

if (sHostName.indexOf('dev') >= 0)
    sEnvironment = 'devwww.web.ppg.com';
else if (sHostName.indexOf('stg') >= 0)
    sEnvironment = 'wwwtest.web.ppg.com';
else
    sEnvironment = 'www.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('http://www.ppg.com/ppgaf/pittsburgh/images/Timeless%20Interior/mhi_flash_page.html','600','400','no','no','no','no');
}

function flashManorHallTimelessExt() {
    openCenteredWindow('http://www.ppg.com/ppgaf/pittsburgh/timeless/main.htm','600','440','no','no','no','no');
}

function flashSealGrip() {
    openCenteredWindow('http://www.ppg.com/ppgaf/pittsburgh/sealgrip/seal_grip_flash.html','610','436','no','no','no','no');
}

function flashSunProof() {
    openCenteredWindow('http://www.ppg.com/ppgaf/pittsburgh/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('http://' + sToolEnvironment + '/updates.asp','632','700','yes','no','no','yes');
}

function specialOffersWindow() {
  openWindow('\/special_offers.htm','632','700','yes','no','no','no');
}

function paintCalcWindow() {
  openWindow('http://' + sToolEnvironment + '/calculator.asp', '632','700','yes','no','no','no' );
}

function locatorPopup() {
    openWindow('\/where_to_buy.htm?Zip=' + document.forms[0].Zip.value,'736','600','yes','no','no','no');
}

function locatorPopup2() {
    openWindow('\/where_to_buy.htm','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 msdsPopup() {
    openCenteredWindow('http://www.ppg.com/pafpainttools/default.asp?intBrand=1&amp;startPage=msds','636','450','yes','no','no','no');
}

function contactPopup() {
    openWindow('\/contact_us.htm','636','600','yes','no','no','no');
}

function offersPopup() {
    openWindow('http:\/\/' + sToolEnvironment + '\/olympic_updates.htm','636','700','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() {
	if ((document.forms[0].Zip.value.length != 5) || (!isNumeric(document.forms[0].Zip.value))) {
		alert("Please enter a valid 5-digit ZIP code.");
		document.forms[0].Zip.value = "";
		document.forms[0].Zip.focus();
	}
    else {
        locatorPopup();
        //var win = window.open('where_to_buy.htm','locator','height=400,width=736');
	    //document.forms[0].target = "where_to_buy.htm?Zip=" + document.forms[0].Zip.value;
	    //document.forms[0].submit();
	}
}

function openLocate() {
//	    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');
}

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' />");
}