  // Open new pop-up window with url, width and height
  function openWindow(url,width,height) {
   var left = (window.screen.width - width) / 2;
   var top = (window.screen.height - height) / 2;
   var parameters = 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',toolbar=0,menubar=0,location=0,status=0,scrollbars=1,titlebar=0,resizable=0';
   window.open(url,'popup',parameters);
  }



function loadscreen(){
	document.body.innerHTML = '' ;
	document.body.style.background = "url(/images/soleil.gif) no-repeat center center" ;
}
function input_out(el,s){
	if( '' == el.value ){
		el.value = s ;
	}
}

function input_in(el,s){
	if( s == el.value ){
		el.value = '' ;
	}
}
function update_name_display(){
	var fn = document.getElementsByName('firstname')[0].value ;
	var ln = document.getElementsByName('lastname')[0].value ;
	var fn_new = (fn.length>0) ? fn : 'Firstname' ;
	var ln_new = (ln.length>0) ? ln : 'Lastname' ;
	document.getElementById('container_display1').innerHTML = fn_new+' '+ln_new.charAt(0).toUpperCase()+'.' ;
	document.getElementById('container_display2').innerHTML = fn_new+' '+ln_new ;
}
function update_highlights_counter(){
	var max = 64 ;
	var chars = document.getElementsByName('highlights')[0].value.length ;
	var left = max - chars ;
	if( left < 0 ){
		var message = '<span style="color:#F87311;">'+(-1*left) + ' too many characters</span>' ;
	}
	else{
		var message = left + ' characters left' ;
	}
	document.getElementById('highlights_counter').innerHTML = message ;
}
function update_residence_options(){
	var residence = document.getElementById('checkbox_residence').checked ;
	var display = residence ? '' : 'none' ;
	var cr = getElementsByClass('container_residence') ;
	for( i=0,l=cr.length ; i<l ; i++ ){
		cr[i].style.display = display ;
	}
}
function update_property_options(){
	var pid_sel = document.getElementById('pid_selector') ;
	var pid = pid_sel[pid_sel.selectedIndex].value ;
	var clt = document.getElementById('container_landtype') ;
	var cft = document.getElementById('container_farmtype') ;
	var cht = document.getElementById('container_hometype') ;
	var crt = document.getElementById('container_ranchtype') ;
	var ccb = document.getElementById('container_category_blank') ;
	var la  = document.getElementById('label_area') ;
	clt.style.display = 'none' ;
	cft.style.display = 'none' ;
	cht.style.display = 'none' ;
	crt.style.display = 'none' ;
	ccb.style.display = 'none' ;
	var cr = document.getElementById('category_required') ;
	if( 1 == pid ){
		clt.style.display = '' ;
		la.innerHTML = 'Area *' ;
		cr.innerHTML = '*' ;
	}
	else if( 2 == pid ){
		cft.style.display = '' ;
		la.innerHTML = 'Area *' ;
		cr.innerHTML = '*' ;
	}
	else if( 3 == pid ){
		cht.style.display = '' ;
		la.innerHTML = 'Lot Size *' ;
		cr.innerHTML = '(optional)' ;
	}
	else if( 4 == pid ){
		crt.style.display = '' ;
		la.innerHTML = 'Area *' ;
		cr.innerHTML = '*' ;
	}
	else {
		document.getElementById('container_category_blank').style.display = '' ;
	}
	//var rooms_disabled = 3 == pid ? false : true ;
	//document.getElementById('bedrooms').disabled = rooms_disabled ;
	//document.getElementById('bathrooms').disabled = rooms_disabled ;
}
function update_county(current){
	var ss = document.getElementById('state_selector') ;
	var state = ss[ss.selectedIndex].value ;
	$('#county_container').load('http://www.horseclicks.com/ajax.php?action=counties&state=' + state + (current?('&current='+current):'') ) ;
}
function update_state(){
	var state_required = document.getElementById('state_required') ;
	var state_selector = document.getElementsByName('state')[0] ;
	var country_selector = document.getElementsByName('country')[0] ;
	var current_country = country_selector[country_selector.selectedIndex].value ;
	if( 'US'==current_country || 'CA'==current_country ){
		state_required.innerHTML = '*' ;
		state_selector.disabled = false ;
	}
	else{
		state_selector.selectedIndex = 0 ;
		state_required.innerHTML = '(optional)' ;
		state_selector.disabled = true ;
	}
}
function update_county_disable(){
	var county_required = document.getElementById('county_required') ;
	var county_selector = document.getElementsByName('county')[0] ;
	var country_selector = document.getElementsByName('country')[0] ;
	var current_country = country_selector[country_selector.selectedIndex].value ;
	if( 'US'==current_country ){
		county_required.innerHTML = '*' ;
		if( county_selector ){
			county_selector.disabled = false ;
		}
	}
	else{
		county_selector.selectedIndex = 0 ;
		county_required.innerHTML = '(optional)' ;
		county_selector.disabled = true ;
	}
}
function update_state_disable(){
	var state_selector = document.getElementsByName('state')[0] ;
	var country_selector = document.getElementsByName('country')[0] ;
	var current_country = country_selector[country_selector.selectedIndex].value ;
	if( 'US'==current_country || 'CA'==current_country ){
		state_selector.disabled = false ;
	}
	else{
		state_selector.selectedIndex = 0 ;
		state_selector.disabled = true ;
	}
}
function update_price_label(){
	var price_labels = getElementsByClass('price_label') ;
	var type_selector = document.getElementsByName('tid')[0] ;
	var current_type = type_selector.selectedIndex ;
	if( 2==current_type ){
		var newlabel = 'Stud Fee' ;
	}
	else{
		var newlabel = 'Price' ;
	}
	for( var i=0,l=price_labels.length ; i<l ; i++ ){
		price_labels[i].innerHTML = newlabel ;
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function confirm_url(url,message){
	if ( window.confirm(message) ){
		window.location = url;
 	}
}

function switch_mainpic(path,xpath){
	if( xpath && path ){
		var html = '<a href="javascript:xpic(\''+xpath+'\');"><img id="mainpic" src="'+path+'" /></a>' ;
	}else if( path ){
		var html = '<img id="mainpic" src="'+path+'" />' ;
	}
	if( html ){
		document.getElementById('mainpic_container').innerHTML = html ;
	}
}
function xpic(path){
	var width = 497 ;
	var height = 500 ;
	var left = (window.screen.width - width) / 2 ;
	var top = (window.screen.height - height) / 2 ;
	var parameters = 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar=0,menubar=0,location=0,status=0,titlebar=0,resizable=0' ;
	window.open('/m_bigpics.php?path='+path,'',parameters) ;
}

