﻿// JScript File
        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 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,factory,keyWords,Description,visible,picturePreview,Abstract){
            if(Title.value=="")
              {
                alert(MessageTitle.value);
                return false;
              }
              else
              {
                  //validChars = "abcdefghijklmnopqrstuvwxyz1234567890_-'";
                  validChars="abcdefghijklmnopqrstuvwxyz1234567890_-'абвгдеёжзийклмнопрстуфхцчшщъыьэюяабвгдеёжзийклмнопрстуфхцчшщъыьэюяДобропожаловатьвDEKO";
                  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;  
                  if (language != '/hu/' || language != '/ru/') {
                    var name = replace(title," ","-");
                    name=name.toLowerCase();
                    name=replace(name,"&","and");
		  }
                  var parentid= hdparentid.value;     
                  var order= Order.value;
                  var Parentpath = parentpath.value;
                  var  pic= picturePreview.src.replace("http://deko-dekodk.massarde.dk/","");
                  xsldoc="configuration\\Layout\\System\\ShowDocument.xsl"
                  if(language == '/hu/'|| language == '/ru/')
                  { 
                     if(Name.value=="") 
                          {
                                 alert(MessageName.value);
                                 return false;
                          }
                      else
                      {     
                        name=Name.value;
                        name= name.trim();
                        name=replace(name,"- ","-")
                        name = replace(name," ","-");
                        name=replace(name,"&","and");
                        name= name.toLowerCase();                             
                        name=replace(name,"_","-");
                        name=replace(name,"/","-");
                        name=replace(name," ","-")
                        name=replace(name,"æ","ae")
                        name=replace(name,"å","aa")
                        name=replace(name,"ø","oe")
                        name=replace(name,"é","e")
                        name=replace(name,"ü","ue")
                        name=replace(name,"ä","ae")
                        name=replace(name,"ö","oe")
                        name=replace(name,"ß","ss")
                        name=replace(name,",","")
                   
                         for (i=1 ;i< name.length;i++)
	                     {
	                        thisChar=name.substr(i,1);
	                   
		                    if ( validChars.indexOf(thisChar)==-1 ){
		                        alert(MessageNameValue.value);
		            	        return false;
			                }
		                 }	
                                          
                      }  
                  }
                 
                  else
                  {
                        name= Title.value;
                        name= name.trim();
                        name=replace(name,"- ","-")
                        name = replace(name," ","-");
                        name=replace(name,"&","and");
                        name= name.toLowerCase();                             
                        name=replace(name,"_","-");
                        name=replace(name,"/","-");
                        name=replace(name," ","-")
                        name=replace(name,"æ","ae")
                        name=replace(name,"å","aa")
                        name=replace(name,"ø","oe")
                        name=replace(name,"é","e")
                        name=replace(name,"ü","ue")
                        name=replace(name,"ä","ae")
                        name=replace(name,"ö","oe")
                        name=replace(name,"ß","ss")
                        name=replace(name,",","")
                   
                         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(factory!="distributornet")
                  {
                    if (factory=='distributor')
                     { if(Description.value!= '')
                    var theXML = ToXml.xml("SaveDistTeamDocument",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;}
                    
                    }
                    else{     
                    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)+getxml(pic)+getxmlWithCDATA(Abstract.value));}
                    else
                   { showmetaTags('Editor','Title');
                    return false;}}
                  }
                  else
                   {var theXML = ToXml.xml("SaveDistributorDocument",getxmlWithCDATA(title)+getxmlWithCDATA(data)+getxml(parentid)+getxml(xsldoc)+getxml(order)+getxml(type)+getxml(Parentpath)+getxml(language)+getxmlWithCDATA(name)+getxml(show)+getxml(pic)+getxmlWithCDATA(Abstract.value));}
                  //<!--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=="")                          
                              {
                                
                                 if(factory!="distributornet" && factory!="distributor")
                                   window.location=language+Parentpath+name+".aspx";
                                 else if (factory=="distributornet")                                 
                                  window.location="/distributornet/" +language+Parentpath+name+".aspx";
                                 else    if (factory=="distributor")                              
                                 window.location="/distributor"+language+ Parentpath+name+".aspx";
                              }
                              else
                              {
                             
                                 if(factory!="distributornet" && factory!="distributor")
                                        window.location= Parentpath+name+".aspx";
                                   else if (factory=="distributornet")
                                         window.location= "/DistributorNet/" +Parentpath+name+".aspx";
                                     else    if (factory=="distributor") 
                                    window.location= "/distributor/"+Parentpath+name+".aspx";
                                   
                                    }
                                    
                                    
                                  return false;
                              }
                   }
              
          }
          
          
          
        function SaveNews(Contents,Title,Name,parentid,Date,Abstract,picturePreview,type,Parentpath,language,MessageTitle,MessageName,MessageNameValue,MessageAlreadyExists,MsgInvalidValues,subsite){
            if (Title.value=="")
              {
                    alert(MessageTitle.value);
                    return false;
              }
              else
              {
                  validChars="abcdefghijklmnopqrstuvwxyz1234567890.%_-'абвгдеёжзийклмнопрстуфхцчшщъыьэюяабвгдеёжзийклмнопрстуфхцчшщъыьэюяДобропожаловатьвDEKO";
                  var oEditor = FCKeditorAPI.GetInstance(Contents.id) ;
                  var data= oEditor.GetHTML();
                  var trimmed = data.trim() ;
                  var  title= Title.value;  
                  var name = replace(title," ","-");
                  name=name.toLowerCase();
                  name=replace(name,"&","and");

                  if (language == '/hu/' || language == '/ru/')
                  { 
                     if(Name.value=="") 
                          {
                                 alert(MessageName.value);
                                 return false;
                          }
                      else
                      {     
                            name=Name.value;
                            name=name.toLowerCase();
	                        name=replace(name,"- ","-")
	                        name = replace(name," ","-");
	                        name=replace(name,"&","and");
	                        name= name.toLowerCase();                             
	                        name=replace(name,"%","");
	                        name=replace(name,".","");
	                        name=replace(name,"_","-");
	                        name=replace(name,"/","-");
	                        name=replace(name," ","-")
	                        name=replace(name,"æ","ae")
	                        name=replace(name,"å","aa")
	                        name=replace(name,"ø","oe")
	                        name=replace(name,"é","e")
	                        name=replace(name,"ü","ue")
	                        name=replace(name,"ä","ae")
	                        name=replace(name,"ö","oe")
	                        name=replace(name,"ß","ss")
	                        name=replace(name,",","")


                            for (i=1 ;i< name.length;i++)
	                         {
                                thisChar=name.substr(i,1);	                    
                                if ( validChars.indexOf(thisChar)==-1 ){
                                    alert(MessageNameValue.value);
        	                        return false;
                                }
		                     }                      
                      }
                  }
                 
                  else
                  {
                  
                        name= Title.value;
                        name= name.trim();
                        name=replace(name,"- ","-")
                        name = replace(name," ","-");
                        name=replace(name,"&","and");
                        name= name.toLowerCase();                             
                        name=replace(name,"_","-");
                        name=replace(name,"%","");
                        name=replace(name,".","");
                        name=replace(name,"/","-");
                        name=replace(name," ","-")
                        name=replace(name,"æ","ae")
                        name=replace(name,"å","aa")
                        name=replace(name,"ø","oe")
                        name=replace(name,"é","e")
                        name=replace(name,"ü","ue")
                        name=replace(name,"ä","ae")
                        name=replace(name,"ö","oe")
                        name=replace(name,"ß","ss")
                        name=replace(name,",","")
                        name=replace(name,"'","")
                         for (i=1 ;i< name.length;i++)
	                     {
	                        thisChar=name.substr(i,1);
	                   
		                    if ( validChars.indexOf(thisChar)==-1 ){
		                        alert(MessageNameValue.value);
		            	        return false;
			                }
		                 }
                  }
                  pic= picturePreview.src.replace("http://deko.dotnet.dir.dk/","");
                  xsldoc="configuration\\Layout\\System\\ShowDocument.xsl"
                  var  ToXml=new MyXml();
                  if(subsite!="distributornet")
                  var theXML = ToXml.xml("SaveNews",getxmlWithCDATA(title)+getxmlWithCDATA(data)+getxml(parentid)+getxml(xsldoc)+getxml(type)+getxml(Parentpath)+getxml(language)+getxml(pic)+getxml(Date.value)+getxml(Abstract.value)+getxmlWithCDATA(name));
                  else
                  var theXML = ToXml.xml("SaveDistributorNews",getxmlWithCDATA(title)+getxmlWithCDATA(data)+getxml(parentid)+getxml(xsldoc)+getxml(type)+getxml(Parentpath)+getxml(language)+getxml(pic)+getxml(Date.value)+getxml(Abstract.value)+getxmlWithCDATA(name));
                  //<!--calling getRemotecust method to get values from xml file-->
                  co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);    
               
                  if(co!="")
                    {   
                      if(co=="Date")
                        alert(MsgInvalidValues.value);
                      else                      
                        alert(MessageAlreadyExists.value);
                        return false;
                    }
                     else
                     {    if(subsite!="distributornet")
                          window.location=Parentpath+"/"+name+".aspx";
                          else
                          window.location="/distributornet/"+Parentpath+"/"+name+".aspx";
                                
                         
                      }
                      
                         
                  }
               return false;
          }
            
          function DeleteDocument(id,parentid,order,pageName,path,language,Message,hdMsgSubPage,subsite){       
              if(id=="")
              {return false;}
              var answer =confirm(document.getElementById(Message).value+"["+pageName+"]?" );
              if(answer)
              {
                  var  ToXml=new MyXml();
                  
                  if(subsite!="distributornet" && subsite!="distributor")
                        var theXML = ToXml.xml("DeleteDocument",getxml(id)+getxml(parentid)+getxml(order)+getxml(language));
                  else if(subsite=="distributornet")
                      var theXML = ToXml.xml("DeleteDistributorDocument",getxml(id)+getxml(parentid)+getxml(order)+getxml(language));
                  else if(subsite=="distributor")
                    var theXML = ToXml.xml("DeleteDistTeamDocument",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
                  {  if(subsite!="distributornet" && subsite!="distributor")
                        window.location="/Default.aspx";
                    else if(subsite=="distributornet")
                        window.location="/distributornet/Default.aspx?pageid="+parentid;  
                               else if(subsite=="distributor")
                        window.location="/distributor/Default.aspx";   }
               }
               else
                 return false;               
          
          }
          
           function createNewDocument(Parent,parentPath){
           
              window.location="\Default.aspx?createdocument="+Parent+"&ParentPaht="+parentPath;
             return false;
       
          }
          
          function EditDocument(Documentid){
              window.location="\Default.aspx?EditDocument="+Documentid.value;
              return false;
          }
          
          
          function UpdateDocumentContents(Contents,Title,hdid,type,ParentPath,subsite,language,visible,keyWords,Description,MessageNameValue,Name,discription,picturePreview,Date) {
              var oEditor = FCKeditorAPI.GetInstance(Contents.id) ;
              //validChars="abcdefghijklmnopqrstuvwxyz1234567890_-'";
              validChars="abcdefghijklmnopqrstuvwxyz1234567890%._-'абвгдеёжзийклмнопрстуфхцчшщъыьэюяабвгдеёжзийклмнопрстуфхцчшщъыьэюяДобропожаловатьвDEKO";
              var data= oEditor.GetHTML();
              var  title= Title.value;  
              var id= hdid.value;
              var  pic= picturePreview.src.replace("http://deko-dekodk.massarde.dk","");
              var  ToXml=new MyXml();
              var show;
              
              if(visible.checked)
                  show= false;
              else
                  show =true;

              if (language == '/hu/' || language == '/ru/') {    
                  var name= Name.value;
                  name = name.trim();
              } else {
                var name = title.trim()};  
                name=replace(name,"- ","-")              
                name = replace(name," ","-");
                name=replace(name,"&","and");
                name= name.toLowerCase();                             
                name=replace(name,"_","-");
                name=replace(name,"%","");
                name=replace(name,".","");
                name=replace(name,"/","-");
                name=replace(name," ","-")
                name=replace(name,"æ","ae")
                name=replace(name,"å","aa")
                name=replace(name,"ø","oe")
                name=replace(name,"é","e")
                name=replace(name,"ü","ue")
                name=replace(name,"ä","ae")
                name=replace(name,"ö","oe")
                name=replace(name,"ß","ss")
                name=replace(name,",","")
                 name=replace(name,"'","")
               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 index= ParentPath.lastIndexOf("/");
              var newname=ParentPath.substring(index+1);
              ParentPath=ParentPath.replace(newname,name+".aspx");
              
                if(subsite!="distributornet" && subsite!="distributor"  )
             { var theXML = ToXml.xml("UpdateDocument",getxmlWithCDATA(title)+getxmlWithCDATA(data)+getxml(id)+getxml(type)+getxmlWithCDATA(keyWords.value)+getxmlWithCDATA(Description.value)+getxml(ParentPath)+getxml(name)+getxml(show)+getxml(discription.value)+getxml(pic)+getxml(Date.value));
            
             }
              else if(subsite=="distributornet")
             {
               var theXML = ToXml.xml("UpdateDistributorDocument",getxmlWithCDATA(title)+getxmlWithCDATA(data)+getxml(id)+getxml(type)+getxml(ParentPath)+getxml(show)+getxml(discription.value)+getxml(pic));
               }
              else
             {  var theXML = ToXml.xml("UpdateDistTeamDocument",getxmlWithCDATA(title)+getxmlWithCDATA(data)+getxml(id)+getxml(type)+getxmlWithCDATA(keyWords.value)+getxmlWithCDATA(Description.value)+getxml(ParentPath)+getxml(name)+getxml(show));}
              <!--calling getRemotecust method to get values from xml file-->
              co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);    
              if(subsite!="distributornet" && subsite!="distributor")
              window.location=ParentPath;
              else if (subsite=="distributornet")
               window.location="/distributornet/"+ParentPath;
               else if (subsite=="distributor")
               window.location="/distributor/"+ParentPath;
              return false;
             
              
          }
          
          function changelanguage(language,path,site){
              
           
                path=path.replace('.aspx','');
                 path=path.replace('/','');
                 if(site!="distributornet")
                    window.location="/Default.aspx?language="+language+"&name="+path;
                 else
                   window.location="/distributornet/Default.aspx?language="+language+"&name="+path;
              return false; 
          }
          
          function changewebLanguage(language) {
              window.location="/Default.aspx?setLanguage="+language;
              return false;  
          }
          
	function menuInit() {
		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,site){
            if(id!="" ){
              var  ToXml=new MyXml();
              if(site!="distributornet" && site!="distributor")
                 var theXML = ToXml.xml("MoveNext",getxml(id)+getxml(parentid)+getxml(order)+getxml(language));
              else if(site=="distributornet")
                var theXML = ToXml.xml("DistributorMoveNext",getxml(id)+getxml(parentid)+getxml(order)+getxml(language));
              else if(site=="distributor")
                 var theXML = ToXml.xml("DistTeamMoveNext",getxml(id)+getxml(parentid)+getxml(order)+getxml(language));   
              //<!--calling getRemotecust method to get values from xml file-->
              co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
              if(site!="distributornet" && site!="distributor")
                window.location="/Default.aspx?id="+id;    
                else if(site=="distributornet")
                 window.location="/distributornet/Default.aspx?id="+id;
               else if(site=="distributor")
                  window.location="/distributor/Default.aspx?id="+id;
               }
              else
              window.location="/Default.aspx";    
          }
          
          function MoveBackWard(id,parentid,order,language,site){
            if(id!="" ){
              var  ToXml=new MyXml();
               if(site!="distributornet" && site!="distributor")
              var theXML = ToXml.xml("MoveBackWard",getxml(id)+getxml(parentid)+getxml(order)+getxml(language));
              else if(site=="distributornet")
                var theXML = ToXml.xml("DistributorMoveBackWard",getxml(id)+getxml(parentid)+getxml(order)+getxml(language));
                    else if(site=="distributor")
                   var theXML = ToXml.xml("DistTeamMoveBackWard",getxml(id)+getxml(parentid)+getxml(order)+getxml(language));   
              //<!--calling getRemotecust method to get values from xml file-->
              co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
                if(site!="distributornet"  && site!="distributor")
                     window.location="/Default.aspx?id="+id;    
                else if(site=="distributornet")
                     window.location="/distributornet/Default.aspx?id="+id;
                else if(site=="distributor")
                    window.location="/distributor/Default.aspx?id="+id;
                 }
              else
              window.location="/Default.aspx";    
          }
          
           function ChangeDestination(newParentid,pageid,parentid,order,parentPath,name,language,site){
             if(newParentid!="" ){
                id=pageid;
                if(id!="" ){
                     parentPath= parentPath.replace('.aspx','/');
                     parentPath+=name+".aspx";
                      var  ToXml=new MyXml();
                     if(site!="distributornet" && site!="distributor")
                         var theXML = ToXml.xml("ChangeDestination",getxml(id)+getxml(newParentid)+getxml(parentid)+getxml(order)+getxml(parentPath)+getxml(language));
                      else if(site=="distributornet")
                        var theXML = ToXml.xml("ChangeDistributorDestination",getxml(id)+getxml(newParentid)+getxml(parentid)+getxml(order)+getxml(parentPath)+getxml(language));
                     else if(site=="distributor") 
                     var theXML = ToXml.xml("ChangeDistributorTeamDestination",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);
                      if(site!="distributornet" && site!="distributor")
                         window.location="/Default.aspx?id="+id;    
                        else if(site=="distributornet")
                         window.location="/distributornet/Default.aspx?id="+id; 
                        else if(site=="distributor") 
                          window.location="/corp/Default.aspx?id="+id; 
                 }
               }
              else
              window.location="/Default.aspx";    
          }
          
          function GetPageList()
          {
              xsldoc="configuration\\Layout\\System\\PageList.xsl"
              var  ToXml=new MyXml();
              var theXML = ToXml.xml("GetPageList",getxml(xsldoc));
              //<!--calling getRemotecust method to get values from xml file-->
              co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);   
              alert(co);
          
          }
          function  AddNewDistributor(language){
              countryId=document.getElementById('hdCountryId').value;
              name=   document.getElementById('parentPath').value;
              //alert(name);
              name=name.replace(".aspx","");
              name=name.replace("/","");
              if(language=='/uk/')
                window.location="/Default.aspx?name=uk/distributors&AddDistributor="+countryId;
              else if (language=='/dk/')
                 window.location="/Default.aspx?name=dk/eksport&AddDistributor="+countryId;
              else if (language=='/hu/')
                     window.location="/Default.aspx?name=hu/Forgalmazok&AddDistributor="+countryId;
             else if (language=='/de/')
                     window.location="/Default.aspx?name=de/haendler&AddDistributor="+countryId;
              else
              window.location="/Default.aspx?name="+name+"&AddDistributor="+countryId;
          
          }
          
       function  EditDistributors(id,postition){
          name=   document.getElementById('parentPath').value;
          name=name.replace(".aspx","");
          name=name.replace("/","");
          window.location="/Default.aspx?name="+name+"&EditDistributors="+id+"&position="+postition;
          
          }
		
    function SaveDistriutor(Name,Founded,CompanySize,GeographicTerritory,Description,Fax,picturePreview,Telephone,Website,txtE_mail,City,language,Address,path)
    {
         countryList = document.getElementById('Country');
              countryid= countryList.value;            
              var logo= picturePreview.src.substring(picturePreview.src.lastIndexOf('/'));  
              var pic="";            
              var  ToXml=new MyXml();            
              var theXML = ToXml.xml("SaveDistributor",getxmlWithCDATA(Name.value)+getxml(Founded.value)+getxml(CompanySize.value)+getxml(GeographicTerritory.value)+getxmlWithCDATA(Description.value)+getxml(Fax.value)+getxml(pic)+getxml(Telephone.value)+getxml(Website.value)+getxml(txtE_mail.value)+getxml(City.value)+getxml(Address.value)+getxml(countryid));
              <!--calling getRemotecust method to get values from xml file-->               
              co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML); 
              window.location=path+"?countryid="+countryid;
              return false;
             
              
    }
    
    function UpdateDistriutor(Name,Founded,CompanySize,GeographicTerritory,Description,Fax,picturePreview,Telephone,Website,txtE_mail,City,language,id,Address)
    {
         countryList = document.getElementById('Country');
             countryid= countryList.value;      
              var logo="";
              var  ToXml=new MyXml();
              var theXML = ToXml.xml("UpdateDistriutor",getxml(Name.value)+getxml(Founded.value)+getxml(CompanySize.value)+getxml(GeographicTerritory.value)+getxml(Description.value)+getxml(Fax.value)+getxml(logo)+getxml(Telephone.value)+getxml(Website.value)+getxml(txtE_mail.value)+getxml(City.value)+getxml(id)+getxml(Address.value));
              <!--calling getRemotecust method to get values from xml file-->
              co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML); 
              window.location=path+"?countryid="+countryid;
              return false;
    }
    
     function DeleteDistributor(id,countryId,hdDeletePage)     
    {        
              var answer =confirm(document.getElementById('hdDeleteDistributor').value);
              if(answer){
              var  ToXml=new MyXml();
              var theXML = ToXml.xml("DeleteDistriutor",getxml(id));
              <!--calling getRemotecust method to get values from xml file-->
              co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML); 
              GetDistributors(countryId);}
    }
    
 
   
    
    function Search(language)
    { 
             query= document.getElementById("txtSearch").value
             query=query.trim();
             if(query!=""){
              var  ToXml=new MyXml();
              xsldoc="configuration\\Layout\\System\\SearchResults.xsl"
              var theXML = ToXml.xml("Search",getxml(xsldoc)+getxmlWithCDATA(query)+getxml(language));
              <!--calling getRemotecust method to get values from xml file-->
              co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
              alert(co);
              document.getElementById("search").value="";    
              document.getElementById("search").innerHTML=co;
             }
    }
    
    
    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;}
        if(document.getElementById('txtkeyWords').value=='')
        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;
 	
}

function sendMail(firm,name,adres,code,city,country ) {

	var  ToXml=new MyXml();
	var theXML = ToXml.xml("SendEmail",getxml(firm)+getxml(name)+getxml(adres)+getxml(code)+getxml(city)+getxml(country)); 
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
	window.location = "/dk/produkter.aspx";
}

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get

	if (qs == null)
	qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

	// Turn <plus> back to <space>
	// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &

	// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
		value = unescape(pair[1])
		else
		value = name

		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;

	var value=this.params[key]
	if (value==null) value=default_;

	return value
}

