﻿// JScript File
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
addLoadEvent(init);
//window.onload = init;
        function getRemoteCust(){
            var argv = getRemoteCust.arguments;
            var pageName = argv[0];
            var theXML = argv[2];
            httpRequest = getXmlHttpRequestObject();
            httpRequest.open('Post',pageName , false);
            httpRequest.send(theXML);
            return httpRequest.responseText;
          }
          
          function getxml(value){
            return '<Arg type="String">' + value + '</Arg>';
          }

          function getPage(value){
            alert(value);
          }

          function MyXml(){
            this.Int=Int
            this.Float=Float
            this.Bool=Bool
            this.xml=xml
          }
          
          function Int(value){
            return '<Arg type="int">' + value + '</Arg>';
          }

          function Long(value){
            return '<Arg type="long">' + value + '</Arg>';
          }

          function Bool(value){
          return '<Arg type="bool">' + value + '</Arg>';
          }
          
          function Float(value){
            return '<Arg type="Float">' + value + '</Arg>';
          }
          
          function xml(functionName,xml){
            return '<Xml><FunctionName>'+functionName+'</FunctionName>'+ xml + '</Xml>';
          }
          
          function getxmlExtended(type,id,value){
            return '<Arg type="' + type+'" id="' + id+ '">' + value + '</Arg>';
          }
          
           function getxmlWithCDATA(value){
            return '<Arg type="String"><![CDATA['+ value + ']]></Arg>';
          }
          
          function LogonUser(){
           
          }
          
          
          function getXmlHttpRequestObject() {
	            if (window.XMLHttpRequest) {
		            return new XMLHttpRequest(); //Not IE
	            } 
	            else if(window.ActiveXObject) {
		             return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	           } 
	      }
          
        String.prototype.trim = function() 
        { return this.replace(/^\s+|\s+$/g, ''); } 
        
              function replace(string,text,by) {
            // Replaces text with by in string
                var strLength = string.length, txtLength = text.length;
                if ((strLength == 0) || (txtLength == 0)) return string;

                var i = string.indexOf(text);
                if ((!i) && (text != string.substring(0,txtLength))) return string;
                if (i == -1) return string;

                var newstr = string.substring(0,i) + by;

                if (i+txtLength < strLength)
                    newstr += replace(string.substring(i+txtLength,strLength),text,by);

                return newstr;
        }

       function SaveDocumentContents(Contents,Title,hdparentid,Order,type,parentpath,language,Name,MessageTitle,MessageName,MessageNameValue,MessageAlreadyExists,keyWords,Description,visible){
         
            if(Title.value=="")
              {
                alert(MessageTitle.value);
                return false;
              }
              else
              {
                  validChars="abcdefghijklmnopqrstuvwxyz1234567890_-"
                  var oEditor = FCKeditorAPI.GetInstance(Contents.id) ;
                  var data= oEditor.GetHTML();                 
                  var trimmed = data.trim() ;
                  var show;
                    if(visible.checked)
                    show= false;
                    else
                    show =true;
                  var  title= Title.value;  
                  var name = replace(title," ","-");
                  name=name.toLowerCase();
                  name=replace(name,"&","and");
                  var parentid= hdparentid.value;     
                  var order= Order.value;
                  var Parentpath = parentpath.value;
                   xsldoc="configuration\\Layout\\System\\ShowDocument.xsl"
                  if(language!='uk/')
                  { 
                     if(Name.value=="") 
                     {
                         alert(MessageName.value);
                         return false;
                     }
                     else
                     {
                        name= Name.value;
                        name= name.trim();
                        name = replace(name," ","-");
                        name=replace(name,"&","and");
                        name= name.toLowerCase();
                             
                        name=name.replace("_","-");
                        name=name.replace(" ","-")
                        name=name.replace("æ","ae")
                        name=name.replace("å","aa")
                        name=name.replace("ø","oe")
                        name=name.replace("é","e")
                        name=name.replace("ü","ue")
                        name=name.replace("ä","ae")
                        name=name.replace("ö","oe")
                        name=name.replace("ß","ss")
                        name=name.replace(",","")
                   
                         for (i=1 ;i< name.length;i++)
	                     {
	                        thisChar=name.substr(i,1);
	                   
		                    if ( validChars.indexOf(thisChar)==-1 ){
		                        alert(MessageNameValue.value);
		            	        return false;
			                }
		                 }
                     }
                  }
                      else
                  {
                   for (i=1 ;i< name.length;i++)
	                             {
	                                thisChar=name.substr(i,1);	                    
		                            if ( validChars.indexOf(thisChar)==-1 ){
		                                alert(MessageNameValue.value);
		            	                return false;
			                        }
		                         }
                  
                  }
                  
                  var  ToXml=new MyXml();
                 if(Description.value!= '')
                  {var theXML = ToXml.xml("SaveDocument",getxmlWithCDATA(title)+getxmlWithCDATA(data)+getxml(parentid)+getxml(xsldoc)+getxml(order)+getxml(type)+getxml(Parentpath)+getxml(language)+getxmlWithCDATA(name)+getxmlWithCDATA(keyWords.value)+getxmlWithCDATA(Description.value)+getxml(show));}                  
                  else
                  {
                  showmetaTags('Editor','Title');
                    return false;
                    }
                  <!--calling getRemotecust method to get values from xml file-->
                  co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);    
                  if(co!="")
                    { 
                        alert(MessageAlreadyExists.value);
                        return false;
                    }
                     else
                     {
                         
                          Parentpath = Parentpath.replace('.aspx','/');
                          if(Parentpath=="")
                          {
                            window.location=language+Parentpath+"/"+name+".aspx";
                          }
                          else
                          {
                          window.location=Parentpath+"/"+name+".aspx";}
                         
                          return false;
                      }
                  }
              
          }
            
            
        
          function DeleteDocument(id,parentid,order,pageName,path,language,Message,hdMsgSubPage){
              if(id=="")
              {return false;}
              var answer =confirm(document.getElementById(Message).value+"["+pageName+"]?" );
              if(answer)
              {
                  var  ToXml=new MyXml();
                  var theXML = ToXml.xml("DeleteDocument",getxml(id)+getxml(parentid)+getxml(order)+getxml(language));
                  <!--calling getRemotecust method to get values from xml file-->
                  co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);     
                  if(co!="")
                    alert(document.getElementById(hdMsgSubPage).value);
                  else
                    window.location="/Default.aspx?pageid="+parentid;       
               }
               else
               return false;               
          
          }
          
           function createNewDocument(Parent,parentPath){
         
              window.location="/Default.aspx?createdocument="+Parent+"&ParentPaht="+parentPath;
             return false;
       
          }
          
          function EditDocument(parentpath){
           
              window.location=parentpath;
          
              return false;
          }
          
          
          function UpdateDocumentContents(Contents,Title,hdid,type,ParentPath,name,MessageNameValue,visible,keyWords,Description){
    
              var oEditor = FCKeditorAPI.GetInstance(Contents.id) ;
               var show;
                if(visible.checked)
                    show= false;
                    else
                    show =true;
              validChars="abcdefghijklmnopqrstuvwxyz1234567890_-";
                var name = Title.value.trim();
                name = replace(name," ","-");
                name=replace(name,"&","and");
                name= name.toLowerCase();                             
                name=name.replace("_","-");
                name=name.replace(" ","-")
                name=name.replace("æ","ae")
                name=name.replace("å","aa")
                name=name.replace("ø","oe")
                name=name.replace("é","e")
                name=name.replace("ü","ue")
                name=name.replace("ä","ae")
                name=name.replace("ö","oe")
                name=name.replace("ß","ss")
                name=name.replace(",","")
                 for (i=1 ;i< name.length;i++)
	                     {
	                        thisChar=name.substr(i,1);
	                   
		                    if ( validChars.indexOf(thisChar)==-1 ){
		                              alert(document.getElementById(MessageNameValue).value);		        
		            	        return false;
			                }
		                 }
              var data= oEditor.GetHTML();
              var  title= Title.value;  
              var id= hdid.value;
              var  ToXml=new MyXml();
              
               var index= ParentPath.lastIndexOf("/");
              var newname=ParentPath.substring(index+1);
              ParentPath=ParentPath.replace(newname,name);
              
              var theXML = ToXml.xml("UpdateDocument",getxmlWithCDATA(title)+getxmlWithCDATA(data)+getxml(id)+getxml(type)+getxml(ParentPath)+getxmlWithCDATA(name)+getxml(show)+getxmlWithCDATA(keyWords.value)+getxmlWithCDATA(Description.value));
              <!--calling getRemotecust method to get values from xml file-->
              co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
                window.location=ParentPath+".aspx";
                 return false;
          }
          
          function changelanguage(language){
              
            
              window.location="/Default.aspx?language="+language;
              return false;  
          }
          
           function changewebLanguage(language){
              
            
              window.location="/Default.aspx?webLanguage="+language;
              return false;  
          }
          
	function init() {
		if(document.getElementById('menu')){
			liElements=document.getElementById('menu').getElementsByTagName('li');
			for (i=0;i<liElements.length;i++) {
				if (liElements[i].getElementsByTagName('ul').length>0 && liElements[i].getElementsByTagName('h2').length==0) {
					liElements[i].getElementsByTagName('a')[0].className='x';
					//showing what menus are open
					if (!liElements[i].childNodes[1].href) {
						targetNode=0;
					} else {
						targetNode=1;
					}
					//if (liElements[i].childNodes[0])
					liElements[i].onmouseover=function() {
						this.childNodes[targetNode].className='x active';
					}
					liElements[i].onmouseout=function() {
						this.childNodes[targetNode].className='x';
					}
				}
				if (liElements[i].getElementsByTagName('h2').length>0) {
					liElements[i].onmouseover=function() {
						this.className='active';
					}
					liElements[i].onmouseout=function() {
						this.className='inactive';
					}
				}
			}
			links=document.getElementsByTagName('a');
			for (i=0;i<links.length;i++) {
				links[i].onclick=function() {
					//alert(this.parentNode.parentNode.parentNode.firstChild.className);
				}
			}
		}
    }

    function MoveForward(id,parentid,order,language){
            if(id!="" ){
              var  ToXml=new MyXml();
              var theXML = ToXml.xml("MoveNext",getxml(id)+getxml(parentid)+getxml(order)+getxml(language));
              <!--calling getRemotecust method to get values from xml file-->
              co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
              window.location="/Default.aspx?id="+id;      }
              else
              window.location="/Default.aspx";    
          }
          
          function MoveBackWard(id,parentid,order,language){
            if(id!="" ){
              var  ToXml=new MyXml();
              var theXML = ToXml.xml("MoveBackWard",getxml(id)+getxml(parentid)+getxml(order)+getxml(language));
              <!--calling getRemotecust method to get values from xml file-->
              co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
                window.location="/Default.aspx?id="+id;     }
              else
              window.location="/Default.aspx";    
          }
          
           function ChangeDestination(newParentid,pageid,parentid,order,parentPath,language){
             if(newParentid!="" ){
                id=pageid;
                if(id!="" ){
                      
                      var  ToXml=new MyXml();
                      var theXML = ToXml.xml("ChangeDestination",getxml(id)+getxml(newParentid)+getxml(parentid)+getxml(order)+getxml(parentPath)+getxml(language));
                      <!--calling getRemotecust method to get values from xml file-->
                      co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
                        window.location="/Default.aspx?id="+id;    
                 }
               }
              else
              window.location="/Default.aspx";    
          }
          
          
    function showmetaTags(Contents,Title)
    {  
    
        if(document.getElementById('txtDescription').value==''){
        editor = document.getElementById(Contents);
       var oEditor = FCKeditorAPI.GetInstance(editor.id) ;
        var data= oEditor.GetHTML();
       var first=data.indexOf("<p>");
       var second =data.indexOf("</p>");
        data= data.substring(first,second);
        data=removeHTMLTags(data);       
       document.getElementById('txtDescription').value= data;}      
        document.getElementById('txtkeyWords').value= document.getElementById(Title).value;
		document.getElementById('saveDocument').style.display='none';
		document.getElementById('metaTags').style.display='block';
		document.getElementById('tabs').getElementsByTagName('ul')[0].getElementsByTagName('li')[0].getElementsByTagName('a')[0].className='';
		document.getElementById('tabs').getElementsByTagName('ul')[0].getElementsByTagName('li')[1].getElementsByTagName('a')[0].className='selected';
		 
    }
    
    function showDocument(){
     
        document.getElementById('saveDocument').style.display='block'; 
        document.getElementById('metaTags').style.display='none';
		document.getElementById('tabs').getElementsByTagName('ul')[0].getElementsByTagName('li')[0].getElementsByTagName('a')[0].className='selected';
		document.getElementById('tabs').getElementsByTagName('ul')[0].getElementsByTagName('li')[1].getElementsByTagName('a')[0].className='';
		
        
    
    }
   function showhideText(box,id) { 
    
       var elm = document.getElementById(id) ;
       elm.style.display = box.checked? "block":"none"
        }
    
    function removeHTMLTags(data){
 
 		var strInputCode = data;
 		/* 
  			This line is optional, it replaces escaped brackets with real ones, 
  			i.e. &lt; is replaced with < and &gt; is replaced with >
 		*/	
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
 
   // Use the alert below if you want to show the input and the output text
   //		alert("Input code:\n" + strInputCode + "\n\nOutput text:\n" + strTagStrippedText);	
   return strTagStrippedText;
 	
}