var ns = (document.all)? false : true;

pic1= new Image(100,25); 
pic1.src="assets/templates/default/images/nav_tri.png"; 

function redirectUrl(url) {
   if (url.value !== 0) {
     location = url;	
   }	
}

/* MOUSEOVER BG IMAGE STATES FOR MAIN NAV */
function navOver(cn) {
    document.getElementById(cn).className = 'current';	  
}

function navOut(cn) {
  document.getElementById(cn).className = 'nav_main';
}

function navLink(lnk) {
  document.location = lnk;	
}

var n=0;

/* DISPLAY/HIDE AGENTS LIST */
function displayAgents(n) {
	var agents_list = document.getElementById('agents_list');
	var form = document.testimonial; 
	
	if (form.country) {
	  if (n==1){ 
		  fetchCountryAgents(form.country.value);
		}	
	}
	
	if (agents_list.style) {
		//show 
		if (n==1) {
			agents_list.style.display = 'block';
		} else {
			document.testimonial.agents_name.selectedIndex=0;
			agents_list.style.display = 'none';
		}		
	}
}


/* DISPLAY/HIDE ADV SEARCH OPTS - COURSE FINDER */
var showOpts = 0;

function showAdvOpts(){
	var optsDiv = document.getElementById('adv_search_opts');
	
	//--show
	if (showOpts===0) {
		optsDiv.style.display = 'block';
		showOpts=1;
	} else if (showOpts==1) {
		//--hide
		optsDiv.style.display = 'none';
		showOpts=0;
	}

}

/* FOOTER */
function footerOver(img,io) {
  var src = img.src;
  var newsrc;

  if (io==1) {
	  newsrc = src.replace('grey_','colour_');
	  img.src = newsrc;
  } else {
	  newsrc = src.replace('colour_','grey_');
	  img.src = newsrc;
  }

}

var _base = 'assets/snippets/';

function fetchCountryAgents(country) {
	var url = _base + 'Ajax/fetchdata.php';		
	
    var pars = Object.toQueryString({
            	'q':url,
				'action': 'fetchCountryAgents',
				'country': country
				});

	new Ajax('index-ajax.php', {postBody: pars, noCache: true, onComplete: displayCountryAgents, update: $('results_agents')}).request();	
}

function displayCountryAgents() {
	
}

function checkAgentsList(country) {
   var agents_list = document.getElementById('agents_list');
   if (agents_list.style.display=='block') {
   	  fetchCountryAgents(country);
   }	
}

function fetchSchoolsList(country) {
	
	var form = document.testimonial;
	
	document.getElementById('frow_course').style.display = 'none';
	document.getElementById('frow_school').style.display = 'none';
	
	if (form.course.options) {
		form.course.options.length =0;		
	}
	
	var url = _base + 'Ajax/fetchdata.php';		

    var pars = Object.toQueryString({
            	'q':url,
				'action': 'fetchSchools',
				'country': country
				});

	new Ajax('index-ajax.php', {postBody: pars, noCache: true, onComplete: displaySchoolsList, update: $('results_school')}).request();

}

function displaySchoolsList() {
  if (document.testimonial.schools.options.length >1) {
	document.getElementById('frow_school').style.display = 'inline';
  }	
}

function fetchCourseList(school) {
	
	var form = document.testimonial;
	
	document.getElementById('frow_course').style.display = 'none';
	
	var url = _base + 'Ajax/fetchdata.php';			
      			
    var pars = Object.toQueryString({
            	'q':url,
				'action': 'fetchCourses',
				'school': school
				});

	new Ajax('index-ajax.php', {postBody: pars, noCache: true, onComplete: displayCoursesList, update: $('results_course')}).request();	
}


function displayCoursesList() {
  if (document.testimonial.course.options.length >1) {
	document.getElementById('frow_course').style.display = 'inline';
  }	
}

/****************************************************************************/

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 updateTrackerHistory(tab) {
	var trackerId = readCookie('historyTracker');
	var currentUrl = location.href;
	var tabId = document.getElementById(tab);
	var tabParentId = tabId.parentNode.parentNode.id;

	var url = _base + 'Ajax/historyTracker.php';
	var tabs2 = '';
	
	if (tabParentId == 'tabs2') {
		tabs2 = '&tabs2=' + tab;
		tab = 'courses';
	}
	
	var req = new Request({
		url: 'index-ajax.php',
		data: 'q='+ url +'&doc='+ docId +'&tab='+ tab + tabs2+ '&id='+ trackerId +'&page='+ escape(location.href),
	    onSuccess: function(txt){}}
		);
	
	req.send();
		
}

/****************************************************************************/

function modList(selectbox){
	var i;
	var x=0;
	
	var otherbox = document.BecomeAnAgentForm.schools_other;
	var slctd=0;
	

	for(x=otherbox.options.length-1;x>=0;x--)
	{
	  otherbox.remove(i);
	}
	
	for(i=0;i<=selectbox.options.length;i++)
	{
		
	  if (selectbox.options[i]) {
		  
		if(!selectbox.options[i].selected){	
			otherbox.options[otherbox.length] = new Option(selectbox.options[i].text,selectbox.options[i].value);		
		} else {
			
			if (slctd<3) {
			  slctd++;
			} else{ 
			  selectbox.options[i].selected=false;
			}

		}
		
	  }	
	}
	
	if (slctd>3) {
	  alert('only 3 can be chosen');
	}

}
