function checkMenu()
{
	if(document.getElementById('kind_imot').value == 18)
	{
		document.getElementById('tarea').style.display = 'none';
		document.getElementById('parcel').style.display = 'inline';
		document.getElementById('parcel').value = "Парцел...";
	}
	else if(document.getElementById('kind_imot').value == 19)
	{
		document.getElementById('parcel').style.display = 'none';
		document.getElementById('tarea').style.display = 'inline';
		document.getElementById('tarea').value = "Търговска площ...";
	}
	else
	{	
		document.getElementById('tarea').style.display = 'none';
		document.getElementById('parcel').style.display = 'none';
	}
}
function choiceName()
{
	switch(document.getElementById('target').value)
	{
		case '1':
		document.getElementById('costomer').innerHTML = "Данни на продавача:";
		document.getElementById('area_to').style.display = "none";
		document.getElementById('hide_to').style.display = "none";
		document.getElementById('selected_text').style.display = "none";
		document.getElementById('selected').style.display = "none";
		break;
		case '2':
		document.getElementById('costomer').innerHTML = "Данни на купувача:";
		document.getElementById('area_to').style.display = "inline";
		document.getElementById('hide_to').style.display = "inline";
		document.getElementById('selected_text').style.display = "inline";
		document.getElementById('selected').style.display = "inline";
		break;
		case '3':
		document.getElementById('costomer').innerHTML = "Данни на наемателя:";
		document.getElementById('area_to').style.display = "none";
		document.getElementById('hide_to').style.display = "none";
		document.getElementById('selected_text').style.display = "none";
		document.getElementById('selected').style.display = "none";
		break;
		case '4':
		document.getElementById('costomer').innerHTML = "Данни на наемодателя:";
		document.getElementById('area_to').style.display = "inline";
		document.getElementById('hide_to').style.display = "inline";
		document.getElementById('selected_text').style.display = "inline";
		document.getElementById('selected').style.display = "inline";
		break;
		default:
		document.getElementById('costomer').innerHTML = "Данни:";
		break;
	}
}
function checkMenuDown()
{
	if(document.getElementById('statusimot').value == 6)
	{
		document.getElementById('other').style.display = 'inline';
		document.getElementById('other').value = "Друго...";
	}
	else
	{
		document.getElementById('other').style.display = 'none';		
	}
}
function hideValue(id)
{
	document.getElementById(id).value = "";
}
function largePic(source)
{
	document.mainpics.src = source;	
}

function viewAnime(id, src)
{
	//document.anime.src = "images/newspaper_anime.gif";
	document.getElementById(id).src = src;
}

//alert(navigator.appVersion);
// && navigator.appVersion="7.0"
if(navigator.appName == "Microsoft Internet Explorer")
{
//	alert("V Ie sme!");
//	document.getElementById('footer').style.margin-top = -83+"px";
}
var newwindow='';
function pickerPopup202(ifn,sam){
var bl=screen.width/2-102;
var bt=screen.height/2-104;
page="../includes/fcp202.html"+"?ifn="+escape(ifn)+"&sam="+escape(sam);
if(!newwindow.closed&&newwindow.location){
newwindow.location.href=page;
}
else{
newwindow=window.open(page,"CTRLWINDOW","help=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,dependent=yes,width=250,height=250,left="+bl+",top="+bt+",");
if(!newwindow.opener)newwindow.opener=self;
};
if(window.focus){
newwindow.focus()
}
if(newwindow.closed){
alert('new');
}
}

function changeColorCalc(){
var newwindow;
var color_title=document.getElementById('input_color_title').value;
var color_title=color_title.replace(/#/,"");
var color_text=document.getElementById('input_color_text').value;
var color_text=color_text.replace(/#/,"");
var color_btn_bcgr=document.getElementById('input_color_btn_bcgr').value;
var color_btn_bcgr=color_btn_bcgr.replace(/#/,"");
var color_box_bcgr=document.getElementById('input_color_box_bcgr').value;
var color_box_bcgr=color_box_bcgr.replace(/#/,"");
if((color_title.length==6 || color_title.length==0) && (color_text.length==6 || color_text.length==0) && 
(color_btn_bcgr.length==6 || color_btn_bcgr.length==0) && (color_box_bcgr.length==6 || color_box_bcgr.length==0)){
newwindow=window.open("../includes/calculator_frame.php?color_title="+color_title+"&color_text="+color_text+"&color_btn_bcgr="+color_btn_bcgr+"&color_box_bcgr="+color_box_bcgr,
"Calculator","resizable=0,width=450,height=460");
if(window.focus)newwindow.focus();
}
else{
alert("Некоректно попълнени данни!");
}
}



var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all


function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
				if ((ie||ns6) && document.getElementById("hintbox")){
						dropmenuobj=document.getElementById("hintbox");
						dropmenuobj.innerHTML=menucontents;
						dropmenuobj.style.left=dropmenuobj.style.top=-500;
						if (tipwidth!=""){
							dropmenuobj.widthobj=dropmenuobj.style;
							dropmenuobj.widthobj.width=tipwidth;
						}
						dropmenuobj.x=getposOffset(obj, "left");
						dropmenuobj.y=getposOffset(obj, "top");
						dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px";
						dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px";
						dropmenuobj.style.visibility="visible";
						obj.onmouseout=hidetip;
				}
}


function showhintImg(menucontents, obj, e, tipwidth, tipheight){
				if ((ie||ns6) && document.getElementById("hintbox")){
						dropmenuobj=document.getElementById("hintbox");
						dropmenuobj.innerHTML="<img src='"+menucontents+"' width='"+tipwidth+"' height='"+tipheight+"'/>";
						dropmenuobj.style.left=dropmenuobj.style.top=-500;
						if (tipwidth!=""){
							dropmenuobj.widthobj=dropmenuobj.style;
							dropmenuobj.widthobj.width=tipwidth+"px";
							dropmenuobj.widthobj.height=tipheight+"px";
						}
						dropmenuobj.x=getposOffset(obj, "left");
						dropmenuobj.y=getposOffset(obj, "top");
						dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px";
						dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px";
						dropmenuobj.style.visibility="visible";
						obj.onmouseout=hidetip;
				}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
	var divblock=document.createElement("div");
	divblock.setAttribute("id", "hintbox");
	document.body.appendChild(divblock);
}

if (window.addEventListener) window.addEventListener("load", createhintbox, false)
else if (window.attachEvent) window.attachEvent("onload", createhintbox);
else if (document.getElementById) window.onload=createhintbox;

function NewWin(objpath,w,h)
{
	h=150;
	window.open(objpath,"",'scrollbars=1, resizable=1, width=' +w+ ',height=' +h+ ',left=500,top=400');
}	
function li_hover(elem)
{
	elem.style.background='#F1EFEC';
}
function li_out(elem)
{
	elem.style.background='#FAFAFA';
}


//ot credit-bg
function loadXMLContentRead(url) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest;
        req.onreadystatechange = processReqRead;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqRead;
            req.open("GET", url, true);
            req.send(null);
        }
    }
}

function processReqRead() {
	 if (req.readyState == 4) {
        if (req.status == 200) {
		 if(req.responseText !="")
		 {
		 	content=req.responseText;
			if(content!=""){
			document.getElementById('property_city').innerHTML="";
			arr_cities=content.split("<>");
			for(i=0;i<arr_cities.length-1;i++)
			{
				cities=arr_cities[i];
				det_cities=cities.split("->");
				var option=document.createElement('option');
				option.setAttribute('value',det_cities[0]);
				var currenttext = document.createTextNode(det_cities[1]);
				option.appendChild(currenttext);
				document.getElementById('property_city').appendChild(option);
			}
		}
				
				
			
			
		  }
		}
	}
}

function sel_region(id_region)
{
	loadXMLContentRead("../includes/load_city.php?id_region="+id_region);
}

function choise_action(form_action)
{
	form_target="";
	form_action1="";
	document.calculator.target=form_target;
	if(form_action1!="") document.calculator.action=form_action1;
	
	
}





function isValidPhone(str) {
	str=str.replace(/ /g,'');
	if (str.length < 6) { return false; }
	if (/[^0-9-]/.test(str)) { return false; }

	
	return true;
}
function ValidName(strName) {
	if (/[^A-Za-z -абвгдежзийклмнопрстуфхцчшщъьюяАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯ]/.test(strName)) { return false; }
	return true;
}

function ValidStreetAddress(strAddress) {
	if (strAddress.length < 3) { return false; }
	return true;
}


//za 4islo
function js_check_value_numeric(val,val_min,val_max){
	var objRegExp  =/(^-?\d\d*$)/;
	if(val>=val_min && val<=val_max)return objRegExp.test(val);
	else return false;
}

function validateInteger( strValue ) {
  var objRegExp  = /(^-?\d\d*$)/;

  //check for integer characters
  return objRegExp.test(strValue);
}
function js_check_value_char(val,val_min,val_max){
	if(val.length>=val_min && val.length<=val_max)return true;
	else return false;
}
function js_check_value_checkbox(val,val_min,val_max){
	if(val=='on')return true;
	else return false;
}
function js_check_value_tc(val,val_min,val_max){
	if(val=='on')return true;
	else return false;
}
function change_checkbox(element)
{
	var el=element;
	if(el.checked) el.value='on';
	else el.value='false';
}
function js_check_value_mail(val,val_min,val_max){
	var objRegExp  =/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	return objRegExp.test(val);
}
function validateEmail( strValue) {
var objRegExp  =/(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;

  //check for valid email
  return objRegExp.test(strValue);
}

function send_form()
{
	//window.alert("test"+document.getElementById("nav").value);
	
		if(document.getElementById("nav").value==1)
		{
			if(js_check_form_field_value()==true)return false;
			else return true;
		}else return true;
}

function loadXMLContentRead1(url) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest;
        req.onreadystatechange = processReqRead1;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqRead1;
            req.open("GET", url, true);
            req.send(null);
        }
    }
}

function processReqRead1() {
	 if (req.readyState == 4) {
        if (req.status == 200) {
		 	if(req.responseText !="")
		 	{
				content=req.responseText;
				//alert(document.getElementById('kod_calc'));
				if(content!=""){
				content=content.replace(/\[/g,"&lt;");
				content=content.replace(/\]/g,"&gt;");
					document.getElementById('gen_kod_frame').innerHTML=content;
							
				}
			}
		}
	}
}

function ch_calcs(){
id_calc=document.getElementById('calculator_id').value;
var color_title=document.getElementById('input_color_title').value;
color_title=color_title.replace(/#/,"");
var color_text=document.getElementById('input_color_text').value;
color_text=color_text.replace(/#/,"");
var color_btn_bcgr=document.getElementById('input_color_btn_bcgr').value;
color_btn_bcgr=color_btn_bcgr.replace(/#/,"");
var color_box_bcgr=document.getElementById('input_color_box_bcgr').value;
color_box_bcgr=color_box_bcgr.replace(/#/,"");

url="../calculators/generate_calc_kod.php?calculator_id="+id_calc+"&color_title="+color_title+"&color_text="+color_text+"&color_btn_bcgr="+color_btn_bcgr+"&color_box_bcgr="+color_box_bcgr;
loadXMLContentRead1(url);
return false;
}
