// SEARS GLOBAL JAVASCRIPT FILE

// COOKIE FUNCTIONALITY
function setCookie(name, value, expires, domain, path){
	var theCookie = name+"=" + value + "; ";
	if(expires != true){
		var nextYear = new Date(); nextYear.setFullYear(nextYear.getFullYear() + 1);
		var expires = nextYear.toGMTString();
		theCookie += "expires=" + nextYear.toGMTString() + "; ";
	}
	if(domain){
		theCookie += "domain=" + domain + "; ";
	}
	if(path){
		theCookie +="path=" + path + "; ";
	}
	document.cookie = theCookie;
}
function getCookie(name){
	var pos = document.cookie.indexOf(name);
	if(pos == -1){return false;}
	var start = pos + name.length + 1;
	var end = document.cookie.indexOf(';',start);
	if(end == -1){
		end = document.cookie.length;
	}
	var value = document.cookie.substring(start, end);
	return unescape(value);
}
function deleteCookie(name){
	var now = new Date();
	document.cookie = name + "=0; expires=" + now.toGMTString();
}

// QUERYSTRING OBJECT

function QueryString_Object(URL){
	if(!URL){URL = location.href;} // If no argument, use the document URL
	this.raw = URL.substring(URL.indexOf('?')+1,URL.length); // Grab and store QueryString after the "?"
	this.Name = Array();
	this.Value = Array();
	QueryString_Object.prototype.Get = QueryString_Object_Get;
	
	var args = this.raw.split('&'); // Parse out the parameters separated by "&"
	
	for (var i=0;i<args.length;i++){ // Split out and store each name/value pair
		var pair = args[i].split('=');
	
		temp = unescape(pair[0]).split('+'); // Fix broken unescaping
		temp0 = temp.join(' ');
		
		temp = unescape(pair[1]).split('+');
		temp1 = temp.join(' ');
		
		this.Name[i] = temp0;
		this.Value[i] = temp1;
	}
}
function QueryString_Object_Get(what){ // Get the value based on the parameter name
	for (var i=0;i<this.Name.length;i++){
		if(this.Name[i] == what){
			return this.Value[i];
		}
	}
	return false; // return false if parameter doesn't exist
}


function urlto(arg, intcmp, sid){
        switch(arg) {
                case "customerservice":
                        url = "asp/FramesetRedirect.aspx?url=http://www.sears.com/sr/misc/sears/custserv/custserv_index.jsp?targetPage=/misc/sears/custserv/custserv_index.jsp%26vertical=SEARS%26vertical=SEARS%26intcmp="+intcmp+"%26SID="+sid;
                        break;
        }
        
        linkTo({url:url, type:'o', target:'searsapp'});
}

function leaving(){
     var cartitem = getCookie('cartitem');
	 if(cartitem && cartitem == 'true') {
	 	//alert ("cartitem true =" + cartitem);
	    var popupWin = window.open('popup/pop_up.html','pop_window', 'width=600, height=410 ');
	 }
}

function click2talk() {
     var popupWin = window.open('http://as00.estara.com/ep/?ulbid=96595','click2talk', 'width=427, height=380 '); 
}

// Instantiate Object
//var QueryString = new QueryString_Object();


