


var hh=0
var emailexistmsg="It looks like you're already a Whatuni member, just enter your password to complete this action."
function trimString(str){str=this !=window? this : str;return str.replace(/^\s+/g,'').replace(/\s+$/g,'');}
var cnt = 1;
function addBasket(data_1,thisvalue,showtext1,showtext2, chekBoxId){
/*if(cnt>10){
if(thisvalue.className == "tbox"){
alert("No option to select more than 10 comparisions");
return false;
}else{
cnt--;
}
}else{
if(thisvalue.className == "tbox"){
    cnt++;
}else if(thisvalue.className == "tboxChk"){
    cnt--;
}else if (thisvalue.className == "fclose"){
    cnt--;
}
}*/
//alert("------data_1-------"+data_1+"-------thisvalue---------"+thisvalue+"----------showtext1------------"+showtext1+"-------showtext2----------"+showtext2);
var dowhat="";
if(thisvalue.className == "tbox"){
		thisvalue.className = "tboxChk"
		dowhat = "add"
	}else if (thisvalue.className == "tboxChk"){
		thisvalue.className = "tbox"
		dowhat = "remove"
	//}else if (thisvalue.className == "hclose"){
	}else if (thisvalue.className == "fclose"){
		dowhat = "remove"
	}	
var collegeId='';var courseId=''
var courseNow=''
var checkBoxId = chekBoxId;
if(data_1 !=null&&data_1.indexOf('w=')>=0){
courseNow='true'
courseId=data_1.substring(data_1.indexOf('w=')+2,data_1.length)
collegeId=data_1.substring(2,data_1.indexOf('w=')-1)
if(dowhat=="remove"){collegeId='';}
}else{
collegeId=data_1.substring(2,data_1.length)}
var pagNam=$$('pageName')!=null ? $$('pageName').value : ''
var req;var url='/degrees/addbasket.html?'+data_1+'&fromAjax=true&dowhat='+dowhat+"&pageName="+pagNam
if(typeof XMLHttpRequest !="undefined"){req=new XMLHttpRequest();}
else if(window.ActiveXObject){req=new ActiveXObject("Microsoft.XMLHTTP");}
req.open("POST",url,true);req.onreadystatechange=handlerequest;req.send(url)
function handlerequest(){
if(req.readyState==4){
if(req.status==200){
var resp=req.responseText;var dataarray=resp.split("BREAKBREAK")
var dataArrayLength = dataarray.length;
if(dataArrayLength > 2){
var emptyunimess="Tick 'Save to Shortlist' to compare uni's & get loads of extra info!!"
var emptycoursemess="Tick 'Save to Shortlist' to compare courses & get loads of extra info!!"
var eleIdCollege=''
var spanIdsec=''
with(document){
var paraunimessage = '<small>'+emptyunimess+"</small>";
if($$('oldshortlist') !=null) {paraunimessage = '<p class="blankuni">'+emptyunimess+"</p>"} 
//Commented By Sekhar for wu402 and added below line.
//if(trimString(dataarray[0])!=''){$$('unilist').innerHTML=dataarray[0]}else{$$('unilist').innerHTML=paraunimessage}
if(trimString(dataarray[0])!=''){$$('upperPart').innerHTML=dataarray[0]}else{$$('upperPart').innerHTML=paramessage}    
if(trimString(dataarray[1])!=''){$$('downPart').innerHTML=dataarray[1]}else{$$('downPart').innerHTML=paramessage}    

var eleId='';var spanId='';var textId=''
if($$('secondcheckT_'+collegeId)!=null){textId=$$('secondcheckT_'+collegeId);}
if($$('span_secondcheck_'+collegeId)!=null){spanId=$$('span_secondcheck_'+collegeId);}
if($$('secondcheck_'+collegeId)!=null){eleId=$$('secondcheck_'+collegeId);}
if(courseNow=='true'){eleIdCollege=eleId;spanIdsec=spanId;}
if($$('secondcheckT_'+courseId)!=null){textId=$$('secondcheckT_'+courseId);}
if($$('span_secondcheck_'+courseId)!=null){spanId=$$('span_secondcheck_'+courseId);}
if($$('secondcheck_'+courseId)!=null){eleId=$$('secondcheck_'+courseId);}
if($$('bskchid_'+collegeId)!=null){eleId=$$('bskchid_'+collegeId);}
if($$('bskchid_'+collegeId+'T')!=null){textId=$$('bskchid_'+collegeId+'T');}
if($$('mpage_glow_'+collegeId)!=null){spanId=$$('mpage_glow_'+collegeId);}
if($$('bskchid_'+courseId)!=null){eleId=$$('bskchid_'+courseId);}
if($$('bskchid_'+courseId+'T')!=null){textId=$$('bskchid_'+courseId+'T');}
if($$('mpage_glow_'+courseId)!=null){spanId=$$('mpage_glow_'+courseId);}
if($$('compare')!=null &&  $$('compare').style.display=='block'){
   $$("compare").style.display ="none";
   $$("compared").style.display ="block";
}else if($$('compared')!=null && $$('compared').style.display=='block'){
 $$("compared").style.display ="none";
 $$("compare").style.display ="block";
}
/*Commented By Sekhar for wu402_31012012
if(thisvalue.className == "hclose" &&   $$('bskchid_'+collegeId)!=null ){
$$('bskchid_'+collegeId).className="tbox"
}
if(thisvalue.className == "hclose" && $$('bskchid_'+courseId)!=null ){
$$('bskchid_'+courseId).className="tbox"
}*/

//Added by Sekhar for wu402_31012012
if(thisvalue.className == "fclose" && $$('bskchid_'+collegeId)!=null ){
    $$(checkBoxId).className="tbox"
}
if(thisvalue.className == "fclose" && $$('bskchid_'+courseId)!=null ){
    $$(checkBoxId).className="tbox"
}

textId.innerHTML=(thisvalue.checked ? showtext2 : showtext1)
if(thisvalue.checked==true){
if(courseNow=='true'&&eleIdCollege !=''){eleIdCollege.checked='checked';spanIdsec.className='checkon';}
eleId.checked='checked';spanId.className='checkon'
}else{
eleId.checked=false;spanId.className='checkoff'}
var paramessage = '<small>'+emptycoursemess+"</small>";
if($$('oldshortlist') !=null) {paramessage = '<p class="blankuni">'+emptycoursemess+"</p>"} 
/* 
if(trimString(dataarray[2])!=''){$$('courselist').innerHTML=dataarray[2]}else{$$('courselist').innerHTML=paramessage}
//$$("my_shortlist_uni_count").value=dataarray[1]
//$$("sp_course_count").innerHTML="("+dataarray[3]+" saved)"
//$$("my_shortlist_course_count").value=dataarray[3]
//if(dataarray[1]>3){$$("unilist").style.height='auto'}else{$$("unilist").style.height='76px';}
//if(dataarray[3]>1){$$("courselist").style.height='auto'}else{$$("courselist").style.height='76px';}
if($$("unibasketshowlogmessage") !=null){$$("unibasketshowlogmessage").innerHTML=dataarray[4]};
*/


if($$("unibasketshowlogmessage") !=null){$$("unibasketshowlogmessage").innerHTML=dataarray[2]};//Added By Sekhar for wu402
if($$('oldshortlist') !=null){
    //if(dataarray[4] !=''){
    if(dataarray[2] !=''){ //Added By Sekhar for wu402
    inter=setInterval('ShowBox()',3);return false}
    else{inter=setInterval('HideBox()',3);return false}
    }
//Added By Sekhar for wu402    

$$("s_count").innerHTML = dataarray[3]
$$("hide").style.display = 'block';
}
}else{
    if(courseId == null || courseId == ""){
        $$(checkBoxId).className="tbox";
        if($$('compare')!=null &&  $$('compare').style.display=='block'){
            $$("compare").style.display ="block";
            $$("compared").style.display ="none";
        }       
    }
    else{
        $$(checkBoxId).className="tbox";
        if($$('compare')!=null &&  $$('compare').style.display=='block'){
           $$("compare").style.display ="block";
           $$("compared").style.display ="none";
        }
    }
    alert('Sorry, your compare list is full. Please remove some items to continue to shortlist.');
    $$("hide").style.display = 'none';
    return false;
}
}}}}

function validateLightboxLogin(action,loginStat){
var data=''
var tacandupdate=''
if(action == 'sendmeupdates'){
data= '&termsandcond='+$$("tremcond").checked+'&sendMeUpdates='+$$('updates').checked;
}else{
if($$("lab_pass")!=null&&$$("lab_pass").style.display=='block'){action="podlogin";}
if(loginStat==''){noneblock("loadinggif",'block');noneblock("logingo",'none');noneblock("reggo",'none');noneblock("errormessageregn",'none')
if(action=='login'){data='&userName='+$$("firstname").value+'&password='+$$("poppassword").value
}else{data=data+'&email='+$$("emailbp").value+'&termsandcond='+$$("podtremcond").checked+'&sendMeUpdates='+$$('podUpdates').checked;
tacandupdate = $$("podtremcond").checked+"#"+$$('podUpdates').checked;
if($$("yearOfUniEntry")!=null){data=data+'&yearOfEntry='+$$("yearOfUniEntry").value;}}}
if(loginStat !=''){
noneblock("loadingpodgif",'block');noneblock("reggo",'none');noneblock("regpodgo",'none');noneblock("regpodreset",'none')
if(action=='podlogin'){data='&userName='+$$("podemailbp").value+'&password='+$$("text_pass").value
tacandupdate = $$("podtremcond").checked+"#"+$$('podUpdates').checked;
}else{data=data+'&email='+$$("podemailbp").value+'&termsandcond='+$$("podtremcond").checked+'&podUpdates='+$$("podUpdates").checked;
tacandupdate = $$("podtremcond").checked+"#"+$$("podUpdates").checked;
if($$("podYearOfUniEntry")!=null){data=data+'&yearOfEntry='+$$("podYearOfUniEntry").value;}}}
}
var ajax=new sack()
var url='/degrees/popupregistration.html?dowhat='+action+data+'&loginStat='+loginStat
if(loginStat !=''){url=url+"&cid="+$$("updatecollegeId").value}
if(action == 'sendmeupdates'){url=url+"&cid="+$$("updatecollegeId").value}
ajax.requestFile=url
ajax.onCompletion=function(){handleLoginReq(ajax,action,loginStat,tacandupdate, ($$("podemailbp") !=null ?  $$("podemailbp").value : ""));}
ajax.runAJAX()
return false}





function handleLoginReq(ajax,action,loginStat,tacandupdate, email, password){
  var resp=ajax.response;var dataarray=resp.split("##")
  if(dataarray[0]=='Login success'){
 
    //if(loginStat==''){closeLogin();if(action=='login'){window.location.href=replaceAll(window.location.href,"/userLogin.html?e=logout","/home.html");}else{window.location.href='/degrees/editprofile.html';}}
     if(loginStat=='' || loginStat == 'withoutLogin'){
        closeLogin();if(action=='login'){window.location.href=replaceAll(window.location.href,"/userLogin.html?e=logout","/home.html");
       }else{
        //window.location.href=replaceAll(window.location.href,"/userLogin.html?e=logout","/home.html");
         var password = dataarray[2];
         loginToSystem(email, password);
         noneblock("infopod_postlogin",'block')
         noneblock("infopod_prelogin",'none')
         var tacandupdateArray  =  new Array;
         tacandupdateArray = tacandupdate.split("#");
         if(tacandupdateArray[1]=== "true"){
            $$("updates").checked = true ;
         }
           if(tacandupdateArray[0] === "true"){
           $$("tremcond").checked = true ;
         }
         if(dataarray[3] !=''){
            noneblock("errormessageregn",'block');
            if($$("errormessageregn")!=null){$$("errormessageregn").innerHTML=dataarray[3];}else{$$("errormessageregn").innerHTML="";}    
         }
      }
    }else{
      if(action !='podlogin'){noneblock("regpodgo",'block');noneblock("loadingpodgif",'none');noneblock("errormessagepodregn",'block');$$("errormessagepodregn").innerHTML="<strong>Successfully updated.</strong>";}else{
         window.location.href=replaceAll(window.location.href,"/userLogin.html?e=logout","/home.html")
      }
    }
  }else{
    noneblock("loadinggif",'none');noneblock("logingo",'block');noneblock("reggo",'block');noneblock("errormessageregn",'block')
    if(action=='login'){
        if($$("errormessagelogin")!=null){$$("errormessagelogin").innerHTML=resp;}$$("errormessageregn").innerHTML="";
     }else{
      if(action == 'sendmeupdates'){
      var data_1='z='+$$("updatecollegeId").value;
      var colId=$$("updatecollegeId").value;
      var thisvalue=$$('secondcheck_'+colId);
      thisvalue.checked=true;
      addBasket(data_1,thisvalue,'Shortlist','Shortlisted');
      }
      if(loginStat==''){$$("errormessageregn").innerHTML=resp;if($$("errormessagelogin")!=null){$$("errormessagelogin").innerHTML=""};}
      else{
      noneblock("errormessagepodregn",'block');noneblock("regpodgo",'block');noneblock("loadingpodgif",'none')
      if(resp==emailexistmsg){noneblock("lab_pass",'block');noneblock("lab_forgot",'block');noneblock("lab_indended_yr",'none');noneblock("lab_terms",'none');noneblock("lab_updates",'none');noneblock("regreset",'block');noneblock("regpodreset",'block');}
      $$("errormessagepodregn").innerHTML=resp
      if(action=="podlogin"){noneblock("regpodreset",'block');}}
    }
  }
   return false
 }




function closeLogin(){
hm('newvenue')}
function resetregpod(){
noneblock("lab_pass",'none')
noneblock("lab_forgot",'none')
noneblock("lab_indended_yr",'block')
noneblock("lab_terms",'block')
noneblock("lab_updates",'block');
noneblock("regpodreset",'none')
noneblock("loadingpodgif",'none')
$$("errormessagepodregn").innerHTML=""
return false}

function checkUpdates() {
noneblock("lab_updates",'block')
$$("podUpdates").checked = false;
}

function noneblock(id,value){if($$(id)!=null){$$(id).style.display=value}}

//myShortList.js
//================================
var emptymysearch="No previous searches on Whatuni are recorded right now. \n\n As you explore Whatuni, your  searches will be saved here. You can then click back to them quickly and easily."
var message1="After searching, tick the boxes next to";var message2="to compare in detail, save and order multiple prospectuses"
var message=message1+" uni names "+message2
var cmessage=message1+" course names "+message2
var prosmess="You can only compare up to 4 choices in one go"

function submitNavShortlist(buttonfrom){
with(document){
var myunicount=trimString(getElementById("my_shortlist_uni_count").value)
var mycoursecount=trimString(getElementById("my_shortlist_course_count").value)
var uniobject=getElementById("navshortlistform").shortlistUni
var courseobject=getElementById("navshortlistform").shortlistCourse
var formobject=getElementById("navshortlistform")
var count=0
if(buttonfrom=='uniBasket'){if(myunicount=='0' || myunicount==''){alert(message);return false;}else{return true;}}
if(buttonfrom=='courseBasket'){if(mycoursecount=='0' || mycoursecount==''){alert(cmessage);;return false;}else{return true;}}
if(buttonfrom=='compareuni'){
if(uniobject==null){alert(message);return false;}
if(uniobject !=null){
for(var i=0;i<uniobject.length;i++){if(uniobject[i].checked==true){count=count+1;}}
if(count>4){alert(prosmess);return false}
formobject.action="/degrees/compareuni.html";formobject.submit();return false}}
if(buttonfrom=='comparecourse'){
if(courseobject==null){alert(cmessage);return false;}
if(courseobject !=null){
for(var i=0;i<courseobject.length;i++){if(courseobject[i].checked==true){count=count+1;}}
if(count>4){alert(prosmess);return false}
formobject.action="/degrees/compare-course.html";formobject.submit();return false}}
}
return false}
//function universityScroll(){with(document){getElementById("main2").scrollTop=0;if(getElementById("mscroll").scrollTop){getElementById("main2").scrollTop=getElementById("mscroll").scrollTop;}}}
//function courseScroll(){with(document){getElementById("main2main2").scrollTop=0;if(getElementById("mscrollmscroll").scrollTop){getElementById("main2main2").scrollTop=getElementById("mscrollmscroll").scrollTop;}}}


