function getObj(objName) {
 var isIE = navigator.appName.indexOf("Microsoft") != -1;
 return (isIE) ? window[objName] : document[objName];
}



function popupWin(arg){

 var id = arg.split('id');

 if(document.getElementById(id[1]).checked == '1') document.getElementById(id[1]).checked = 0;
 else document.getElementById(id[1]).checked = 1;

}


function sendTxt(value){
//alert(value);
 getObj("flashMap").sendText(value);
 
}

function showDialog(id)
{
  $(function() {
    $(id).dialog({
            bgiframe: true,
            height: 140,
            modal: true,
            buttons: {
                    Ok: function() {
                            $(this).dialog('close');
                    }
            }
    });
   });
}

function changeVisibility(id)
{
    $(function() {
       $(id).slideToggle('slow', function() {
            // Animation complete.
        });
    });
}

function calculateHypo() {

	var xPriceId = 'price';
	var xOwnInvestId = 'ownInvest';
	var xYearSelectId = 'yearSelect';
	var xResultId = 'result';

	var xMessage1Id = '';
	var xMessage2Id = '';

	var xInterestRate = 0.0569;
	var xOwnInvestRatio = 0.8;
	var xPrice = 0;
	var xOwnInvest = 0;
	var xYear = 0;
	var xResult = 0;

	if (document.getElementById(xPriceId) && document.getElementById(xOwnInvestId) &&
			document.getElementById(xYearSelectId) && document.getElementById(xResultId)) {

		try {
			// PARSE PRICE
			try {
				xPrice = intval(parseInt(trimText(document.getElementById(xPriceId).value)));
			} catch (priceError) {
				xPrice = 0;
			}

			// PARSE OWN INVEST
			try {
				xOwnInvest = intval(parseInt(trimText(document.getElementById(xOwnInvestId).value)));
			} catch (priceError) {
				xOwnInvest = 0;
			}

			// PARSE YEAR
			try {
				xYear = intval(parseInt(document.getElementById(xYearSelectId).options[document.getElementById(xYearSelectId).selectedIndex].value));
			} catch (priceError) {
				xYear = 0;
			}

			if (xPrice > 0 && xYear > 0) {
				// CALCULATE
				xResult = (((xPrice-xOwnInvest)*xInterestRate/12)/(1-Math.pow((1/(1+xInterestRate/12)),(12*xYear))));

				// APPEND RESULT
				document.getElementById(xResultId).value=Math.round(xResult);
				return true;
			}
			document.getElementById(xResultId).value = '';

		} catch (e) {

		}
	}
}

function kbNewWin(src,name,w,h,prop,lp,tp) {
	if ((!w && !h) && (lp && tp)) {
		w = screen.width - (lp * 2);
		h = screen.height - (tp * 2) - tp;
		tp = tp / 2;
	} else if ((w && h) && (!lp && !tp)) {
		lp = (screen.width - w) / 2;
		tp = (screen.height - h) / 2;
	}
	prop = (!prop)? "" : prop+",";
	prop += (!w && !h)? "" : "width="+w+",height="+h+",left="+lp+",top="+tp;
	Win = window.open(src,name,prop);
	Win.focus();
}

function newClerboxWindow(url, title, width, height)
{
    CB_Gallery=new Array(); // creating the array
    CB_Gallery[0]=title; // name of the gallery

    CB_Gallery[1]=new Array(); // array of first item:

    CB_Gallery[1][0]=url; // url
    CB_Gallery[1][1]='iframe'; // type
    CB_Gallery[1][3]=width;
    CB_Gallery[1][4]=height;

    CB_Open('gallery='+title+',,href='+url);
}

function kbCalc () {
    var xPriceId = 'cena';
    var xOwnInvestId = 'sporeni';
    var xYearSelectId = 'splatnost';

    var kbCena = 0;
    var kbSporeni = 0;
    var kbSplatnost = 0;

    // UPRAVA CENY
    try {
            kbCena = intval(parseInt(trimText(document.getElementById(xPriceId).value)));
    } catch (priceError) {
            kbCena = 0;
    }

    // UPRAVA SPORENI
    try {
            kbSporeni = intval(parseInt(trimText(document.getElementById(xOwnInvestId).value)));
    } catch (investError) {
            kbSporeni = 0;
    }

    // UPRAVA SPLATNOSTI
    try {
            kbSplatnost = intval(parseInt(document.getElementById(xYearSelectId).options[document.getElementById(xYearSelectId).selectedIndex].value));
    } catch (yearError) {
            kbSplatnost = 0;
    }

    kbNewWin('http:\x2f\x2fwww.kb.cz\x2fcs\x2fapp\x2fmort_calc.shtml?rates=3&cena='+kbCena+'&sporeni='+kbSporeni+'&splatnost='+kbSplatnost,'kbMortCalc',467,405,'status=yes');
    //newClerboxWindow('http:\x2f\x2fwww.kb.cz\x2fcs\x2fapp\x2fmort_calc.shtml?rates=3&cena='+kbCena+'&sporeni='+kbSporeni+'&splatnost='+kbSplatnost,'Rako reality - Hypoteční kalkulačka',517,605);
}


function intval(mixed_var,base) {
    var tmp;

    var type = typeof(mixed_var);

    if(type == 'boolean'){
        if (mixed_var == true) {
            return 1;
        } else {
            return 0;
        }
    } else if(type == 'string'){
        tmp = parseInt(mixed_var * 1);
        if(isNaN(tmp) || !isFinite(tmp)){
            return 0;
        } else{
            return tmp.toString(base || 10);
        }
    } else if(type == 'number' && isFinite(mixed_var) ){
        return Math.floor(mixed_var);
    } else{
        return 0;
    }
}

function trimText(mixed_var) {
	mixed_var = mixed_var.replace (/\s+/g, '');
	return mixed_var;
}

function changeImage(id)
{
    /* nasatevni promennych */
    var sourceImg = document.getElementById(id);
    var targetImg = document.getElementById('img')
    var href1 = document.getElementById('href1');
    var href2 = document.getElementById('href2');

    /* uprava url */
    var sourceImgSrc = sourceImg.src;
    var url = sourceImgSrc.split('thumbnail/');

    targetImg.src = url[0]+'detail/'+url[1];
    targetImg.alt = sourceImg.alt;
    href1.href = url[0]+url[1];
    href2.href = url[0]+url[1];
}

function setVisibleJs(){
	
	try{
		document.getElementById('js').style.display='block';
	}
	catch(err){
		
	}	
}
