
try {
  //document.writeln("<a href='#' onClick='enableTesting();return false;' style='color:white;'>test</div>");
  //testing = false;
  //if(readCookie("testing") == "true")
  //  testing=true;

  $(function(){
	//if(window.location.toString().indexOf("search") == -1)
	//	$("div.search-1").css("display","none");
	//$("table.kmp-header-1").css("display","none");
	  receiverURL = "http://support.pearsonschool.com/coco/includes/display_objects/custom/ajax/receiver.cfm";
	  if(getUrlVars()["receiver"]){
	    receiverURL=getUrlVars()["receiver"];
	    createCookie("receiver",receiverURL);
		if(readCookie("receiver") != receiverURL)
		  $("a").each(function(){
		  	if(String($(this).attr("href")).indexOf("/kmp/") != -1);
		  		$(this).attr("href",$(this).attr("href")+"#receiver="+receiverURL);
		  });
	  }
	  else if(readCookie("receiver")){
	    receiverURL=readCookie("receiver");
	  }
	  $("body").append(
	  	$("<iframe id='receiverFrame'></iframe>")
			.css({height:0,width:0})
			.attr("src",receiverURL+"?height="+document.body.clientHeight+"&location="+String(document.location).split("#")[0].split("/kmp")[1])
		);
  });

} catch(e) {
  //alert(e.message);
}

function enableTesting(){
  testing=true
  createCookie("testing","true",30);
  alert(readCookie("testing"));
}
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 eraseCookie(name) {
	createCookie(name,"",-1);
}
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('&');
 
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
 
    return vars;
}

