var domain = "http://www.dexia.sk";
var pagePath = "";
var doc = document;
var idWin = "win";
var winLeft = "200px";
var winTop = 80;
var isDragEnd = true;
var widthControl = 70;
var widthEdge = 5;
//------------------------------------------------------------------------
// base JavaScript object
var jS = new Object();
jS.replaceSubstring = function( fullS, oldS, newS ) {
	var rtn = fullS;
	for ( var i = 0; i < fullS.length; i++ ) {
		if ( rtn.substring( i, i + oldS.length ) == oldS ) {
			rtn = rtn.substring( 0, i ) + newS + rtn.substring( i + oldS.length, rtn.length );
			i--;
		}
	}
	return rtn;
}
jS.getScrollTop = function() {
	if( doc.documentElement && doc.documentElement.scrollTop ) {
		return doc.documentElement.scrollTop;	// IE6 +4.01 and user has scrolled
	} else if(doc.body && doc.body.scrollTop) {
		return doc.body.scrollTop;	// IE5 or DTD 3.2
	} else {
		return doc.documentElement.scrollTop;	// other browsers
	}
}
jS.getScrollLeft = function() {
	if( doc.documentElement && doc.documentElement.scrollLeft ) {
		return doc.documentElement.scrollLeft;	// IE6 +4.01 and user has scrolled
	} else if(doc.body && doc.body.scrollLeft) {
		return doc.body.scrollLeft;	// IE5 or DTD 3.2
	} else {
		return doc.documentElement.scrollLeft;	// other browsers
	}
}
//--------------------------------------------------------------------------------------
// global functions of this project
var gF = new Object();
gF.getWinHtml = function( title, id, myWidth ){
	var idNum = jS.replaceSubstring( id, idWin, "" );
	var rtn = "<div class=\"win-top\">";
	rtn += "<div class=\"win-top-left\"></div>";
	rtn += "<div class=\"win-top-center\">";
	rtn += "<div id=\"win-top-nadpis" + idNum + "\" class=\"win-top-nadpis\" style=\"width:" + (myWidth - widthControl) + "px\" onmousedown=\"winO.dragStart(event, '" + id + "', this)\" onmouseup=\"winO.dragEnd(this)\">" + title + "</div>";
	rtn += "<div class=\"win-top-control\">";
	rtn += " <a class=\"win-control\" href=\"javascript:winO.close(" + idNum + ")\"><img border=\"0\" src=\"/C1256A2B002C6206/img/okno/$file/zavriet.gif\" width=\"16\" height=\"15\" alt=\"zavrieť\"></a></div></div>";
	rtn += "<div class=\"win-top-right\"></div>";
	rtn += "</div>";
	rtn += "<div id=\"" + id + "-c\" class=\"win-middle-content\"></div>";
	rtn += "<div class=\"win-bottom\">";
	rtn += "<div class=\"win-bottom-left\"></div>";
	rtn += "<div id=\"win-bottom-center" + idNum + "\" class=\"win-bottom-center\" style=\"width:" + (myWidth - 2 * widthEdge) + "px\"></div>";
	rtn += "<div class=\"win-bottom-right\"></div></div>";
	return rtn;
}
//------------------------------------------------------------
//Ajax object
ajxO = new Object();
ajxO.ajaxSetHtml = function( url, elm, data ) {
    var req = false;
    // branch for native XMLHttpRequest object
    if( window.XMLHttpRequest ) {
        try {
            req = new XMLHttpRequest();
        } catch(e) {
            req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if( window.ActiveXObject ) {
        try {
            req = new ActiveXObject( "Msxml2.XMLHTTP" );
        } catch(e) {
            try {
                req = new ActiveXObject( "Microsoft.XMLHTTP" );
            } catch(e) {
                req = false;
            }
        }
    }
    if( req ) {
        req.onreadystatechange = function(){
            if( req.readyState == 4 ) {
	document.getElementById( elm ).innerHTML = req.responseText;
            }
        }
        req.open("POST", url, true);
        data = typeof data == "undefined" ? "" : data;
        req.send( data );
    }
} 
//-------------------------------------------------------------------------------------
// window object
var winO = new Object();
winO.open = function( title, myWidth, myHeight, idNum, url, myTop, myLeft, evt ){
    var id = idWin + idNum;
    var div = doc.getElementById(id);
    if(div){
        div.style.display = "block";
    } else {
	if( typeof evt == "undefined" ) evt = window.event;
	var mouseTop = evt ? evt.clientY : 0;
	var mouseLeft = evt ? evt.clientX : 0;
        div = doc.createElement("div");
        div.id = id;
        div.className = "win";
        div.innerHTML = gF.getWinHtml(title, id, myWidth);
        winO.winParent = null;
        winO.winParent = doc.getElementById( "middle" );
        winO.winParent.appendChild(div);
        div.style.left =  (mouseLeft + myLeft + jS.getScrollLeft() - myWidth ) + "px";
        div.style.top = ( mouseTop + myTop + jS.getScrollTop() ) + "px";
	div.style.width = myWidth + "px";
        div.style.height = myHeight ? myHeight + "px" : "auto";
    }
    if(typeof arguments[3] != "undefined"){
            var urlAjax = domain + pagePath + url;
            if(url.indexOf("http") == 0) urlAjax = url;
            if(url.indexOf("/") == 0) urlAjax = domain + url;
            if(arguments[3] != "") ajxO.ajaxSetHtml(urlAjax, id + "-c");
     }
}
winO.open2 = function( idW, myTop, myLeft, evt, dFormat ){
	var elmN = doc.getElementById( "win-top-nadpis2" );
	if( typeof dFormat == "undefined" ){
		doc.decimalFormat = "00";
		if( elmN ) elmN.innerHTML = "Kalkulačka na prepočet hodnôt v EUR a SKK"
	}else{
		doc.decimalFormat = dFormat;
		if( elmN ) elmN.innerHTML = "Kalkulačka na prepočet hodnôt podielových fondov v EUR a SKK"
	}
	var id = idWin + idW;
	var div = doc.getElementById( id );
	if( div ){
		if( typeof evt == "undefined" ) evt = window.event;
		var mouseTop = evt ? evt.clientY : 0;
		var mouseLeft = evt ? evt.clientX : 0;
		div.style.left =  (mouseLeft + myLeft + jS.getScrollLeft() - parseInt( div.style.width ) ) + "px";
		div.style.top = ( mouseTop + myTop + jS.getScrollTop() ) + "px";
		div.style.display = "block";
	}
	pocitaj();
}
//--------------------------------------------------------------
winO.close = function(id){
    var win = doc.getElementById( idWin + id );
    if( win ) win.style.display = "none";
}
//-------------------------------------------------------------
winO.dragEnd = function(thisElm){
	doc.onmousemove = null;
	if(thisElm){
		thisElm.style.background = "#204B95";
		thisElm.style.zIndex = "2";
	}
    isDragEnd = true;
}
//-----------------------------------------------------------------------
winO.drag = function( evtMM ){
	if( isDragEnd ) return false;
    if( typeof evtMM == "undefined" ) evtMM = window.event;
    if( !evtMM ) return;
    winO.nowMouseX = evtMM.clientX;
    winO.nowMouseY = evtMM.clientY;
    var difX = winO.lastMouseX - winO.nowMouseX;
    var difY = winO.lastMouseY - winO.nowMouseY;
    winO.win.style.left = (winO.lastWinX - difX) + "px";
    winO.win.style.top = (winO.lastWinY - difY) + "px";
}
//----------------------
winO.dragStart = function(evtMD, id, thisElm){
	isDragEnd = false;
	if( thisElm){
		thisElm.style.background = "#3a7594";
	}
	if(typeof doc.body.ondrag != "undefined") document.body.ondrag = function(){return false;};
	if(typeof doc.body.onselectstart != "undefined") doc.body.onselectstart = function(){return false;};
    if(typeof evtMD=="undefined") evtMD = window.event;
    winO.win = doc.getElementById( id );
    winO.lastMouseX = evtMD.clientX;
    winO.lastMouseY = evtMD.clientY;
    winO.lastWinX = parseInt(winO.win.style.left);
    winO.lastWinY = parseInt(winO.win.style.top);
    winO.win.style.zIndex = "6";
    if( doc.attachEvent ) {
	doc.attachEvent( "onmousemove", winO.drag ); 
    } else {
	doc.addEventListener( "mousemove", winO.drag, true );
    }
}
//------------------------
eTN = new Object();
eTN.odoslat = function(){
	var df = document._win_etn_sk;
	if(!df) {
		window.status = "Form does not exists!"
		return false;
	}
	var ods0 = df.checkBoxNewsLetter[0].value;
	var ods1 = df.checkBoxNewsLetter[1].value;
	var adr = df.textEmailAdresa.value;
	
	if( (ods0 + ods1) == "" ){
		alert( "Označte prosím požiadavku." );
		return false;
	}
	
	var bad = /(^@)|(^\.)/;	// not valid
	var good = /\w+[a-zA-Z0-9\-\.]*\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})$/;	// valid
	if ( bad.test( adr ) || !good.test( adr ) ) { 
  		alert( "Prepáčte, nesprávna adresa." );
  		return false;
	}
	var data = "checkBoxNewsLetter="
	if( df.checkBoxNewsLetter[0].checked ) data += ods0;
	if( df.checkBoxNewsLetter[1].checked ) data += ( "," + ods1 );
	data += "&textEmailAdresa=" + adr;
	ajxO.ajaxSetHtml( "/C1256B5F0028BCAB/win_etn_sk?CreateDocument", "win1-c", data  );
}

