function jgetText () {

	var maxTitle = 60;
	var maxText = 1000;

	if ((maxTitle - $("#titlerus").val().length) > 0) {
		$("#titlerusSym").html(maxTitle - $("#titlerus").val().length);
		$("#titlerus").css("background-color", "#FFFFFF");
	} else {
		$("#titlerusSym").html("<span style='color:red;font-weight:bold'>0</span>");
		$("#titlerus").css("background-color", "#fff2f2");
	}

	if ((maxText - $("#descrrus").val().length) > 0) {
		$("#descrrusSym").html(maxText - $("#descrrus").val().length);
		$("#descrrus").css("background-color", "#FFFFFF");
	} else {
		$("#descrrusSym").html("<span style='color:red;font-weight:bold'>0</span>");
		$("#descrrus").css("background-color", "#fff2f2");
	}

	if ($("#titlerus").val().length > maxTitle) {
		$("#titlerus").val(($("#titlerus").val()).substr(0, maxTitle));
	} else if($("#titlerus").val().length > 0) {
		getCaretPos($("#titlerus"));
		insertAtCursorPosition($("#titlerus"), '');
	}

	if ($("#descrrus").val().length > maxText) {
		$("#descrrus").val(($("#descrrus").val()).substr(0, maxText));
	} else if($("#descrrus").val().length > 0) {
		getCaretPos($("#descrrus"));
		insertAtCursorPosition($("#descrrus"), '');
	}

	if ((maxTitle - $("#titleheb").val().length) > 0) {
		$("#titlehebSym").html(maxTitle - $("#titleheb").val().length);
		$("#titleheb").css("background-color", "#FFFFFF");
	} else {
		$("#titlehebSym").html("<span style='color:red;font-weight:bold'>0</span>");
		$("#titleheb").css("background-color", "#fff2f2");
	}

	if ((maxText - $("#descrheb").val().length) > 0) {
		$("#descrhebSym").html(maxText - $("#descrheb").val().length);
		$("#descrheb").css("background-color", "#FFFFFF");
	} else {
		$("#descrhebSym").html("<span style='color:red;font-weight:bold'>0</span>");
		$("#descrheb").css("background-color", "#fff2f2");
	}

	if ($("#titleheb").val().length > maxTitle) {
		$("#titleheb").val(($("#titleheb").val()).substr(0, maxTitle));
	} else if($("#titleheb").val().length > 0) {
		getCaretPos($("#titleheb"));
		insertAtCursorPosition($("#titleheb"), '');
	}

	if ($("#descrheb").val().length > maxText) {
		$("#descrheb").val(($("#descrheb").val()).substr(0, maxText));
	} else if($("#descrheb").val().length > 0) {
		getCaretPos($("#descrheb"));
		insertAtCursorPosition($("#descrheb"), '');
	}

}

function getCaretPos(obj) {
  if(obj.selectionStart) {
  	return obj.selectionStart;
  } else if(obj.selection) {
	obj.selection = document.selection.createRange().duplicate();
	return true;
  }
  return 0;
}

function insertAtCursorPosition(myTextArea, smilie) {
	str = smilie;
	if (myTextArea.createTextRange && myTextArea.selection) {
	var objTxtRange = myTextArea.selection;
	objTxtRange2=objTxtRange.text;
	objTxtRange.text = (objTxtRange.text.charAt(objTxtRange.text.length - 1) == ' ') ? str + ' ' : str;
	myTextArea.selection = null;
	} else {
		myTextArea.value += str;
		}
	return true;
}
function checkKey(e) {
var targ = e ? e : window.event;
key = targ.keyCode ? targ.keyCode : targ.charCode;
if(key == 13) {
	return false;
}
}

function getCurrentData() {
	var theDate = new Date();
	document.editblock.month.value = theDate.getMonth() + 1;
	document.editblock.year.value = theDate.getYear();
	document.editblock.date.value = theDate.getDate();
}

function getCurrentPayData() {
	var theDate = new Date();
	$("#paymonth").val( theDate.getMonth() + 1 );
	$("#payyear").val( theDate.getYear() );
	$("#paydate").val( theDate.getDate() );
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
function checkFile() {
	if(document.category.title.value=="" || document.category.link.value=="") {
		alert("An file name and menu item is required!");
		return false;
	}
	var rex = /^([0-9a-z]([-_]?[0-9a-z]))/;
	if (document.category.link.value.match(rex) == null) {
		alert("An file name is not valid Only letters (a-z) or numbers (0-9) is required");
		return false;
	}
}
function expandSearch(shift) {
	if ($("#expandSearch").css("display") == 'none') {
		$("#content").animate({top: shift}, 200);
		$("#footer").animate({top: shift}, 200);
		$("#expandSearch").animate({height: 'show', opacity:'show'}, 500);
} else {
		$("#expandSearch").animate({opacity:'hide', height: 'hide'}, 100);
		$("#content").animate({top: "0"}, 'slow');
		$("#footer").animate({top: "0"}, 'slow');
	}
}
function setLogin() {
	$("#logintext").focus(function() {$(this).val("")});
	$("#logintext").blur(function() { if ($(this).val() == '') $(this).val(txtLogin[0]) });
	$("#pass").focus(function() {$(this).val("")});
	$("#pass").blur(function() { if ($(this).val() == '') $(this).val(txtLogin[1]) });
}
function allCorners() {
	Nifty("div#footer","small");
	Nifty("div.card_title","small");
	Nifty("div#search_form","tr bottom small");
	Nifty("div.search_type","tr tl small");
	Nifty("div.red_line","small");
	Nifty("td.red_line","small");
}
function getDiv(name){
	var div = document.getElementById(name);
	if(div.style.display == 'none') {
		div.style.display = 'block';
	} else {
	div.style.display = 'none';
	}
}
function toggle(obj) {
 if(document.getElementById(obj).style.display=="block")
 document.getElementById("drop01").style.display="none";
 else
 document.getElementById("drop01").style.display="block";
}
function delFirm(firmID, firmTitle) {
	var text = textTeg[1]+ '<br />«' + firmTitle + '»?' + '<input type="hidden" id="firmId" value="'+ firmID +'">';
	$.prompt(text, { callback: deleteFirm, buttons:{Ok:true,Cancel:false} }).corner();
}


function deleteFirm(v,m) {
	if(v) {
		$.post('/ajax/delfirm.php', {firmID:m.children('#firmId').val()}, function(result) { window.location.reload(); });
	}
}

$(document).ready(function(){
	allCorners();
	$("#logintext").defaultvalue(txtLogin[0]);
	$("#pass").defaultvalue(txtLogin[1]);
	$(".hideicon").click( function() {
		var firmID = $(this).attr("rel");
		var div = $("#card_banner"+firmID).attr("xxx");

		if ( $("#card"+firmID).css("display")=="none" ) {
			$.post('/ajax/review.php', {firmID:firmID} );
			$("#card_banner"+firmID).html("<iframe src="+div+" frameborder='0' hspace='0' marginheight='0' marginwidth='0' scrolling='No' vspace='0' width='468' height='60'></iframe>");
			$("#shortcard"+firmID).animate( {height: 'hide', opacity:'hide'}, 100 );
			$("#card"+firmID).animate( {height: 'show', opacity:'show'}, 400 );
			$("#slider"+firmID).codaSlider();
			$(this).attr("src", "img/pico/027.gif").attr("alt", textCard[1]).parent();
		} else {
			$("#card_banner"+firmID).html("&nbsp;");
			$("#card"+firmID).animate( {height: 'hide', opacity:'hide'}, 400 );
			$("#shortcard"+firmID).animate( {height: 'show', opacity:'show'}, 100 );
			$(this).attr("src", "img/pico/026.gif").attr("alt", textCard[0]).parent();
		}
	});
})