﻿(function($){ $.fn.simpletooltip = function(){
return this.each(function() {
var text = $(this).attr("title");
$(this).attr("title", "");
if(text != undefined && text != '') {
$(this).hover(function(e){
var tipX = e.pageX + 12;
var tipY = e.pageY + 12;
$(this).attr("title", "");
$("body").append("<div id='simpleTooltip' style='position: absolute; z-index: 100; display: none;'>" + text + "</div>");
if($.browser.msie) var tipWidth = $("#simpleTooltip").outerWidth(true)
else var tipWidth = $("#simpleTooltip").width()
$("#simpleTooltip").width(tipWidth);
$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
}, function(){
$("#simpleTooltip").remove();
$(this).attr("title", text);
});
$(this).mousemove(function(e){
var tipX = e.pageX + 12;
var tipY = e.pageY + 12;
var tipWidth = $("#simpleTooltip").outerWidth(true);
var tipHeight = $("#simpleTooltip").outerHeight(true);
if(tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
if($(window).height()+$(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
});
}
});
}})(jQuery);

function DelCheck(form, text) {
check = confirm(text);
if (check == false) return false;
}

$(document).ready(function(){
var v=$('.forma').val();
if(v=='user'){
$(".formm").val('user');
$('.user_form').slideDown('slow');
$('.comp_form').slideUp('slow');
}
else if(v=='company'){
$(".formm").val('company');
$('.comp_form').slideDown('slow');
$('.user_form').slideUp('slow');
}
$(".help").simpletooltip();
$("input").simpletooltip();
$("textarea").simpletooltip();
$("select").simpletooltip();
});
function search()
{
$("#search_min").hide(300);
$("#search_max").show(300);
$("#right").hide(200).add($("#super").hide(300));
$(".searchnum").hide(200);
}
function anti_search()
{
$("#search_max").hide(300);
$("#search_min").show(300);
$("#right").show(200).add($("#super").show(300));
$(".searchnum").show(200);
}
function change_company(){
var v=$('.forma').val();
if(v=='user'){
$(".formm").val('user');
$('.user_form').slideDown('slow');
$('.comp_form').slideUp('slow');
}
else if(v=='company'){
$(".formm").val('company');
$('.comp_form').slideDown('slow');
$('.user_form').slideUp('slow');
}
}
function symboll(){
var v=$('#area').val();
s='Осталось:';
var sizee=v.length;
s+=600-v.length;
s+=' символов';
if(sizee<=600){
stri=v;
}
$('#area').val(stri);
$('.counter').html(s);
}

function enable(){
var dis = document.getElementById('SubMit').disabled;
var dis2 = document.getElementById('SubMit2').disabled;
if(dis)document.getElementById('SubMit').disabled = false;
else document.getElementById('SubMit').disabled = true;
if(dis2)document.getElementById('SubMit2').disabled = false;
else document.getElementById('SubMit2').disabled = true;
}
function slide(panel){
$(document).ready(function(){
$("#"+panel).slideToggle("slow");
});
}
function show(id){
$(document).ready(function(){
$("#"+id).fadeIn("slow");
});
}
function help(id,img,type,text,src,variables,method){
$("#"+id).jHelperTip({
trigger: type,
source: "ajax",
type: method,
url: src,
data: variables,
loadingImg: img,
loadingText: text,
autoClose: false,
opacity: 0.9
});
}
function posi(e){
if($.browser.msie){
var xx=e.x;
var yy=e.y+80;
}
else{
var xx=e.pageX;
var yy=e.pageY+20;
}
$("#tek").show('slow');
$("#tek").css('left',xx+'px').css('top',yy+'px');
}
function check_all(){
alert('sanjar');
document.getElementById('checkk').checked;
}
function Email ( str )  {
if (str == "") {
alert ("Enter an email address in the field, please.");
return false
}
else if ( str. indexOf ( "@" , 4) == -1 ) {
alert("Error: Вы внесли  " + str + ". Ваш электронный адрес не содержит в себе '@' ." ) ;
return false
}
else if ( str. indexOf ( "." , 7) == -1 ) {
alert("Error:  Вы внесли " + str + ". Ваш электронный адрес не содержит в себе '.' ." ) ;
return false
}
return true
}
function chPage(dom) {
var href= dom.href;
var es = document.getElementsByTagName('INPUT');
for (var i=0; i<es.length; i++)
if (es[i].name.substr(0, 5) == 'chck_' && (es[i].checked || es[i].type=='hidden'))
href+= '&' + es[i].name + '=1';
self.location = href;
}
//Used in renta main page
function CityChanged(toCityID) {
//Hide All options
for (i=1;i<=32;i++) {
var d = document.getElementById('District'+i);
if (d) {
d.style.display = 'none';
d.name = 'DistrictID_';
}
}
var d = document.getElementById('District'+toCityID);
if (d) {
d.style.display = 'inline';
d.name = 'DistrictID';
document.getElementById('DistrictForm').style.visibility = 'visible';
} else {
document.getElementById('DistrictForm').style.visibility = 'hidden';
}
}
//Used in Add Page
function AddImage( Img ) {
var dom = document.getElementById('AddImage'+Img);
if (dom) dom.style.display = 'block';
}
function ChangeFloor( val ) {
var dom1 = document.getElementById('FloorsCnt');
var dom2 = document.getElementById('TotalFloors');
if (val*1!=0) {
dom1.disabled = false;
dom2.disabled = false;
for (i=0;i<=18;i++) {
var d1 = document.getElementById('FloorsCnt'+i);
var d2 = document.getElementById('TotalFloors'+i);
if (i==0) {
d1.selected = true;
d2.selected = true;
} else {
d1.selected = false;
d2.selected = false;
}
if (val*1+i<=18) {
d1.disabled = false;
d1.value = val*1 + i;
d1.innerHTML = val*1 + i;
d2.disabled = false;
d2.value = val*1 + i;
d2.innerHTML = val*1 + i;
} else {
d1.disabled = true;
d1.value = '0';
d1.innerHTML = '';
d2.disabled = true;
d2.value = '0';
d2.innerHTML = '';
}
}
} else {
dom1.disabled = true;
dom2.disabled = true;
}
}
function ChangeFloorsCnt( val ) {
var dom = document.getElementById('TotalFloors');
if (val*1!=0) {
dom.disabled = false;
for (i=0;i<=18;i++) {
var d = document.getElementById('TotalFloors'+i);
if (i==0) {
d.selected = true;
} else {
d.selected = false;
}
if (val*1+i<=18) {
d.disabled = false;
d.value = val*1 + i;
d.innerHTML = val*1 + i;
} else {
d.disabled = true;
d.value = '0';
d.innerHTML = '';
}
}
} else {
dom.disabled = true;
}
}
function ChangeFloor1( val ) {
var dom1 = document.getElementById('FloorsCnt');
if (val*1!=0) {
dom1.disabled = false;
for (i=0;i<=18;i++) {
var d1 = document.getElementById('FloorsCnt'+i);
if (i==0) {
d1.selected = true;
} else {
d1.selected = false;
}
if (val*1+i<=18) {
d1.disabled = false;
d1.value = val*1 + i;
d1.innerHTML = val*1 + i;
} else {
d1.disabled = true;
d1.value = '0';
d1.innerHTML = '';
}
}
} else {
dom1.disabled = true;
}
}
function TurnDisplay( id ) {
var dom = document.getElementById( id );
dom.style.display = 'block';
document.getElementById('id'+1).style.display = 'none';
return false;
}

function CategoryChanged() {
var dom = document.getElementById("CategoryID");
if (dom.value*1 == 1) {
document.getElementById('priceSpan').innerHTML = "&nbsp;*&nbsp;";
document.getElementById('materialSpan').innerHTML = "&nbsp;*&nbsp;";
document.getElementById('areaTtlSpan').innerHTML = "&nbsp;*&nbsp;";
} else {
document.getElementById('priceSpan').innerHTML = "";
document.getElementById('materialSpan').innerHTML = "";
document.getElementById('areaTtlSpan').innerHTML = "";
}
}
function showByNum() {
var dom = document.getElementById('byNum');
if (dom.style.display == 'none') {
dom.style.display = 'block';
try {
document.getElementById('byNumID').focus();
} catch(e) {}
} else
dom.style.display = 'none';
}
//Used Annonce and Service
function TurnAddAnnonce() {
var dom = document.getElementById('AddAnnonce');
dom.style.display = 'block';
document.getElementById('AddAnnonce1').style.display = 'none';
return false;
}
function TurnAddService() {
var dom = document.getElementById('AddService');
dom.style.display = 'block';
document.getElementById('AddService1').style.display = 'none';
return false;
}
function randomNumber (m,n)
{
m = parseInt(m);
n = parseInt(n);
return Math.floor( Math.random() * (n - m + 1) ) + m;
}
function regenerate(dom, asror) {
dom.src = '/anti.php?asror='+randomNumber (4,11);
}
function ajax(url,data,object)
{
$.ajax(
{
url: url,
data: data,
success: function(msg)
{
$(object).html(msg);
}
});
}
function ajaxCity(vals)
{
ajax("/renta/_cities","regionId="+vals,"#cityU");
}
function ajaxCity_(vals)
{
ajax("/renta/_cities_","regionId="+vals,"#cityU_");
}
function ajaxDistrict(vals)
{
ajax("/renta/_districts","cityId="+vals,"#districtU");
}
function ajaxDistrict_(vals)
{
ajax("/renta/_districts_","cityId="+vals,"#districtU_");
}
function toggleAll( Name, Count ) {
var i;
for (i=0;i<Count;i++) {
if (document.getElementById(Name+i) != null) {
if (document.getElementById(Name+i).checked)
document.getElementById(Name+i).checked = false;
else	document.getElementById(Name+i).checked = true;
}
}
}
function addNotepad(data)
{
ajax("/ajax/notepad.php",data,"#notepad");
}
function open_window(url,width,height){
	window.open(url,'_blank','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=yes,width='+width+',height='+height+',top='+(window.screen.height/2 - height/2)+',left='+(window.screen.width/2 - width/2));
	return false;
}

/***********************************************
* Start 
***********************************************/

function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
//end

// valid email -->

function showerror() { 
 alert("E-mail was entered wrong."); 
 } 
 
 function checkmail() 
 { 
 txt=document.entermail.address.value; 
 
 if (txt == "") { 
 alert("Enter E-mail."); 
 return(false) 
 } 
 
 if (txt.indexOf(".") == -1) { 
 alert("Miss symbol \".\""); 
 return(false) 
 } 
 
 dog = txt.indexOf("@"); 
 if (dog == -1) { 
 alert("Miss symbol \"@\"."); 
 return(false) 
 } 
 
 if ((dog < 1) || (dog > txt.length - 5)) { 
 showerror(); 
 return(false) 
 } 
 
 if ((txt.charAt(dog - 1) == '.') || (txt.charAt(dog + 1) == '.')) { 
 showerror(); 
 return(false) 
 } 
 } 
//-->



