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





function get_rezolution(locat,w , h){
	GetScreen(locat+"tracker/get_screen.php?w="+w+"&h="+h);
}

function  WindowClickEventExplorer(e){
	
}

/* author: Ivan Terziev */
/* Creation date: 19.4.2007 г. */
/*document.onmousedown=test_click;
function test_click(e)
{
	if(!e)e=window.event;
	alert(this.id);
}*/
var sel_drop_down;

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 hidetip(e){
	dropmenuobj.style.visibility="hidden"
	dropmenuobj.style.left="0px"
}

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 isValidYear(str) {
	str=str.replace(/ /g,'');
	if (str.length != 4 ) { return false; }
	if (/[^0-9-]/.test(str)) { return false; }
	if(str<1900){ return false; }
	if(str>2008){ 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 send_form57()
{
	//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;
	url="../calculators/generate_calc_kod.php?calculator_id="+id_calc;
	loadXMLContentRead1(url);
	return false;
}



//izbiraiki region ti se listvat vsichki gradove v tozi region
function sel_city(i,g){
	
	var id_region=document.getElementById(g).value;
	
	url="../includes/get_cities.php?id_region="+id_region;

	t_select=document.getElementById(i);

	t_select.innerHTML='';
	
	loadXMLContentDropDown(url);

}

function loadXMLContentDropDown(url){

    if (window.XMLHttpRequest) {

        req = new XMLHttpRequest;

        req.onreadystatechange = processReqDD;

        req.open("GET", url, true);

        req.send(null);

    } else if (window.ActiveXObject) {

        isIE = true;

        req = new ActiveXObject("Microsoft.XMLHTTP");

        if (req) {

            req.onreadystatechange = processReqDD;

            req.open("GET", url, true);

            req.send(null);

        }

    }

}

function processReqDD() {

	 if (req.readyState == 4) {

        if (req.status == 200) {

		 	if(req.responseText !="")

		 	{

		 		msg=req.responseText;

				if (typeof DOMParser == "undefined") {

   					DOMParser = function () {}

   					DOMParser.prototype.parseFromString = function (str, contentType) {

      				if (typeof ActiveXObject != "undefined") {

				         var d = new ActiveXObject("MSXML.DomDocument");

				         d.loadXML(str);

				         return d;

				      } else if (typeof XMLHttpRequest != "undefined") {

				         	var req = new XMLHttpRequest;

				        	req.open("GET", "data:" + (contentType || "application/xml") +

				        	";charset=windows-1251," + encodeURIComponent(str), false);

				        	if (req.overrideMimeType) {

				           		req.overrideMimeType(contentType);

				        	}

							req.send(null);

				        	return req.responseXML;

				      	}

   			  		}

				}

				var xmlobject = (new DOMParser()).parseFromString(msg, "text/xml");

				var root = xmlobject.getElementsByTagName('nmsg')[0];

				

				var items = root.getElementsByTagName("item");

				

				for (var i = 0 ; i < items.length ; i++) {

					var item = items[i];

					var type_elem = item.getAttribute("elem");
					
					switch(type_elem){

						case 'option' :

							var e_option=document.createElement('option');

							try{						

								var currenttext = document.createTextNode(item.firstChild.nodeValue);

								e_option.appendChild(currenttext); 

							}catch(err){

								var currenttext = document.createTextNode("-");

								e_option.appendChild(currenttext); 

							}

							add_elemnt(e_option,item);

							if(sel_drop_down == e_option.value)e_option.selected=true;

							t_select.appendChild(e_option); 

						break;

						

					}

				}

				

				//flag_load_data=1;

			}

		}

	}
//if(flag_sel==1)alert(flag_sel e 1);
}
function loadPodMenu(div_id){
elem=document.getElementById(div_id);
//alert(div_id);
if(elem.style.display=="none") elem.style.display="";
else elem.style.display="none";
}
function add_elemnt(element,xmlelem){

	var elem=element;

	

	var attribute = xmlelem.getAttribute("id");

	if(attribute != '' && attribute != null)elem.setAttribute('id',attribute);

	var attribute = xmlelem.getAttribute("width");

	if(attribute != '' && attribute != null)elem.setAttribute('width',attribute);

	var attribute = xmlelem.getAttribute("colspan");

	if(attribute != '' && attribute != null)elem.setAttribute('colspan',attribute);

	var attribute = xmlelem.getAttribute("bg");

	if(attribute != '' && attribute != null)elem.style.background=attribute;

	var attribute = xmlelem.getAttribute("border");

	if(attribute != '' && attribute != null)elem.style.border=attribute;

	var attribute = xmlelem.getAttribute("color");

	if(attribute != '' && attribute != null)elem.style.color=attribute;

	var attribute = xmlelem.getAttribute("value");

	if(attribute != '' && attribute != null)elem.setAttribute('value',attribute);

	var attribute = xmlelem.getAttribute("js");

	if(attribute!='' && attribute!=null){

		arr_js=attribute.split("#");

		for(i=0;i<arr_js.length;i++){

			str_event=arr_js[i].split("=");

			the_event=str_event[0];

			the_function=str_event[1];

			addEvent(elem, the_event, eval(the_function), false);

		}

	}

}
function showHideIns(div_id){
	elem=document.getElementById(div_id);
	//alert(div_id);
	if(elem.style.display=="none")elem.style.display="";
	//else elem.style.display="none";

}

function completeTablePrice(show){

	elem1=document.getElementById('complete_tbl_price');
	elem2=document.getElementById('part_tbl_price');
	if(show==1)
	{
		elem1.style.display="";
		elem2.style.display="";
	}
	else if(show==0)
	{
		elem1.style.display="none";
		elem2.style.display="";
	}
	
}
function focusOnForm(){
	document.getElementById('name').focus();
}

function chooseCompany(id){
	document.getElementById('ins_company_prices_id').value=id;
	document.forms[0].nav.value=1;
}

function setSupplyData(){
	document.getElementById('supply_name').value=owner['name'];
	document.getElementById('supply_second_name').value=owner['second_name'];
	document.getElementById('supply_last_name').value=owner['last_name'];
	document.getElementById('supply_addr').value=owner['addr'];
	var sel_city = document.getElementById('supply_city');
	var sel_region = document.getElementById('supply_region');
	
	
	for(i=0;i<sel_region.length;i++)
	{
		var opt_reg=document.getElementById('supply_region').options[i].value;
		var opt_text_reg=document.getElementById('supply_region').options[i].text;
		if(opt_reg==owner['region']){
			document.getElementById('supply_region').options[i].selected=true;
		}
	}
	
	if(sel_city.length>0)
	{
		var numb=sel_city.length;
		for(i=0;i<numb;i++)
		{
			sel_city.remove(0);
		}
	}
	
	for(i=0;i<city.length;i++)
	{
		var opt=document.createElement('option');
		opt.setAttribute('value',city[i]['id']);
		var opt_text=document.createTextNode(city[i]['town']);
		opt.appendChild(opt_text);
		sel_city.appendChild(opt);
		if(city[i]['id']==owner['city']){
			opt.selected=true;
		}
	}
	

	
}
function getActionFld(elem){
	
}
function ShowCompleteTablePrice(show){

	elem1=document.getElementById('complete_tbl_price');
	elem2=document.getElementById('show_all_res');
	
	if(show==1)
	{
		elem1.style.display="";
		elem2.style.display="none";
	}
	else if(show==0)
	{
		elem1.style.display="none";
		elem2.style.display="";
	}
	
}
function chooseCompanyAndVnoska(id,vn){
	document.getElementById('ins_company_prices_id').value=id;
	document.getElementById('ins_company_num_vnoski').value=vn;
	document.forms[0].nav.value=1;
}


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=450");
if(window.focus)newwindow.focus();
}
else{
alert("Некоректно попълнени данни!");
}
}

