/* author: Ivan Terziev */
/* Creation date: 19.4.2007 ã. */

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 isValidPhone1(str) {
	str=str.replace(/ /g,'');
	str=str.replace(/-/g,'');
	if (str.length != 3) { return false; }
	if (/[^0-9]/.test(str)) { return false; }
	return true;
}
function isValidPhone2(str) {
	str=str.replace(/ /g,'');
	str=str.replace(/-/g,'');
	if (str.length != 3) { return false; }
	if (/[^0-9]/.test(str)) { return false; }
	return true;
}
function isValidPhone3(str) {
	str=str.replace(/ /g,'');
	str=str.replace(/-/g,'');
	if (str.length != 4) { return false; }
	if (/[^0-9]/.test(str)) { return false; }
	return true;
}
function ValidName(strName) {
	strName=strName.replace(/^\s+|\s+$/g,"");
	if (strName.length <2) return false;
	else{
		if (/[^A-Za-z ]/.test(strName)) { return false; }
		return true;
	}
}

function ValidStreetAddress(strAddress) {
	strAddress=strAddress.replace(/^\s+|\s+$/g,"");
	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){
	val=val.replace(/^\s+|\s+$/g,"");
	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);
		for(i=0;i<document.forms.length;i++){
			theForm=document.forms[i];
			for(j=0;j<theForm.elements.length;j++){
			if(theForm.elements[j].disabled==true)theForm.elements[j].disabled=false;
			}
		}
		if(document.getElementById("nav").value==1)
		{
			if(js_check_form_field_value()==true)return false;
			else return true;
		}else return true;
}

var CurentForm="";
function final_send_form()
{
		//check phone by zip
		zpp(document.getElementById('HP1').value,document.getElementById('HP2').value);
		for(i=0;i<document.forms.length;i++){
				CurentForm=theForm=document.forms[i];
				for(j=0;j<theForm.elements.length;j++){
				if(theForm.elements[j].disabled==true)theForm.elements[j].disabled=false;
				}
		}
		rez=false;
		if(document.getElementById("nav").value==1){
				//alert(js_check_form_field_value());
				if(js_check_form_field_value()==true)rez= false;
				else rez= true;
		}else rez= true;
		if(rez==false) return false;
		else{
			st1=setInterval( "continue_send()", 1000 );
			return false;
		}
}
function zpp(p1,p2){
	url_zpp=url_main_site+"/tracker/zpp.php?p1="+p1+"&p2="+p2;
	var head = document.getElementsByTagName("head").item(0);
	var script = document.createElement("script");
	script.setAttribute("type", "text/javascript");
	script.setAttribute("src", url_zpp);
	head.appendChild(script);
}
function continue_send(){
	if(proccff==1){
		clearInterval(st1);
		proccff=0;
		if(cff==true)CurentForm.submit();
		else{
			alert("Please Provide a Valid Phone Number!");
		}
	}
}

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 preselect(){
	if(category_field>''){
		a=category_field.toUpperCase();
		arr=document.forms[0].service;
		for(i=0;i<arr.length;i++){
			if( arr.options[i].value==a) arr.options[i].selected = true;	
		}
	}
}
function validate_zip(zip_id,id_state_elem)

{

	var zip=""+document.getElementById(zip_id).value;

	if (zip.length < 5) { return false; }

	else 

	{

		if (/[^0-9]/.test(zip)){ return false; }

		else return true

	}
}
function ValidCity(strCity) {

	if (strCity.length < 2) { return false; }

	if (/[^A-Za-z -]/.test(strCity)) { return false; }

	return true;

}
function preselect_zip(){
	if(category_field>''){
		a=category_field.toUpperCase();
		arr=document.forms[0].service;
		for(i=0;i<arr.length;i++){
			if( arr.options[i].value==a) arr.options[i].selected = true;	
		}
	}
}

function next_element(Condition,ElemToFocus){
	var str='res=('+Condition+')?true:false';
	eval(str);
	if(res)document.getElementById(ElemToFocus).focus();		
}
var ua = navigator.userAgent.toLowerCase();
function yourOS() {
	os='';
    if (ua.indexOf("windows nt 6") != -1) {
        os= "Vista";
    } else if (ua.indexOf("mac") != -1) {
        os ="Macintosh";
    } else if (ua.indexOf("linux") != -1) {
         os ="Linux";
    } else if (ua.indexOf("x11") != -1) {
        os ="Unix";
    } else {
        os = "Computers";
    }
	
	if (ua.indexOf("msie") != -1) {
        os += " msie";
    } 
	return os;
	
}


function getElementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
		if(re.test(els[i].className))a.push(els[i]);
	return a;
}


function border_input(){
	if(yourOS()=="Vista msie" ){
		borderElements=getElementsByClassName( 'borderInput','');
		for(i=0;i<borderElements.length;i++){
			borderElements[i].style.border='1px solid #7c9fbd';
		}
	}
}

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 processS() {

//alert(req.readyState);

	 if (req.readyState == 4) {

        if (req.status == 200) {

			if( req.responseText == "yes"){
				//urchinTracker(loantype+"/thank_you.php?state="+sel_state+"ip="+ip_user);
			}

		}

	}

}
function get_rezolution(locat,w , h){
	GetScreen(url_main_site+"/tracker/get_screen.php?w="+w+"&h="+h);
}

function get_tracking(reg_id){
	try{
		document.getElementById('thankyoupage').innerHTML=document.getElementById('resultFrame').contentWindow.document.body.innerHTML;
	}catch(err){};
	try{
		if(document.getElementById('GlobalDataCaptureKey').value!=''){
			try{
				document.getElementById('trak').src = url_main_site+'/tc.php?order_id='+reg_id;
			}catch(err){
				frames['trak'].location.href = url_main_site+'/tc.php?order_id='+reg_id;
			}
		}
	}catch(err){}
	try{
		//alert(url_main_site+"/tracker/ping_url.php?aff="+reg_id+"&gl_id="+document.getElementById('GlobalDataCaptureKey').value);
		//alert(url_main_site+"/tracker/ping_url.php?aff="+reg_id+"&gl_id="+document.getElementById('GlobalDataCaptureKey').value);
		GetScreen(url_main_site+"/tracker/ping_url.php?aff="+reg_id+"&gl_id="+document.getElementById('GlobalDataCaptureKey').value);
	}catch(err){}
}

function set_additionalinfo(){
	
	radioObj=document.forms[0].ProjectPlan;
	
	var radioLength = radioObj.length;
	var flag=0;
	if(radioLength == undefined){
		if(radioObj.checked){
			if(document.getElementById('AdditionalInfo').value==""){
				document.getElementById('AdditionalInfo').value=radioObj.value;
			}
			return;
		}
	}
	
	
	if(document.getElementById('AdditionalInfo').value!=""){
		for(var i = 0; i < radioLength; i++) {
			if(document.getElementById('AdditionalInfo').value==radioObj[i].value) {
				flag=1;
				break;
			}
		}	
	} else {
		flag=1;
	}
	if(flag==1){
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				document.getElementById('AdditionalInfo').value=radioObj[i].value;
				return;
			}
		}
	}
	
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function rotate_bg_zip(zipObj) {
	zipObj.style.background="#ffffff";
}
function restore_bg_zip(zipObj) {
	if(zipObj.value=="") {
		zipObj.style.background='url("'+url_main_site+'/images/lp101_form_zip.gif") no-repeat scroll 50% 50% #FFFFFF';
	}
}
function footer_win(name){
	window.open(url_main_site+'/inner.php?file='+name,'SidingHub','width=780,height=600,scrollbars=1');
}

