// JavaScript Document
if (parent.frames.length > 0) {
    parent.location.href = self.document.location
}

    // This function is indtended to catch the the event when 
    //        a specific page is loaded. 
    // The function will be called each time a page is loaded
    //        that has the main_template.dwt as it's template
    // The function is called from the the onLoad function in 
    //        the body tag
    // The URL of the page that just loaded is sent as the 
    //        parameter ('url'), to  this function.
function onLoaded(url){

// Sets an "access" cookie (after visitor left his identity)
  if (url.indexOf("ack.htm") > -1){//Practice analysis.
	setCookie("visitor_ci852","100220",60);
  }
  else if (url.indexOf("index.php") > -1
		|| url == "http://www.measurable-solutions.com/"
		|| url == "http://www.measurable-solutions.com"
		){
	MM_CheckFlashVersion('7,0,0,0','Content on this page requires a newer version of Adobe Flash Player. Do you want to download it now?');
  }
  else if (url.indexOf("ack_dvd.htm") > -1){//contact us.
	setCookie("visitor_ci852","100210",60);
  }
  else if (url.indexOf("our_program_npc.php") > -1 && getCookieValue("captured") != "yes"){
    postStatRequest('investment_calc', 'page_load', '1');
  }
  else if (url.indexOf("TherapyTimes20090401.htm") > -1){
    if (!getCookieValue("20090401TT")){
      postStatRequest('20090401TT', 'loads', '1');
      setCookie("20090401TT","loads","90");
    }
  }
  else if (url.indexOf("clientResults.php?prom=20090408") > -1
		   && getCookieValue("prom") == ""){
	setCookie("prom","20090408","30");
    postStatRequest('resultsPage', 'loads', '1');
  }
  else if (url.indexOf("TherapyTimes20090415.htm") > -1){
	document.getElementById("method_new_patients").focus();
  }
		// Sets a cookie if it is a referrer other then M-S.com
  if (document.referrer.indexOf("measurable-solutions.com") < 0
			&& document.referrer != null
			&& !(!document.referrer)
			&& document.referrer != ""){
	setCookie("referrer",document.referrer,"21");
  }
		// Opens the survey on the home page if there is an Advance
		//	eblast cookie or an sendIt cookie set. this function 
		//	can probably be remove in the middle of June 09.
  if (	url.indexOf("contact.htm") == -1
		&& document.getElementById("survey")
		&& (	getCookieValue("ref") == "advance05072009"
				|| getCookieValue("ref") == "sendIt05062009"
				|| getCookieValue("ref") == "TT05072009webAdd"
				|| getCookieValue("ref") == "CC05182009"
			)
		
	  ){
	setSurveyVisible();
  }

  if (	document.getElementById("referrer")
		&& getCookieValue("referrer")){
    document.getElementById("referrer").value = getCookieValue("referrer");
  }

  if (document.getElementById("reference")
		&& getCookieValue("ref")
		&& url.indexOf(".htm") > -1){
    document.getElementById("reference").value = getCookieValue("ref");
  }
		// If this load is from the eblast and a home page load.
		// The cookie is set on the landing page (/landing/index.php)
  if (getCookieValue("ref") == "PT041609reach" &&
        (url == "http://www.measurable-solutions.com/" ||
         url == "http://www.measurable-solutions.com" || 
         url == "www.measurable-solutions.com" ||
         url == "www.measurable-solutions.com/" ||
         url.indexOf("measurable-solutions.com") > -1
		 )
	  ){
    postStatRequest('PT041609reach', 'loads', '1');
  }
}
	// ONLOADED FUNCTION ENDS

function setTableHeight(){
  var mainTable = document.getElementById('mainTable');
  var mainTableHeight = mainTable.style.height;

  if (window.innerHeight != undefined){ //Firefox
    if (window.innerHeight > mainTableHeight ) mainTableHeight = window.innerHeight;
  }
  else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth != 'undefined'
	 && document.documentElement.clientWidth != 0){// IE
    if (mainTableHeight < document.documentElement.clientHeight)
	  mainTableHeight = document.documentElement.clientHeight;
  }
  else if (mainTableHeight < document.getElementsByTagName('body')[0].clientHeight){
	  mainTableHeight = document.getElementsByTagName('body')[0].clientHeight;
  }
  mainTable.style.height = mainTableHeight+"px";
}

function getCookieValue(name){
  if (document.cookie.length>0){
    c_start=document.cookie.indexOf(name+"=");
    if (c_start!=-1){ 
      c_start=c_start + (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 setCookie(name,value,expDays){
  if (!expDays) expDays = 90;
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expDays);
  document.cookie = name + "=" +escape(value)+((expDays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/";
}

function legitimateAccess(level){
  var grant = false;
  var cookieValue = 0;
  if (getCookieValue("visitor_ci852")){
	cValue = parseInt(getCookieValue("visitor_ci852"));
	if ( cValue >= level ) grant = true;
  }
  return grant;
}
