$(document).ready(function()
{
    $(".defaultText").focus(function(srcc){if ($(this).val() == $(this)[0].title){$(this).removeClass("defaultTextActive");$(this).val("");}});
    $(".defaultText").blur(function(){if ($(this).val() == ""){$(this).addClass("defaultTextActive");$(this).val($(this)[0].title);}});
    $(".defaultText").blur();
    $("#search").submit(function(){clearInputs()});
    $("#qsearch").submit(function(){clearInputs()});
});


function clearInputs(){
    var allInputs = $(":input");
	var no=allInputs.length;
	for(var i=0; i<no; i++) {
		if (allInputs[i].title == allInputs[i].value) allInputs[i].value="";
	}
}

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

function tooltip()
{
	$("img.tooltip").mouseover
	(
		function (event)
		{
			var text = this.name;
			$(this).removeAttr("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;

			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");
			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();
		}
	);

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

}

function tooltip_info()
{
	$("img.tooltip_info").mouseover
	(
		function (event)
		{
			var text = this.name;
			$(this).removeAttr("title");
			old_title=text;

			x = event.pageX+40;
			y = event.pageY+0;

			$("body").append("<div id='tooltip_info'>"+text+"</div>");
			$("#tooltip_info").css("left", x).css("top", y);
		}
	);

    $("div.tooltip_info").mouseover
	(
		function (event)
		{
			var text = this.name;
			$(this).removeAttr("title");
			old_title=text;

			x = event.pageX+40;
			y = event.pageY+0;

			$("body").append("<div id='tooltip_info'>"+text+"</div>");
			$("#tooltip_info").css("left", x).css("top", y);
		}
	);


	$("span.tooltip_info").mouseover
	(
		function (event)
		{
			var text = this.id;

			x = event.pageX+15;
			y = event.pageY+15;

			$("body").append("<div id='tooltip_info'>"+text+"</div>");
			$("#tooltip_info").css("left", x).css("top", y);
		}
	);

	$("input.tooltip_info").mouseover
	(
		function (event)
		{
			var text = this.title;
			$(this).removeAttr("title");
			old_title=text;
			x = event.pageX+15;
			y = event.pageY+15;

			$("body").append("<div id='tooltip_info'>"+text+"</div>");
			$("#tooltip_info").css("left", x).css("top", y);
		}
	);

	$("img.tooltip_info").mouseout(
		function (event)
		{
			$("#tooltip_info").remove();
			$(this).attr("title", old_title);
		}
	);

	$("div.tooltip_info").mouseout(
		function (event)
		{
			$("#tooltip_info").remove();
			$(this).attr("title", old_title);
		}
	);

	$("span.tooltip_info").mouseout(
		function (event)
		{
			$("#tooltip_info").remove();
		}
	);

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

}


function n_window(theurl,w,h)
{
 var the_width=w;
 var the_height=h;
 var from_top=200;
 var from_left=200;
 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';
 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;
 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 {
	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	try {
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	xmlhttp=false;
	}
}
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;
	}
}

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 clickBanner(id, url) {

	url_str="include/get_info.php?type=banner&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);

	xmlhttp.onreadystatechange = function () {

		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			location.reload(false);
		}
	}
	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";
          if (document.getElementById("info_message_"+val)!= null) document.getElementById("info_message_"+val).style.display="none";
          if (document.getElementById("info_message_other_val"+val)!= null) document.getElementById("info_message_other_val"+val).style.display="block";

    }
else if (selected_val=="")
{
    	  document.getElementById("span_"+val+"_other_val").style.display="none";
          if (document.getElementById("info_message_"+val)!= null) document.getElementById("info_message_"+val).style.display="block";
          if (document.getElementById("info_message_other_val"+val)!= null) document.getElementById("info_message_other_val"+val).style.display="none";

}


	else
    {
    	  document.getElementById("span_"+val+"_other_val").style.display="none";
          if (document.getElementById("info_message_"+val)!= null) document.getElementById("info_message_"+val).style.display="none";
          if (document.getElementById("info_message_other_val"+val)!= null) document.getElementById("info_message_other_val"+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 && sel_value=="-1")
{
           	if (document.getElementById("span_"+caption1+"_other_val")!= null) document.getElementById("span_"+caption1+"_other_val").style.display="block";  // ?????????? ???? 1
           	if (document.getElementById("span_"+caption2+"_other_val")!= null) document.getElementById("span_"+caption2+"_other_val").style.display="block";  // ?????????? ???? 2
            if (document.getElementById("info_message_"+caption1)!= null) document.getElementById("info_message_"+caption1).style.display="none";
            if (document.getElementById("info_message_"+caption2)!= null) document.getElementById("info_message_"+caption2).style.display="none";
            if (document.getElementById("info_message_other_val"+caption1)!= null) document.getElementById("info_message_other_val"+caption1).style.display="block";
            if (document.getElementById("info_message_other_val"+caption2)!= null) document.getElementById("info_message_other_val"+caption2).style.display="block";
            if (document.getElementById(caption2)!=null){
                document.getElementById(caption2).disabled = false;
                document.getElementById(caption2).options.length = 1;
                document.getElementById(caption2).options[1] = new  Option(other_str, "-1");
    			document.getElementById(caption2).options[1].style.color="green";
                document.getElementById(caption2).selectedIndex=1;
            }
}
else if (sel_value=="")
{
        if (document.getElementById("info_message_"+caption1)!= null) document.getElementById("info_message_"+caption1).style.display="block";
        if (document.getElementById("info_message_"+caption2)!= null) document.getElementById("info_message_"+caption2).style.display="none";
        if (document.getElementById("info_message_other_val"+caption1)!= null) document.getElementById("info_message_other_val"+caption1).style.display="none";
        if (document.getElementById("info_message_other_val"+caption2)!= null) document.getElementById("info_message_other_val"+caption2).style.display="none";
      	if (document.getElementById("span_"+caption1+"_other_val")!= null) document.getElementById("span_"+caption1+"_other_val").style.display="none";
        if (document.getElementById(caption2)!=null){
        document.getElementById(caption2).disabled = true;
       	document.getElementById("span_"+caption2+"_other_val").style.display="none";
        }
}
else
{
        if (document.getElementById("info_message_"+caption1)!= null) document.getElementById("info_message_"+caption1).style.display="none";
        if (document.getElementById("info_message_"+caption2)!= null) document.getElementById("info_message_"+caption2).style.display="block";
        if (document.getElementById("info_message_other_val"+caption1)!= null) document.getElementById("info_message_other_val"+caption1).style.display="none";
        if (document.getElementById("info_message_other_val"+caption2)!= null) document.getElementById("info_message_other_val"+caption2).style.display="none";
      	if (document.getElementById("span_"+caption1+"_other_val")!= null) document.getElementById("span_"+caption1+"_other_val").style.display="none";
       	if (document.getElementById("span_"+caption2+"_other_val")!= null) document.getElementById("span_"+caption2+"_other_val").style.display="none";
        if (document.getElementById(caption2)!=null)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] .....
 		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");
			document.getElementById(caption2).options[depIndex].style.color="green";
			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);
        	if(sel_value.toUpperCase()==dep_name.toUpperCase()) {document.getElementById(caption2).options[depIndex].style.backgroundcolor="#cccccc"; document.getElementById(caption2).options[depIndex].style.color="red";}
			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).options.length = 0;
			document.getElementById(next_caption1).options[0] = new  Option(next_top_str1, "");
			document.getElementById(next_caption1).disabled = true;
            document.getElementById("info_message_"+next_caption1).style.display="none";
            if (document.getElementById("info_message_other_val"+next_caption1)!= null) document.getElementById("info_message_other_val"+next_caption1).style.display="none";
			document.getElementById("span_"+next_caption1+"_other_val").style.display="none";

			if(other_val){
			// if other value selected
			if(sel_value=="-1") {
				document.getElementById("span_"+next_caption1+"_other_val").style.display="inline";
                if (document.getElementById("info_message_other_val"+next_caption1)!= null) document.getElementById("info_message_other_val"+next_caption1).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).options[1].style.color="green";
				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="inline";
				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) {
var selected_index = document.getElementById(caption1).selectedIndex;
var id = document.getElementById(caption1).options[selected_index].value;
document.getElementById(caption2).disabled = false;

if (sec_val=="-1")
{
           	if (document.getElementById("span_"+caption2+"_other_val")!= null) document.getElementById("span_"+caption2+"_other_val").style.display="block";  // ?????????? ???? 2
            if (document.getElementById("info_message_"+caption2)!= null) document.getElementById("info_message_"+caption2).style.display="none";
            if (document.getElementById("info_message_other_val"+caption2)!= null) document.getElementById("info_message_other_val"+caption2).style.display="block";
}

url_str="include/get_info.php?type=depending&field="+dep_id+"&field_no="+field_no+"&dep="+id;

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

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] .....
 		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");
			document.getElementById(caption2).options[depIndex].style.color="green";
            if (sec_val=="-1") document.getElementById(caption2).selectedIndex=depIndex;
        	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.toUpperCase()==dep_name.toUpperCase()) {document.getElementById(caption2).selectedIndex=depIndex; found=1;}
			depIndex++;
		}
if(!found && sec_val && other_val) {
//  alert ("not found");
	document.getElementById(caption2).selectedIndex=1;
	document.getElementById("span_"+caption2+"_other_val").style.display="block";
	document.getElementById(caption2+"_other_val").value=sec_val;
    }
	}
}
xmlhttp.send(null);

}


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 = 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++;

			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++;
			}

		}
	}
}
	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;
			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++){
        if(formElements[i] == submitButton)
        continue;
        if(formElements[i].type == "submit"){formElements[i].disabled = "true";}
    }
}
