// when the state changes, update the regions
function change_state() {
	param = MM_findObj('state').options[MM_findObj('state').selectedIndex].value;
	qry = 'cmd=region_search&state=' + param;
	ajax_request(qry, 'region_select');
	select_regions();
}


function is_array(ob) {
	var is_array = false;
	var count = 0;
	for (var i = 0; i < ob.options.length; i++) {
		if (ob.options[i].selected) {
			count++;
		}
	}
	if (count > 1) {
		is_array = true;
	}

	return is_array;
}

function submit_search() {
	//alert(document.getElementById('regions').selectedIndex);
	
	if (document.getElementById('regions').selectedIndex < 0) {
		alert('Please select one or more region to search');
	} else {

		if (is_array(document.getElementById('regions'))) {
			//alert('is array');
			document.advance_search.submit();
			
		} else {
			//alert('not array');
			document.advance_search.action = '/weddingvenues/'+document.getElementById('regions').options[document.getElementById('regions').selectedIndex].value; 
			document.advance_search.submit();

		}
	}
}

function fnMap(id){
	mapShifting(id, 'au_map_self');
}

function fnStateUpdates_AJAX(id){
	mapShifting(id, 'au_map_container');

	// update the state selected
	states = MM_findObj('state');
	for (i = 0; i < states.length; i++) {
		if (id == states.options[i].value.toLowerCase()) {
			states.selectedIndex = i;
			change_state();
		}
	}
}

function mapShifting(id, base_id){
	var top = 176;
	switch(id){
		case 'tas':
		$('#'+base_id).css({'background-position':'0 -'+(top*1)+'px'});
		break;
		case 'vic':
		$('#'+base_id).css({'background-position':'0 -'+(top*2)+'px'});
		break;
		case 'nsw':
		$('#'+base_id).css({'background-position':'0 -'+(top*3)+'px'});
		break;
		case 'qld':
		$('#'+base_id).css({'background-position':'0 -'+(top*4)+'px'});
		break;
		case 'sa':
		$('#'+base_id).css({'background-position':'0 -'+(top*5)+'px'});
		break;
		case 'nt':
		$('#'+base_id).css({'background-position':'0 -'+(top*6)+'px'});
		break;
		case 'wa':
		$('#'+base_id).css({'background-position':'0 -'+(top*7)+'px'});
		break;
		case 'act':
		$('#'+base_id).css({'background-position':'0 -'+(top*8)+'px'});
		break;
		case 'none':
		$('#'+base_id).css({'background-position':'0 0'});
		break;
	}
}

function email() {
	if (MM_findObj('verify').value == 'wedding') {
		MM_findObj('email_venue').submit();
	} else { 
		alert('Please answer the verification question');
	}
}

function show_pic(img) {
	i = MM_findObj('pic');
	i.src = img;
}

scrollStep=1;
timerLeft="";
timerRight="";

function toLeft(id){
  MM_findObj(id).scrollLeft=0;
}

function scrollDivLeft(id){
  clearTimeout(timerRight) ;
  MM_findObj(id).scrollLeft+=scrollStep;
  timerRight=setTimeout("scrollDivLeft('"+id+"')",10);
}

function scrollDivRight(id){
  clearTimeout(timerLeft);
  MM_findObj(id).scrollLeft-=scrollStep;
  timerLeft=setTimeout("scrollDivRight('"+id+"')",10);
}

function toRight(id){
  MM_findObj(id).scrollLeft=MM_findObj(id).scrollWidth
}

function stopMe(){
  clearTimeout(timerRight) 
  clearTimeout(timerLeft)
}

<!--                             
function popupwiz(page){ var name = 'PopUp' ;var options = 'width=552,height=450,scrollbars=yes' ;myPopup = window.open(page, name, options) ;}                                           
function popupwizpc(page){ var name = 'PopUp' ;var options = 'width=552,height=345,' ;myPopup = window.open(page, name, options) ;}                                           
function popupwizimages(page) { var name = 'PopUp' ;var options = 'width=420,height=320,' ;myPopup = window.open(page, name, options) ;}                             
function popupwizetf(page){ var name = 'PopUp' ; var options = 'width=300,height=335,' ; myPopup = window.open(page, name, options) ;}                                                         
function popupwizlarge(page){ var name = 'PopUp' ;var options = 'width=800,height=700,scrollbars=yes' ;myPopup = window.open(page, name, options) ;}                                           
// -->   


function show_ad (zone, params) {
	
   var m3_u = (location.protocol=='https:'?'https://openx.banneradvts.com/delivery/ajs.php':'http://openx.banneradvts.com/delivery/ajs.php');
   var m3_r = Math.floor(Math.random()*99999999999);
   if (!document.MAX_used) document.MAX_used = ',';
   document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
   document.write ("?zoneid=" + zone);
   document.write ('&amp;cb=' + m3_r);
   if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
   document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
   document.write ("&amp;loc=" + escape(window.location + params));
   if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
   if (document.context) document.write ("&context=" + escape(document.context));
   if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
   
   document.write ("'><\/scr"+"ipt>");

}

function select_regions() {
	regions = MM_findObj('regions')
	for (i=0; i <= regions.options.length - 1; i++) {
		regions.options[i].selected = true;
	}
	regions.options[0].selected = false;
	regions.options[0].selected = true;
}