var ajax=new Array();

function getCityList(sel)
{
	var countryCode=sel.options[sel.selectedIndex].value;
	var campus=document.getElementById('hidcampus').value;
	document.getElementById('campus').options.length=0;	// Empty city select box
	if(countryCode.length>0){
		var index=ajax.length;
		ajax[index]=new sack();
		
		ajax[index].requestFile='getCities.php?location='+countryCode+'&campus='+campus;	// Specifying which file to get
		ajax[index].onCompletion=function(){ createCities(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function createCities(index)
{
	var obj=document.getElementById('campus');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}


function getSubCategoryList(sel)
{
	var category=sel.options[sel.selectedIndex].value;
	document.getElementById('campus').options.length=0;	// Empty city select box
	if(category.length>0){
		var index=ajax.length;
		ajax[index]=new sack();
		
		ajax[index].requestFile='getSubCategories.php?category='+category;	// Specifying which file to get
		ajax[index].onCompletion=function(){ createSubCategories(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}
function createSubCategories(index)
{
	var obj=document.getElementById('dhtmlgoodies_subcategory');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}	

$(document).ready(function()
{
	$('.sliding_divs') 
	.before('<div id="nav">') 
	.cycle
	({ 
		fx:     'turnLeft', 
		speed:  'slow',
		timeout: 0, 
		pager:  '#nav' 
	});
	
	function reset_form()
	{
		$("#kwords").attr('value',"Enter keyword(s)");
		$("#type").attr('value',"0");
		$("#loc").attr('value',"0");
		$("#worktype").attr('value',"0");
		$("#faculty_select").attr('value',"");
		$("#faculty_discipline_div").hide();
		$("#days").attr('value',"0");
		$("#sortBy").attr('value',"default");
	}
	
	$("#reset_form").click(function()
	{	
		reset_form();
	});
	
	$('.rotate_images').cycle(
	{
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...,
		speed:  1000 
	});

	if(!jQuery.support.cssFloat)
		$('#top_menu div').bgiframe();
	
	$("#links_nav li").click(function () {
		$("div.links").hide();
		$("."+$(this).attr('name')).show();		
	});
	
	$("#type").change(function()
	{
		var job_category_value=$(this).attr('value');
		
		if
		(
			job_category_value=="academic_positions"||
			job_category_value=="academic_tafe_positions"||
			job_category_value=="lecturers_and_tutors_jobs"||
			job_category_value=="other_academic_jobs"||
			job_category_value=="principal_senior_lecturers_jobs"||
			job_category_value=="professors_readers_chairs_jobs"||
			job_category_value=="grants_and_scholarships_jobs"||
			job_category_value=="veterinary_and_biomedical_sciences_jobs"
		)
		{
			show_faculty_disciplines();
		}
		else
		{
			hide_faculty_disciplines();
		}
	});
	
	function show_faculty_disciplines()
	{
		$("#faculty_discipline_div").show();
	}
	
	function hide_faculty_disciplines()
	{	
		$("#faculty_select").attr('value','');
		$("#faculty_discipline_div").hide();
	}

	$("#more_topic_div_wrap").corner();
	$("#suggest_topic_div").corner();
	
	function clear_form_elements(ele) 
	{
		alert('a');
		$(ele).find(':input').each(function() 
		{
			switch(this.type) 
			{
				case 'password':
				case 'select-multiple':
				case 'select-one':
				case 'text':
				case 'textarea':
					$(this).val('');
					break;
				case 'checkbox':
				case 'radio':
					this.checked = false;
			}
		});
	}

	$(".rpt-sort a").attr('href','');
	$("#NAME a").css("color","red");
	/*$(function() 
	{
		$("#type")
			.mouseover(function()
			{
				$(this)
					.data("origWidth", $(this).css("width"))
					.css("width", "auto");
					
				$("#loc")
					.data("other_width",$("#loc").css("width"))
					.css("width",'180px');
			})
			.mouseout(function(){
				$(this).css("width", $(this).data("origWidth"));
				
				$("#loc").css("width",$("#loc").data("other_width"));
			});
	});*/
});

function show_hide_extended_locations()
{
/*
	if(document.getElementById('loc').value != '------ ALL  Locations -------')
	{
	document.getElementById('extended_location').style.display='block';
	getCityList(document.getElementById('loc'));
	}
	else
	{
	document.getElementById('extended_location').style.display='none';
	}
*/
}

//implementation of Do Not Show this window again
var expDate=new Date();
expDate.setTime(expDate.getTime()+365*24*60*60*1000); // one year

function setCookie(isName,isValue,dExpires)
{
	document.cookie=isName+"="+isValue+";expires="+dExpires.toGMTString();
}

function getCookie(isName)
{
	cookieStr=document.cookie;
	startSlice=cookieStr.indexOf(isName+"=");
	if (startSlice==-1)
	{
	return false;
	}
	endSlice=cookieStr.indexOf(";",startSlice+1)
	if (endSlice==-1)
	{
	endSlice=cookieStr.length;
	}
	isData=cookieStr.substring(startSlice,endSlice);
	isValue=isData.substring(isData.indexOf("=")+1,isData.length);
	return isValue;
}
/////////////////////////////////////////////////////////////////////////

function popitup(url) 
{
	if (!getCookie('subscribe_popup'))
	
	{
	//find user's screen size
	var screenW=640,screenH=480;
	if(parseInt(navigator.appVersion)>3) 
	{
		screenW=screen.width;
		screenH=screen.height;
	}
	else if(navigator.appName=="Netscape"&& parseInt(navigator.appVersion)==3&&navigator.javaEnabled()) 
	{
		var jToolkit=java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize=jToolkit.getScreenSize();
		screenW=jScreenSize.width;
		screenH=jScreenSize.height;
	}
	//document.write("Screen width="+screenW+"<br>"+"Screen height="+screenH);
	var left=(screenW-475)/2;
	var top=(screenH-600)/2;
	newwindow=window.open(url,'name','height=600,width=475,location=no,menubar=no,scollbars=no,status=no,toolbar=no,resizable=no');
	newwindow.moveTo(left,top);
	if (window.focus) 
	{
		newwindow.focus()
	}
	return false;
	}
}

function open_subscriber_popup(url)
{
	//find user's screen size
	var screenW=640, screenH=480;
	if(parseInt(navigator.appVersion)>3) 
	{
		screenW=screen.width;
		screenH=screen.height;
	}
	else if(navigator.appName=="Netscape"&& parseInt(navigator.appVersion)==3&&navigator.javaEnabled()) 
	{
		var jToolkit=java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize=jToolkit.getScreenSize();
		screenW=jScreenSize.width;
		screenH=jScreenSize.height;
	}
	//document.write("Screen width="+screenW+"<br>"+"Screen height="+screenH);
	var left=(screenW-520)/2;
	var top=(screenH-700)/2;
	var newwindow=window.open(url,'name','height=700,width=520,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes');
	newwindow.moveTo(left,top);
	if (window.focus) 
	{
		newwindow.focus()
	}
	return false;
}


function open_survey_popup(url)
{
	//if (!getCookie('survey_popup'))
	if (!getCookie('survey_HE_popup'))
	{
	//find user's screen size
	var screenW=640,screenH=480;
	if(parseInt(navigator.appVersion)>3) 
	{
		screenW=screen.width;
		screenH=screen.height;
	}
	else if(navigator.appName=="Netscape"&& parseInt(navigator.appVersion)==3&&navigator.javaEnabled()) 
	{
		var jToolkit=java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize=jToolkit.getScreenSize();
		screenW=jScreenSize.width;
		screenH=jScreenSize.height;
	}
	//document.write("Screen width="+screenW+"<br>"+"Screen height="+screenH);
	var left=(screenW-475)/2;
	var top=(screenH-600)/2;
	newwindow=window.open(url,'name','height=200,width=475,location=no,menubar=no,scollbars=no,status=no,toolbar=no,resizable=no');
	newwindow.moveTo(left,top);
	if (window.focus) 
	{
		newwindow.focus()
	}
	return false;
	}
}

function submit_to_popup()
{
	name = document.getElementById("name").value;
	email = document.getElementById("email").value;
	return open_subscriber_popup('subscribe_popup.php?name='+name+'&email='+email);
}
