
location.querystring = (function() {

	// The return is a collection of key/value pairs

	var result = {};

	// Gets the query string with a preceeding '?'

	var querystring = location.search;

	// document.location.search is empty if a query string is absent

	if (!querystring)
		return result;

	// substring(1) to remove the '?'

	var pairs = querystring.substring(1).split("&");
	var splitPair;

	// Load the key/values of the return collection

	for (var i = 0; i < pairs.length; i++) {
		splitPair = pairs[i].split("=");
		result[splitPair[0]] = splitPair[1];
	}

	return result;




})();

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function noUpgrade(goback){
	createCookie('browserCheck',true,0);
	if(goback.indexOf("dev.abcfamily.com")!=-1 || goback.indexOf("community.abcfamily.go.com")!=-1){
		document.location.href = "http://abcfamily.go.com/abcfamily/path/section_Global/page_BrowserCheck?goback="+goback+"&cookieSet=tea";
	}else{
		//document.location.href = goback+"?noupgrade=true";
		document.location.href = "http://"+goback+"?noupgrade=true";
	}
	
	
}

function cookieCheck(){
	var currentPage = document.location.href;
	var isCheck = readCookie('browserCheck');
	if(!isCheck && currentPage.indexOf("upgrade-browser")==-1){
		//document.location.href = "http://dev.abcfamily.com/content/upgrade-browser?goback="+currentPage;
		document.location.href = "http://community.abcfamily.go.com/content/upgrade-browser?goback="+currentPage.substring(7);
	}

}


var val = window.location.querystring["goback"];

if(val==null || val==undefined || val=="undefined" || val==""){
	val="abcfamily.go.com";
}
//var val = tempval.substring(7);

var upgradeCheck = window.location.querystring["noupgrade"];

var teaCookie = window.location.querystring["cookieSet"];

if(teaCookie=="tea"){
	createCookie('browserCheck',true,0);
	//document.location.href = val+"?noupgrade=true";
	document.location.href = "http://"+val+"?noupgrade=true";
}



if(!upgradeCheck){
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ffversion<3)
	 cookieCheck();
  //document.write("You're using FF 2.x or lower")
 
}else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion<7)
	  cookieCheck();
  //document.write("You're using IE6 or lower")
}
}else{
	createCookie('browserCheck',true,0);
}
