/******************************************************************************/
/* Moodul: unetmenu_IE4.js                                                    */
/* Autor: Ilhan Nisamedtinov                              */
/* Funktsionaalsus:                                   */
/*                  Unet3 IE4 brauser versioonis kasutatavad navigeerimis     */
/*                  skriptid.                             */
/* Alustatud: 06/09/2001                              */
/******************************************************************************/

var tabFlag=1, triggerFlag=1;
var browserIE=1; // IE JS DOM
var topWinObj=window;
var fileDownloadCheckTimer;

if(navigator.appName=='Netscape' || navigator.appName=='Opera' || navigator.appName=='Konqueror') browserIE=0;

if(topWinObj.opener) topWinObj=topWinObj.opener;
if(topWinObj.parent) topWinObj=topWinObj.parent;
if(topWinObj.top)    topWinObj=topWinObj.top;
                     
function un3FireEvent(eventObj, eventName){
  var tmpStr;
  
  if(!eventObj)
    return false;
    
  tmpStr = eventObj.getAttribute(eventName);
      
  if(!tmpStr || tmpStr.toString()=='')
    return false;

  return eval(tmpStr.toString().replace("function anonymous()","").replace("{","").replace("}",""));
          
}
          
function getInnerHTML(objID, frameObj){
 
 if(!frameObj)
   frameObj=window;
   
 if(browserIE){
   if(arguments[2]){
     if(frameObj.document.all(objID).tagName=='SPAN')
        frameObj.document.all(objID).innerHTML = arguments[2];
     else
        frameObj.document.all(objID).text = arguments[2];
   }
   else          
     return frameObj.document.all(objID).innerHTML;
 }
 else{
   if(arguments[2])
     frameObj.document.getElementById(objID).innerHTML = arguments[2];
   else      
     return frameObj.document.getElementById(objID).innerHTML;
 }
}

function getDOMObj(objID){
 
 var frameObj;
  
 if(!arguments[1])
   frameObj=window;
 else
   frameObj=arguments[1];
     
 if(browserIE)
   return eval("frameObj.document.all." + objID);
 else{
   if(frameObj.document.getElementsByName(objID).length<2)
     return frameObj.document.getElementById(objID);
   else 
     frameObj.document.getElementsByName(objID);        
 }  
}    

function tabTriggerPress(e)
{   
if(!browserIE || navigator.appVersion.indexOf('Macintosh') )
    {
    var eName;
    if(browserIE)
    {
        e = event;
        eName = e.srcElement;
    }
    else
    {
        eName = e.target;
    }
    
    var inpKey = e.keyCode ? e.keyCode :
            e.keyChar ? e.keyChar :
            e.which ? e.which : void 0;

    
    if(inpKey==13 || inpKey==3)
        {
              if ((eName.tagName=="INPUT" && 
                   eName.type!="textarea" &&
                   eName.type!="button" &&
                   eName.id!="searchid001") ||
                   eName.tagName=="SELECT" ) {
                focusNext(eName);

                return false;}
            else return true;
        }
    else 
        return true;
    }
}

function tabTrigger(e){
    
    var eName;
    if(browserIE)
    {
        e = event;
        eName = e.srcElement;
    }
    else
    {
        eName = e.target;
    }
    var inpKey = e.keyCode ? e.keyCode :
            e.keyChar ? e.keyChar :
            e.which ? e.which : void 0;
    
    if(eName.name=="buttonA"){
     eName.click();
     return true;
   }

   if(inpKey==9){
     tabFlag = 1;
     return true;
   }
   if(inpKey!=13 && inpKey!=10)
      return true;

   if(eName.tagName!="INPUT")
      return true;

   if(eName.type=="textarea"||eName.type=="radio"||eName.type=="checkbox") 
      return true;

    if (eName.id=="searchid001")
       return true;
    
    if (eName.type=="button")
       return true;

    if (browserIE) e.keyCode = 9;                 

    tabFlag = 0;
    return true;        
    
}


function matchElement(param) {
   if (param.form == null)
       return -1;
   for (i = 0; i < param.form.length; i++)
      if (param.form.elements[i].name == param.name) return i;
   return -1;
}

function nextFocusable(param, i) {
   if (i < (param.length - 1)) i += 1; else return -1;
   for (j = i; j < param.length; j++)
      if (param.elements[j].type != "hidden") return j;
   return -1;
}

function focusNext(param) { 
    var tmp;
    i = matchElement(param); 
    if (i != -1) {
       i = nextFocusable(param.form, i);
    
       if (i != -1) param.form.elements[i].focus();
       else {
           tmp = getDOMObj("buttonA");
           if (tmp) tmp.focus();
       }
   }
}

                  
function showSelects(isOn) {

  var divs = getDOMObj("selectdiv");
 
  if(divs){
    
    if(divs.length>0) {
       for(i=0;i<divs.length;i++) {
          divs(i).style.visibility = isOn ? "visible" : "hidden";         
       }
    }
    else {           
        divs.style.visibility = isOn ? "visible" : "hidden";               
     }
                
  }
}  

function Unet_MenuCallSession(actURL,actpar,acttar, lockStatus, e){
	Unet_MenuCall(actURL, actpar + '&sesskey='+document.sessionData.sesskey.value+'&lang='+document.sessionData.unetlanguage.value+'&unetmenuhigh='+document.sessionData.unetmenuhigh.value ,acttar, lockStatus, e);
}

function Unet_MenuCall(actURL,actpar,acttar, lockStatus, e){


 var actlock=document.sessionData.unetmenulock.value;  
 var defURL=document.sessionData.unetURL.value; 

 var customHref = $('a[customHref]').attr('customHref');
 
 if (customHref && actpar.indexOf("act=REMOTEADVISORY") > -1){
   var additionalParams = "&name=" + $('#fname').val() + "&surname=" + $('#lname').val()  + 
   					      "&cif=" + $('#cif').val() + "&register_code=" + $('#idcode').val() + 
   					      "&from=" + $('#domain').val() + "&method=" + $('#method').val() + 
   					      "&documentNumber=" + $('#documentNumber').val() + "&phoneNumber=" + $('#phoneNumber').val(); 
   window.open("?" + actpar + additionalParams);
   return false;
 }
 if (actURL==''&&actpar==''&&acttar=='') 
    return false;

 if((parseInt(lockStatus) && actlock==actpar && (actURL != '' || actURL != defURL ))) {
	return false;	 
    // Warn-message removed 
 }
 actlock=(actURL=='')?defURL:actURL;

 if(actlock==defURL || actlock.substring(0,1)=='/'){  
    
	if (actpar.indexOf("sesskey") ==-1) 
		 actlock += '?sesskey=' + document.sessionData.unetsesskey.value;
	else actlock += '?';
	
	if (actlock.substring(0,1)=='/' && actpar.indexOf("authtype") ==-1 && typeof goPopUp!=='undefined' && typeof goPopUp.sAuthType!=='undefined') 
		 actlock += ((actlock.substring(actlock.length - 1) == '?') ? '' : '&') + 'authtype=' + goPopUp.sAuthType;
	
    if ($('#ssoid').val()){
        actlock += ((actlock.substring(actlock.length - 1) == '?') ? '' : '&') + 'ssoid='+ $('#ssoid').val() + "&" + "firstName=" + $('#fname').val() + "&" + "lastName=" + $('#lname').val() + "&" + "idcode=" + $('#idcode').val();
    }
    if(actpar.indexOf("&lang=") == -1)
        actlock += ((actlock.substring(actlock.length - 1) == '?') ? '' : '&') + 'lang='+ document.sessionData.unetlanguage.value;

     if((actpar+"X")!="X")
        actlock += ((actlock.substring(actlock.length - 1) == '?') ? '' : '&') + actpar;
     
     if (typeof document.sessionData.contentonly !=='undefined' && document.sessionData.contentonly.value == 'true') {
         if((actpar+"X")!="X" ) 
             actlock += ((actlock.substring(actlock.length - 1) == '?') ? '' : '&') + 'contentonly=1'; 
     }
    // menuprefix
    if(document.sessionData && actpar.indexOf("frnam")==-1)
       if(document.sessionData.frnam)
         if(document.sessionData.frnam.value!='')
        actlock+=("&frnam=" + document.sessionData.frnam.value);
    
    /* HFK Menustate fields */
    if (actpar.indexOf("unetmenuhigh") ==-1)
    	actlock+=("&unetmenuhigh=" + document.sessionData.unetmenuhigh.value);
    

    if (typeof document.sessionData.basePath !== "undefined") 
    	actlock = document.sessionData.basePath.value + actlock ;
    
    
    if((acttar+"X")=="X"||acttar=="main"){

       if(parseInt(lockStatus))
          document.sessionData.unetmenulock.value=actpar;
                     
       window.location.href=actlock;              
       
    }
    else { 
    		if (acttar.substring(0,4)=='tab_')
    			window.open(actlock , acttar );
    		else 
    			window.open(actlock , acttar , "height=600,left=37,top=10;width=800,scrollbars=1,resizable=1");
         }
  
  }
  else{
  
     defURL = document.sessionData.unetOldURLs.value;
     
     if(defURL.indexOf(actlock)!=-1){

    	 defURL = document.sessionData.unetsesskey.value;    
    	 
    	 if (actlock.indexOf("sesskey") ==-1)  
    		 actlock+=("?sesskey=" + defURL);
    
        if(actpar!='')
           actlock+=("&"+actpar);

        topWinObj.location.replace(actlock);
        
     }
     else{ 
        if(acttar + "X" != 'X'){

          if(acttar=='_top') {
         topWinObj.location.href=actlock;
        }     
        else 
         window.open(actlock + (actpar+"X"=="X"?"":"?"+actpar) , acttar);
 
        }
        else{
 
       window.open(actlock + (actpar+"X"=="X"?"":"?"+actpar),"UnetLisa");
 
      }
     }
  }
}

function Unet_FormSubmitOnClick(formName, actURL, actParam, actTarget, lockStatus, e) {
	if(triggerFlag) { 
		triggerFlag=0;
		Unet_FormSubmit(formName, actURL, actParam, actTarget, lockStatus, e);
	}
	if(typeof(FP)!='undefined' && FP && FP.loadtext && FP.loadtext>'')
		showLoader(FP.loadtext);
	return false;	
}

function Unet_FormSubmitOnFocus(formName, actURL, actParam, actTarget, lockStatus, e) {
	if(!tabFlag) { 
		tabFlag=1;
		Unet_FormSubmit(formName, actURL, actParam, actTarget, lockStatus, e);
		triggerFlag=0;
	}
	if(typeof(FP)!='undefined' && FP && FP.loadtext && FP.loadtext>'')
		showLoader(FP.loadtext);
	return false;	
}

function Unet_FormSubmit(formName, actURL, actParam, actTarget, lockStatus, e) {
   var IsLocked = document.sessionData.unetmenulock.value;
   var formObj;

   /* Kui menyy on juba lukus ja valitud valik ei lukusta, */
   /* siis k2ivitub ylekysimine                            */
   
   /* Keerame lukustuse maha (v.a. LOGIN2) */
   
   if(actParam!='LOGIN2')
      IsLocked = 'none';
   
   if(IsLocked != 'none' && !parseInt(lockStatus)) {
      
      // Warn-message and return removed
      // return true;
      
   }
   
   /* Kui "lukustust" pole */

   if(IsLocked == 'none') {      
      
      if(formName!='')
         formObj = document.forms[formName];
    
      /* Kui vastava nimeline vorm dokumendil puudub */
         
      if(!formObj)      
         return false;

      /*For checking confirmatin checkbox*/
      if (!confirmed())
    	  return false;

      /* HFK --> Menustate --> */
      
      if(formObj.unetmenuhigh)
         formObj.unetmenuhigh.value = document.sessionData.unetmenuhigh.value;
     
      /* <-- */        

      /* Vormi sihi m22ramine */
      
      if(actURL == '') 
           actURL = document.sessionData.unetURL.value;       
      
      formObj.action = actURL;
      
      /* Sessiooniv6tme integreerimine andmefreimist */
      
      if(formObj.sesskey && document.sessionData.unetsesskey.value != '') 
         formObj.sesskey.value = document.sessionData.unetsesskey.value;
       
      // Aktsepteeringu sihtpunkti ("form.target") m22ramine
              
      if(actTarget != 'main' && actTarget != ''){
        window.open("", actTarget);          
      }

      formObj.target= actTarget;

      /* Kui valik lukustab menyy (lockStatus = 1) */
      
      if(parseInt(lockStatus))  
         document.sessionData.unetmenulock.value="lock"; 
      
      if(formObj.act && actParam != '') {
         if(actParam.indexOf("&task=") > 0) {
            var input = formObj["task"];
            if(typeof input === 'undefined'||input.tagName.toLowerCase() !== 'input') {
               input = document.createElement("input");
               input.name = "task";
               input.type = "hidden";
               formObj.appendChild(input);
            }
            var newAct = actParam.substring(0, actParam.indexOf("&task="));
            formObj.act.value = newAct;
            var newTask = actParam.substring(actParam.indexOf("&task=") + 6);
            input.value = newTask;
         } else {
            formObj.act.value = actParam;
         };
      };
        
      if(formObj.act&&actParam=='LOGIN1')
      {
     
        if(formObj.uposcontainer&&formObj.certifiedpath&&formObj.uncertifiedpath){
     
             var i=0;
         
         while(formObj.uposcontainer[i]&&!formObj.uposcontainer[i].checked){
        i++;
         }
                    
         if(formObj.cert&&formObj.cert.checked)
             formObj.action=formObj.certifiedpath.value + formObj.uposcontainer[i].value;
         else
         formObj.action=formObj.uncertifiedpath.value + formObj.uposcontainer[i].value;
                                        
        }
        else{
    
          if(formObj.cert&&formObj.cert.checked)
         formObj.action=document.forms["sessionData"].certifiedurl.value;
          else
         formObj.action=document.forms["sessionData"].uncertifiedurl.value;
         
    }
          
    formObj.submit();
    
      }
    
  else {
        formObj.submit();      
  }
   }
   else{                         // LOCKED

     return true;
   }
   
}

       
 
function Unet_LulluCall(pars,xPos,yPos,wwidth,wheight){

   var urlStr, styleStr, lulluWin;

   urlStr = document.sessionData.unetURL.value + '?sesskey=' + document.sessionData.unetsesskey.value + "&aken=NONSESSION&" + pars;

   if(isNaN(parseInt(xPos)))
      xPos=100; 

   if(isNaN(parseInt(yPos)))
      yPos=100; 

   if(isNaN(parseInt(wheight)))
      wheight=600; 

   if(isNaN(parseInt(wwidth)))
      wwidth=600; 

   styleStr = "scrollbars=yes,resizable=yes,location=no,menubar=no,toolbar=no,screenX=" + xPos.toString() + ",screenY=" + yPos.toString() + ",width=" + wwidth.toString() + ",height=" + wheight.toString(); 

   var token = "finished";
   $.removeIbCookie("fileDownloadToken");

   fileDownloadCheckTimer = window.setInterval(function () {
	   var cookieValue = $.IbCookie('fileDownloadToken');
	   if (cookieValue == token)
		   finishDownload();
    }, 1000);
    tb_show('', urlStr + '#TB_iframe?width='+ wwidth + '&height=' + wheight + '&autoscale=1');
   
}

function Unet_ExtLulluCall(pars,xPos,yPos,wwidth,wheight, ext){

       if (ext=="") ext = 'pdf';    
       var urlStr, styleStr, lulluWin;
       var urlArray = (document.sessionData.unetURL.value).toString().split(".");
       var urlBegin = urlArray[0];
       
       urlStr = urlBegin + "." + ext + '?sesskey=' + document.sessionData.unetsesskey.value + "&aken=NONSESSION&" + pars;

       if(isNaN(parseInt(xPos)))
          xPos=100; 

       if(isNaN(parseInt(yPos)))
          yPos=100; 

       if(isNaN(parseInt(wheight)))
          wheight=600; 

       if(isNaN(parseInt(wwidth)))
          wwidth=600; 

       styleStr = "scrollbars=yes,resizable=yes,location=no,menubar=no,toolbar=no,screenX=" + xPos.toString() + ",screenY=" + yPos.toString() + ",width=" + wwidth.toString() + ",height=" + wheight.toString(); 

       var token = "finished";
	    $.removeIbCookie("fileDownloadToken");
	    
       fileDownloadCheckTimer = window.setInterval(function () {
         var cookieValue = $.IbCookie('fileDownloadToken');
         if (cookieValue == token)
          finishDownload();
       }, 1000);
       tb_show('', urlStr + '#TB_iframe?width='+ wwidth + '&height=' + wheight + '&autoscale=1');
    }

function finishDownload() {
	 window.clearInterval(fileDownloadCheckTimer);
	    $.removeIbCookie("fileDownloadToken");

	 tb_remove();
	 //alert("Download finished");
	}

function Unet_pdfCall(pars){

   var urlArray = (document.sessionData.unetURL.value).toString().split(".");
   var urlBegin = urlArray[0];
    
    
   var urlStr =  urlBegin + ".pdf" + '?sesskey=' + document.sessionData.unetsesskey.value + "&" + pars;
   window.location.href = urlStr;

}

function hideLullu(){

   window.close();

}

function changeSel (selObj, cVal) {
    var ind=0;

    if(typeof(selObj)=='undefined'||!selObj.options)
    return true;

    if(cVal=='')selObj.options[0].selected=true;
 
    else {
        
        while(1){
            if(selObj.options[ind].value== cVal){
            selObj.options[ind].selected=true;
            break; 
            }
            ind++;
            if(ind>=selObj.options.length)
              break;
        };

    };
};

//paneb püsti linnukese, kas on hetkel käimasolevaid ajax päringuid
global_ajaxeventrunning=false,
global_ajaxstack=[];
$('html').bind('ajaxStart',function() {
	global_ajaxeventrunning=true;
}).bind('ajaxStop',function() {
	var stack;
	if (global_ajaxstack.length > 0) {
		stack = global_ajaxstack.shift();
		global_ajaxeventrunning=false;
		stack[0].apply(stack[1],stack[2]);
		delete stack;
	} else {
		global_ajaxeventrunning=false;
	}
});

function Unet_ajaxget(cTarget, cCheckExists,  cParams, cFunction,cTableLoaderElem){
	if (global_ajaxeventrunning) { //kui on teisi hetkel käimasolevaid ajaxpäringuid, siis tehakse antud päring hiljem - ainult üks ajax päring paralleelselt (sessiooni aegumisel välja lendamise välistamine ajax päringu puhul)
        global_ajaxstack.push([Unet_ajaxget,this,[cTarget,cCheckExists,cParams,cFunction,cTableLoaderElem]]);
		return;
	}
	
    if (typeof(cCheckExists)=='string'&&cCheckExists != '' && cTarget!='json' ) {
        var element = $(cCheckExists)[0];
        if( element ) return;
    }
    
    var cTarget2 = "";  
    var cTargets = cTarget.split(',');
    var cTarget1 = cTargets[0];
    if (cTargets.length > 1)
    cTarget2 = cTargets[1];
    var vars = {}, hash;
    if( cParams.indexOf('ajax_target') < 0 )
        vars.ajax_target = cTarget;
    //vars.sesskey = document.sessionData.sesskey.value;
	vars.sesskey = (document.sessionData.sesskey) ? document.sessionData.sesskey.value : document.sessionData[0].sesskey.value;
    var hashes = cParams.split('#');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        if (hash[0]!=''){
        	for (var j=1; j<hash.length; j++) {
        		vars[hash[0]] = (!vars[hash[0]] ? '' : vars[hash[0]] + '=') + hash[j];
        	}
        }
    }
  /*
  if($(cTarget).is('span'))$(cTarget).html('<span class="loader05">...</span>');
  else $(cTarget).html('<div class="loader02"><span>...</span></div>');
  */
  $(cTarget).html('<div class="loading02"><p>' + locales.simpleloader + '</p></div>');

    
  var cUrl = "?";
  if (UserSetupArray[8]!=undefined) cUrl = UserSetupArray[8];

  $.post(cUrl,
    vars ,   
    function(html){ 
	    if (html.substr(html.length-1)=='$'&&html.indexOf('id="loginpage"')===-1) { //sessioonivõtmete vahetamine lehel
			var sesskeystart = html.lastIndexOf('$',html.length-2),
			    newsesskey = html.substring(sesskeystart+1,html.length-1),
			    html=html.substring(0,sesskeystart),
			    links=$('a[href*="sesskey="],a[onclick*="sesskey="]'),
				forms=$('form[action*="sesskey="]'),
				imgs=$('img[src*="sesskey="]'),
				img,
				src,
				form,
			    href,
				action,
			    link,
			    i = links.length,
			    oldsesskey=document.forms.sessionData.sesskey.value;
			while(i) { //vahetame linkides, nii hrefis kui ka clickis
			    i--;
			    link=$(links[i]);
			    href=link.attr('href').replace(oldsesskey,newsesskey);
			    link.attr('href',href);
			}
			i = forms.length;
			while(i) { //vahetame formi actionites
                i--;
                form=$(forms[i]);
                action=form.attr('action').replace(oldsesskey,newsesskey);
                form.attr('action',action);
            }
			i = imgs.length;
            while(i) { //vahetame piltide src-des, võibolla ebavajalik
                i--;
                img=$(imgs[i]);
                src=img.attr('src').replace(oldsesskey,newsesskey);
                img.attr('src',src);
            }
			$('input[value="'+oldsesskey+'"]').val(newsesskey); //vahetame input väljades
			//usearch.initParams();
			usearch.sesskey=newsesskey; //vahetame otsingus
			if (document.sessionData.sesskey) //vahetame sessionData vormil
			     document.sessionData.sesskey.value=newsesskey;
		    else
			     document.sessionData[0].sesskey.value=newsesskey;
				 
            if (document.sessionData.unetsesskey) //vahetame sessionData vormil, võibolla ebavajalik
                 document.sessionData.unetsesskey.value=newsesskey;
            else
                 document.sessionData[0].unetsesskey.value=newsesskey;				 
			//updateSesskeyInVariables(window,oldsesskey,newsesskey);
			$('#searchid001').setOptions({'url':usearch.makeSearchURL("sact=getsuggestion")}); //vahetame otsingus
		}
        if( html.indexOf('timeout_page') >= 0 ) {
            var element = $('#timeout_page');
            if (element.length===0) {
                $('#messages').append(html);
                tb_show("", "#TB_inline?height=300&width=600&inlineId=timeout_page&modal=true", null);
            }
        }
        else if( html.indexOf('id="loginpage"') >= 0 ) {
            $('html').html(html); 
            }
        else {  
            if (cTarget1!='') { 
                if (cTarget1=='json') {
                   if (typeof(cCheckExists)=='string'&&cCheckExists=='')
                   {
                       
                       try {
                           
                           var jObj = $.parseJSON(html);
                           
                           if (jObj&&jObj.length>0) {
                                for(var i = 0; i<jObj.length; i++) {
                                    jCurr = jObj[i];
                                    switch (jCurr.type) {
                                        case "func":
                                            eval(jCurr.data);
                                            break;
                                        default:
                                    
                                            break;
                                    }
                                
                                }   
                           }
                       
                       } catch (err) {
                           alert(err);
                       }

                    }
                    else { 
                       var obj;
                       try {
                           obj=eval(html);
                       } catch (err) {
                           obj=html;
                       }
                       cCheckExists(obj);
                    }      
                }   
                else {  
                    $(cTarget1).html(html);  
                    if (!cTableLoaderElem) {
                      initContent($(cTarget1));
                      //$(document).trigger('respondUpdate');
                    }
                }
                //$('.showtooltip').tooltip(); 
            }
            if (cTarget2!='')  {
                $(cTarget2).html(html); 
                if (!cTableLoaderElem) {
                  initContent($(cTarget2));
                  //$(document).trigger('respondUpdate');
                }
            }
        }
        if (typeof cFunction == 'function') {
       		 cFunction(html);
        }	
        if (cTableLoaderElem) {
        	$(cTableLoaderElem).trigger('customeventDone');
        }
    }
  ); 
 
 }


/*
    usearch.initParams();

    // Search autocomplete
    var tempsearch=$('#searchid001');
    if (tempsearch.length > 0) {
        tempsearch.autocomplete(usearch.makeSearchURL("sact=getsuggestion"), {
            max: 10,
            resultsClass: 'ac_results ac_results2',
            attachto: 'DIV.a',
            matchContains: true,
            minChars: 0,
            cacheLength: 0,
            scroll: false
        }).result(function(event, data, formatted){
            usearch.doSearch();
        });
    }
*/
    // special offers removal function
    function removeItem03(t){
        $('LI.item',$(t).parents('UL.offers02')[0]).addClass('first');
        if($('LI.item',$(t).parents('UL.offers02')[0]).length > 1){
            $(t).remove();
        } else {
            if ( $($(t).parents('DIV.block01')).length > 0 ){
                $($(t).parents('DIV.block01')[0]).remove();
            } else {
                $($(t).parents('UL.offers02')[0]).remove();
            }
        }
    }



 function sumToNationalDec(number,len){
     number = number.toString().replace(new RegExp(" ","g"),"").valueOf();
     var sumStr = "";
     if (!isNaN(number)&&!isNaN(len)) {
         number = new Number(number);
         var sumStr = number.toFixed(len).toString();
         var sumStrArray = sumStr.split(".");
         var sumBegin = sumStrArray[0];
         var sumEnd = sumStrArray[1];
         var formatType = document.sessionData.sessnum.value;
         switch(formatType){
            case "1":
                sumStr = sumBegin + ".";
                break;
            case "2":
                sumStr = sumBegin + ",";
                break;
            case "3":
                sumBegin = thousandSeparator(sumBegin," ");
                sumStr = sumBegin + ".";
                break;
            case "4":
                sumBegin = thousandSeparator(sumBegin," ");
                sumStr = sumBegin + ",";
                break;
            case "5":
                sumBegin = thousandSeparator(sumBegin);
                sumStr = sumBegin + ".";
                break;
            case "6":
                sumBegin = thousandSeparator(sumBegin,".");
                sumStr = sumBegin + ",";
                break;
            case "7":
                sumBegin = thousandSeparator(sumBegin,"'");
                sumStr = sumBegin + ".";
                break;
            case "8":
                sumBegin = thousandSeparator(sumBegin,"'");
                sumStr = sumBegin + ",";
                break;
         }
         if (typeof(sumEnd)=="undefined")
             sumStr=sumStr.substring(0,sumStr.length-1);
         else
             sumStr+=sumEnd;
     }
     return sumStr;
}
 function thousandSeparator(n,sep) {
     var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
     sValue=n;
     if (sep === undefined) {sep=',';}
     while(sRegExp.test(sValue)) {
         sValue = sValue.replace(sRegExp, '$1'+sep+'$2');
     }
     return sValue; 
}

function dateToNationalStr(date){
    
    
    
    
    var dateStr = "";
    
    if (typeof(date)!='string')
        return dateStr;
        
    var datestrArray = date.split(".");
    if (datestrArray.length==1) {
        date=date.substr(6,2)+"."+date.substr(4,2)+"."+date.substr(0,4);
        datestrArray = date.split(".");
    }
    if (datestrArray[0].length == 1) datestrArray[0] = "0" + datestrArray[0];
    if (datestrArray[1].length == 1) datestrArray[1] = "0" + datestrArray[1];
    
    if (datestrArray.length==3&&datestrArray[2].length==4) {
        var formatType = document.sessionData.sessdate.value;
        switch(formatType){
        case "1":
            dateStr = datestrArray[0] + "." + datestrArray[1] + "." + datestrArray[2]; /*DD.MM.YYYY*/
            break;
        case "2":
            dateStr = datestrArray[0] + "/" + datestrArray[1] + "/" + datestrArray[2]; /*DD/MM/YYYY*/
            break;
        case "3":
            dateStr = datestrArray[0] + "-" + datestrArray[1] + "-" + datestrArray[2]; /*DD-MM-YYYY*/
            break;
        case "4":
            dateStr = datestrArray[2] + "." + datestrArray[1] + "." + datestrArray[0]; /*YYYY.MM.DD*/
            break;
        case "5":
            dateStr = datestrArray[2] + "/" + datestrArray[1] + "/" + datestrArray[0]; /*YYYY/MM/DD*/
            break;
        case "6":
            dateStr = datestrArray[2] + "-" + datestrArray[1] + "-" + datestrArray[0]; /*YYYY-MM-DD*/
            break;
        case "8":
            dateStr = datestrArray[1] + "/" + datestrArray[0] + "/" + datestrArray[2]; /*MM/DD/YYYY*/
            break;
        case "11":
            dateStr = datestrArray[0] + "." + datestrArray[1] + "." + datestrArray[2].substr(2); /*DD.MM.YY*/
            break;
        case "12":
            dateStr = datestrArray[0] + "/" + datestrArray[1] + "/" + datestrArray[2].substr(2); /*DD/MM/YY*/
            break;
        case "20":
            dateStr = datestrArray[2] + " " + datestrArray[1] + " " + datestrArray[0]; /*YYYY MM DD*/
            break;
        }
    }
    return dateStr;
}
function nationalToSum(sumStr){
         var sumNum;
         var formatType = document.sessionData.sessnum.value;
         switch(formatType){
            case "1":
                sumNum = sumStr.valueOf();
                break;
            case "2":
                var sumStrArray = sumStr.split(",");
                var sumBegin = sumStrArray[0];
                var sumEnd = sumStrArray[1];
                sumNum = (sumBegin + "." + sumEnd).valueOf();
                break;
            case "3":
                var sumStrArray = sumStr.split(".");
                var sumBegin = sumStrArray[0];
                var sumEnd = sumStrArray[1];
                sumBegin = sumBegin.replace(new RegExp(" ","g"),"");
                sumNum = (sumBegin + "." + sumEnd).valueOf();
                break;
            case "4":
                var sumStrArray = sumStr.split(",");
                var sumBegin = sumStrArray[0];
                var sumEnd = sumStrArray[1];
                sumBegin = sumBegin.replace(new RegExp(" ","g"),"");
                sumNum = (sumBegin + "." + sumEnd).valueOf();
                break;
            case "5":
                var sumStrArray = sumStr.split(".");
                var sumBegin = sumStrArray[0];
                var sumEnd = sumStrArray[1];
                sumBegin = sumBegin.replace(new RegExp(",","g"),"");
                sumNum = (sumBegin + "." + sumEnd).valueOf();
                break;
            case "6":
                var sumStrArray = sumStr.split(",");
                var sumBegin = sumStrArray[0];
                var sumEnd = sumStrArray[1];
                sumBegin = sumBegin.replace(new RegExp("\\.","g"),"");
                sumNum = (sumBegin + "." + sumEnd).valueOf();
                break;
            case "7":
                var sumStrArray = sumStr.split(".");
                var sumBegin = sumStrArray[0];
                var sumEnd = sumStrArray[1]; 
                sumBegin = sumBegin.replace(new RegExp("'","g"),"").replace(new RegExp("´","g"),"").replace(new RegExp("`","g"),"");
                sumNum = (sumBegin + "." + sumEnd).valueOf();
                break;
            case "8":
                var sumStrArray = sumStr.split(",");
                var sumBegin = sumStrArray[0];
                var sumEnd = sumStrArray[1];
                sumBegin = sumBegin.replace(new RegExp("'","g"),"").replace(new RegExp("´","g"),"").replace(new RegExp("`","g"),"");
                sumNum = (sumBegin + "." + sumEnd).valueOf();
                break;
         }
         return parseFloat(sumNum);
}

function nationalToDate(dateStr){
        var formatType = document.sessionData.sessdate.value;
        var helpDate;
        switch(formatType){
        case "1":
            break;
        case "2":
            var datestrArray = dateStr.split("/");
            dateStr = datestrArray[0] + "." + datestrArray[1] + "." + datestrArray[2];
            break;
        case "3":
            var datestrArray = dateStr.split("-");
            dateStr = datestrArray[0] + "." + datestrArray[1] + "." + datestrArray[2];
            break;
        case "4":
            var datestrArray = dateStr.split(".");
            dateStr = datestrArray[2] + "." + datestrArray[1] + "." + datestrArray[0];
            break;
        case "5":
            var datestrArray = dateStr.split("/");
            dateStr = datestrArray[2] + "." + datestrArray[1] + "." + datestrArray[0];
            break;
		case "6":
            var datestrArray = dateStr.split("-");
            dateStr = datestrArray[2] + "." + datestrArray[1] + "." + datestrArray[0];
            break;	
        case "8":
            var datestrArray = dateStr.split("/");
            dateStr = datestrArray[1] + "." + datestrArray[0] + "." + datestrArray[2];
            break;
        case "11":
            var datestrArray = dateStr.split(".");
            helpDate = new Date(datestrArray[2],datestrArray[1],datestrArray[0]);
            dateStr = datestrArray[0] + "." + datestrArray[1] + "." + helpDate.getFullYear();
            break;
        case "12":
            var datestrArray = dateStr.split("/");
            helpDate = new Date(datestrArray[2],datestrArray[1],datestrArray[0]);
            dateStr = datestrArray[0] + "." + datestrArray[1] + "." + helpDate.getFullYear();
            break;
        case "20":
            var datestrArray = dateStr.split(" ");
            dateStr = datestrArray[2] + "." + datestrArray[1] + "." + datestrArray[0];
            break;
        }
        return dateStr;
}

function constantDateStrToNationalStr(dateStr){
//Used in vpfondinfo.js for chart date formatter
    var formatType = document.sessionData.sessdate.value;
    var datestrArray = dateStr.split("-");
    switch(formatType){
        case "1":
            dateStr = datestrArray[2] + "." + datestrArray[1] + "." + datestrArray[0];
            break;
        case "2":
            dateStr = datestrArray[2] + "/" + datestrArray[1] + "/" + datestrArray[0];
            break;
        case "3":
            dateStr = datestrArray[2] + "-" + datestrArray[1] + "-" + datestrArray[0];
            break;
        case "4":
            dateStr = datestrArray[0] + "." + datestrArray[1] + "." + datestrArray[2];
            break;
        case "5":
            dateStr = datestrArray[0] + "/" + datestrArray[1] + "/" + datestrArray[2];
            break;
        case "6":
            dateStr = datestrArray[0] + "-" + datestrArray[1] + "-" + datestrArray[2];
            break;
        case "8":
            dateStr = datestrArray[1] + "/" + datestrArray[2] + "/" + datestrArray[0];
            break;
        case "20":
            dateStr = datestrArray[0] + " " + datestrArray[1] + " " + datestrArray[2];
            break;
    }
    return dateStr;
}

function nationalToDateD(datestr){
		datestr = nationalToDate(datestr);
		datestr = datestr.split('.');
	    var date=new Date(datestr[2],datestr[1]-1,datestr[0]);
	    return date;
}


function isDate(datestr){
	datestr = datestr.split('.');
	var date=new Date(datestr[2],datestr[1]-1,datestr[0]);
	var ifdate= !(date.getFullYear()!=datestr[2]||date.getMonth()!=datestr[1]-1||date.getDate()!=datestr[0]);
	return ifdate;
}


function randomNationalToSum(rNational) {

    var firstpart;
    var secondpart;
    
    if (typeof(rNational)=="number")
       rNational=rNational.toString();
    
    var placer = rNational.lastIndexOf(".");
    var placer1 = rNational.lastIndexOf(",");
    
    
    if (placer1>placer)
        placer=placer1;
    
    if (placer===-1) { //ei leitud komade eraldajat
        rNational = rNational.replace(new RegExp(" ","g"),"").replace(new RegExp("'","g"),"").replace(new RegExp("´","g"),"").replace(new RegExp("`","g"),"");
    }
    else { 
        //if(rNational.length-placer<=3) { //on koma eraldaja
            firstpart = rNational.substr(0,placer);
            secondpart = rNational.substr(placer+1);
            firstpart = firstpart.replace(new RegExp("\\.","g"),"").replace(new RegExp(",","g"),"").replace(new RegExp(" ","g"),"").replace(new RegExp("'","g"),"").replace(new RegExp("´","g"),"").replace(new RegExp("`","g"),"");
            rNational = firstpart + "." + secondpart;
        /*
    	} else { //on ainult tuhandeliste eraldajad
            rNational = rNational.replace(new RegExp("\\.","g"),"").replace(new RegExp(",","g"),"").replace(new RegExp(" ","g"),"").replace(new RegExp("'","g"),"").replace(new RegExp("´","g"),"").replace(new RegExp("`","g"),"");
        }
        */
    }
    
    if (isNaN(rNational))
        return "VIGA";
    else
        return parseFloat(rNational);
    
}

function xFormatterArray(numpoints,howmany) {
    return Math.floor((numpoints-1)/(howmany-1));
}

function getNationalHighchartsDateFormat(){
    var formatType = document.sessionData.sessdate.value,dateFormatStr='';
    
    switch(formatType){
	    case "1":
	        dateFormatStr = "%d.%m.%Y"; /*DD.MM.YYYY*/
	        break;
	    case "2":
	        dateFormatStr = "%d/%m/%Y"; /*DD/MM/YYYY*/
	        break;
	    case "3":
	        dateFormatStr = "%d-%m-%Y"; /*DD-MM-YYYY*/
	        break;
	    case "4":
	        dateFormatStr = "%Y.%m.%d"; /*YYYY.MM.DD*/
	        break;
	    case "5":
	        dateFormatStr = "%Y/%m/%d"; /*YYYY/MM/DD*/
	        break;
	    case "6":
	        dateFormatStr = "%Y-%m-%d"; /*YYYY-MM-DD*/
	        break;		
	    case "8":
	        dateFormatStr = "%m/%d/%Y"; /*MM/DD/YYYY*/
	        break;
	//    case "11":
	//        dateFormatStr = "%d.%m.%y"; /*DD.MM.YY*/
	//        break;
	//    case "12":
	//        dateFormatStr = "%d/%m/%y"; /*DD/MM/YY*/
	//        break;
	    case "20":
	        dateFormatStr = "%Y %m %d"; /*YYYY MM DD*/
	        break;
    }
    return dateFormatStr;
}

function initMenu() {
	
	/*Menu*/
    $(window).bind('orientationchange.menu01 resize.menu01', function () {
        if (getMedia() === 'wide' || $.IbCookie('responsive') === 'desktop') {
            fitMenu();
        }
        $('.ui-autocomplete-input').autocomplete('close');
    });

    $('#menu01 UL.menu00drop').on('click', 'A', function (e) {
        if (getMedia() === 'medium' || getMedia() === 'narrow') {
            e.preventDefault();
            e.stopPropagation();
            if ($('#menu01 UL.menu00open').length === 0) {
                var tmp = $(this).closest('UL').clone(false);
                tmp.removeAttr('class').addClass('menu00open').insertAfter($(this).closest('UL'));
            } else {
                $('#menu01 UL.menu00open').remove();
            }
        }
    });
    try {
        if (window.parent.$(window).width() >= 1000 || $.IbCookie('responsive') === 'desktop') { fitMenu(); }
    } catch (e) {}

    $('#menu01 UL.menu01').on('click mouseenter', 'LI > A.hasdrop, P:not(:has(A))', function (e) {
        e.preventDefault();
        e.stopPropagation();
        if ((getMedia() === 'narrow' || getMedia() === 'medium') && e.type === 'mouseenter') { return; }
        var t = $(this);
        if (getMedia() === 'wide' || $.IbCookie('responsive') === 'desktop') {
            // Make dropdown menus
            if (t.closest('LI').is(':not(.home)')) {
                window.clearTimeout(droptimer);
                if ((e.type === 'mouseenter' && !isTouchDevice()) || (e.type === 'click' && isTouchDevice())) {
                    if (t.closest('UL.menu01').hasClass('open')) {
                        showMenu(t, e);
                    } else {
                        if (e.type === 'click') {
                            showMenu(t, e);
                        } else {
                            droptimer = window.setTimeout(function () {
                                showMenu(t, e);
                            }, 250);
                        }
                    }
                } else if (!isTouchDevice() && e.type === 'click') {
                    if (!t.closest('UL.menu01').hasClass('open')) {
                        window.clearTimeout(droptimer);
                        showMenu(t, e);
                    }
                }
            } else {
                return;
            }
        } else {
            t.closest('LI, .set').toggleClass('mob-open');
            setMobMenuSize();
        }
    });

	
}
jQuery.fn.swapWithNext = function() {
	return this.each(function() { 
		to = $(this).next();
		var copy_to = $(this).next().clone(true);
        var copy_from = $(this).clone(true);
        $(to).replaceWith(copy_from);
        $(this).replaceWith(copy_to);
    });
};
$(document).ready(function() {
	$('a.helpico02').prev('p.error').swapWithNext();
});


function confirmed() {
	if ($("#confirmappl").length > 0 && $(':focus').attr('name')=='buttonA'){
		if(document.getElementById("confirmappl").checked) {
	        $("#confirmError").addClass("hidden");
	        return true;
	     } else {
	         $("#confirmError").removeClass("hidden");
	         triggerFlag=1; tabFlag=0;
	         return false;
	     }
	} else {
		return true;
	}	
}
