function popUp(url,options,name) 
{
	if (!options)
	{
		options = 'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=600,height=450';
	}	
	window.open(url,name,options);
}


  
function validateNonBlank(textfield) {
    if(isBlank(textfield.value) == true) {  
        alert('Please enter in a value.');
        textfield.focus();
        textfield.select();
        return false;        
    }
    return true;
}
  
function printWindow() {
bV = parseInt(navigator.appVersion);
if (bV >= 4) window.print();
}

/** takes a string and returns true if the value has length 0 or contains only spaces */   
function isBlank(value) {
    for(i=0; i<value.length; i++) {
	    if (value.charAt(i) != ' '){           
			return false;
		}	
	}
	return true;
}  

function trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}

function ltrim(str) {
	return str.replace(/^\s+/,"");
}

function rtrim(str) {
	return str.replace(/\s+$/,"");
}


function setCookie(c_name,value)
{
	var expiredays=360;
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	//document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	document.cookie=c_name+ "=" +escape(value)+";path=/"+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
  	{
  		c_start=document.cookie.indexOf(c_name + "=");
  		if (c_start!=-1)
    		{ 
    			c_start=c_start + c_name.length+1; 
    			c_end=document.cookie.indexOf(";",c_start);
    			if (c_end==-1) 
				c_end=document.cookie.length;
    			return unescape(document.cookie.substring(c_start,c_end));
    		} 
 	}
	return "";
}


function deleteCookie(name) 
{
   var exdate=new Date();
   exdate.setDate(exdate.getDate()-1);
   document.cookie = name + "=;expires="+exdate.toGMTString();
}


function parseCookie(text) 
{
    var strA = ";";
    var strB = " ";
    while ( text.indexOf(strA) != -1)
    {
        text = text.replace(strA,strB);
    }
    return text;
}


function TakesCookies()

{

    var GetsCookie = (navigator.cookieEnabled)?true:false

    // If the browser does not support cookie check

    if(typeof navigator.cookieEnabled=="undefined" && !cookieEnabled)

    {

        // Try setting up a test cookie

        document.cookie = "SampleCookie";

        // And see if it got set successfully

        GetsCookie = (document.cookie.indexOf("SampleCookie")!=-1)?true:false

    }

    return GetsCookie;

}
 

function CookieTest()

{

    // TakesCookies is now set to the proper value

    if(TakesCookies())

    {

        alert("This browser accepts cookies");

    }

    else

    {

        alert("This browser does not accept cookies");

    }

}

// This function returns the number representing the run environment we are
// using.  It is used to tell the Pep Boys store locator service the url to
// return to when a store is selected.
//
// 1 = localhost (developer workstation)
// 2 = dev
// 3 = test
// 4 = staging
// 5 = production
function getEnvironment()
{
	var URL = document.URL + "";
	var environment = "5";
	
	if (URL.indexOf("//localhost/") != -1)
	{
	    environment = "1";
	}
        else if (URL.indexOf("//localhost:7001/") != -1)
	{
		environment = "1";
	}
	else if (URL.indexOf("//mfr.dev.") != -1)
	{
		environment = "2";
	}
	else if (URL.indexOf("//mfr.test.") != -1)
	{
		environment = "3";
	}
	else if (URL.indexOf("//mfr.staging.") != -1)
	{
		environment = "4";
	}
	
	return environment;
}

// Jumps to store locator page, after deriving URL based on environment
// in which we are running.
function jumpToStoreLocator()
{
	var environment = getEnvironment();
	var URL = "http://pepboys.know-where.com/pepboys/cgi/index?HOSTNAME=" + environment;
        document.location = URL;	
}

function jumpToStoreLocatorForTires()
{
	var environment = getEnvironment();
	var URL = "http://pepboys.know-where.com/pepboys/cgi/index?HOSTNAME=" + environment+"&PATH=2";
        if (environment == "1")
            {
              URL = "http://pepboys.know-where.com/pepboys/cgi/index?HOSTNAME=" + environment+"&PATH=2";  
            }
            
        else if (environment == "2")
            {
              URL = "http://pepboys.know-where.com/pepboys/cgi/index?HOSTNAME=" + environment+"&PATH=2";  
            }
            
        else if (environment == "3")
            {
              URL = "http://pepboys.know-where.com/pepboys/cgi/index?HOSTNAME=" + environment+"&PATH=2";  
            }
        else if (environment == "4")
            {
              URL = "http://pepboys.know-where.com/pepboys/cgi/index?HOSTNAME=" + environment+"&PATH=2";  
            }
        else if (environment == "5")
            {
              URL = "http://pepboys.know-where.com/pepboys/cgi/index?HOSTNAME=" + environment+"&PATH=2";  
            }
        document.location = URL;	
}
	
