var sHostName = window.location.hostname;
var sDealerEnvironment; //Added by saty119 on 06/25/07 for Etemplate Conversion of Dealer Search
var sEBillingEnvironment; 

if (sHostName.indexOf('enlighten') >= 0)
    {
		sEnvironment = 'buyat.ppg.com'; /* Extra Line added since name of internal Enlighten dev server contains dev in name */
		sDealerEnvironment = 'buyat.ppg.com'; //Added by saty119 on 06/25/07 for Etemplate Conversion of Dealer Search
    	sToolEnvironment = 'pp-tools.enlighten.com';
    }
else if (sHostName.indexOf('dev') >= 0)
    {
		sEnvironment = 'devwww.web.ppg.com';
		//sDealerEnvironment = 'sgofetemdev1.edev.nac.ppg.com';  //Added by saty119 on 06/25/07 for Etemplate Conversion of Dealer Search
		sDealerEnvironment = 'devwww.porterpaints.com';   //added by saty161 on 07/03/2008 for ETemplate Conversion 2.0 of Dealer Search.
    	sToolEnvironment = 'tools.porterpaints.com';
    	sEBillingEnvironment = 'sdrsedev2web1.edev.nac.ppg.com';
    }
else if (sHostName.indexOf('stg') >= 0)
    {
		sEnvironment = 'wwwtest.web.ppg.com';
		sDealerEnvironment = 'stgwww.porterpaints.com';    //Added by saty119 on 06/25/07 for Etemplate Conversion of Dealer Search
    	sToolEnvironment = 'tools.porterpaints.com';
    	sEBillingEnvironment = 'stgbuyat.ppg.com';
    }  
else if (sHostName.indexOf('test') >= 0)
    {
		sEnvironment = 'wwwtest.web.ppg.com';
		sDealerEnvironment = 'www.porterpaints.com';    //Added by saty119 on 06/25/07 for Etemplate Conversion of Dealer Search
    	sToolEnvironment = 'tools.porterpaints.com';
    	sEBillingEnvironment = 'stgbuyat.ppg.com';
    }       
else
    {
		sEnvironment = 'buyat.ppg.com';
		sDealerEnvironment = 'www.porterpaints.com'; //Added by saty119 on 06/25/07 for Etemplate Conversion of Dealer Search
    	sToolEnvironment = 'tools.porterpaints.com';
    	sEBillingEnvironment = 'buyat.ppg.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 contactPopup() {
    openWindow('\/contact_us.htm','636','600','yes','no','no','no');
}

function designspectrumPopup() {
    openCenteredWindow('http:\/\/www.eisoftwareapps.com\/Porter_v1.00\/main.html','760','540','no','no','no','no');
}

function email_page(pageURL) {
  openCenteredWindow('http:\/\/tools.porterpaints.com\/email_page.asp?pageURL=' + pageURL,'665','700','yes','no','no','no');
}
function highPerformance(){
	openWindow('http://corporate.ppg.com/ppg/paf/hpc/default.htm','730','630','yes','no','no','yes');
}

function legalPopup() {
    openWindow('\/legal_notices_and_privacy_policies.htm','676','600','yes','no','no','no');
}

function locatorPopup2() {
    //openWindow('\/Store_locator\/Store_locator.aspx', '659', '600', 'yes', 'no', 'no', 'no');
    window.open('\/Store_locator\/Store_locator.aspx', target = '_self');
}

function msdsPopup() {
	//openCenteredWindow('http://www.ppg.com/pafpainttools/default.asp?intBrand=6&startPage=msds','630','450','no','no','no','no');
    //openCenteredWindow('http://'+ sDealerEnvironment +'/pafpainttools/default.asp?intBrand=6&startPage=msds','630','450','no','no','no','no');
    //openCenteredWindow('http://' + sDealerEnvironment + '\/MSDS/MSDS.aspx?intBrand=6',target='_self');
    window.open('\/MSDS/MSDS.aspx?intBrand=6', target = '_self');
}

function OpenContractorLocator()
 {
    openWindow('http:\/\/' + sEBillingEnvironment + '\/PAFContractorLoc/ContractorSearch/ContractorSearch.aspx?Brand=PORTER','1200','930','yes','yes','yes','yes');
}

function openLocate() {
	//openWindow('\/where_to_buy.htm','620','430','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:\/\/' + sDealerEnvironment + '\/pafpainttools\/dealerSearch\/Store_locator\/Store_locator.aspx?Brand=6';            //added by saty161 on 9th july, 2008 for PAFPaintTool app conversion from Etem 1.0 to 2.0
	//paintToolUrl = 'http:\/\/' + sDealerEnvironment + '\/Store_locator\/Store_locator.aspx?Brand=6';            //added by saty161 on 9th july, 2008 for PAFPaintTool app conversion from Etem 1.0 to 2.0
	//openWindow( paintToolUrl ,'620','430','yes','no','no','no');                                                     //added by saty161 on 9th july, 2008 for PAFPaintTool app conversion from Etem 1.0 to 2.0
	window.open('\/Store_locator\/Store_locator.aspx?Brand=6', target = '_self');
}

function locatorPopup() {
    //added by saty161 on 23 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:\/\/' + sDealerEnvironment + '\/pafpainttools\/dealerSearch\/Store_locator\/Store_locator.aspx?Zip=' + document.forms[0].zip.value + '&Brand=6';      //new line added by saty161
    //paintToolUrl = 'http:\/\/' + sDealerEnvironment + '\/Store_locator\/Store_locator.aspx?Zip=' + document.forms[0].zip.value + '&Brand=6';      //new line added by saty161
    //openWindow(paintToolUrl,'659','600','yes','no','no','no')                                                                                                                                             //new line added by saty161
    //commented by saty161 on 23 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,'659','600','yes','no','no','no');
    window.open('\/Store_locator\/Store_locator.aspx?Zip=' + document.forms[0].zip.value + '&Brand=6', target = '_self');                                                                         //existing line commented by saty161
}

function paintCalcWindow() {
	openWindow('\/paintCalc.aspx', '662','700','yes','no','no','no' );
}

function ppgafPopup() {
    openWindow('http:\/\/' + sEnvironment + '\/PPGAF/school.asp?where=portpaint','900','630','yes','no','no','no');
}
function OpeneBilling()
 {
    openWindow('http:\/\/' + sEBillingEnvironment + '\/ContractorMaintenance/eBilling/Enrollment.aspx?Brand=Porter','1200','930','yes','yes','yes','yes');
}
function OpeneBillingSite()
 {
    openWindow('https://ebill.ppg.com/OA_HTML/AppsLocalLogin.jsp','1200','930','yes','yes','yes','yes');
}
function printSpecialOffers(which) {
    openCenteredWindow('\/special_offers\/print.htm?offer=' + which,'700','320','yes','no','no','no');
}

function specialOffersWindow() {
	openWindow('\/special_offers.htm','632','700','yes','no','yes','yes');
}

function updatesWindow() {
    //openWindow('http:\/\/' + sToolEnvironment + '\/updates.asp','665','700','yes','no','no','yes');
    openWindow('\/Updates.aspx', '665', '700', 'yes', 'no', 'no', 'yes');
}

function updatesVOCWindow() {
    //openWindow('http:\/\/' + sToolEnvironment + '\/updates.asp?subj=voc','665','700','yes','no','no','yes');
    openWindow('\/Updates.aspx?subj=voc', '665', '700', 'yes', 'no', 'no', 'yes');
}

function printPage(pagetoPrint) {
tmpPth = window.location.pathname;
if ((tmpPth.indexOf("/products/") == 0) && (tmpPth.substr(tmpPth.length-10).toLowerCase() == "/index.htm"))
{
    tmpUri = tmpPth.substr(0,tmpPth.length-9)+"print.htm";
    dcsMultiTrack("DSC.dcssip",window.location.hostname,"DCS.dcsuri",tmpUri,"WT.ti","Product Print");
}
tmpPth=tmpUri="";
window.print(pagetoPrint);
}

function virtualpainterPopup() {
    openCenteredWindow('\/virtual_painter.htm','636','540','no','no','no','no');
}

function validateZip() 
{
    /* Begin: added by saty161 on 25th July08 for Change Request 8 #217830 */
    var usZipPattern = /\d{5}/                      
    var canZipPattern = /^[a-zA-Z][0-9][a-zA-Z].[0-9][a-zA-Z][0-9]$/
    var altCanZipPattern = /^[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]$/
    var inputValue = document.forms[0].zip.value;
    /*End: code aded by saty161 on 25th July08 */
    
	if ((!document.forms[0].zip.value) || (document.forms[0].zip.value == 'Enter ZIP/Postal Code')) 
	{
		alert("Please enter a valid ZIP/Postal code.");
		document.forms[0].zip.value = "";
		document.forms[0].zip.focus();
	}
    else 
    {
        //locatorPopup();  //commented by saty161 ib 25th July08 for change request 8 #217830
        
       /* Begin: added by saty161 on 25th July08 for Change Request 8 #217830 */ 
        if ((inputValue.length) != 0)
        {
            if (inputValue != inputValue.match(canZipPattern) && inputValue != inputValue.match(usZipPattern) && inputValue != inputValue.match(altCanZipPattern)) 
				{
				    alert("Please enter a valid ZIP/Postal code.");
				    document.forms[0].zip.value = ""; 
				    document.forms[0].zip.focus();
			     }
			else {					
					locatorPopup();
			     }	
        }
        else
        {
             alert("Please enter a valid ZIP/Postal code.");
		     document.forms[0].zip.value = "";
		     document.forms[0].zip.focus();
        }
        /*End: code aded by saty161 on 25th July08 */
        
	}
}

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 stripSpaces(inputField) {
  // gets rid of leading and trailing spaces in an input field
  var x = inputField;
  return(x.replace(/^\W+/,'')).replace(/\W+$/,'');
}

function validateEmailPageForm() {
    if (stripSpaces(document.forms[0].yourname.value).length < 1) {
      alert("Please enter your name.");
      document.forms[0].yourname.value = "";
		  document.forms[0].yourname.focus();
		  return false;    
    }
    else if (!eCheck(document.forms[0].youremailadd.value)) {
		  alert("Please enter a valid email address for yourself.");
		  document.forms[0].youremailadd.focus();
		  return false;
	  }
    else if (stripSpaces(document.forms[0].toname.value).length < 1) {
      alert("Please enter the name of the person you're sending to.");
      document.forms[0].toname.value = "";
		  document.forms[0].toname.focus();
		  return false;    
    }
    else if (!eCheck(document.forms[0].toemailadd.value)) {
		  alert("Please enter a valid email address for the person you're sending to.");
		  document.forms[0].toemailadd.focus();
		  return false;
	  }
    else
	    document.forms[0].submit();
}
