/*window.onload = function () {
	if (document.getElementById('pchange') != null) {
		$('pchange').onsubmit = function(){
			passwdChange();
			return false;
		}
	}
}
*/
function addcounty(memberid, countyid){
	cselect = document.getElementById('countyids');
	cselect.selectedIndex = 0;
	
	new Ajax.Updater('alert_counties', base_url + '/members/ajaxaddcounty.php', {
		method: 'post',
		postBody: 'memberid=' + memberid + '&countyid=' + countyid
	});
	
	new Effect.Appear('alert_counties');
	//new Effect.Appear('alert_counties', {duration:1, from:0, to:1.0});
	return false;
}

function deletecounty(memberid, countyid){
	cselect = document.getElementById('countyids');
	cselect.selectedIndex = 0;

	new Ajax.Updater('alert_counties', base_url + '/members/ajaxdeletecounty.php', {
		method: 'post',
		postBody: 'memberid=' + memberid + '&countyid=' + countyid
	});

	//new Effect.Appear('alert_counties', {duration:1, from:0, to:1.0});
	return false;
}

function faddcounty(countyid){
	
	var chidden = document.getElementById("fcounties");
	
	var stateselect = document.getElementById("state2");
	var statenum = stateselect.selectedIndex;
	
	var counties = chidden.value;
	var newfcounties='';
	if( counties.length == 0 ){
		newfcounties += statenum + ':' + countyid;
	}
	else{
		var count=0;
		if(countyid==1){
		 var oldfcounties = counties.split(',');
		 	for(var i=0; i<oldfcounties.length; i++){
		 		var help = oldfcounties[i].split(':');
		 		if(help[0] != statenum){
					if(count==0){
						newfcounties =help[0]+':'+help[1];
					}else{
						newfcounties +=','+help[0]+':'+help[1];
					}	
					count++;	 		
		 			
		 		}
		 	}
		 	if(count ==0){
		 		newfcounties +=  + statenum + ':' +countyid;
		 	}else{
		 		newfcounties += ',' + statenum + ':' +countyid;
		 	}
			
		}else{
			newfcounties = counties;
			var oldfcounties = counties.split(',');
				
		 		
		 	for(var i=0; i<oldfcounties.length; i++){
		 		var help = oldfcounties[i].split(':');
		 		if(help[0] == statenum && help[1] == 1){
					count++;	 		
		 			
		 		}
		 	}
		 	if(count==0){
		 		newfcounties += ',' + statenum + ':' + countyid;
		 	}
			
		}
		
	}
	
	chidden.value = newfcounties;
	
	new Ajax.Updater('falert_counties', base_url + '/free-email-alerts/ajaxcounties.php', {
		method: 'post',
		postBody: 'countiesnum=' + newfcounties + '&statenum=' + statenum
	});
	
}


function fdeletecounty( scnum ){
	
	var chidden = document.getElementById("fcounties");
	
	var ahidden = new Array();
	ahidden = chidden.value.split(",");
	
	var newhidden = new Array();
	
	for( var i=0; i<ahidden.length; i++ ){
		
		if( ahidden[i] != scnum )	newhidden.push( ahidden[i] );
	}
	
	
	var newfcounties = newhidden.join(",");
	
	chidden.value = newfcounties;
	
	new Ajax.Updater('falert_counties', base_url + '/free-email-alerts/ajaxcounties.php', {
		method: 'post',
		postBody: 'countiesnum=' + newfcounties
	});
	
}


function selectAllCounties(){
	
	var stateselect = document.getElementById("state2");
	var statenum = stateselect.selectedIndex;
	
	var chidden = document.getElementById("fcounties");
	
	var ahidden = new Array();
	ahidden = chidden.value.split(",");
	
	var newhidden = new Array();
	
	for( var i=0; i<ahidden.length; i++ ){
		
		var scarray = ahidden[i].split(":");
		if( scarray[0] != statenum )	newhidden.push( ahidden[i] );
	}
	
	if( newhidden.length > 0 )	newhidden.push( ',' + statenum + ':' + 'all' );
	
	var newfcounties = newhidden.join(",");
	
	chidden.value = newfcounties;
	
	new Ajax.Updater('falert_counties', base_url + '/free-email-alerts/ajaxcounties.php', {
		method: 'post',
		postBody: 'countiesnum=' + newfcounties
	});
	
}

function subscriptionInfo(){
	cselect = document.getElementById('acc_state');
	var stateid = cselect.selectedIndex;
	
	mtype = document.getElementsByName('mtypeid');
	var mtypeid = 0;
	for( var i=0; i<mtype.length; i++ ){
		
		if( mtype[i].checked == true )	mtypeid = mtype[i].value;
	}
	//var mtypeid = mtype.value;
	
	term = document.getElementsByName('term_length');
	var termid = 0;
	for( var i=0; i<term.length; i++ ){
		
		if( term[i].checked == true )	termid = term[i].value;
	}

	promoc = document.getElementById('promo');
	var promocode = promoc.value;
	
	new Ajax.Updater('subscription_info', 'https://www.nadhlandforsale.com/register/ajaxsubscriptioninfo.php', {
		method: 'post',
		postBody: 'stateid=' + stateid + '&mtypeid=' + mtypeid + '&termid=' + termid + '&promo=' + promocode
	});
	
	new Effect.Appear('subscription_info');
	//new Effect.Appear('alert_counties', {duration:1, from:0, to:1.0});
	return false;
}

function subscriptionInfoPromotion(promotype){
	
	cselect = document.getElementById('acc_state');
	var stateid = cselect.selectedIndex;

	promoc = document.getElementById('promo');
	var promocode = promoc.value;
	
	new Ajax.Updater('subscription_info', 'https://www.nadhlandforsale.com/register/ajaxsubscriptioninfo-promotion.php', {
		method: 'post',
		postBody: 'stateid=' + stateid + '&promotype=' + promotype + '&promo=' + promocode
	});
	
	new Effect.Appear('subscription_info');
	//new Effect.Appear('alert_counties', {duration:1, from:0, to:1.0});
	return false;
}


function subscriptionInfo2(){
	//cselect = document.getElementById('acc_state');
	//var stateid = cselect.selectedIndex;
	
	mtype = document.getElementsByName('mtypeid');
	var mtypeid = 0;
	for( var i=0; i<mtype.length; i++ ){
		
		if( mtype[i].checked == true )	mtypeid = mtype[i].value;
	}
	//var mtypeid = mtype.value;
	
	term = document.getElementsByName('term_length');
	var termid = 0;
	for( var i=0; i<term.length; i++ ){
		
		if( term[i].checked == true )	termid = term[i].value;
	}

	promoc = document.getElementById('promo');
	var promocode = promoc.value;
	
	
	new Ajax.Updater('subscription_info', '/register/ajaxsubscriptioninfo', {
		method: 'post',
		postBody: 'mtypeid=' + mtypeid + '&termid=' + termid + '&promo=' + promocode
	});
	
	new Effect.Appear('subscription_info');
	//new Effect.Appear('alert_counties', {duration:1, from:0, to:1.0});
	return false;
}

function subscriptionInfoPromotion2(promotype){
	
	//cselect = document.getElementById('acc_state');
	//var stateid = cselect.value;

	promoc = document.getElementById('promo');
	var promocode = promoc.value;
	
	//new Ajax.Updater('subscription_info', '/register/ajaxsubscriptioninfo-promotion.php', {
	new Ajax.Updater('subscription_info', '/register/ajaxsubscriptioninfo', {
		method: 'post',
		postBody: 'promotype=' + promotype + '&promo=' + promocode
	});
	
	new Effect.Appear('subscription_info');
	//new Effect.Appear('alert_counties', {duration:1, from:0, to:1.0});
	return false;
}


function passwdForm(nid){
	
	new Ajax.Updater('passwd_form', 'https://www.nadhlandforsale.com/register/ajaxpasswdform.php', {
		method: 'post',
		postBody: 'nid=' + nid
	});
	
	new Effect.Appear('passwd_form');
	//new Effect.Appear('passwd_form', {duration:1, from:0, to:1.0});
	return false;
}

function passwdLink(nid){
	
	new Ajax.Updater('passwd_form', 'https://www.nadhlandforsale.com/register/ajaxpasswdlink.php', {
		method: 'post',
		postBody: 'nid=' + nid
	});
	
	new Effect.Appear('passwd_form');
	//new Effect.Appear('passwd_form', {duration:1, from:0, to:1.0});
	return false;
}

function passwdChange(){
	
	new Ajax.Updater ('passwd_form', 'https://www.nadhlandforsale.com/register/ajaxpasswdchange.php', {
		method:'post', 
		postBody:'old_passwd='+$F('old_passwd')+'&new_passwd='+$F('new_passwd')+'&confirm_new_passwd='+$F('confirm_new_passwd')+'&nid='+$F('nid')
	});
	new Effect.Appear('passwd_form');
}


function passwdForm2(nid){
	
	new Ajax.Updater('passwd_form', 'https://www.northamericanlandnetwork.com/register/ajaxpasswdform.php', {
		method: 'post',
		postBody: 'nid=' + nid
	});
	
	new Effect.Appear('passwd_form');
	//new Effect.Appear('passwd_form', {duration:1, from:0, to:1.0});
	return false;
}

function passwdLink2(nid){
	
	new Ajax.Updater('passwd_form', 'https://www.northamericanlandnetwork.com/register/ajaxpasswdlink.php', {
		method: 'post',
		postBody: 'nid=' + nid
	});
	
	new Effect.Appear('passwd_form');
	//new Effect.Appear('passwd_form', {duration:1, from:0, to:1.0});
	return false;
}

function passwdChange2(){
	
	new Ajax.Updater ('passwd_form', 'https://www.northamericanlandnetwork.com/register/ajaxpasswdchange.php', {
		method:'post', 
		postBody:'old_passwd='+$F('old_passwd')+'&new_passwd='+$F('new_passwd')+'&confirm_new_passwd='+$F('confirm_new_passwd')+'&nid='+$F('nid')
	});
	new Effect.Appear('passwd_form');
}


function expireInfo(){
	
	if (document.getElementById('expire-info') != null) {
		new Ajax.Updater('expire-info', base_url + '/members/ajaxexpireinfo.php');
		new Ajax.Updater('expire-info', 'https://www.nadhlandforsale.com/members/ajaxexpireinfo.php');
		new Effect.Appear('expire-info', {duration:1, from:0, to:1.0});
	}
}

function del_listing(xTitle,xId) {
	
	var delThis = confirm("Are you sure you want to delete the listing \"" + xTitle + "\"?");
	if (delThis == true) {
		window.location="view-listing.php?cn=" + xId + "&del=1";
	}
}

function onAddListingLoad() {	
		
	var ptinput = document.getElementsByName("property_types[]");
		
	var ischecked = false;
	for( var i=0; i<ptinput.length; i++ ){
			
		var divelem = document.getElementById( ptinput[i].id + "_details" );
			
		if( ptinput[i].checked == true ){	divelem.style.display = ""; ischecked = true; }
		else								divelem.style.display = "none";
			
	}
		
	var divgeneral = document.getElementById("general");
	if( ischecked == false ){
		divgeneral.style.display = "none";
	}
	else{
		divgeneral.style.display = "";
	}
	
	document.getElementById('forsale').focus();
	
	//GetMap();	
}

function stateSelected(){
	
	showCounties();
	showLakes();
	showRivers();
	
	//var sselect = document.getElementById('listing_state');
	//var soption = sselect.options[sselect.selectedIndex];
	TryFindLoc();
	
	return false;
}

function stateSelected2(){
	
	showCounties();
	showLakes();
	showRivers();
	
	return false;
}

function showCounties(){
	
	cselect = document.getElementById('listing_state');
	var stateindex = cselect.selectedIndex;
	
	var ldiv = document.getElementById("listing_county");
	ldiv.innerHTML = '<img src="/images/spinner.gif" alt="loading..." />';
	
	new Ajax.Updater ('listing_county', base_url + '/manage-listings/ajaxshowcounties.php', {
		method:'post', 
		postBody:'state='+stateindex
	});
	new Effect.Appear('listing_county');
}

function showLakes(){
	
	cselect = document.getElementById('listing_state');
	var stateindex = cselect.selectedIndex;
	
	new Ajax.Updater ('listing_lake', base_url + '/manage-listings/ajaxshowlakes.php', {
		method:'post', 
		postBody:'state='+stateindex
	});
	new Effect.Appear('listing_lake');
}

function showRivers(){
	
	cselect = document.getElementById('listing_state');
	var stateindex = cselect.selectedIndex;
	
	new Ajax.Updater ('listing_river', base_url + '/manage-listings/ajaxshowrivers.php', {
		method:'post', 
		postBody:'state='+stateindex
	});
	new Effect.Appear('listing_river');
}

function showBeaches(){
	
	cselect = document.getElementById('listing_state');
	var stateindex = cselect.selectedIndex;
	
	new Ajax.Updater ('listing_beach', base_url + '/manage-listings/ajaxshowbeaches.php', {
		method:'post', 
		postBody:'state='+stateindex
	});
	new Effect.Appear('listing_beach');
}


function switchDisplay(element){
	
	if( element.style.display == "none" )	element.style.display = "";
	else element.style.display = "none";
	
	
	return false;	
}

function isCheckedAny(groupname){
	
	var elemarray = document.getElementsByName( groupname );
	
	var ischecked = false;
	for( var i=0; i<elemarray.length; i++ ){
		
		if( elemarray[i].checked == true )	ischecked = true;
	}
	
	return ischecked;
}

function showPropertyDetails(ptype){
	
	//var divgeneral = document.getElementById("general");
	//if( divgeneral.style.display == "none" )	divgeneral.style.display = "";
	
	var divelement = document.getElementById( ptype + "_details" );
	var chelement = document.getElementById( ptype );
	if( chelement.checked == true )		divelement.style.display = "";
	else								divelement.style.display = "none";
	
	var divgeneral = document.getElementById("general");
	if( isCheckedAny("property_types[]") )	divgeneral.style.display = "";
	else									divgeneral.style.display = "none";
	
	
	if( ptype == 'lake' )	showLakes();
	if( ptype == 'river' )	showRivers();
	if( ptype == 'coastal' )	showBeaches();		
	
	
	return false;
}

function saveSelectedHslide( arrayname, hiddenid ){
			
	var shidden = document.getElementById(hiddenid);
	var sarray = document.getElementsByName(arrayname);
			
	var checked_values = new Array();
	for( var i=0; i<sarray.length; i++ ){
				
		if( sarray[i].checked == true )	checked_values.push(sarray[i].value);
	}
			
	shidden.value = checked_values;
}

function showHideContent(divid, aid, anamehide, anameshow){
		
	var divac = document.getElementById(divid);
	var aac = document.getElementById(aid);
		
	if( divac.style.display == "none" )	{
		divac.style.display = "";
		aac.innerHTML = anamehide;
	}
	else{
		divac.style.display = "none";
		aac.innerHTML = anameshow;
	} 
}

