/*
	*	
	* OxyClassifieds.com : PHP Classifieds (Nulled by Yola - hood.hustlin@gmail.com)
	* version 6.0
	*  
	*
*/

$(document).ready(function ()
{
	tooltip();
});

function tooltip()
{
	//var old_title;

	$("img.tooltip").mouseover
	(		
		function (event) 
		{ 
			var text = this.name;
			$(this).removeAttr("title"); // trick to disable default show title
			old_title=text;

			x = event.pageX+5;
			y = event.pageY+5;
								
			$("body").append("<div id='tooltip'>"+text+"</div>");
			$("#tooltip").css("left", x).css("top", y);
		}
	);
	$("span.tooltip").mouseover
	(		
		function (event) 
		{ 
			var text = this.id;
			//$(this).removeAttr("title"); // trick to disable default show title
			//old_title=text;
			
			x = event.pageX+5;
			y = event.pageY+5;
								
			$("body").append("<div id='tooltip'>"+text+"</div>");
			$("#tooltip").css("left", x).css("top", y);
		}
	);

	$("input.tooltip").mouseover
	(		
		function (event) 
		{ 
			var text = this.title;
			$(this).removeAttr("title"); // trick to disable default show title
			old_title=text;
			x = event.pageX+5;
			y = event.pageY+5;

			$("body").append("<div id='tooltip'>"+text+"</div>");
			$("#tooltip").css("left", x).css("top", y);
		}
	);
		
	$("img.tooltip").mouseout(
		function (event)
		{
			$("#tooltip").remove();
			//$(this).attr("title", old_title); // enable back title
		}
	);

	$("span.tooltip").mouseout(
		function (event)
		{
			$("#tooltip").remove();
			//$(this).attr("title", old_title); // enable back title
		}
	);

	$("input.tooltip").mouseout(
		function (event)
		{
			$("#tooltip").remove();
			$(this).attr("title", old_title); // enable back title
		}
	);

}


function n_window(theurl,w,h)
{
 // set the width and height
 var the_width=w;
 var the_height=h;
 // set window position
 var from_top=200;
 var from_left=200;
 // set other attributes
 var has_toolbar='no';
 var has_location='no';
 var has_directories='no';
 var has_status='no';
 var has_menubar='no';
 var has_scrollbars='yes';
 var is_resizable='yes';
 // attributes put together
 var the_atts='width='+the_width+'show,height='+the_height+',top='+from_top+',screenY='+from_top+',left='+from_left+',screenX='+from_left;
 the_atts+=',toolbar='+has_toolbar+',location='+has_location+',directories='+has_directories+',status='+has_status;
 the_atts+=',menubar='+has_menubar+',scrollbars='+has_scrollbars+',resizable='+is_resizable;
 // open window
 window.open(theurl,'',the_atts);
}

function myConfirm(msg)
{
    if(!confirm(msg)) return false;
    return true;
}

function doSel(obj)
{
     for (i = 0; i < obj.length; i++)
        if (obj[i].selected == true)
           eval(obj[i].value);
}

function changeLoc(obj, base, field, param) {

     for (i = 0; i < obj.length; i++)
        if (obj[i].selected == true)
		location.href=base+"?"+param+"&"+field+"="+obj[i].value;

}



function getxmlhttp() {

var xmlhttp=false;
try {
	// if Javascript version>5
	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	//if not use the older ActiveX object
	try {
	//if using IE
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	xmlhttp=false;
	}
}
// if not using IE, create a javascript instance of the object
if(!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp=new XMLHttpRequest();
}

return xmlhttp;

}

function CountTitleLeft(field, max) {
	if (field.value.length > max)
		field.value = field.value.substring(0, max);
}
function splitMapsCoord(str) {
	if(!str) return 0;
	var split_str=str.split(",");
	var no = split_str.length;
	if(no!=3) return 0;
	return split_str;
}


function PreloadImages(str){
	
	a = str.split(",");
	var d=document; if(d.images){
	    if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length;
	
	    for(i=0; i<a.length; i++) {
		if (a[i].indexOf("#")!=0){ 
		    d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
		}
	    }
	}
}

function SwapImagesThick(str){

document.getElementById('bigImg').innerHTML=str;
document.getElementById('galleryVideo').style.display="none";
document.getElementById('bigImg').style.display="block";
tb_init('a.thickbox, area.thickbox, input.thickbox');

}

function SwapToVideo(){

document.getElementById('bigImg').style.display="none";
document.getElementById('galleryVideo').style.display="block";

}

function CountTextLeft(myForm, field, count) {

	if (typeof myForm.no_words == 'undefined') return;

	var text=field.value + " ";
	var no_words=myForm.no_words.value;
	if(no_words>0)
	{
		var cleanedStr = text.replace('\n', "");
		cleanedStr = cleanedStr.replace('\r', "");
		cleanedStr = cleanedStr.replace(/\s+/g," ");
		var splitString = cleanedStr.split(" ");
		var word_count = splitString.length -1;
		words_left=no_words-word_count;
		count.value=words_left;
	}
}

//uncomment while commenting the other "CountTextLeft" function for latin + chinese characters

/*
function CountTextLeft(myForm, field, count) {

	if (typeof myForm.no_words == 'undefined') return;

	var text=field.value + " ";
	var no_words=myForm.no_words.value;
	if(no_words>0)
	{

		var counter,i,cutPos;
		counter=0;
		for(i=0;i<text.length;i++){
			while(text.charAt(i)==' '|| text.charAt(i)=='\n'|| text.charAt(i)==','|| text.charAt(i)=='.') i++;
			if((text.charAt(i+1)==' '||text.charAt(i+1)=='\n' || text.charAt(i+1)==','|| text.charAt(i+1)=='.' || text.charCodeAt(i+1)>255 || i==text.length-1) && text.charCodeAt(i)<=255) counter++;
			if(text.charCodeAt(i)>255){//skip if was space before!!!!
				if(i>0 && text.charAt(i-1)!=' '||text.charAt(i-1)!='\n' || text.charAt(i-1)!=','|| text.charAt(i-1)!='.')
				counter++;
			}
			if(counter==no_words) cutPos= i;
		}

		words_left=no_words-counter;
		
		if(words_left<0) {
			text = text.substring(0,cutPos);
			field.value = text;
			words_left=0;
		}
		count.value=words_left;
	}
}
*/
function strchlen(str){
	var counter,i;
	counter=0;
	for(i=0;i<str.length;i++){
		if(str.charCodeAt(i)>255){
			counter++;
		}
	}
	return counter;
}

function strenlen(str){
	var counter,i;
	counter=0;
	for(i=0;i<str.length;i++){
	while(str.charAt(i)==' '||str.charCodeAt(i)>255||str.charAt(i)=='\n') i++;
	if(str.charAt(i+1)==' '||str.charAt(i+1)=='\n'||str.charCodeAt(i+1)>255||i==str.length-1) counter++;
	}
	return counter;
}
/*
function submitForm(myForm)
{
	var dv;

	var ns4=document.layers
	var ns6=document.getElementById&&!document.all
	var ie4=document.all

	if (ns4) dv=document.loading;
	else if (ns6) dv=document.getElementById("loading").style;
	else if (ie4) dv=document.all.loading.style;

	if(stripHTML==1)
	{
		var re= /<\S[^><]*>/g;
		myForm.title.value=myForm.title.value.replace(re, "");
		myForm.description.value=myForm.description.value.replace(re, "");
	}
	if(ns4) dv.visibility="block";
	else if (ns6||ie4) dv.display="block";
myForm.submit();
}
*/


function clickBanner(id, url, live_site) {

	url_str=live_site+"/include/get_info.php?type=banner&id="+id;
	$.ajax({
		url: url_str,
		success: function(data) {
			window.location.href = url;
		}
	});
}

function onDelete(id,str,obj_type)
{

	if (myConfirm(str)==false) return;
	var url_str="include/actions.php?action=delete&object="+obj_type+"&id="+id;

	xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.onreadystatechange = function () {

		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			location.reload(true);
		}
	}
	xmlhttp.send(null);
}

function onSold(id, obj_type) {

	var url_str="include/actions.php?action=sold&object="+obj_type+"&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.onreadystatechange = function () {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			location.reload(true);
		}
	}
	xmlhttp.send(null);
}

function onUnsold(id, obj_type) {

	var url_str="include/actions.php?action=unsold&object="+obj_type+"&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.onreadystatechange = function () {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			location.reload(true);
		}
	}
	xmlhttp.send(null);
}

function onRented(id, obj_type) {

	var url_str="include/actions.php?action=rented&object="+obj_type+"&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.onreadystatechange = function () {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			location.reload(true);
		}
	}
	xmlhttp.send(null);
}

function onUnrented(id, obj_type) {

	var url_str="include/actions.php?action=unrented&object="+obj_type+"&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.onreadystatechange = function () {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			location.reload(true);
		}
	}
	xmlhttp.send(null);
}

function add_to_fav(id, confirm_str, done_str, site_url) {
	if(confirm_str!="" && myConfirm(confirm_str)==false) return;
	var url_str = site_url+"/include/actions.php?action=favourite&object=listing&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.onreadystatechange = function () {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			alert(done_str);
			location.reload(true);
		}
	}
	xmlhttp.send(null);
}

function checkOther(elem, val) {

	var selected_index = elem.selectedIndex;
	var selected_val = elem.options[selected_index].value;

	if(selected_val=="-1") 
		document.getElementById("span_"+val+"_other_val").style.display="block";
	else 
		document.getElementById("span_"+val+"_other_val").style.display="none";

}

function selDepending(field_no, caption1, caption2, dep_id, categ_id, other_val, other_str, live_site) {

var selected_index = document.getElementById(caption1).selectedIndex;
var sel_value = document.getElementById(caption1).options[selected_index].value;

if(other_val){
if(sel_value=="-1") {
	document.getElementById("span_"+caption1+"_other_val").style.display="block";
	document.getElementById("span_"+caption2+"_other_val").style.display="block";
	document.getElementById(caption2).disabled = false;
	document.getElementById(caption2).options.length = 1;
	document.getElementById(caption2).options[1] = new  Option(other_str, "-1");
	document.getElementById(caption2).selectedIndex=1;
	//return;
} else {
	document.getElementById("span_"+caption1+"_other_val").style.display="none";
	document.getElementById("span_"+caption2+"_other_val").style.display="none";
}
}

sel_value = encodeURIComponent(sel_value);

document.getElementById(caption2).disabled = false;
url_str=live_site+"/include/get_info.php?type=depending&field="+dep_id+"&dep="+sel_value+"&field_no="+field_no+"&cat="+categ_id;

var xmlhttp=getxmlhttp();
xmlhttp.open("GET",url_str);

xmlhttp.onreadystatechange = function () {

	if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {

		var dep_str=xmlhttp.responseText;//response=top_str:next_caption1:next_caption2:next_top_str1:next_top_str2:id[0],name[0]:id[1],name[1] .....
//alert(dep_str);
 		var split_dep=dep_str.split(":");
		var no = split_dep.length;
		document.getElementById(caption2).options.length = 0;
		var depIndex = 0;
		document.getElementById(caption2).options[depIndex] = new  Option(split_dep[0], "");
		depIndex++;

		if(other_val) {
			document.getElementById(caption2).options[depIndex] = new  Option(other_str, "-1");
			if(sel_value==-1) document.getElementById(caption2).selectedIndex=1;
			depIndex++;
		}

		for (var j=5;j<no;j++) {
			split_d=split_dep[j].split(',');
			var dep_id=split_d[0];
			var dep_name=split_d[1];
			document.getElementById(caption2).options[depIndex] = new  Option(dep_name, dep_name);
			depIndex++;
		}

		var next_caption1 = split_dep[1];
		var next_caption2 = split_dep[2];

		var next_top_str1 = split_dep[3];
		var next_top_str2 = split_dep[4];

		if( next_caption1 && document.getElementById(next_caption1)!=null ) { 

			document.getElementById(next_caption1).options.length = 0;
			document.getElementById(next_caption1).options[0] = new  Option(next_top_str1, "");
			document.getElementById(next_caption1).disabled = true;

			if(other_val){
			// if other value selected
			if(sel_value=="-1") {
				document.getElementById("span_"+next_caption1+"_other_val").style.display="block";
				document.getElementById(next_caption1).disabled = false;
				document.getElementById(next_caption1).options.length = 1;
				document.getElementById(next_caption1).options[1] = new  Option(other_str, "-1");
				document.getElementById(next_caption1).selectedIndex=1;
			} else {
				document.getElementById("span_"+next_caption1+"_other_val").style.display="none";
			}
			}//end if other_val

		}
		if(next_caption2) { 

			document.getElementById(next_caption2).options.length = 0;
			document.getElementById(next_caption2).options[0] = new  Option(next_top_str2, "");
			document.getElementById(next_caption2).disabled = true;

			if(other_val){
			// if other value selected
			if(sel_value=="-1") {
				document.getElementById("span_"+next_caption2+"_other_val").style.display="block";
				document.getElementById(next_caption2).disabled = false;
				document.getElementById(next_caption2).options.length = 1;
				document.getElementById(next_caption2).options[1] = new  Option(other_str, "-1");
				document.getElementById(next_caption2).selectedIndex=1;
			} else {
				document.getElementById("span_"+next_caption2+"_other_val").style.display="none";
			}
			}//end if other_val

		}

	}
}
xmlhttp.send(null);

}

function oldDepending(field_no, caption1, caption2, dep_id, sec_val, other_val, other_str, live_site) {

var selected_index = document.getElementById(caption1).selectedIndex;
var id = document.getElementById(caption1).options[selected_index].value;

if(other_val){
if(id=="-1") {
	document.getElementById("span_"+caption1+"_other_val").style.display="block";
	document.getElementById("span_"+caption2+"_other_val").style.display="block";
	document.getElementById(caption2).disabled = false;
	document.getElementById(caption2).options.length = 1;
	document.getElementById(caption2).options[1] = new  Option(other_str, "-1");
	document.getElementById(caption2).selectedIndex=1;
	return;
} else {
	document.getElementById("span_"+caption1+"_other_val").style.display="none";
	document.getElementById("span_"+caption2+"_other_val").style.display="none";
}
}

id = encodeURIComponent(id);

document.getElementById(caption2).disabled = false;
url_str="include/get_info.php?type=depending&field="+dep_id+"&field_no="+field_no+"&dep="+id;
var xmlhttp=getxmlhttp();
// syncronous ajax
xmlhttp.open("GET",url_str,false);//we want to wait for other requests to finish

xmlhttp.send(null);
var dep_str=xmlhttp.responseText;//response=--:id[0],name[0]:id[1],name[1] .....

var split_dep=dep_str.split(":");
var no = split_dep.length;
document.getElementById(caption2).options.length = 0;
var depIndex = 0;
document.getElementById(caption2).options[depIndex] = new  Option(split_dep[0], "");
depIndex++;

if(other_val) {
	document.getElementById(caption2).options[depIndex] = new  Option(other_str, "-1");
	depIndex++;
}
var found = 0;
for (var j=5;j<no;j++) {
	split_d=split_dep[j].split(',');
	var dep_id=split_d[0];
	var dep_name=split_d[1];
	document.getElementById(caption2).options[depIndex] = new  Option(dep_name, dep_name);
	if(sec_val==dep_name) { document.getElementById(caption2).selectedIndex=depIndex; found=1; }
	depIndex++;
}
if(!found && sec_val && other_val) { 
	document.getElementById(caption2).selectedIndex=1;
	document.getElementById("span_"+caption2+"_other_val").style.display="block";
	document.getElementById(caption2+"_other_val").value=sec_val;
}
}


function adjustTotal(myForm, price, field, no_decimals) {

	var total = myForm.full_total.value;

	if(field.checked==true) {
		// add to total
		total = parseFloat(total)+parseFloat(price);
	} else {
		// substract from total
		total = parseFloat(total)-parseFloat(price);
	}
	myForm.full_total.value = total.toFixed(no_decimals);
	document.getElementById("total").innerHTML = total.toFixed(no_decimals);	

	getDiscount (myForm,"ads", 0);

}

function changePriority(myForm, val) {

	//var total = document.getElementById("total").innerHTML;
	var total = myForm.full_total.value;
	var prev = myForm.pri.value;
	if(!prev) prev=0;
	if(!val) val=0;
	total = parseFloat(total)+parseFloat(val);
	total = parseFloat(total)-parseFloat(prev);
	myForm.pri.value = val;
	myForm.full_total.value = total;
	document.getElementById("total").innerHTML = total;

	getDiscount (myForm,"ads", 0);

}

function getDiscount (myForm, type, hide_processors) {

if (typeof myForm.discount_code == 'undefined') return;

var total = myForm.full_total.value;

if(!total) return;

var code = myForm.discount_code.value;
url_str="include/get_info.php?type=discount&id="+code+"&dtype="+type+"&amount="+total;
var xmlhttp=getxmlhttp();
xmlhttp.open("GET",url_str);
xmlhttp.onreadystatechange = function () {

	if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {

		var new_total=xmlhttp.responseText;

		if(new_total==-1) new_total = total;
		document.getElementById("total").innerHTML = new_total;

		if(hide_processors) {
			if(new_total==0) document.getElementById("processors").style.display = "none";
			else document.getElementById("processors").style.display = "block";
		}
	}
}

xmlhttp.send(null);
}


function onChangePlan(myForm) {

	var i;
	var selected_plan;

	if(typeof myForm.package.length == "number") {
		var radioLength = myForm.package.length;
		for (i = 0; i<radioLength;i++) {
			if(myForm.package[i].checked) selected_plan = myForm.package[i].value;
		}
	}
	else selected_plan = document.getElementById("package").value;

	if(!selected_plan) return;
	url_str="include/get_info.php?type=sub_price&id="+selected_plan;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.onreadystatechange = function () {

	if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var ret_str=xmlhttp.responseText;//response=price
		var amount = parseFloat(ret_str);

		myForm.full_total.value = amount;
		document.getElementById("total").innerHTML = amount;	

		getDiscount (myForm,"ads");

	}
	}
	xmlhttp.send(null);
	
}

function radioSelected() {
var search = document.searchFolderContents.search
var radioLength = (typeof search.length == "number") ? (search.length) : 1;
}

function reloadDep(str, live_site) {

var selected_index = document.getElementById('qs_category').selectedIndex;
var cat = document.getElementById('qs_category').options[selected_index].value;
url_str=live_site+"/include/get_info.php?type=reload_depending&str="+str+"&cat="+cat;

var xmlhttp=getxmlhttp();
xmlhttp.open("GET",url_str);

xmlhttp.onreadystatechange = function () {

	if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var dep_str=xmlhttp.responseText;//response=field1_caption,top_str1,field2_caption,top_str2,val1,val2,val3^field2_caption,top_str2,val1,val2,val3
		if(!dep_str) return;

 		var split_dep=dep_str.split("^");
		var no_fields = split_dep.length;

		for (var idx=0;idx<no_fields;idx++) {

	 		var vals=split_dep[idx].split(",");
			var no = vals.length;
			caption = "qs_"+vals[0];
			top_str = vals[1];
			caption2 = "qs_"+vals[2];
			top_str2 = vals[3];

			document.getElementById(caption).disabled=false;
			document.getElementById(caption).options.length = 0;
			var depIndex = 0;
			document.getElementById(caption).options[depIndex] = new  Option(top_str, "");
			depIndex++;

			// empty second field
			document.getElementById(caption2).options.length = 0;
			document.getElementById(caption2).options[0] = new  Option(top_str2, "");
			document.getElementById(caption2).disabled=true;

			if (no<=4) { document.getElementById(caption).disabled=true; continue; }

			for (var j=4;j<no;j++) {
				document.getElementById(caption).options[depIndex] = new  Option(vals[j], vals[j]);
				depIndex++;
			}

		} //end for (var idx=1;idx<no;idx++) 
	}
}
	xmlhttp.send(null);

}

function checkAll(doc) {
  var c = new Array();
  c = doc.getElementsByTagName('input');
  for (var i = 0; i < c.length; i++)
  {
    if (c[i].type == 'checkbox')
    {
      c[i].checked = true;
    }
  }
}
function uncheckAll(doc)
{
  var c = new Array();
  c = doc.getElementsByTagName('input');
  for (var i = 0; i < c.length; i++)
  {
    if (c[i].type == 'checkbox')
    {
      c[i].checked = false;
    }
  }

}

function checkDeleteData(field_vis, field) {
	if(document.getElementById(field_vis).value=='') document.getElementById(field).value = '';
	return 1;
}

function onDeleteAlert(id) {

	url_str="include/actions.php?object=alert&action=delete&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.onreadystatechange = function () {

		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			location.reload(true);
		}
	}
	xmlhttp.send(null);

}

function onDeleteSavedSearch(id) {

	url_str="include/actions.php?object=search&action=delete&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.onreadystatechange = function () {

		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			location.reload(true);
		}
	}
	xmlhttp.send(null);

}


function onChangeLocation(id, table) {

	url_str="include/get_info.php?type=browse_location&table="+table+"&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.onreadystatechange = function () {

		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var result = xmlhttp.responseText;
			var split_dep=result.split(",");
			var no_fields = split_dep.length;
			var tab; var location_div;

			for (var idx=0;idx<no_fields;idx++) {
	
				tab = "location_tab"+split_dep[idx];
				location_div = "loc1_"+split_dep[idx];

				if(id==split_dep[idx]) {
					document.getElementById(tab).className="active";
					document.getElementById(location_div).style.display="block";
				} else {
					document.getElementById(tab).className="";
					document.getElementById(location_div).style.display="none";
				}
			}
		}
	}
	xmlhttp.send(null);
}

function onChangeMake(id, table) {

	url_str="include/get_info.php?type=browse_make&table="+table+"&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.onreadystatechange = function () {

		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var result = xmlhttp.responseText;
			var split_dep=result.split(",");
			var no_fields = split_dep.length;
			var tab; var make_div;

			for (var idx=0;idx<no_fields;idx++) {
	
				tab = "make_tab"+split_dep[idx];
				make_div = "make1_"+split_dep[idx];

				if(id==split_dep[idx]) {
					document.getElementById(tab).className="active";
					document.getElementById(make_div).style.display="block";
				} else {
					document.getElementById(tab).className="";
					document.getElementById(make_div).style.display="none";
				}
			}
		}
	}
	xmlhttp.send(null);
}


function onQuickSearch(myForm,live_site) {

	var selected_index = myForm.qs_category.selectedIndex;
	var selected_val = myForm.qs_category.options[selected_index].value;
	var split_str=selected_val.split(",");
	id=split_str[0];

	url_str=live_site+"/include/get_info.php?type=quick-search&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str,true);
	xmlhttp.onreadystatechange = function () {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var str=xmlhttp.responseText;//response=ul_str
			if(str!='0') {
				var split_str=str.split(",");
				var no = split_str.length;
				for(f=0; f< no; f++) {
					div_spec=split_str[f];
					var split_spec=div_spec.split("=");
					var field_name=split_spec[0];
					
					if(document.getElementById(field_name)!=null) {

					if(split_spec[1]==1) {
						$("#"+field_name).fadeIn();
					}
					else 
						$("#"+field_name).fadeOut();
					}
				}
			}

		}
	}
	xmlhttp.send(null);
}


function disableOtherSubmitButtons(submitButton)
{
if(!submitButton)
{
alert("no object found");
return;
}

if(!submitButton.type)
{
alert("no type attribute");
return;
}

if(submitButton.type != "submit")
{
alert("no submit button");
return;
}

if(!submitButton.form)
{
alert("parentless button (no form)");
return;
}

var formElements = submitButton.form.elements;

for(var i=0; i<formElements.length; i++)
{
//leave the pressed button as is...
if(formElements[i] == submitButton)
continue;

//disable all other submit buttons
if(formElements[i].type == "submit")
{
formElements[i].disabled = "true";
}
}
}

function IsNumeric(inputVal) {
	if (isNaN(parseFloat(inputVal))) {
		return false;
	}
	return true;
}

function chooseCateg(myForm, no) {

        var selBox = "category"+no;
        var selected_val = document.getElementById(selBox).value;
        url_str="include/get_info.php?type=subcat&id="+selected_val;

var xmlhttp=getxmlhttp();
xmlhttp.open("GET",url_str);

xmlhttp.onreadystatechange = function () {

        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var result=xmlhttp.responseText;//response=cat_id:cat_name^cat_id:cat_name ....
                                                // or 0 if the category has no subcats
                if(result==0) {

                        myForm.category.value = selected_val;
                        for(var i=no+1;i<=5; i++) {
                                cDiv = "level"+i;
                                document.getElementById(cDiv).style.display="none";
                        }
			document.getElementById("Choose_categ").disabled = false;
                        return;
                }

                var split_res=result.split("^");
                var no_cats = split_res.length;

                var nextBox = "category"+(no+1);
                var nextDiv = "level"+(no+1);
                document.getElementById(nextDiv).style.display="block";
                document.getElementById(nextBox).options.length = 0;

                for(var i=no+2;i<=5; i++) {
                        cDiv = "level"+i;
                        document.getElementById(cDiv).style.display="none";
                }

                document.getElementById("category").value = '';
		document.getElementById("Choose_categ").disabled = true;
                document.getElementById(nextBox).options[0] = new  Option(' - ', '');

                for (var idx=1;idx<=no_cats;idx++) {

                        var vals=split_res[(idx-1)].split(":");
                        cid = vals[0];
                        cname = vals[1];

                        document.getElementById(nextBox).options[idx] = new  Option(cname, cid);
                } //end for (var idx=1;idx<no;idx++)
        }
}
        xmlhttp.send(null);


}

