function doSubmit(pg){
	document.forms[0].page.value = pg + 1;
	document.forms[0].action = 'quick_results.php';
	document.forms[0].submit();
}
function clearValue(box){
	$(box).value = '';
	$('but').style.display = "block";
}
function searchMlsNumber(box){
	//alert($('box').value);
	window.open('http://www.searchmyrtlebeachcondos.com/property/condo/'+$(box).value+".htm");
}
function toggleOp (obj) {

	if (obj.getStyle('opacity') == '0') {
		myFader = new Fx.Style(obj, 'opacity', {duration: 1000}).start(0,1);
	} else {
		myFader = new Fx.Style(obj, 'opacity', {duration: 1000}).start(1,0);
	}
}
function hide_form(){
document.forms[0].style.display = "none";

}
function show_form(){
	document.forms[0].style.display = "block";
}
function show_elements(){
	$('theForm').reset();
}
function checkinput(){

	//if($('available').value == 'Choose City'){
	//	alert("Please Select a City");
	 //	return false;
	 //	}
	if($('available').value == 'Choose City' && $('mprice').value == '0')	{
		alert('You must make a choice')
	}


}
function update_div(curdiv,textdiv){
	if($(curdiv).id == 'mprice'){
		if($('mprice').value >= $('xpricer').value){
		alert('The minimum price \n must be less than\nthe maximum price of '+$('xpricer').value)
		for(var index=0; index<$('mprice').length; index++) {
				$('mprice').options[index].selected = false;
		}
		return;
		}
	}
	if($(curdiv).id == 'xpricer'){
		if($('xpricer').value <= $('mprice').value){
		alert('The maximum price \n must be more than\nthe minimum price of '+$('mprice').value);
		for(var index=0; index<$('xpricer').length; index++) {
				$('xpricer').options[index].selected = false;
		}
		return;
		}
	}
	if(textdiv != 'special'){
	$(textdiv+'_txt').innerHTML =$(curdiv).options[$(curdiv).selectedIndex].text;
	}else{
		$(textdiv+'_txt').innerHTML = '';
		for(var index=0; index<$(curdiv).length; index++) {
			if($(curdiv).options[index].selected){
				if($(curdiv).options[index].text == 'None' && $(curdiv).length > 1){

				}else{
				$(textdiv+'_txt').innerHTML += $(curdiv).options[index].text+', '
				}
			}
		}

	}

	checkZip();
	if(textdiv != 'special'){
	expand(textdiv,'default');
	}
	$(curdiv).blur();
}
function changeTorf(obj){
	$('torf').innerHTML = obj;
}
function expand(curobj,hide){
if(curobj == 'bathrooms'){
	var div = $('bathholder');
	if(div.style.display == 'none'){
		div.style.display = 'block';
	}else{
		div.style.display = 'none';
	}

}

	if($(curobj+'_state').innerHTML == 'open'){
		$(curobj+'_state').innerHTML = 'close';

	}else{
		$(curobj+'_state').innerHTML = 'open';
	}

	var div = $(curobj);
	if(div.style.display == 'none'){
		div.style.display = 'block';
	}else{
		div.style.display = 'none';
	}

}

function expandmea(curobj, hide) {

	document.getElementById('placespot').innerHTML = curobj;
	var list = new Array(3);
	var lista = new Array(3);
	list[0] = 'city';
	list[1] = 'area';
	list[2]	= 'complex';
	lista[0] = 'search';
	lista[1] = 'sa';
	lista[2] = 'saaa';
	var x =0;
	for(x =0;x<3;x++){
		if(list[x] == $(curobj).id)var a = x;
		$(list[x]).style.display = 'none';
	}
	var folder = $(curobj);
	folder.style.display = 'block';
	stuff = $(lista[a]);
	var i;
	var arrgbox = new Array();
	for (i = 0; i < stuff.options.length; i++) {

			 arrgbox[i] = stuff.options[i].text;
	}
	$('placetype').innerHTML = arrgbox.join(', ');
	checkZip();
}
function expandme(curobj, hide) {

	if($('sres1').innerHTML == 'open'){
		$('sres1').innerHTML = 'close';
	}else{
		$('sres1').innerHTML = 'open';
	}
	var list = new Array(3);
	list[0] = 'city';
	list[1] = 'area';
	list[2]	= 'complex';
	var x = 0;
	var i;
	var theone ='';
	var thetype = new Array;
	thetype = document.getElementsByName('selectby');
	for(i = 0; i < thetype.length; i++) {
		if(thetype[i].checked == true)
		{
			theone = thetype[i].value;
		}
	}
	if(theone == ''){
	theone = 'city';
	thetype[0].checked = true;
	}
	var box = $(curobj);
	if(box.style.display == 'none'){
		box.style.display = 'block';
		expandmea(theone);
	}else{
		box.style.display = 'none';
		for(i = 0; i < list.length; i++) {
			 $(list[i]).style.display = 'none';
		}
	}
}





function showMe(oProject) {
	document.location.href =
	'http://www.searchmyrtlebeachcondos.com/list_properties/condo/0-0/project/' + oProject + '/page1.htm';
}

function startList() {
	if(!document.body.currentStyle) return;
	var subs = document.getElementsByName('submenu');
	if(subs){
	for(var i=0; i<subs.length; i++) {
		var li = subs[i].parentNode;
		if(li) {
			li.onmouseover = function() {
				this.style.background ='#feedee';
				this.lastChild.style.visibility = 'visible';

			}
			li.onmouseout = function() {
				this.style.background ='#95f4ee';
				this.lastChild.style.visibility = 'hidden';
			}
		}
	}
	}
	var subsa = document.getElementsByName('submenua');
	if(subsa)	{
	for(var i=0; i<subsa.length; i++) {
		var li = subsa[i].parentNode;
		if(li) {
			li.onmouseover = function() {
				this.style.background ='#feedee';
				this.lastChild.style.visibility = 'visible';

			}
			li.onmouseout = function() {
				this.style.background ='#ffffff';
				this.lastChild.style.visibility = 'hidden';
			}
		}
	}
	}
}

function moveit(fbox, tbox) { //this is the script to move from available to select

	var doout = '';
	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;
	for (i = 0; i < tbox.options.length; i++) {
		if(tbox.options[i].text == 'All' && $(tbox).id == 'search' )
		{
			alert('Please remove All\n from the Search Box\n before adding a new city')
			return;
		}
		arrLookup[tbox.options[i].text] = tbox.options[i].value;
		arrTbox[i] = tbox.options[i].text;
	}
	var fLength = 0;
	var tLength = arrTbox.length;
	for(i = 0; i < fbox.options.length; i++) {
		arrLookup[fbox.options[i].text] = fbox.options[i].value;
		if (fbox.options[i].selected && fbox.options[i].value != '') {
			if(fbox.options[i].text == 'All' && $(fbox).id != 'search'){
				if(tbox.length > 0){
					for(x = 0 ; x < tbox.length ; x++){
						arrFbox[fLength] = tbox.options[x].text;
						fLength++;
					}
				}
				arrTbox[0] = fbox.options[i].text;
				arrTbox.length = 1;
		}else{
			arrTbox[tLength] = fbox.options[i].text;
			tLength++;
		}
	}
	else {
	arrFbox[fLength] = fbox.options[i].text;
	fLength++;
	}
	}
	arrFbox.sort();
	arrTbox.sort();
	fbox.length = 0;
	tbox.length = 0;
	var c;

	for(c = 0; c < arrFbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrFbox[c]];
		no.text = arrFbox[c];

		fbox[c] = no;

		if(tbox.name == 'available'){
			doout = doout + ',' + arrFbox[c];
		}
		if(fbox.name == 'avaliable'){
			alert('gege');
			no.selected = true;
			alert( no.text);
		}

		if(tbox.name == 'aa'){
			doout = doout + ',' + arrFbox[c];
		}
		if(tbox.name == 'aaaa'){
			doout = doout + ',' + arrFbox[c];
		}
	}
	for(c = 0; c < arrTbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrTbox[c]];
		no.text = arrTbox[c];
		if(tbox.name == 'search'){
			doout = doout + ',' + arrTbox[c];
			no.selected = true;
		}
		if(tbox.name == 'sa'){
			doout = doout + ',' + arrTbox[c];
			no.selected = true;
		}
		if(tbox.name == 'saaa'){
			doout = doout + ',' + arrTbox[c];
			no.selected = true;
		}
		tbox[c] = no;
	}
	  checkZip();
	document.getElementById('placetype').innerHTML = doout.replace(/^\,/,'');

}

 function checkZip() {
	$('results').style.color = '#ff0000';
	$('results').innerHTML = 'UPDATING';
	var thetype = new Array();
	var qhold   = new Array();
	var arrLookup = new Array();
	var thename = '';
	thetype = document.getElementsByName('selectby');

	var i;
	var theone ='';
	for(i = 0; i < thetype.length; i++) {
		if(thetype[i].checked == true)
		{
			theone = thetype[i].value;
		}
	}
	if(theone == '')theone = 'city';
	switch (theone) {
			case 'city':
			thename = 'search';
			theone = 'City';
			break;

			case 'hiddenareaid':
			thename = 'sa';
			theone = 'HiddenAreaID';
			break;

			case 'project_section_code':
			thename = 'saaa';
			theone = 'Project_Section_Code'

	}



	mlist = document.getElementById(thename);

	for (i = 0; i < mlist.options.length; i++)
		{
		if(theone == 'Project_Section_Code'){
		 arrLookup[i] = theone + ' like \''+ mlist.options[i].value+'\' ';
		}else{
		if(mlist.options[i].value == 'All'){
			i = mlist.options.length;
		}else{
		arrLookup[i] = theone + ' = \''+ mlist.options[i].value+'\' ';
		}
		}
}
	qhold[0] = 'Status_Description = \'ACTIVE\' '
	if(arrLookup.length > 0){
	qhold[1] = '('+arrLookup.join(' or ')+')';
	}else{
		qhold[1] = '';
	}
	if($('cort').value != 'all'){
	qhold[2] = 'Type = \'' + $('cort').value.toUpperCase()+'\'';
	}

	if($('mprice').value == 'No Min'){
		qhold[3] = 'Asking_Price > 0';
	}else{
		var holder = $('mprice').value.replace(/\,/g,'')
		holder = holder.replace(/\\$/,'');
		holder = holder.replace(/\s/,'');
		qhold[3] = 'Asking_Price > '+holder;
	}

	if($('xpricer').value == 'No Max'){
		qhold[4] = 'Asking_Price < 999999999';
	}else{
		var holderx = $('xpricer').value.replace(/\,/g,'')
		holderx = holderx.replace(/\\$/,'');
		holderx = holderx.replace(/\s/,'');
		qhold[4] = 'Asking_Price < '+holderx;
	}
	switch($('bedr').value){
			case 'Efficiency' :
				qhold[5] = 'Bedrooms = \'Efficiency\' ';
			break;
			case '1' :
				qhold[5] = '(Bedrooms = 1 or Bedrooms = 2 or Bedrooms = 3 or Bedrooms = 4 or Bedrooms = 5 or Bedrooms = 6 or bedrooms = \'7+\') ';
			break;
			case '2' :
				qhold[5] = '(Bedrooms = 2 or Bedrooms = 3 or Bedrooms = 4 or Bedrooms = 5 or Bedrooms = 6 or Bedrooms = \'7+\') ';
			break;
			case '3' :
				qhold[5] = '(Bedrooms = 3 or Bedrooms = 4 or Bedrooms = 5 or Bedrooms = 6 or Bedrooms = \'7+\') ';
			break;
			case '4' :
				qhold[5] = '( Bedrooms = 4 or Bedrooms = 5 or Bedrooms = 6 or Bedrooms = \'7+\') ';
			break;
			case '5' :
				qhold[5] = '( Bedrooms = 5 or Bedrooms = 6 or Bedrooms = \'7+\') ';
			break;
			case '6' :
				qhold[5] = '(  Bedrooms = 6 or Bedrooms = \'7+\') ';
			break;

	}
	if($('torf').innerHTML == 'Total'){
		qhold[6] = ' Full_Baths + Half_Baths >= '+$('bathr').value;
	}else{
		qhold[6] = ' Full_Baths  >= '+$('bathr').value;
	}
	if($('styler').value != 'Any'){
		qhold[7] = 'Style = \''+$('styler').value+'\'';
	}
	if($('ager').value != 'Any'){
		qhold[8] = ' Stuff like \'%'+$('ager').value+'%\' ';
	}
	if($('locationr').value != 'any'){
		qhold[9]  = ' Stuff like \'%'+$('locationr').value+'%\' ';
	}
	if($('specialr').value != 'none'){
		holdme = new Array();
		var hLength = 0;
		for(var index=0; index<$('specialr').length; index++) {
			if($('specialr').options[index].selected){
				holdme[hLength] = 'stuff like \'%'+ $('specialr').options[index].value + '%\' ';
				hLength++;
				}
			}
			qhold[10]	= '('+ holdme.join(' and ') + ')';
		}

var ii = 0;
var qcom = new Array();
qhold.each( function(addto){
if(addto != '' && addto != undefined){
qcom[ii]= addto;
ii++;
			}
		}
		);

query = 'where '+ qcom.join(' and ');
var url = 'ajaxlocal.php?'+query;
var params = '';
var ajax = new Ajax.Updater(
{success: 'results'},
url,
{method: 'get', parameters: params,onSuccess:flashtext, onFailure: reportError});

}
hex = 255;
function fadetext(){

if(hex>0) { //If color is not black yet
hex-=4; // increase color darkness
document.getElementById('results').style.color='rgb('+hex+',0,0)';
setTimeout('fadetext()',30);
}
else
hex=255 //reset hex value

}
var cnt = 0;
function flashtext(){
	if(cnt < 2) {

		setTimeout('flashtext()',400);
		cnt ++;
		if($('results').style.color == '#ff0000'){
			$('results').style.color='#000000';
			$('sresults').style.color = '#000000';
		}else{
			$('results').style.color='#ff0000';
			$('sresults').style.color = '#ff0000';
			$('results').style.fontSize='28px';
			$('sresults').style.fontSize = '28px';
		}

	}else{
		$('results').style.color='#000000';
		$('sresults').style.color = '#000000';
		$('results').style.fontSize='20px';
		$('sresults').style.fontSize = '20px';
		cnt = 0;
}
}
function setfield(){

alert('set');
}

function reportError(request) {
$('results').innerHTML = 'Error';
}
