var adminOpenWindowWidth=900;
var adminOpenWindowHeight=650;

function keyhandler(sender) {
		if (window.event.keyCode == 13) {
				//senderName = document.getElementById(sender).name;
				document.getElementById(sender).focus();
				//__doPostBack(senderName,'');
		}	
}

function keyhandler2(sname) {
	if (window.event.keyCode == 13) {				
			__doPostBack(sname,'');					
			event.returnValue=false;
		}				
}
function keyhandler3() {
	if (window.event.keyCode == 13) {
		window.event.keyCode = 0;
		return false;
	}
}
	
function opencontentwin(url,target,params) {
	var newwin = window.open(url,target,params);
	newwin.focus();
}

function OpenModuleTemplate(baseurl,tbid,target) {
  var moduleTemplate = window.open(baseurl + "/contentxxl/admin/themeboxmanager/admin/editthemebox.aspx?tbid="+tbid+"&targetid="+target+"","","width="+adminOpenWindowWidth+"px,height="+adminOpenWindowHeight+"px");
  moduleTemplate.focus();
}

function openOEM(mid, mdefid, itemid, lang, target)
{
	var params = "height=650,width=900,status=off,menu=off,toolbar=off";
	var url = baseurl + "/contentxxl/admin/objecteditmanager/objecteditmanager.aspx?";
	url +=  "mid="+ mid;
	url += "&itemid=" + itemid;
	url += "&mdefid=" + mdefid; 
	url += "&lang=" + lang;
	opencontentwin(url, target, params);								
}

function selectObject(mdefid)
{
	var params = "center:yes;dialogWidth:900px;dialogHeight:650px;status:no;resizible:yes" ;
	var url = baseurl + "/contentxxl/admin/ObjectBrowser/ObjectBrowser.aspx?";
	if (mdefid==null)
		mdefid = 0;
	url += "&selmdefid=" + mdefid; 
	url += "&selector=1";
	return window.showModalDialog(url,"sel_obj",params);
}

function selectObjectNoModal(mdefid)
{
    var pWidth = adminOpenWindowWidth;
    var pHeight = adminOpenWindowHeight;
	var params = "width="+pWidth+"px,height="+pHeight+"px,status=0;" ;
	var url = baseurl + "/contentxxl/admin/ObjectBrowser/ObjectBrowser.aspx?";
	if (mdefid==null)
		mdefid = 0;
	url += "&selmdefid=" + mdefid; 
	url += "&selector=1";
	var win = window.open(url,"sel_obj",params);
	win.moveTo((screen.width / 2) - (pWidth / 2),(screen.height / 2) - (pHeight / 2));
	win.focus();
}


//--- This two function inserted for flash-module
function enableActiveX (containerID)
{
	// No IE = no need to enable
    if (getInternetExplorerVersion() != -1)
    {
        // Get container
        var container = document.getElementById(containerID);
        // Get html in noscript 
        var html = container.innerHTML; 
        // Write html back to container
        container.innerHTML = html;
    }
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// Found at: 
// http://msdn.microsoft.com/workshop/author/dhtml/overview/browserdetection.asp
{
    var rv = -1; // Return value assumes failure
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        var ua = navigator.userAgent;
        var re  = new RegExp ("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec (ua) != null)
        {
        	rv = parseFloat (RegExp.$1);
        }
    }
    return rv;
}

//-----------------------------------------------------------------------------------
//--- for smartedit use this instead of innerHTML
//----------------------------------------------------------------------------------
    var output = '';
    var opentag = '<';
    var closetag = '>';
    function getHTMLContent(obj) {
        output = '';
        //-- only for test
        //-- w = window.open('','myoutput');
        getHTML(obj.childNodes);
        //--w.document.write(output);
        
        return output;
    }

    
    function getHTML(Nodes) {
        var i;
        for(i=0; i < Nodes.length;i++) {
            //alert(Nodes[i].nodeType + ' - ' + Nodes[i].nodeName);
            // Type 1 = Elementknoten
            if(Nodes[i].nodeType == 1) {
                 
                if(Nodes[i].nodeName.charAt(0) != '/' && Nodes[i].nodeName != '') {
           
                    output += opentag+Nodes[i].nodeName.toLowerCase();
                   
                    var x;
                    for(x=0; x < Nodes[i].attributes.length;x++) {
                      if((Nodes[i].attributes[x].nodeValue > '' || Nodes[i].attributes[x].nodeName.toLowerCase() == 'alt') && (Nodes[i].attributes[x].nodeName.toLowerCase() != 'contenteditable') && (Nodes[i].attributes[x].nodeName.toLowerCase() != 'start') && (Nodes[i].attributes[x].nodeName.toLowerCase() != 'loop')) {
                      
                        if(!(Nodes[i].nodeName.toLowerCase() == 'object' && Nodes[i].attributes[x].nodeName.toLowerCase() == 'alt')) {
                          output += ' '+Nodes[i].attributes[x].nodeName.toLowerCase()+'="'+Nodes[i].attributes[x].nodeValue+'"';
                        }
                      }
                    }
                    if(Nodes[i].style.cssText > '') {
                        output += ' style="'+ Nodes[i].style.cssText +'"'
                    }
                    if(Nodes[i].nodeName.toLowerCase() == 'img' || Nodes[i].nodeName.toLowerCase() == 'hr' || Nodes[i].nodeName.toLowerCase() == 'br' || Nodes[i].nodeName.toLowerCase() == 'input' || Nodes[i].nodeName.toLowerCase() == 'area') {
                        output += ' /'+closetag;
                    } else {
                        output += closetag;
                    }
                    if(Nodes[i].nodeName == 'SCRIPT') {
                     output += Nodes[i].innerHTML;
                    }
                    if(Nodes[i].nodeName.toLowerCase() == 'style') {
                     output += Nodes[i].innerHTML;
                    }
                }
            }
            // Type 3 = Textknoten
            if(Nodes[i].nodeType == 3) {
              output += ChangeToHTMLEntities(Nodes[i].nodeValue);
            }
            if(Nodes[i].hasChildNodes()) {
              getHTML(Nodes[i].childNodes);
            }
            // Type 1 = "wertlose" Textknoten schließen
            if(Nodes[i].nodeType == 1 && (!(Nodes[i].nodeName.toLowerCase() == 'img' || Nodes[i].nodeName.toLowerCase() == 'hr' || Nodes[i].nodeName.toLowerCase() == 'br' || Nodes[i].nodeName.toLowerCase() == 'input' || Nodes[i].nodeName.toLowerCase() == 'area' || Nodes[i].nodeName.toLowerCase().charAt(0) == '/'))) {
              output += opentag+'/'+Nodes[i].nodeName.toLowerCase()+closetag;
            }      
        }
   
   }

   
   function ChangeToHTMLEntities(input) {
     input = input.replace("&","&amp;");
     return input;
   }
   
   // for collapsing the answers (must be paragraph element)
   function collapseFAQ(ClassName) {
    var elems = document.getElementsByTagName("p");
    for(i = 0; i< elems.length;i++) {
      elems[i].setAttribute("id","col"+i);    
      if(elems[i].className == ClassName) {
       //for Firefox, Opera
       elems[i].setAttribute("onclick", "collapseAnswer(this.id)");
       //for IE
       elems[i].onclick = new Function("collapseAnswer(this.id)");
       elems[i+1].style.display = "none";
      }
    }
  }
  function collapseAnswer(obj) {
    var nextnumber = Number(obj.replace(/col/i,""));
    if(document.getElementById("col"+(nextnumber+1)).style.display == "none") {
      document.getElementById("col"+(nextnumber+1)).style.display = "block";
      document.getElementById("col"+(nextnumber)).className += " collapseactive"
    }
    else {
      document.getElementById("col"+(nextnumber+1)).style.display = "none";
      document.getElementById("col"+(nextnumber)).className = document.getElementById("col"+(nextnumber)).className.replace(/collapseactive/,"")
    }
  }