var thewin;

function changePage(selectObj) {
	if( selectObj.value != '' ){
		thePageForm = selectObj.parentNode;
		thePageForm.submit();
	}
}
function show_hide(id, show){
	el = document.getElementById(id);
	if (null==show) show = el.style.display=='none';
	el.style.display = (show ? '' : 'none');
}
function able_disable(id){
	el = document.getElementById(id);
	if(el.disabled==true)el.disabled=false;
	else el.disabled=true;
}
function openWindow(url){
	var theUrl = url;
	thewin = window.open(theUrl,'arbitrary',"menubar=no,location=no,resizable=no,scrollbars=yes,status=no,dependent=yes,width=415,height=350,alwaysRaised=yes");
}
function popWindow(url,w,h){
	var theUrl = url;
	thewin = window.open(theUrl,'arbitrary',"menubar=no,location=no,resizable=no,scrollbars=yes,status=no,dependent=yes,width="+w+",height="+h+",alwaysRaised=yes");
}
function returnDay(inputBox,wantedValue){
	if(window.opener && !window.opener.closed)
	inbox = window.opener.document.getElementById(inputBox).value=wantedValue;
	window.close();
}
function showBig(input){
	source = input.src;
	label = input.alt;
	document.bigImage.src=source;
	bigLabel = document.getElementById("bigLabel");
	bigLabel.innerHTML = label; 
}
function popThis(input,loc_dog){
	var xWind;
	imageName = input.src
	imageName = imageName.substr(imageName.lastIndexOf("/")+1);
	urlUse = "showImage.php?image=" + imageName + "&location_id=" + loc_dog;
	xWind = window.open(urlUse, "modWindowName","menubar=no,location=no,resizable=no,scrollbars=no,status=no, dependent=yes, width=" + (input.width+10)+ ", height=" + (input.height+200) + ", alwaysRaised=yes");
	xWind.reload;
}
function swap(){
	show_hide('old');
	show_hide('new'); 
	show_hide('pricenow');
	show_hide('pricenext');
}
function putdate(inval){
	var start_input = window.document.forms[0].elements[0];
	var end_input = window.document.forms[0].elements[1];
	//	arrival = x.getElementById("new_start_date");
	wholedatestring = inval.substring(2);
	tmon = wholedatestring.substring(0,2);
	tdate = wholedatestring.substring(3,5)
	tyear = wholedatestring.substring(6,12);
	
	adselect = inval.substring(0,1);
	if(adselect=="A"){
		start_input.value = wholedatestring;
	}
	else if(adselect=="D"){
		end_input.value = wholedatestring;
	}
	
	
//	alert(inval.substring(0,1));
	ajaxManager('load_page','availability.php?dval='+tmon+''+tdate+''+tyear+'&ret=$ret','calendarWrap')

}
function buildQuery(){
//	slp = document.getElementById("sleeps").value;
//	pool = document.getElementById("pool").value;
	var bed='';
	ded = window.document.getElementsByName("beds");
	for(var i=0;i<ded.length;i++)if(ded[i].checked){bed=ded[i].value;break;}
	city = window.document.getElementById("city").value;
	arrival = window.document.getElementById("arrival_d").value;
	arrival = decodeURI(arrival);
	departure = window.document.getElementById("departure_d").value;
	departure = encodeURI(departure);
	searchstring = 'gallery-retrieve.php?beds='+bed+'&city='+city+'&arrival_d='+arrival+'&departure_d='+departure;
	ajaxManager('load_page',searchstring,'galleryResults');
}
function buildQuery2() {
  //slp = document.getElementById("sleeps").value;
  //pool = document.getElementById("pool").value;
	var bed='';
	var city='';
	var arrival='';
	var departure='';
	var searchstring = '';
	var pid='';
	var amenstring;
	ded = window.document.getElementsByTagName("input");
	for(var i=0;i<ded.length;i++){
		if(ded[i].checked){
			var nm = ded[i].name;
			var nm = nm.replace('amenity[','');
			var nm = nm.replace(']','');
			amenstring += "amenity[]="+nm+"&";
			amenstring = amenstring.replace("undefined","");
		}
	}
	bed = window.document.getElementById("beds")[window.document.getElementById("beds").selectedIndex].value;
	//pid = window.document.getElementById("pid_field")[window.document.getElementById("pid_field").selectedIndex].value;
	//var golfpkg = window.document.getElementById('golfp').value;
	var prop_box = window.document.getElementById('pid_update').value;
	if(prop_box.length==0)pid = "";
	else pid = window.document.getElementById("myHidden").value;
	city = window.document.getElementById("city2")[window.document.getElementById("city2").selectedIndex].value;
	arrival = window.document.getElementById("dateB").value;
	arrival = decodeURI(arrival);
	departure = window.document.getElementById("dateE").value;
	departure = encodeURI(departure);
//	var searchcriteria = 'beds='+bed+'&city='+city+'&arrival_d='+arrival+'&departure_d='+departure+'&searchpid='+pid;
	var searchstring = 'gallery-retrieve.php?beds='+bed+'&city='+city+'&arrival_d='+arrival+'&departure_d='+departure+'&searchpid='+pid+'&'+amenstring;
	ajaxManager('load_page',searchstring,'galleryResults','on');
}
function ability(div_name){
	var dhandle = document.getElementById(div_name);
	namz = dhandle.getElementsByTagName('*');
	for(var i=0;i<namz.length;i++){
		var elem = namz[i];
		if(elem.nodeName.toLowerCase() == 'select' || 'input'){
			if(elem.disabled)elem.disabled=false;
			else elem.disabled=true;
		}
	}
}
function reset_discounts(div_name){
	var x= confirm("Are you sure you wish to reset to current discount percentages?");
	if(!x)return 0;
	else{
		alert("If you would like to restore the default discount percentages please insure that you click the submit button below.");
		var dhandle = document.getElementById(div_name);
		alert(dhandle);
		namz = dhandle.getElementsByTagName('*');
		for(var i=0;i<namz.length;i++){
			var elem = namz[i];
			if(elem.nodeName.toLowerCase() == 'select'){
				elem.value = 0;
	//			if(elem.disabled)elem.disabled=false;
	//			else elem.disabled=true;
			}
		}
		document.forms[0].submit();
	}
}
function select_all(div_name,on_off){
		var dhandle = window.document.getElementById(div_name);
		namz = dhandle.getElementsByTagName('*');
		for(var i=0;i<namz.length;i++){
			var elem = namz[i];
			if(elem.disabled==true)continue;
			if(on_off=="on")elem.checked=true;
			if(on_off=="off")elem.checked=false;
		}
}
function check_update(div_name){
	var dhandle = window.document.getElementById(div_name);
	namz = dhandle.getElementsByTagName('*');
	for(var i=0;i<namz.length;i++){
		var elem = namz[i];
		if(elem.disabled==true)continue;
		else{
			if(elem.getAttribute("name")){
				if(elem.getAttribute("name")){
					var fname = elem.getAttribute("name");
					if(fname.indexOf("check_number")>=0){
						//elem.innerHTML = fname;
						var fpid = fname.substring(fname.indexOf("[")+1,fname.indexOf("]"));
						var usable_id = "check_number" + fpid;
						var use_rec = "reconciled"+fpid;
						if(document.getElementById(use_rec).checked==true)
							document.getElementById(usable_id).value = document.getElementById("mass_checks").value;
					}
				}
			}
		}
	}
	
}

function workingOverlay(toggle){
	var cover_div = document.getElementById("cover_overlay");
	if(cover_div){
		if(toggle=="on"){
			cover_div.style.display="inline";
		}else{
			cover_div.style.display="none";
		}		
	}
}

function swap_delivery(d_or_s){
	var series_handle = document.getElementById("series");
	var delivery_handle = document.getElementById("delivery_days");
	var deliver_when = document.getElementById("emailwhen");

	if(d_or_s=="series"){
		series_handle.disabled=false;
		delivery_handle.disabled=true;
		deliver_when.disabled=true;
//		alert(deliver_when[1]);
	}
	if(d_or_s=="delivery"){
		series_handle.disabled=true;
		delivery_handle.disabled=false;
		deliver_when.disabled=false;
	}
}
function buildCommissions(rep,mndate,new_percent,sales_rep,date1,date2,basis,PID,chk_num,reconciled,notes){
	ajaxManager('load_page','sales_ajax.php?user='+rep+'&month='+mndate+'&percent='+new_percent+'&rep='+sales_rep+'&date1='+date1+'&date2='+date2+'&basis='+basis+'&PID='+PID+'&check_num='+chk_num+'&reconcile='+reconciled+'&notes='+notes,'sales_report_area');
}
function buildReconcile(chk_num,PID,sales_rep,date1,date2,basis){
	ajaxManager('load_page','sales_ajax.php?PID='+PID+'&check_num='+chk_num+'&rep='+sales_rep+'&date1='+date1+'&date2='+date2+'&basis='+basis,'sales_report_area');
}
function contact_chooser(itm,form_id){
	var theform = document.getElementById(form_id);
	theform.action = itm.value;
	theform.submit();
	
}
function show_cbox(){
	document.getElementById('cc_hold').style.display='block';
	document.getElementById('e-check').style.display='none';
	document.getElementById('pp_button').style.display='none';
}
function show_pp(){
document.getElementById('pp_button').style.display='block';
	document.getElementById('e-check').style.display='none';
	document.getElementById('cc_hold').style.display='none';
}
function show_echek(){
	document.getElementById('e-check').style.display='block';
	document.getElementById('cc_hold').style.display='none';
	document.getElementById('pp_button').style.display='none';
	
}
