/* Screen Width/Hegiht Detection Function */
function getPageSize() {

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all
																			// but
																			// Explorer
																			// Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla
				// and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement
			&& document.documentElement.clientHeight) { // Explorer 6 Strict
														// Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
	return arrayPageSize;
}

/* Popup Functions */
function showPopup(srcUrl, callerName, destName) {
	// window.scrollTo(0, 0);

	var popup = document.getElementById("popup");
	var popup_bg = document.getElementById("popup_bg");
	var caller_obj = document.getElementById(callerName);
	var dest_obj = document.getElementById(destName);
	var dest_obj_inner = document.getElementById(destName + "_inner");
	var winSize = getPageSize();

	// alert(document.documentElement.clientHeight);
	// alert(document.body.clientHeight);
	var clientWidth = winSize[0];
	var clientHeight = winSize[1];

	// alert(clientWidth);
	// alert(popup_bg);

	if (!popup || !popup_bg)
		return true;

	popup_bg.style.width = (clientWidth - 20) + 'px';
	popup_bg.style.height = clientHeight + 'px';
	popup_bg.style.display = 'block';

	var callerObj = document.getElementById(callerName);
	// alert(callerObj.offsetTop);

	var callerTop = 0;
	var popupTopPos = (callerObj.offsetTop > 300) ? callerObj.offsetTop - 180
			: 150;
	var popupLeftPos = ((clientWidth / 2) - 200);

	// alert("X: " + popupTopPos + ", Y: " + popupLeftPos);

	window.scrollTo(clientWidth / 2, popupTopPos - 20);

	popup.style.top = popupTopPos + 'px'; // ((clientHeight/2)-200)
	popup.style.left = popupLeftPos + 'px';
	popup.style.display = 'block';

	dest_obj.style.height = dest_obj_inner.style.height = "200px";

	// alert(dest_obj_inner.offsetHeight);

	sizePopup(true);

	if (srcUrl != "") {
		// loadPopupContent(srcUrl, destName);
		dest_obj_inner.style.height = dest_obj.offsetHeight;
		dest_obj_inner.innerHTML = "<iframe src='"
				+ srcUrl
				+ "' id='popup_iframe' style='border: 0px; width: 100%; height: "
				+ dest_obj.offsetHeight
				+ "px;' frameborder='0' scrolling='no'></iframe>";
		loadingPopup();
	}

	return false;
}

function loadPopupContent(srcUrl, destName, params) {
	var dest_obj = document.getElementById(destName);
	var dest_obj_inner = document.getElementById(destName + "_inner");

	var popupframe_l = document.getElementById("popupframe_l");
	var popupframe_r = document.getElementById("popupframe_r");
	var popupframe_b = document.getElementById("popupframe_b");

	if (srcUrl != "") {
		if (dest_obj) {
			// alert(caller_obj.style);
			dest_obj.style.background = 'url(/images/corporate/ajax-loader.gif) no-repeat center';
			if (dest_obj_inner) {
				dest_obj_inner.style.display = "none";
			}
		}

		response = "";
		conn = _sendx(srcUrl);
		// alert(conn);

		if (conn && conn.status == 200) {
			response = conn.responseText;
		}

		if (dest_obj) {
			if (dest_obj_inner) {
				dest_obj_inner.innerHTML = response;
				dest_obj_inner.style.display = "";

				if (popupframe_l)
					popupframe_l.style.height = dest_obj_inner.offsetHeight + 'px';
				if (popupframe_r)
					popupframe_r.style.height = dest_obj_inner.offsetHeight
							+ "px";
				if (popupframe_b)
					popupframe_b.style.top = dest_obj_inner.offsetHeight + "px";

			}
			dest_obj.style.background = '#FFF';
		}
	}

	return false;
}

function sizePopup(noparent) {
	var popup_iframe = false;
	if (window.parent && !noparent) {
		var doc = window.parent.document;
		var dest_obj_inner = document.body;
		popup_iframe = doc.getElementById("popup_iframe");

	} else {
		var doc = document;
		var dest_obj_inner = document.getElementById("popup_frame_center");
		// popup_iframe = doc.getElementById("popup_iframe");
		// alert("Inner: " + dest_obj_inner.offsetHeight);
	}

	var dest_obj = doc.getElementById("popup_frame_center");
	var popupframe_l = doc.getElementById("popupframe_l");
	var popupframe_r = doc.getElementById("popupframe_r");
	var popupframe_b = doc.getElementById("popupframe_b");

	dest_obj.style.background = "#FFF";
	if (popup_iframe) {
		popup_iframe.style.display = "";
	}

	if (popupframe_l)
		popupframe_l.style.height = dest_obj_inner.offsetHeight + 'px';
	if (popupframe_r)
		popupframe_r.style.height = dest_obj_inner.offsetHeight + "px";
	if (popupframe_b)
		popupframe_b.style.top = dest_obj_inner.offsetHeight + "px";

	if (dest_obj)
		dest_obj.style.height = dest_obj_inner.offsetHeight + "px";

	if (popup_iframe) {
		popup_iframe.style.height = dest_obj_inner.offsetHeight + "px";
	}

}

function loadingPopup() {
	var popup_iframe = false;
	if (window.parent) {
		var doc = window.parent.document;
	} else {
		var doc = document;
	}
	popup_iframe = doc.getElementById("popup_iframe");
	var dest_obj = doc.getElementById("popup_frame_center");
	var dest_obj_inner = doc.getElementById("popup_frame_center_inner");

	dest_obj.style.background = '#FFF url(/images/corporate/ajax-loader.gif) no-repeat center';
	if (popup_iframe)
		popup_iframe.style.display = "none";
}

function hidePopup() {
	if (window.parent) {
		var doc = window.parent.document;
	} else {
		var doc = document;
	}

	var dest_obj_inner = doc.getElementById("popup_frame_center_inner");

	doc.getElementById('popup').style.display = 'none';
	doc.getElementById('popup_bg').style.display = 'none';
	dest_obj_inner.innerHTML = "";
}

/* Dropdown Block Functions */
function chArchive(id) {
	chClassName('a_' + id, chDisplayStatus(id, 'sprite-tv minus sprite-tv_minus', 'sprite-tv plus sprite-tv_plus'));
}

function chDisplayStatus(id, trueValue, falseValue) {
	var obj = document.getElementById(id);
	
	if (obj.style.display == 'block') {
		obj.style.display = 'none';
		if (trueValue) {
			return falseValue
		} else {
			return false;
		}
	} else {
		obj.style.display = 'block';
		if (trueValue) {
			return trueValue
		} else {
			return true;
		}
	}
}

// SHOW HIDE METHOD FOR TV PROGRAMM
function CheckH() {
	
	var y = document.getElementById("RTv").clientHeight; // right side
	var c = document.getElementById("Cepy").clientHeight; // left side
	//alert("Left>"+c +"-"+y);
	if (y < c) {
		//var FromToT = FromTo + FromTo;
		
		try
		{
			
			var x = document.getElementById("DoBr").style.height = c + "px";
		}
		catch(err)
		{
			;
			//var x = document.getElementById("DoBr").style.height = 200 + "px";
			
		}
		
		
	}
;

	//alert('Left =' + c + '- Right'+ y + '='+ an)
//alert('--> right' + y);
	
} 


var openDiv = '';
function showHide(div,trueValue, falseValue) {
    var d = document.getElementById(div);
    var z = document.getElementById('2'+div); // left <td>
    var t = document.getElementById('3'+div);
    var m = document.getElementById('4'+div); // TvName
    var y = document.getElementById('5'+div); // tr left
    var r = document.getElementById('6'+div); // tr left
   
    if (d != 'undefined') {
        
    	if (div == openDiv) {
    		
    		
    		 var x = document.getElementById(openDiv);
             x.setAttribute("class", "TvT");
             
             z.setAttribute("class", "TvT");
           
    				m.setAttribute("class", "TvT");

    				t.setAttribute("class", "TvT");	
    				

    	                
    	            y.setAttribute("className", "_back");   
    	            y.setAttribute("class","_back"); 
    	            
    	            m.className='TvN';
    	            t.className='TvT'; // for any browser!!
    	            
    	                    	                
    	            r.setAttribute("className", "_back");   
    	            r.setAttribute("class","_back"); 
             
    			
    				d.style.display = (d.style.display == 'block' ? 'none' : 'block');
    				z.style.display = (z.style.display == 'block' ? 'none' : 'block');
    				
        				
    				if(d.style.display == 'block') {
    					
    					t.setAttribute("class", "TvTimeActive2"); 
    		            t.setAttribute("className", "TvTimeActive2"); 
    		           
    		            m.setAttribute("className", "TvTimeActive2"); 
    		            m.setAttribute("class", "TvTimeActive2"); 
    		            
    		            y.setAttribute("class", "back"); 
    		            y.setAttribute("className", "back"); 

    		            r.setAttribute("class", "backT"); 
    		            r.setAttribute("className", "backT");
    		          
    					
    		            
    				}
    				
    		
            // Same div clicked, no problem, code will handle show/hide below
             // No open divs
        } else 
        	{
            // Different div
            if (openDiv != '') {
                // Close the currently open div
                var x = document.getElementById(openDiv);
                x.setAttribute("class", "TvT");
                x.style.display = 'none';
               
                var x = document.getElementById('2'+openDiv);
                x.style.display = 'none';
                
                var x = document.getElementById('3'+openDiv); //hiddne time class
              
                x.setAttribute("className", "TvT");   
                x.setAttribute("class", "TvT"); 
                //  x.style.color="";
                
                var x = document.getElementById('4'+openDiv); //hiddne time class
                
                x.setAttribute("className", "TvN");   
                x.setAttribute("class", "TvN"); 
                
                var x = document.getElementById('5'+openDiv); //hiddne time class
                
                x.setAttribute("className", "_back");   
                x.setAttribute("class","_back"); 
                
                var x = document.getElementById('6'+openDiv); //hiddne time class
                
               x.setAttribute("className", "_back");   
               x.setAttribute("class","_back"); 
               
                               
                
            } 
            // Set the new div as the open div
            openDiv = div;
            d.style.display = (d.style.display == 'block' ? 'none' : 'block');
            z.style.display = (z.style.display == 'block' ? 'none' : 'block');
          
          
            
            // t.style.color="green";
            t.setAttribute("class", "TvTimeActive2"); 
            t.setAttribute("className", "TvTimeActive2"); 
           
            m.setAttribute("className", "TvTimeActive2"); 
            m.setAttribute("class", "TvTimeActive2"); 
            
            y.setAttribute("class", "back"); 
            y.setAttribute("className", "back"); 

            r.setAttribute("class", "backT"); 
            r.setAttribute("className", "backT");
           
        }
         
        
    }

 
}

function cStyles() {
	alert('da');
	div = document.getElementById("d1");

	t1 = document.getElementById("t1");
	h_style = document.defaultView.getComputedStyle(div, '').getPropertyValue("height");
	t1.setAttribute("value", h_style); 

	}

function OpenTvDiv(id, trueValue, falseValue) {

	for (i = 1; i <= 20; i++) { // so you can add more than 2
		var divname = id;

		var divstyle = document.getElementById(divname).style;
		divstyle.display = (id == divname) ? 'block' : 'none';
	}
}

function chClassName(id, className) {
	document.getElementById(id).className = className;
}

/* Galery Popup Window */
function popupGalery(galery_url) {
	window
			.open(
					galery_url,
					'GaleryPopup',
					'width=605,height=595,directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=no,addressbar=no');
}

/* Print Page Function */
function printCurrentPage() {
	var redir_url = "";
	// var query = window.location.search.substring(0);
	// var vars = query.split("&");

	var loc = new String(window.location);
	var ref = "";
	var params_key = Array();
	var params_val = Array();
	var sVarLine = "";

	if (loc.indexOf("?") != -1) {
		// alert("Params Founds");
		ref = String(loc.substring(0, loc.indexOf('?')));
		sVarLine = "&"
				+ String(loc.substring(loc.indexOf('?') + 1, loc.length));
		// alert("Params Found: " + sVarLine);
		// var uriParts = new
		// RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(loc);

	} else {
		ref = loc;
	}

	ref += "?print_page=yes" + sVarLine;

	// New Window Opener
	// window.open(ref,'GaleryPopup');

	// Current Window Opener
	window.location.replace(ref);
}
