/**************************************/
/*	javascript for diversity abroad	*/
/**************************************/


/********** quick links and main menu *********/
function searchinit()	{
	var f = document.getElementById('cse-search-box');
	if (!f) {
		f = document.getElementById('searchbox_demo');
	}
	if (f && f.q) {
		var q = f.q;
		var n = navigator;
		var l = location;
		if (n.platform == 'Win32') {
			q.style.cssText = 'border: 1px solid #7e9db9; padding: 2px;';
		}
		var b = function() {
			if (q.value == ''){
				// change the path to your intended background image or color
				q.style.background = '#ffffff';
			}
		};
		var f = function() {
			// This part is when query box is in focus
	        q.style.background = '#ffffff';
		};
		q.onfocus = f;
		q.onblur = b;
		// JS regex that calls blur function when query is not submitted
		if (!/[&?]q=[^&]/.test(l.search)) {
			b();
		}
	}
}

function gotolink(linkid) {							
	if(linkid != '') {
		var slinkids = "url" + linkid;
		var tar = "tar" + linkid;
		
		if(document.getElementById(tar).value == 1) {
			document.frmquick.action = document.getElementById(slinkids).value;		
			document.frmquick.target = '_blank';	
		} else if (document.getElementById(tar).value == 0) {
			document.frmquick.action = 'http://staging.diversityabroad.com/' + document.getElementById(slinkids).value;
			document.frmquick.target = '_self';
		}
		document.getElementById('quicklinks').style.visibility='hidden';
		document.frmquick.submit();
	}							
}							
function dropopt(){ 
	if (document.getElementById('quicklinks').style.visibility=='visible') 
	{
		document.getElementById('quicklinks').style.visibility='hidden';
		
	} else if (document.getElementById('quicklinks').style.visibility=='hidden') {
		document.getElementById('quicklinks').style.visibility='visible';
		
	}
}

var menuids=["suckertree1", "suckertree2", "suckertree3", "suckertree4"] //Enter id(s) of SuckerTree UL menus, separated by commas
										
function buildsubmenus(){
	for (var i=0; i<menuids.length; i++){	
		var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul");
    		for (var t=0; t<ultags.length; t++){
		    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
			if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
				ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
			else //else if this is a sub level submenu (ul)
				ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
		    ultags[t].parentNode.onmouseover=function(){
	    			this.getElementsByTagName("ul")[0].style.display="block"
		    }
		    ultags[t].parentNode.onmouseout=function(){
			    this.getElementsByTagName("ul")[0].style.display="none"
	    		}
		}
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
			ultags[t].style.visibility="visible"
			ultags[t].style.display="none"
		}
	}
}

if (window.addEventListener)
	window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
	window.attachEvent("onload", buildsubmenus)

var previd="";
var previd1="";

function HttpRes_pcde(id){
	if(previd==""){}
	else{
		document.getElementById(previd).style.display='none';
	}
	document.getElementById(id).style.display='block';	
	previd=id;
}
/************** \\ END // **************/

/******** login and register **********/
function displayuser() {
	var uname=document.getElementById('username').value;
	if(uname!="username")
		document.getElementById('username').value=uname;
	if(uname=="")
		document.getElementById('username').value='username';
}

function fdisplayuser() {
	var uname=document.getElementById('username').value;
	
	if(uname!="username") {
		document.getElementById('username').value=uname;
	} else if (uname=="username") {
		document.getElementById('username').value='';
	} else if (uname=="") {
		document.getElementById('username').value='username';
	}
}
	
function displaypass() {
	var pwd=document.getElementById('passwd').value;
	if(pwd!="password")
		document.getElementById('passwd').value=pwd;
	if(pwd=="")
		document.getElementById('passwd').value='password';
}


function fdisplaypass() {
	var pwd=document.getElementById('passwd').value;
	
	if(pwd!="password") {
		document.getElementById('passwd').value=pwd;
	} else if (pwd=="password") {
		document.getElementById('passwd').value='';
	} else if (city=="") {
		document.getElementById('passwd').value='password';
	}
}
/************** \\ END //**************/

/************ newsletter ****************/
function changeTask() {
	var email;
	var max_length = 15;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

	if (filter.test(document.communicatorMod.email.value)) {
		email = document.communicatorMod.email.value;
		var a = true;
	} else {
		alert("Please enter a valid email address.");
		var a = true; return false;
	}
	try {
		if(document.communicatorMod.subscriber_name.length < 1) {
			alert("Please enter a Subscriber Name. Thanks.");
			return false;
		}
				}
	catch(e) {}
	return true;
}
/*************** \\ END // *****************/

/************ student airfare **************/
function fnValidateFare() {
	if(document.farefinder.outboundAirport.value == "")
	{
		alert("Please enter \"From\" place");
		document.farefinder.outboundAirport.focus();
		return false;
	}
	else if(document.farefinder.inboundAirport.value == "")
	{
		alert("Please enter \"To\" place");
		document.farefinder.inboundAirport.focus();
		return false;
	}
	else if(document.farefinder.outboundDay.value == "")
	{
		alert("Please select Departure date");
		document.farefinder.outboundDay.focus();
		return false;
	}
	else if(document.farefinder.outboundMonth.value == "")
	{
		alert("Please select Departure Month");
		document.farefinder.outboundMonth.focus();
		return false;
	}
	else if(document.farefinder.inboundDay.value == "" && (document.farefinder.tripType[0].checked == true))
	{
		alert("Please select Return date");
		document.farefinder.inboundDay.focus();
		return false;
	}
	else if(document.farefinder.inboundMonth.value == "" && (document.farefinder.tripType[0].checked == true))
	{
		alert("Please select Return Month");
		document.farefinder.inboundMonth.focus();
		return false;
	}
	else{
		//window.location="http://www.studentuniverse.com/fly/searchUtil?partner=diversityabroad&utm_source=booking+engine&utm_medium=partner&utm_campaign=compare+price&utm_content=search+box";
		window.location="http://www.studentuniverse.com";
	}
}
/**************** \\ END // ****************/

//hleftoff = new Image(); hleftoff.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_left_curve_off1.gif"; hlefton = new Image(); hlefton.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_left_curve_on1.gif"; hbackoff = new Image(); hbackoff.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_back_off.gif"; hbackon = new Image(); hbackon.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_back_on.gif"; hrightoff = new Image(); hrightoff.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_right_curve_off2.gif"; hrighton = new Image(); hrighton.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_right_curve_on1.gif"; tleftoff = new Image(); tleftoff.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_left_curve_off2.gif"; tlefton = new Image(); tlefton.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_left_curve_on2.gif"; tbackoff = new Image(); tbackoff.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_back_off.gif"; tbackon = new Image(); tbackon.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_back_on.gif"; trightoff = new Image(); trightoff.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_right_curve_off2.gif"; trighton = new Image(); trighton.src = "http://images.webresint.com/images/rbh/express/bighw/esp_big_right_curve_on1.gif"; function HostelsOn() { document.images.hleft.src = hlefton.src; var hback = document.getElementById("hback"); hback.className = "backon"; document.images.hright.src = hrighton.src; document.images.tleft.src = tleftoff.src; var tback = document.getElementById("tback"); tback.className = "backoff"; document.images.tright.src = trightoff.src; } function ToursOn() { document.images.hleft.src = hleftoff.src; var hback = document.getElementById("hback"); hback.className = "backoff"; document.images.hright.src = hrightoff.src; document.images.tleft.src = tlefton.src; var tback = document.getElementById("tback"); tback.className = "backon"; document.images.tright.src = trighton.src; }

function populateCitySelect( country ) {
	newcountry = country.replace(/ /g,'');
	if ( newcountry.length == 0 ) {
    		document.theForm.ChosenCity.length = 1;
	    document.theForm.ChosenCity.options[0] = new Option('Choose a country:');
	    document.theForm.ChosenCity.options[0].value = '';
	    return;
	}
	if ( country == 'Holland' ) {
    		newcountry = 'Netherlands';
	}
  	if ( country == 'Britain' ) {
    		newcountry = 'England';
  	}
  	newOptions = eval(newcountry+'Array');
  	document.theForm.ChosenCity.length = 1;
  	document.theForm.ChosenCity.options[0] = new Option('Choose a city :');
  	document.theForm.ChosenCity.options[0].value = '';
  	document.theForm.ChosenCity.options[0].selected = true;
  	var citylength = newOptions.length + 1;
  	for ( i=0; i<newOptions.length; i++ ) {
    		document.theForm.ChosenCity.length++;
	    thisEntry = newOptions[i];
    		newOption = new Option( thisEntry );
	    //newOption.value = 'C' + thisEntry + ';' + country;
	    	newOption.value = thisEntry;
    		document.theForm.ChosenCity.options[i+1] = newOption;
  	}
  	document.theForm.ChosenCity.length = citylength;
  	if(newOptions.length == 1) document.theForm.ChosenCity.options[1].selected = true;
}

function convertURL(){
	alert(document.theForm.ChosenCountry.options[selectedIndex].value);return;
}