//AJAX code here
var isNav, isIE;
//Browser checking
if(parseInt(navigator.appVersion)>=4){
	if(navigator.appName=="Netscape") {
		isNav=true;
	}else {
	  	isIE=true;
	}
}
if (isNav) {
		style = "";
}else {
		style = "inline";
}

function displayVenueDetail(){ 
	var counter=0;
	var venues='';
	for(i=0;i<document.form1.elements.length;i++) {
		if(document.form1.elements[i].name=='chkVenue[]' && document.form1.elements[i].checked){
				counter++;	
				venues+=','+document.form1.elements[i].value;
		}
	}
	if(counter>0){ 
		var strSubmit = "vid="+venues+"&flag=displayAllVenue";
		var strURL = "selectVenue.php?auctionID=<?=$_REQUEST['auctionID']?>";
		var strResultFunc = "displayResultVenues";
		xmlhttpPost(strURL, strSubmit, strResultFunc);
	}
}

function displayVenueDetailForAjax(){ 
	var counter=0;
	var venues=document.getElementById("venueIDs").value;
	var auctionID=document.getElementById("auctionID").value;
	
	if(venues!=undefined){ 
		var strSubmit = "task=displayVenues&vid="+venues+"&auctionNum="+auctionID;
		var strURL = "ajax/auction-details-ajax.php";
		var strResultFunc = "displayResultVenues";
		xmlhttpPost(strURL, strSubmit, strResultFunc);
	}
}

function displayEventDetail(val, id,venueId){	
	document.getElementById("show_hide").value=val;
	document.getElementById("dynamicCounter").value=id;
	document.getElementById("jsVenue").value=venueId;
	var auctionID=document.getElementById('auctionID').value;
	var mainshowVar='show'+id;
	var mainHideVar='hide'+id;
	var counter=document.getElementById('totalVenue').value;
	if(val=='show')	{
		for (var i=1; i<=counter; i++)	{
			if(i!=id)	{
				var hideVar='hide'+i;
				var showVar='show'+i;
				document.getElementById(hideVar).style.display = 'none';
				document.getElementById(showVar).style.display =  style;
			}
		}
		document.getElementById(mainshowVar).style.display = 'none';
		document.getElementById(mainHideVar).style.display =  style;
		document.getElementById('show_event').style.display = style;
		var strSubmit = "vid="+venueId;
		var strURL = "selectVenue.php?auctionID="+auctionID;
		//alert(strSubmit);return false;
		var strResultFunc = "displayResultleft";
		//document.getElementById("loader_div_left").innerHTML = '<img src=\'<?php  echo $_SITE_PATH1?>images/indicator_002.gif\'>';
		xmlhttpPost(strURL, strSubmit, strResultFunc);
	}
	if(val=='hide')	{
		document.getElementById(mainshowVar).style.display = style;
		document.getElementById(mainHideVar).style.display = 'none';
		document.getElementById('show_event').style.display = 'none';
	}
}

var result;

function displayResultleft(result){ 
	document.getElementById("venueBoxTR").style.display = 'none';
	document.getElementById("venueBoxTD").style.display = 'none';

	document.getElementById("venueBox").innerHTML = '';
	document.getElementById("venueBox").innerHTML = result;
}
function displayResultVenues(result){
	document.getElementById("venueBoxTR").style.display = '';
	document.getElementById("venueBoxTD").style.display = '';
	document.getElementById("venueBoxTD").innerHTML = '';
	document.getElementById("venueBoxTD").innerHTML = result;
}

/*function imageDisplay(){
	counter=document.getElementById('counter').value;
	if(document.getElementById('type').value==1){
		for(i=1;i<=counter;i++)	{
			document.getElementById('t_'+i).style.display="block";
		}
	}else{
		for(i=1;i<=counter;i++)	{
			document.getElementById('t_'+i).style.display="none";
		}
	}
}*/

function imageSearch(frmobj){
	auctionID=document.getElementById('auctionID').value;
	//if (comb!="Delete"){
	frmobj.action = "auction-details.php?auctionID="+auctionID;
	frmobj.submit();
	//}
}

function show_select_option(id){
	if(id=='stateIDLeft'){
		if(document.getElementById('countyID'))
			document.getElementById('countyID').value='';
		//document.getElementById('show_secure').style.display='inline';
		document.form1.submit();
	}else{
		if(document.getElementById('stateIDLeft'))
			document.getElementById('stateIDLeft').value='';
		document.form1.submit();
	}
}

function excelDownload(path,lastViewed){
	location.href=path;
	document.getElementById('excel').checked=false;
}

function lateAddition(){
	document.getElementById('lateAddition').value='yes';
	document.getElementById('viewUpdatedProperties').value=''; 
	document.form1.submit();
}
function viewUpdatedProperties(){
	document.getElementById('viewUpdatedProperties').value='yes'; 
	document.getElementById('lateAddition').value=''; 
	document.form1.submit();
}

function validateSearchAuctionDetails()
{
		var flag_fill=0;
		var myFields=new Array();
		myFields[0]="stateIDLeft";
		myFields[1]="beds";
		myFields[2]="baths";
		myFields[3]="sqFtMin";
		myFields[4]="propertyAddress";
		myFields[5]="propertyZip";
		myFields[6]="venueCode";
		for (x in myFields)
		{
			if(document.getElementById(myFields[x]).value!='' )
			{
				var flag_fill=1;
				break;
			}
		}
		
		var MasterString="Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
		var flag=false;
		var visitor="";
		
		if(flag_fill==0)
		{
			visitor +=  "\n- Please fill at select one search value"; 
		}
		
	
	if(visitor != "")
	{
		MasterString = MasterString + visitor;
		
		flag=true;
	}
		
	if (flag == true)
	{
		alert(MasterString);
		return false;
	}
		
}

	//join the selected venue values
var CheckedIDs = new Array();
function setVenueIDs(vval,auctionID,tdId,typ,runUpdate){

	var chkID="chkBox_"+tdId;
	var imgID="showHideIMG_"+tdId;
	var shwHidetxtSpanID="showHideTxt_"+tdId;
	var trID="showHideRow_"+tdId;
	var venuetrId="venueBoxTR_"+vval;
	var chckd="";
	if(typ=="chkbox"){
		chckd=$("#"+chkID).attr("checked");
	}else{
		if(typ=="show"){
			chckd="show";
		}else{
			chckd="hide";
		}
	}

		// if checkbox checked or the show/hide link is used to show the venue tr
	if (chckd!=undefined && (chckd==true || chckd=="show")){
		$("#"+chkID).attr("checked",true);
		CheckedIDs.push(vval);
		if(document.getElementById(trID)){
			document.getElementById(trID).style.backgroundColor="#FFFAEA";
		}
		if(imgID!=undefined && imgID!=""){
			$("#"+imgID).attr("src","images/single-orange-down-arrow.gif");
		}
		if(shwHidetxtSpanID!=undefined && shwHidetxtSpanID!=""){
			$("#"+shwHidetxtSpanID).html("");
			var shwHideText="<a href=\"javascript:setVenueIDs('"+vval+"','"+auctionID+"','"+tdId+"','hide','1');\" class='blueTxt2' style='text-decoration:none'><strong>Hide Venue Details</strong></a>";
			$("#"+shwHidetxtSpanID).html(shwHideText);
		}
		document.getElementById(venuetrId).style.display = style;
	}else{
		var idxdd;
		for(var i=0; i<CheckedIDs.length; i++){
			var vv=parseInt(CheckedIDs[i]);
			if(vv==parseInt(vval)){
				idxdd=i;
			}
		}
		CheckedIDs.splice(idxdd,1); 
		if(document.getElementById(trID)){
			document.getElementById(trID).style.backgroundColor="#FFFFFF";
		}

		$("#"+chkID).attr("checked","");
		
		if(imgID!=undefined && imgID!=""){
			$("#"+imgID).attr("src","images/single-orange-arrow.gif");
		}
		if(shwHidetxtSpanID!=undefined && shwHidetxtSpanID!=""){
			$("#"+shwHidetxtSpanID).html("");
			var shwHideText="<a href=\"javascript:setVenueIDs('"+vval+"','"+auctionID+"','"+tdId+"','show','1');\" class='blueTxt2' style='text-decoration:none'><strong>Show Venue Details</strong></a>";
			$("#"+shwHidetxtSpanID).html(shwHideText);
		}
		document.getElementById(venuetrId).style.display = 'none';
	}
	var ids=CheckedIDs.join(",");
	document.getElementById("venueIDs").value=ids;
	
	
	if(ids!=""){
		//update the following select boxes on the basis of the venues selected
		update_selectBoxes("city",ids,auctionID);
		update_selectBoxes("county",ids,auctionID);
		update_selectBoxes("propertyTyp",ids,auctionID);
		update_selectBoxes("yearBuilt",ids,auctionID);
		update_selectBoxes("previouslyValuedTo",ids,auctionID);
		update_selectBoxes("sqFtMin",ids,auctionID);
	}else{
		//update the following select boxes on the basis of the default venues
		var overAllVnus=document.getElementById("overAllVenues").value;
		update_selectBoxes("city",overAllVnus,auctionID);
		update_selectBoxes("county",overAllVnus,auctionID);
		update_selectBoxes("propertyTyp",overAllVnus,auctionID);
		update_selectBoxes("yearBuilt",overAllVnus,auctionID);
		update_selectBoxes("previouslyValuedTo",overAllVnus,auctionID);
		update_selectBoxes("sqFtMin",overAllVnus,auctionID);
	}

	//used to display and hide the venue trs
	//displayVenueDetailForAjax();
	
		//run the funciton if the chkvenue is not passed in url and checkbox or show/hide link is clicked
	if(runUpdate=="1"){
				//reset the values for different fields on the venue check box checked
		$("#propertyCounty").attr("value","");
		$("#stateIDLeft").attr("value","");
		$("#lateAdditions").attr("value","");
		$("#viewUpdatedProperties").attr("value","");
		$("#pageNum").attr("value","");
		$("#pageGroup").attr("value","");
		//update the search result on the basis of venue selected
		update_contents(auctionID);
	}

}

function update_selectBoxes(boxTyp,vid,auctionID){
	var para = "task=updateSelectBoxes&boxTyp="+boxTyp+"&vid="+vid+"&auctionNum="+auctionID;
	$.ajax({
		 type: "POST",
		 url: "ajax/auction-details-ajax.php",
		 async: true,
		 global: true,
		 data: para,
		 success: function(result){
			//	alert(result);
		    var arrResult=result.split("~|~");
			var arrOpts=arrResult[0];
			var divId=arrResult[1];	
			if(parseInt(divId)==1){
				document.getElementById("dvstateIDLeft").innerHTML="";
				document.getElementById("dvstateIDLeft").innerHTML=arrOpts;
			}else if(parseInt(divId)==2){
				document.getElementById("dvpropertyType").innerHTML="";
				document.getElementById("dvpropertyType").innerHTML=arrOpts;
			}else if(parseInt(divId)==3){
				document.getElementById("dvyearBuilt").innerHTML="";
				document.getElementById("dvyearBuilt").innerHTML=arrOpts;
			}else if(parseInt(divId)==4){
				document.getElementById("dvpropertyCounty").innerHTML="";
				document.getElementById("dvpropertyCounty").innerHTML=arrOpts;
			}else if(parseInt(divId)==5){
				document.getElementById("dvpreviouslyValuedTo").innerHTML="";
				document.getElementById("dvpreviouslyValuedTo").innerHTML=arrOpts;
			}else if(parseInt(divId)==6){
				document.getElementById("dvsqFtMin").innerHTML="";
				document.getElementById("dvsqFtMin").innerHTML=arrOpts;
			}
		   return false;
		 }
	});


	//var strSubmit = "task=updateSelectBoxes&boxTyp="+boxTyp+"&vid="+vid+"&auctionNum="+auctionID;
	//var strURL = "ajax/auction-details-ajax.php";
	//var strResultFunc = "displayBoxesValues";
	//xmlhttpPost(strURL, strSubmit, strResultFunc);
}

function displayBoxesValues(result){
	var arrResult=result.split("~|~");
	var arrOpts=arrResult[0];
	var divId=arrResult[1];	
	if(parseInt(divId)==1){
		document.getElementById("dvstateIDLeft").innerHTML="";
		document.getElementById("dvstateIDLeft").innerHTML=arrOpts;
	}else if(parseInt(divId)==2){
		document.getElementById("dvpropertyType").innerHTML="";
		document.getElementById("dvpropertyType").innerHTML=arrOpts;
	}else if(parseInt(divId)==3){
		document.getElementById("dvyearBuilt").innerHTML="";
		document.getElementById("dvyearBuilt").innerHTML=arrOpts;
	}else if(parseInt(divId)==4){
		document.getElementById("dvpropertyCounty").innerHTML="";
		document.getElementById("dvpropertyCounty").innerHTML=arrOpts;
	}
}



	//function used to switch the page view between list and grid view
function setViewType(viewVal,auctionID){
	document.getElementById("viewType").value=viewVal;
	update_contents(auctionID);
	
	//used to display and hide the venue trs
	//displayVenueDetailForAjax();
}

	//function used to reset the records per page var
function setRecordsPerPage(recsPerPage){
	$("#pageNum").attr("value","");
	$("#pageGroup").attr("value","");
	auctionID=document.getElementById('auctionID').value;
	document.getElementById("recsPerPage").value=recsPerPage;
	update_contents(auctionID);
	
	//used to display and hide the venue trs
	//displayVenueDetailForAjax();
}



