function trimString(inString){
  return inString.replace(/^\s+|\s+$/g,"");
}

function $$(id){
  return document.getElementById(id);
}

function cpeApplyNowWebClick(obj, collegeid, subOrderItemId, networkId, externalUrl){
  //alert('onclick --> cpeApplyNowWebClick("'+obj+'", "'+collegeid+'", "'+subOrderItemId+'", "'+networkId+'", "'+externalUrl+'")'); /* remove SOP */
  var appServerName = "www.whatuni.com";
  if($$("appServerName") !=null && $$("appServerName").value != 'null'){
    appServerName = $$("appServerName").value;
  }
  var s_account="hotcourseswhatunicomprod";    /* TODO uncomment live account */
  //var s_account="hotcoursestest"
  var s=s_gi(s_account);
  s.linkTrackVars="server,channel,hier1,prop32,prop33,prop34,prop40,prop41,prop42,prop43,prop44,eVar32,eVar33,eVar34,eVar40,eVar41,eVar42,eVar43,eVar44,events";
  s.linkTrackEvents="event18";
  s.events="event18";
  s.eVar32=s.prop32=collegeid;
  s.eVar33=s.prop33="H.AN."+collegeid; //+"."+subOrderItemId+"."+networkId; /* TODO remove 'CPE' from key & subOrderItemId*/
  s.eVar34=s.prop34=s.pageName;
  s.server=appServerName;
  s.channel="whatuni:all"
  s.hier1="whatuni,all"
  s.eVar32=collegeid;

  /* CPE */
  var sc_prob40 = $$('sc_prob40').value;
  var sc_prob41 = "whatuni";
  var sc_prob42 = $$('sc_prob42').value;
  var sc_prob43 = $$('sc_prob43').value;
  var sc_prob44 = $$('sc_prob44').value;
  /* avoid keyword if category have value*/
  if((sc_prob42 != null && trimString(sc_prob42).length > 0 && sc_prob42 != 'null') &&
     (sc_prob43 != null && trimString(sc_prob43).length > 0 && sc_prob43 != 'null')){
    sc_prob42 = "";
    sc_prob43 = trimString(sc_prob43);
  }
  if(sc_prob40 != null && sc_prob40 != 'null'){s.prop40=sc_prob40;}
  s.prop41=sc_prob41;
  if(sc_prob42 != null && sc_prob42 != 'null'){s.prop42=sc_prob42;}
  if(sc_prob43 != null && sc_prob43 != 'null'){s.prop43=sc_prob43;}
  if(sc_prob44 != null && sc_prob44 != 'null'){s.prop44=sc_prob44;}

  s.tl(obj,'o', 'webclick:'+ collegeid);
  if(networkId == null || trimString(networkId).length == 0 || networkId == 'null'){
	networkId = '2';
  }
  if(subOrderItemId == null || trimString(subOrderItemId).length == 0 || subOrderItemId == 'null'){
	subOrderItemId = '0';
  }
  cpeDbStatsLogging(collegeid, subOrderItemId, networkId, externalUrl, "APPLYNOW");
}

function cpeWebClick(obj, collegeid, subOrderItemId, networkId, externalUrl){
 // alert('onclick --> cpeWebClick("'+obj+'", "'+collegeid+'", "'+subOrderItemId+'", "'+networkId+'", "'+externalUrl+'")'); /* remove SOP */
  var appServerName = "www.whatuni.com";
  if($$("appServerName") !=null && $$("appServerName").value != 'null'){
    appServerName = $$("appServerName").value;
  }
  var s_account="hotcourseswhatunicomprod";    /* TODO uncomment live account */
  //var s_account="hotcoursestest"
  var s=s_gi(s_account);
  s.linkTrackVars="server,channel,hier1,prop32,prop33,prop34,prop40,prop41,prop42,prop43,prop44,eVar32,eVar33,eVar34,eVar40,eVar41,eVar42,eVar43,eVar44,events";
  s.linkTrackEvents="event14";
  s.events="event14";
  s.eVar32=s.prop32=collegeid;
  s.eVar33=s.prop33="H.WC."+collegeid; //+"."+subOrderItemId+"."+networkId; /* TODO remove 'CPE' from key & subOrderItemId*/
  s.eVar34=s.prop34=s.pageName;
  s.server=appServerName;
  s.channel="whatuni:all"
  s.hier1="whatuni,all"
  s.eVar32=collegeid;

  /* CPE */
  var sc_prob40 = $$('sc_prob40').value;
  var sc_prob41 = "whatuni";
  var sc_prob42 = $$('sc_prob42').value;
  var sc_prob43 = $$('sc_prob43').value;
  var sc_prob44 = $$('sc_prob44').value;
  /* avoid keyword if category have value*/
  if((sc_prob42 != null && trimString(sc_prob42).length > 0 && sc_prob42 != 'null') &&
     (sc_prob43 != null && trimString(sc_prob43).length > 0 && sc_prob43 != 'null')){
    sc_prob42 = "";
    sc_prob43 = trimString(sc_prob43);
  }
  if(sc_prob40 != null && sc_prob40 != 'null'){s.prop40=sc_prob40;}
  s.prop41=sc_prob41;
  if(sc_prob42 != null && sc_prob42 != 'null'){s.prop42=sc_prob42;}
  if(sc_prob43 != null && sc_prob43 != 'null'){s.prop43=sc_prob43;}
  if(sc_prob44 != null && sc_prob44 != 'null'){s.prop44=sc_prob44;}

  s.tl(obj,'o', 'webclick:'+ collegeid);
  if(networkId == null || trimString(networkId).length == 0 || networkId == 'null'){
	networkId = '2';
  }
  if(subOrderItemId == null || trimString(subOrderItemId).length == 0 || subOrderItemId == 'null'){
	subOrderItemId = '0';
  }
  cpeDbStatsLogging(collegeid, subOrderItemId, networkId, externalUrl, "WEBSITE");
}

function cpeProfileInnerLinkWebClick(obj, collegeid, subOrderItemId, networkId){
  //alert('onclick --> cpeProfileInnerLinkWebClick("'+obj+'", "'+collegeid+'", "'+subOrderItemId+'", "'+networkId+'", "'+externalUrl+'")'); /* remove SOP */
  var appServerName = "www.whatuni.com";
  if($$("appServerName") !=null && $$("appServerName").value != 'null'){
    appServerName = $$("appServerName").value;
  }
  var s_account="hotcourseswhatunicomprod";    /* TODO uncomment live account */
  //var s_account="hotcoursestest"
  var s=s_gi(s_account);
  s.linkTrackVars="server,channel,hier1,prop32,prop33,prop34,prop40,prop41,prop42,prop43,prop44,eVar32,eVar33,eVar34,eVar40,eVar41,eVar42,eVar43,eVar44,events";
  s.linkTrackEvents="event14";
  s.events="event14";
  s.eVar32=s.prop32=collegeid;
  s.eVar33=s.prop33="H.WC."+collegeid; //+"."+subOrderItemId+"."+networkId; /* TODO remove 'CPE' from key & subOrderItemId*/
  s.eVar34=s.prop34=s.pageName;
  s.server=appServerName;
  s.channel="whatuni:all"
  s.hier1="whatuni,all"
  s.eVar32=collegeid;

  /* CPE */
  var sc_prob40 = $$('sc_prob40').value;
  var sc_prob41 = "whatuni";
  var sc_prob42 = $$('sc_prob42').value;
  var sc_prob43 = $$('sc_prob43').value;
  var sc_prob44 = $$('sc_prob44').value;
  /* avoid keyword if category have value*/
  if((sc_prob42 != null && trimString(sc_prob42).length > 0 && sc_prob42 != 'null') &&
     (sc_prob43 != null && trimString(sc_prob43).length > 0 && sc_prob43 != 'null')){
    sc_prob42 = "";
    sc_prob43 = trimString(sc_prob43);
  }
  if(sc_prob40 != null && sc_prob40 != 'null'){s.prop40=sc_prob40;}
  s.prop41=sc_prob41;
  if(sc_prob42 != null && sc_prob42 != 'null'){s.prop42=sc_prob42;}
  if(sc_prob43 != null && sc_prob43 != 'null'){s.prop43=sc_prob43;}
  if(sc_prob44 != null && sc_prob44 != 'null'){s.prop44=sc_prob44;}

  s.tl(obj,'o', 'webclick:'+ collegeid);
  
  if(networkId == null || trimString(networkId).length == 0 || networkId == 'null'){
	networkId = '2';
  }
  if(subOrderItemId == null || trimString(subOrderItemId).length == 0 || subOrderItemId == 'null'){
	subOrderItemId = '0';
  }  
  var externalUrl = substringFromHref(obj);  
  var sectionNameObj = $$("currentSectionName");  
  var sectionName = "Overview";
  
  if(sectionNameObj != null) {
	sectionName = sectionNameObj.value;
  }  
  if(sectionName == null || trimString(sectionName).length == 0 || sectionName == 'null'){
	sectionName = 'Overview';
  }  
  //alert("1) sectionName: "+sectionName);  
  sectionName = getSeoSectionName(sectionName);  
  //alert("2) sectionName: "+sectionName);  
  cpeDbStatsLogging(collegeid, subOrderItemId, networkId, externalUrl, "WEBSITE_PROFILE_INNERLINK", sectionName);
}

function cpeProspectusWebformClick(obj, collegeid, subOrderItemId, networkId, externalUrl){
  //alert('onclick --> cpeProspectusWebformClick("'+obj+'", "'+collegeid+'", "'+subOrderItemId+'", "'+networkId+'", "'+externalUrl+'")'); /* remove SOP */
  var appServerName = "www.whatuni.com";
  if($$("appServerName") !=null && $$("appServerName").value != 'null'){
    appServerName = $$("appServerName").value;
  }
  var s_account="hotcourseswhatunicomprod";    /* TODO uncomment live account */
  //var s_account="hotcoursestest"
  var s=s_gi(s_account);
  s.linkTrackVars="server,channel,hier1,prop32,prop33,prop34,prop40,prop41,prop42,prop43,prop44,eVar32,eVar33,eVar34,eVar40,eVar41,eVar42,eVar43,eVar44,events";
  s.linkTrackEvents="event14";
  s.events="event14";
  s.eVar32=s.prop32=collegeid;
  s.eVar33=s.prop33="H.ES.RP.WC."+collegeid; //+"."+subOrderItemId+"."+networkId;/* TODO remove 'CPE' from key & subOrderItemId*/
  s.eVar34=s.prop34=s.pageName;
  s.server=appServerName;
  s.channel="whatuni:all"
  s.hier1="whatuni,all"
  s.eVar32=collegeid;

  /* CPE */
  var sc_prob40 = $$('sc_prob40').value;
  var sc_prob41 = "whatuni";
  var sc_prob42 = $$('sc_prob42').value;
  var sc_prob43 = $$('sc_prob43').value;
  var sc_prob44 = $$('sc_prob44').value;
  /* avoid keyword if category have value*/
  if((sc_prob42 != null && trimString(sc_prob42).length > 0 && sc_prob42 != 'null') &&
  (sc_prob43 != null && trimString(sc_prob43).length > 0 && sc_prob43 != 'null')){
    sc_prob42 = "";
    sc_prob43 = trimString(sc_prob43);
  }
  if(sc_prob40 != null && sc_prob40 != 'null'){s.prop40=sc_prob40;}
  s.prop41=sc_prob41;
  if(sc_prob42 != null && sc_prob42 != 'null'){s.prop42=sc_prob42;}
  if(sc_prob43 != null && sc_prob43 != 'null'){s.prop43=sc_prob43;}
  if(sc_prob44 != null && sc_prob44 != 'null'){s.prop44=sc_prob44;}

  s.tl(obj,'o', 'webclick:'+ collegeid);
  if(networkId == null || trimString(networkId).length == 0 || networkId == 'null'){
	networkId = '2';
  }
  if(subOrderItemId == null || trimString(subOrderItemId).length == 0 || subOrderItemId == 'null'){
	subOrderItemId = '0';
  }
  cpeDbStatsLogging(collegeid, subOrderItemId, networkId, externalUrl, "PROSPECTUS_WEBFORM");
}

function cpeEmailWebformClick(obj, collegeid, subOrderItemId, networkId, externalUrl){
  //alert('onclick --> cpeEmailWebformClick("'+obj+'", "'+collegeid+'", "'+subOrderItemId+'", "'+networkId+'", "'+externalUrl+'")'); /* remove SOP */
  var appServerName = "www.whatuni.com";
  if($$("appServerName") !=null && $$("appServerName").value != 'null'){
    appServerName = $$("appServerName").value;
  }
  var s_account="hotcourseswhatunicomprod";    /* TODO uncomment live account */
  //var s_account="hotcoursestest"
  var s=s_gi(s_account);
  s.linkTrackVars="server,channel,hier1,prop32,prop33,prop34,prop40,prop41,prop42,prop43,prop44,eVar32,eVar33,eVar34,eVar40,eVar41,eVar42,eVar43,eVar44,events";
  s.linkTrackEvents="event14";
  s.events="event14";
  s.eVar32=s.prop32=collegeid;
  s.eVar33=s.prop33="H.ES.WC."+collegeid; //+"."+subOrderItemId+"."+networkId;/* TODO remove 'CPE' from key & subOrderItemId*/
  s.eVar34=s.prop34=s.pageName;
  s.server=appServerName;
  s.channel="whatuni:all"
  s.hier1="whatuni,all"
  s.eVar32=collegeid;

  /* CPE */
  var sc_prob40 = $$('sc_prob40').value;
  var sc_prob41 = "whatuni";
  var sc_prob42 = $$('sc_prob42').value;
  var sc_prob43 = $$('sc_prob43').value;
  var sc_prob44 = $$('sc_prob44').value;
  /* avoid keyword if category have value*/
  if((sc_prob42 != null && trimString(sc_prob42).length > 0 && sc_prob42 != 'null') &&
  (sc_prob43 != null && trimString(sc_prob43).length > 0 && sc_prob43 != 'null')){
    sc_prob42 = "";
    sc_prob43 = trimString(sc_prob43);
  }
  if(sc_prob40 != null && sc_prob40 != 'null'){s.prop40=sc_prob40;}
  s.prop41=sc_prob41;
  if(sc_prob42 != null && sc_prob42 != 'null'){s.prop42=sc_prob42;}
  if(sc_prob43 != null && sc_prob43 != 'null'){s.prop43=sc_prob43;}
  if(sc_prob44 != null && sc_prob44 != 'null'){s.prop44=sc_prob44;}

  s.tl(obj,'o', 'webclick:'+ collegeid);
  if(networkId == null || trimString(networkId).length == 0 || networkId == 'null'){
	networkId = '2';
  }
  if(subOrderItemId == null || trimString(subOrderItemId).length == 0 || subOrderItemId == 'null'){
	subOrderItemId = '0';
  }
  cpeDbStatsLogging(collegeid, subOrderItemId, networkId, externalUrl, "EMAIL_WEBFORM");
}

function cpeProspectusFormSubmit(obj, collegeid, subOrderItemId, cpeQualificationNetworkId){
  //alert('onclick --> cpeProspectusFormSubmit("'+obj+'", "'+collegeid+'", "'+subOrderItemId+'", "'+cpeQualificationNetworkId+'")'); /* remove SOP */
  var appServerName = "www.whatuni.com";
  if($$("appServerName") !=null && $$("appServerName").value != 'null'){
    appServerName = $$("appServerName").value;
  }   
  var s_account="hotcourseswhatunicomprod";    /* TODO uncomment live account */
  //var s_account="hotcoursestest"
  var s=s_gi(s_account);      
  s.linkTrackVars="server,channel,hier1,prop32,prop33,prop34,prop40,prop41,prop42,prop43,prop44,eVar32,eVar33,eVar34,eVar40,eVar41,eVar42,eVar43,eVar44,events";
  s.linkTrackEvents="event16";         
  s.events="event16";       
  s.eVar32=s.prop32=collegeid;    
  s.eVar33=s.prop33="H.ES.RP."+collegeid; //+"."+subOrderItemId+"."+cpeQualificationNetworkId;/* TODO remove 'CPE' from key & subOrderItemId*/
  s.eVar34=s.prop34=s.pageName;  
  s.server=appServerName;      
  s.channel="whatuni:all"
  s.hier1="whatuni,all"  
  s.eVar32=collegeid;    
  
  /* CPE */    
  var sc_prob40 = $$('sc_prob40').value;   
  var sc_prob41 = "whatuni";
  var sc_prob42 = $$('sc_prob42').value;
  var sc_prob43 = $$('sc_prob43').value;
  var sc_prob44 = $$('sc_prob44').value; 
  /* avoid keyword if category have value*/
  if((sc_prob42 != null && trimString(sc_prob42).length > 0 && sc_prob42 != 'null') && 
  (sc_prob43 != null && trimString(sc_prob43).length > 0 && sc_prob43 != 'null')){
    sc_prob42 = "";
    sc_prob43 = trimString(sc_prob43);
  }    
  if(sc_prob40 != null && sc_prob40 != 'null'){s.prop40=sc_prob40;}
  s.prop41=sc_prob41;
  if(sc_prob42 != null && sc_prob42 != 'null'){s.prop42=sc_prob42;}
  if(sc_prob43 != null && sc_prob43 != 'null'){s.prop43=sc_prob43;}
  if(sc_prob44 != null && sc_prob44 != 'null'){s.prop44=sc_prob44;}
  
  s.tl(obj,'o', 'webclick:'+ collegeid);     
}

function cpeEmailFormSubmit(obj, collegeid, subOrderItemId, cpeQualificationNetworkId){
  //alert('onclick --> cpeEmailFormSubmit("'+obj+'", "'+collegeid+'", "'+subOrderItemId+'", "'+cpeQualificationNetworkId+'")'); /*  remove SOP */
  var appServerName = "www.whatuni.com";
  if($$("appServerName") !=null && $$("appServerName").value != 'null'){
    appServerName = $$("appServerName").value;
  }   
  var s_account="hotcourseswhatunicomprod";    /* TODO uncomment live account */
  //var s_account="hotcoursestest"
  var s=s_gi(s_account);      
  s.linkTrackVars="server,channel,hier1,prop32,prop33,prop34,prop40,prop41,prop42,prop43,prop44,eVar32,eVar33,eVar34,eVar40,eVar41,eVar42,eVar43,eVar44,events";
  s.linkTrackEvents="event13";         
  s.events="event13";       
  s.eVar32=s.prop32=collegeid;    
  s.eVar33=s.prop33="H.ES.AC."+collegeid; //+"."+subOrderItemId+"."+cpeQualificationNetworkId;/* TODO remove 'CPE' from key & subOrderItemId*/
  s.eVar34=s.prop34=s.pageName;  
  s.server=appServerName;      
  s.channel="whatuni:all"
  s.hier1="whatuni,all"  
  s.eVar32=collegeid;    
  
  /* CPE */    
  var sc_prob40 = $$('sc_prob40').value;   
  var sc_prob41 = "whatuni";
  var sc_prob42 = $$('sc_prob42').value;
  var sc_prob43 = $$('sc_prob43').value;
  var sc_prob44 = $$('sc_prob44').value; 
  /* avoid keyword if category have value*/
  if((sc_prob42 != null && trimString(sc_prob42).length > 0 && sc_prob42 != 'null') && 
  (sc_prob43 != null && trimString(sc_prob43).length > 0 && sc_prob43 != 'null')){
    sc_prob42 = "";
    sc_prob43 = trimString(sc_prob43);
  }    
  if(sc_prob40 != null && sc_prob40 != 'null'){s.prop40=sc_prob40;}
  s.prop41=sc_prob41;
  if(sc_prob42 != null && sc_prob42 != 'null'){s.prop42=sc_prob42;}
  if(sc_prob43 != null && sc_prob43 != 'null'){s.prop43=sc_prob43;}
  if(sc_prob44 != null && sc_prob44 != 'null'){s.prop44=sc_prob44;}
  
  s.tl(obj,'o', 'webclick:'+ collegeid);     
}

function cpeDbStatsLogging(collegeid, subOrderItemId, networkId, externalUrl, clickType, sectionName){
  //alert('cpeDbStatsLogging("'+collegeid+'", "'+subOrderItemId+'", "'+networkId+'", "'+externalUrl+'", "'+clickType+'", "'+sectionName+'")'); /* remove SOP */
  var ajax=new sack();
  /* puts an entry in "wu_stats_log_pkg.add_log_fn" */
  var url = '/degrees/ajaxlogging/cpe-web-click-db-logging.html?z='+collegeid+"&subOrderItemId="+subOrderItemId+"&networkId="+networkId+"&externalUrl="+externalUrl+"&clickType="+clickType+"&sectionName="+sectionName;     
  //alert("url: "+url);  
  ajax.requestFile = url;
  /* Specify function that will be executed after file has been found */
  ajax.onCompletion = function(){ responseData(ajax); };	
  ajax.runAJAX();
}

function responseData(ajax){
  return false;
}

function substringFromHref(obj){
	var p_url = "";
	if(obj != null){
		var hrefValue = obj.href;
		//alert("1) obj: "+obj);
		if((hrefValue.indexOf('OBJ_PLS_TRACK_WUNI_WEBSITE') > -1) || (hrefValue.indexOf('p_url') > -1)){
			//alert("11) hrefValue: "+hrefValue);
			var hrefArray = hrefValue.split("&");
			for(var i=0; i<hrefArray.length; i++){
				//alert("111) hrefArray[i]: "+hrefArray[i]);
				if(hrefArray[i].indexOf('p_url=') > -1){
					p_url = hrefArray[i];
				}						
			}
			p_url = p_url.substring(6);	
			//alert("222) p_url: "+p_url);
			//var p_url=hrefValue.substring(hrefValue.indexOf('p_url=')+2,hrefValue.length)
			//alert("p_url: "+p_url);	
		} else {
			p_url = hrefValue
			//alert("333) p_url: "+p_url);
		}
	}
	//alert("999) p_url: "+p_url);
	return p_url;
}

function getSeoSectionName(sectionName){
	if(sectionName == 'Overview') return 'Overview';
	if(sectionName == 'Accommodation & Location') return 'Location';
	if(sectionName == 'Student Union & Entertainment') return 'Entertainment';
	if(sectionName == 'Courses, Academics & Facilities') return 'Facilities';
	if(sectionName == 'Welfare') return 'Welfare';
	if(sectionName == 'Fees And Funding') return 'Funding';
	if(sectionName == 'Job Prospects') return 'Prospects';
	if(sectionName == 'Contact Details') return 'Contact';
	return sectionName;
}


