//===================================================
	function openWin( windowURL, windowName, windowFeatures ) { 
		return window.open( windowURL, windowName, windowFeatures ) ; 
	}
//===================================================
	function smallwindow(str)
	{
		var leftVal = (screen.width-300) / 2;
		var topVal = (screen.height-200) / 2;
		
		newWindow = window.open( str, null, 'width=300,height=200,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0,top='+topVal+',left='+leftVal+'' );
		newWindow.focus();
	     	return false;
	}
//===================================================
	function smallwindow_sized(str,xwidth,xheight)
	{
		var leftVal = (screen.width-xwidth) / 2;
		var topVal = (screen.height-xheight) / 2;

		newWindow = window.open( str, null, 'width='+xwidth+',height='+xheight+',toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1,left='+leftVal+',top='+topVal+'' );
		newWindow.focus();
	     	return false;
	}
//===================================================
function IsNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

//transfer
function skok(kam)
	{
	 	location = kam;
	}

//onfocus input
function cistic(komu,original)
	{
	if (komu.value==original)
	 { 	komu.value=''; }
	}
	
//onblur input
function opravar(komu,co)
	{
		if (komu.value=='')
	 	 { komu.value=co; }
	 flip_class();
	}
	
//kontrola formulara main
function kontroluj_main(formularius)
	{
      if (formularius.nick.value=="meno")
	     {
		  alert("Musíš zadať meno !");
		  formularius.nick.focus();
		  return false;
		 }
	  else if (formularius.txt.value=="")
	    {
		 alert("Musíš zadať text k otazke");
		 formularius.txt.focus();
		 return false;
		}
	  else
	    {
	     return true;
		}
	}

//kontrola formulara quest	
function kontroluj_quest(formularius)
	{
      if (formularius.quest.value=="otazka")
	     {
		  alert("Musíš zadať nazov otazky !");
		  formularius.quest.focus();
		  return false;
		 }
      else if (formularius.nick.value=="meno")
	     {
		  alert("Musíš zadať meno !");
		  formularius.nick.focus();
		  return false;
		 }
	  else if (formularius.txt.value=="")
	    {
		 alert("Musíš zadať text k otazke");
		 formularius.txt.focus();
		 return false;
		}
	  else
	    {
	     return true;
		}
	}	
	
//flip farby v inputoch
function flip_class() 
{
		 var tab=document.getElementById('nick');
		 if (tab.value=='meno')
		  {tab.className='sform';}
		 else
		  {tab.className='sform_flip';}
		 tab=document.getElementById('email');
		 if (tab.value=='email')
		  {tab.className='sform';}
		 else
		  {tab.className='sform_flip';}
		 tab=document.getElementById('www');
		 if (tab.value=='www')
		  {tab.className='sform';}
		 else
		  {tab.className='sform_flip';}
}

//flip textu butonov aktivujucich scrolling
function flipbutton(nieco,text1,text2)
{
	if (nieco.value==text1)
	 { nieco.value=text2; }
	else
	 { nieco.value=text1; }
	 flip_class();
}

//podla kukis nastav pozadie (ak sa ti to podari:)
function dartbg_onload()
{
	var dartbg = GetCookie('dartbg');
	if (dartbg==null)
	 { SetCookie("dartbg",1);
	   flip_bg_online(1);
	 }
	else if (dartbg!=1)
	 { SetCookie("dartbg",dartbg);
	   flip_bg_online(dartbg);
	 }
}
//===================================================
	function myFill(name,value){
		var fox = document.getElementById(name)
		fox.value = value
	}
//===================================================
	function myGet(name){
		var fox = document.getElementById(name)
        if (fox.value==undefined){
            x="";
        }
		else if (fox.value==""){
            x="";
        }
		else{
            x=fox.value;
        }
		return x
	}
//===================================================
	function myGetX(name){
		var fox = document.getElementById(name)
		return fox
	}
//===================================================
	function flipcolor(obj)
	{
		var b=obj.className;
		if (b=="colflip1"){
		obj.className="colflip31";
		}else if(b=="colflip2"){
		obj.className="colflip32";
		}
		else if(b=="colflip32"){
		obj.className="colflip2";
		}
		else if(b=="colflip31"){
		obj.className="colflip1";
		}

		else if(b=="colflip1light"){
		obj.className="colflip2light";
		}
		else if(b=="colflip2light"){
		obj.className="colflip1light";
		}
	}
//===================================================
	function flipselected(obj){
		var b=obj.className;
		if (b=="colflip1"){
		obj.className="colflip71";
		}else if(b=="colflip2"){
		obj.className="colflip72";
		}
		else if(b=="colflip32"){
		obj.className="colflip72";
		}
		else if(b=="colflip31"){
		obj.className="colflip71";
		}
		else if(b=="colflip72"){
		obj.className="colflip32";
		}
		else if(b=="colflip71"){
		obj.className="colflip31";
		}
	}
//===================================================
	function flipcolor_menu_old(obj)
	{
		var b=obj.className;
		if (b=="menu_in"){
		obj.className="menu_out";
		}else if(b=="menu_out"){
		obj.className="menu_in";
		}
	}
//===================================================
    function flip_menu(obj){
      //alert(obj.style.backgroundImage)
        var b=obj.className;
        if (b=="mmenu_off"){
            obj.className="mmenu_on";
        }else if(b=="mmenu_on"){
            obj.className="mmenu_off";
        }else if(b=="mmenu_sel"){
            obj.className="mmenu_unsel";
        }else if (b=="smenu_off"){
            obj.className="smenu_on";
        }else if(b=="smenu_on"){
            obj.className="smenu_off";
        }

    }
//===================================================
    function form_check_registration(obj){
	
	 DisableAllInput(false);
//&& myGet("txt_registration_type")!=1
     if (myGet("txt_loginr")=="" ){
    		alert("Login je povinny");
    		myGetX("txt_loginr").focus();
    		return false;
    	}
      else if (myGet("txt_passwordr")=="")
        {
    	 alert("Heslo je povinne");
   		 myGetX("txt_passwordr").focus();
    	 return false;
    	}
      else if (myGet("txt_passwordr")!=myGet("txt_password2"))
        {
    	 alert("Heslo je nespravne ! Prosim napiste heslo znova.");
    	 myGetX("txt_password2").focus();
    	 return false;
    	}
		/*
      else if (myGet("txt_name")=="")
        {
    	 alert("Name is required.");
    	 myGetX("txt_name").focus();
    	 return false;
    	}
		*/
		/*
      else if (myGet("txt_tel")=="" && myGet("txt_mobil")=="")
        {
    	 alert("Phone or Mobile is required.");
    	 myGetX("txt_mobil").focus();
    	 return false;
    	}
		*/
      else{
    	return true;
    	}
    }
//............................................... Cookies management
function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}

function SetCookie (name, value) {  
var DartExpDays = 30;
var DartExp = new Date(); 
DartExp.setTime(DartExp.getTime() + (DartExpDays*24*60*60*1000));

var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var expires=DartExp; //add by dart
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}

function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
//===================================================
	function DisableAllInput(xdisable){
		var xDoc = document.body.getElementsByTagName("input");
		var xSel = document.body.getElementsByTagName("select");
		var i=0
		var s=""
		//disable all textbox, checkbox
		for (i=0;i<xDoc.length;i++){
			if (xDoc.item(i).getAttribute("type") != "submit"){
				xDoc.item(i).disabled=xdisable;
			}
		}
		//disable all select
		for (i=0;i<xSel.length;i++){
				xSel.item(i).disabled=xdisable;
		}
		return true
	}

//======================================================
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
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 "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

//======================================================
function MakeZebraCalculation(row_actual, col_max, row_max){
	var crc_val=0
	var arr = new Array()
	var str_res=""

	for (i=1;i<=col_max;i++){
		crc_val=crc_val+parseInt(myGet("cbo_"+row_actual+"_"+i));
	}
	myFill("txt_crc_"+row_actual,crc_val);
	for (j=0;j<row_max;j++) arr[j]=myGet("txt_crc_"+(j+1));
	arr.sort();
	myFill("txt_answer",arr.join(""));
	
}
//======================================================
function MakeChkCalculation(){
	var str_res=""

	for (i=1;i<=25;i++){
		if (myGetX("chk_interactive_"+i).checked==true){
			str_res=str_res+"1";
		}else{
			str_res=str_res+"0";
		}
	}

	//myFill("txt_answer",str_res);
	myFill("txt_answer",bin2dec(str_res));
	return true;
}
//======================================================
function MakeNumbQCalculation(){
	var str_res=""
	var InteractiveId=myGet("txt_numbq_InteractiveId")

	for (i=1;i<=InteractiveId;i++){
		str_res=str_res+myGet("txt_numbq_"+i);
	}

	myFill("txt_answer",str_res);
}
//======================================================
// BINARY TO DECIMAL CONVERTER FUNCTION 
function bin2dec(init) {
var power = init.length;
var output = 0;
for (i=0;i<=power;i++)
	{if(init.charAt(i) == 0)
	 {var preout = 0;}
	else
	 {var xty = power - i - 1;
	  var preout = Math.pow(2, xty);
	 }
	var output = output+preout; 
	}
return output;
}
//======================================================
// DECIMAL TO BINARY CONVERTER FUNCTION -->
function dec2bin(nub) {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;
   if (nub.length == 0) alert("Input is Blank");
   for (i = 0; i < nub.length && blnResult == true; i++)
      {
      strChar = nub.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
	if (blnResult != false) 
	{
		var i;
		var j;
		var result="";
		var ib;
		while (nub != 1)
			{
				j = nub % 2;
				i = (nub - j) / 2
				nub = i;
				ib = j.toString();
				result = ib + result;
			}
		result = "1" + result;
		return result;
	}
	return "Numbers Only"
}
//======================================================
function SwapTabs(newTab,oldTab) {
	if (document.getElementById)
	{
		document.getElementById(newTab).style.display = "inline";
		document.getElementById(oldTab).style.display = "none";
		return false;
	}
	else if (document.all)
	{
		document.all[oldTab].style.display = "none";
		document.all[newTab].style.display = "inline";
		return false;
	}
	else {
		return true;
	}
}
//======================================================
function myShowHide(objID,show){
		var objCT=myGetX(objID);
		
		show = typeof(show) != 'undefined' ? show : -1;
		
		if (show==-1){
			if (objCT.style.display==""){
				objCT.style.display="none";
			}else{
				objCT.style.display="";
			}
		}else if(show==1){
			objCT.style.display="";
		}else{
			objCT.style.display="none";
		}
}

//======================================================
//	Ajax - functions
//======================================================
	function send_xmlhttprequest(myfunction, method, url, idDiv,content) {

		if( !window.XMLHttpRequest ) XMLHttpRequest = function(){
		  try{ return new ActiveXObject("MSXML3.XMLHTTP") }catch(e){}
		  try{ return new ActiveXObject("MSXML2.XMLHTTP.3.0") }catch(e){}
		  try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
		  try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
		  throw new Error("Could not find an XMLHttpRequest alternative.")
		};
		var xmlhttp = new XMLHttpRequest
		
	    if (!xmlhttp) {
	        return false;
	    }

			xmlhttp.open(method, url);
			xmlhttp.onreadystatechange = function() {
				myfunction(xmlhttp,idDiv);
			};
		
		xmlhttp.setRequestHeader("Content-type", "text/plain; charset=UTF-8");
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	    xmlhttp.send(content);
	    return true;
	}
//======================================================
	function ajax_url_send(url,idDiv) {
		
	    if (!send_xmlhttprequest(ajax_url_management, 'GET', url,idDiv)) {
	        return false;
	    }
	    return true;
	}
//======================================================
	function ajax_url_management(xmlhttp,idDiv) {
	    if (xmlhttp.readyState == 4) {
			var response = xmlhttp.responseText;
			document.getElementById(idDiv).innerHTML = response;
			
			if(typeof window.myAjaxReturn == 'function') {
				// function exists, so we can now call it
				myAjaxReturn(response);
			}
	    }
	}
//======================================================
// Base64 code from Tyler Akins -- http://rumkin.com
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}
//======================================================
function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}
//===================================================
	function openFormInNewWindow(frm, wname){
		var leftVal = (screen.width-300) / 2;
		var topVal = (screen.height-200) / 2;
		
		var aWindow = window.open( '', wname, 'width=300,height=200,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0,top='+topVal+',left='+leftVal+'' );
		if (!aWindow.opener) aWindow.opener = self;

		frm.target = wname;
		frm.submit();
	}