/* author: Ivan Terziev */
/* Creation date: 19.4.2007 ã. */
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="-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 isValidDate(yyyy,mm,dd)
{
	function isLeapYear(year)
	{
		if (year % 400 == 0) return true;
		if (year % 100 == 0) return false;
		if (year % 4 == 0) return true;
	}

	var months = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	months[1] += isLeapYear(yyyy) ? 1 : 0;

	return (dd >= 01 && dd <= months[mm - 1]) ? true : false;
}

function IsEgnValid(egn)
{
 
	var weights = new Array(2,4,8,5,10,9,7,3,6);
	var crc = 0;
	var year = Number(egn[0] + egn[1]);
	var month = Number(egn[2] + egn[3]);
	var day = Number(egn[4] + egn[5]);

	if (month > 40)
	{
		if (!isValidDate(2000 + year, month - 40, day)) return false;
	}
	else if (month > 20)
	{
		if (!isValidDate(1800 + year, month - 20, day)) return false;
	}
	else
	{
		if (!isValidDate(1900 + year, month, day)) return false;
	}

	if (!egn.match(/\d{10}/g)) return false; // Check if 10 digits

	for (var i = 0; i < 9; i++)
	{
		crc += egn.charAt(i) * weights[i];
	}

	crc = crc % 11;

	if (crc == 10) crc = 0;

	if (crc != egn.charAt(9)) 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;
}

function loadTypeRated(){
	
	var term_deposit=document.getElementById('term_deposit').value;
	
	url="../includes/inicial_select_field.php?term_deposit="+term_deposit;

	t_select=document.getElementById("type_rated");

	t_select.innerHTML='';
	
	loadXMLContentDropDown(url);

}

function load_currency2(){
	var currency=document.getElementById('currency1').value;
	document.getElementById('currency2').value=currency;
}
function load_currency1(){
	var currency=document.getElementById('currency2').value;
	document.getElementById('currency1').value=currency;
}

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 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 sofiia_change(val){
	el=document.getElementById("hide_addr").firstChild;
	//alert(el.innerHTML);
	if(val==43)el.firstChild.nodeValue="Ðàéîí: ";
	else el.firstChild.nodeValue="Ãðàä/Ñåëî: ";
}

function showBuletinMail(){
	if(document.getElementById("agree").checked){
		document.getElementById("mail").style.display='';
		document.getElementById("buletin_mail").style.display='';
		document.getElementById("send").style.display='';
	}else{
		document.getElementById("mail").style.display='none';
		document.getElementById("buletin_mail").style.display='none';
		document.getElementById("send").style.display='none';
	}
}
function checkEmail( strValue, send_btn) {
	//check for valid email
	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,}))$/
	var rez=objRegExp.test(strValue);
	if(rez==false)alert("Ìîëÿ âúâåäåòå êîðåêòåí å-ìåéë!");
	else {
		document.calculator.send_btn.value=send_btn;
		document.calculator.submit();
	}
}