IE=window.ActiveXObject;
var browser=navigator.appName;
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.xml=xml
}
function xml(functionName,xml){
	return '<Xml><FunctionName>'+functionName+'</FunctionName>'+ xml + '</Xml>';
}
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest(); //Not IE
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	} 
}    


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
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	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 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 sendDkMail(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="/distributor/dk/rekvirer-brochure/brochuren-er-bestilt.aspx";
}
function sendDEMail(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="/distributor/de/weitere-information/thank-you.aspx";
}
    
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
}       
// various variables needed for the filebrowser to work

var contextType=0;
var activeFile;
var addImageForNews;

var uploadActive=false;

function showContext() {
	return popContext(tempX,tempY);
}

function resizeCheck() {
	//if the user is in the middle of renaming a file, then the new file name must be submitted upon resize
	if (document.getElementById('renameField')) {
		if (document.getElementById('renameField').style.display=='block') {
			renameSubmit();
		}
	}
}
ie5=false;
ns6=false;
function popContext(x,y) {
	var contextMenu=document.getElementById('contextMenu');
	contextMenu.style.display='inline';
	contextMenu.style.left=x+'px';
	contextMenu.style.top=y+'px';
	if (typeof translateUseImageForNews=='undefined') {
		translateUseImageForNews='Use image for news';
		translateUpload='Upload file';
		translateCreateFolder='Create folder';
		translatePasteFolder='Paste';
		translateCut='Cut';
		translateRename='Rename';
		translateDelete='Delete';
	}

	switch (contextType) {
		case 0:
			contextMenu.innerHTML=document.getElementById('OnboardcontextMenu').innerHTML;
			return false;
		case 1:
			contextMenu.innerHTML=document.getElementById('OnFilescontextMenu').innerHTML;;
			return false;
	}
	document.getElementById('uploadField').style.display='none';
}
ie6=false;
if (IE || ns6) {
	document.onclick = unPopContext;
}

function unPopContext() {
	if (document.getElementById('contextMenu')) {
		document.getElementById('contextMenu').style.display='none';
		if (!uploadActive) {
			document.getElementById('uploadField').style.display='none';
		}
	}
}
function activateContextMenus() {
	if (document.getElementById('cmeLibraryBrowserFileList')) {
		fileCollection=document.getElementById('cmeLibraryBrowserFileList').getElementsByTagName('a');
		for (i=0;i<fileCollection.length;i++) {
			fileCollection[i].onmouseover=function() {
				switchContextType(1);
				setActiveFile(this);
			}
			fileCollection[i].onmouseout=function() {
				switchContextType(0);
			}
		}
	}
}
function switchContextType(bool) {
	contextType=bool;
}

function setActiveFile(obj) {
	activeFile=obj;
}
function sendPicturePath(path) {
	tempPath=unescape(path.replace("\\","\/"));
	document.getElementById('picturePreview').src = tempPath;
	document.getElementById('picture').value = tempPath;
	closed();
}

function renameFile(language) {
	var renameField=document.getElementById('renameField');
	renameField.style.display='inline';
	resizeCheck();
	renameField.style.top=(findPos(activeFile)[1]+46)+"px";
	renameField.style.left=(findPos(activeFile)[0])+"px";
	unPopContext();
	document.form1.rename.value=activeFile.childNodes[1].nodeValue;
	document.form1.rename.focus();
	document.form1.rename.onblur = renameSubmit;
}
function renameSubmit(language) {
	//submit the value of the rename textarea any way you like
	xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";
	var value=document.getElementById('Current').value;
	valueToSubmit=document.form1.rename.value;
	//hide the renamefield
	var renameField=document.getElementById('renameField');
	renameField.style.display='none';
	var oldvalue = activeFile.childNodes[2].value;
	var  ToXml=new MyXml();
	var theXML = ToXml.xml("RenameFolder",getxml(oldvalue)+getxml(valueToSubmit)+getxml(xsldoc)+getxml('en-US'));
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);     
	document.getElementById("cme").innerHTML= co;  
	getmenu();	
}

function newFolderRename(newFolderName) {
	fileCollection=document.getElementById('cmeLibraryBrowser').getElementsByTagName('a');
	for (i=0;i<fileCollection.length;i++) {
		if (fileCollection[i].childNodes[1].nodeValue==newFolderName) {
			activeFile=fileCollection[i];
			renameFile();
		}
	}
}

function showUploadForm() {
	unPopContext();
	var uploadField=document.getElementById('uploadField');
	uploadField.style.top=(document.body.clientHeight/2)-50+"px";
	uploadField.style.left=(document.body.clientWidth/2)-125+"px";
	uploadField.onmouseover=function() {
		uploadActive=true;
	}
	uploadField.onmouseout=function() {
		uploadActive=false;
	}
	uploadField.style.display='block';
	return false;
}

function pngCheck() {
	//a script to fix IE6-'s incapabilities of showing transparent PNGs
	if (ie6) {
		if (document.getElementById('cmeLibraryBrowser')) {
			imgCollection=document.getElementById('cmeLibraryBrowser').getElementsByTagName('img');
			for (i=0;i<imgCollection.length;i++) {
				thisURL=imgCollection[i].src;
				imgCollection[i].style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+thisURL+'\',sizingMethod=\'scale\')';
				imgCollection[i].src='/Style/CMEimages/transparent.gif';
			}
		}
		
	}
}


if (document.captureEvents) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
	if (document.getElementById('fader')) {
		if (IE) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft;
			tempY = event.clientY + document.body.scrollTop;
		} else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX;
			tempY = e.pageY;
		}  
		if (tempX < 0){tempX = 0;}
		if (tempY < 0){tempY = 0;}  
		return true;
	}
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function cutFolder() {
	var name =activeFile.childNodes[1].nodeValue;
	var value=activeFile.childNodes[2].value;
	var  ToXml=new MyXml();
	var theXML = ToXml.xml("CutFolder",getxml(value)+getxml(name));
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML); 
}

function PasteFolder(language) {
	var xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";     
	var value=document.getElementById('Current').value;
	var  ToXml=new MyXml();
	var theXML = ToXml.xml("PasteFolder",getxml(value)+getxml(xsldoc)+getxml(language));
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML); 
	document.getElementById("cme").innerHTML= co;  
	getmenu();
}

function DeleteFolder(language) {
	xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";
	var value=document.getElementById('Current').value;         
	var name =activeFile.childNodes[2].value;
	var  ToXml=new MyXml();
	var theXML = ToXml.xml("DeleteFolder",getxml(name)+getxml(xsldoc)+getxml(language));
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
	document.getElementById("cme").innerHTML= co;  
	getmenu();
}


function CreateFolder(language) {
	var value=document.getElementById('Current').value;
	xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";
	var  ToXml=new MyXml();
	var theXML = ToXml.xml("CreateFolder",getxml(value)+getxml(xsldoc)+getxml(language));
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML); 
	document.getElementById("cme").innerHTML= co;   
	getmenu();
}
var checkInterval;
var currentScrollPosition;
function GetDocumentLibrary(current, forNews,language) {
    var currentScrollPosition=this.pageYOffset || document.documentElement.scrollTop;
	xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";
	var  ToXml=new MyXml();
	var theXML = ToXml.xml("GetFilesAndFolder",getxml(current)+getxml(xsldoc)+getxml(forNews)+getxml(language));
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
	cmeDiv=document.getElementById('cme');
	//begin: animation script inserted by Rasmus
	if (document.getElementById('cme').innerHTML.length==0) {
		var navigationContainer=document.getElementById('navigationContainer');
		document.body.style.overflow='hidden';
		navigationContainer.style.height=navigationContainer.getElementsByTagName('OBJECT')[0].height+"px";
		navigationContainer.getElementsByTagName('OBJECT')[0].style.display='none';
		$("#cme").fadeIn(300);
	}
	
	//end: animation script inserted by Rasmus
	cmeDiv.innerHTML= co;
	var interfaceContainer=document.getElementById('interfaceContainer');
	addImageForNews=forNews;
	getmenu();
	contextType=0;
	return false;
}

function GetParent(current, forNews,language) {
	xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";
	var ToXml=new MyXml();
	var theXML = ToXml.xml("GetParentFolder",getxml(current)+getxml(xsldoc)+getxml(forNews)+getxml(language));
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
	cmeDiv=document.getElementById('cme');
	if (document.getElementById('cme').innerHTML.length==0) {
		$("#cme").fadeIn(300);
	}
	//end: animation script inserted by Rasmus
	cmeDiv.innerHTML= co;
	addImageForNews=forNews;
	getmenu();
	contextType=0;
	return false;
}
function getSearch(site) {
	var index= site.lastIndexOf("/");
	site=site.replace("/","");
	site=site.substring(3); 
	site=site.replace("/","");
	if (site!='') {
		window.location="/"+site+"/Default.aspx?action=search";
	} else {
		window.location="/Default.aspx?action=search";
	}
	return false;
}
  
function getSitemap(site) {
	var index= site.lastIndexOf("/");
	site=site.replace("/","");
	site=site.substring(3); 
	site=site.replace("/","");
	if (site!='')
		window.location="/"+site+"/Default.aspx?action=sitemap";
	else
		window.location="/Default.aspx?action=sitemap";
	return false;
}

function getmenu() {
	pngCheck();
	if (ie6) {
		document.getElementById('cmeLibraryBrowser').style.width='550px';
	}
	if (browser.indexOf('msie 7')==-1) {
		if (document.getElementById('interfaceContainer')) {
			document.getElementById('interfaceContainer').style.width='100%';
		}
	}
	activateContextMenus();
}
function closed() {
	var navigationContainer=document.getElementById('navigationContainer');
	navigationContainer.getElementsByTagName('OBJECT')[0].style.display='inline';
	document.body.style.overflow='auto';
	document.getElementById("cme").innerHTML= "";
}
  
function GetDistributors(countryId,rowid) {
	if (document.getElementById('hdCountryId')) {
		document.getElementById('hdCountryId').value=countryId;
	}
	if (countryId != '0') {	   
	    xsldoc="configuration\\Layout\\System\\Distributorlist.xsl";
		var ToXml=new MyXml  ;
		var theXML=ToXml.xml("GetDistributors",getxml(xsldoc)+getxml(countryId)+getxml(rowid));
		var co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML).toString().split("&lt;").join("<").split("&gt;").join(">");
		document.getElementById('distributor').innerHTML=co;
	}

}

function GetCountryid(countryId, language) {
    switch(language) {
		case "/dk/":
		    window.location = "/dk/forhandlere/forhandlere.aspx?countryId=" + countryId;
			break;
		case "/de/":
			window.location = "/de/haendler/haendler.aspx?countryId=" + countryId;
			break;
		case "/nl/":
			window.location = "/nl/wereldwijd/wereldwijd.aspx?countryId=" + countryId;
			break; 
         case "/ru/":
             window.location = "/ru/distributors/distributors.aspx?countryId=" + countryId;
             break;
         case "/hu/":
             window.location = "/hu/distributors/distributors.aspx?countryId=" + countryId;
             break;
		default:
			window.location = "/uk/distributors/distributors.aspx?countryId=" + countryId;
			break;
	}
}
function GetCustomer(Id) {
	if (Id!='0') {
		xsldoc="configuration\\Layout\\System\\CustomerDetail.xsl";
		var ToXml=new MyXml  ;
		var theXML=ToXml.xml("GetCustomer",getxml(xsldoc)+getxml(Id));
		co=getRemoteCust("/RemotFunctionPage.aspx","doStuf",theXML);
		if (co!="") {
			document.getElementById('distributor').innerHTML=co;
		} else {
			window.location="/distributornet/Default.aspx?mode=logout";
		}
	}

}
function GetPriceList(priceGroup,discountGroup,CurrencyCode) {
	xsldoc="configuration\\Layout\\System\\PriceList.xsl";
	var ToXml=new MyXml  ;
	var theXML=ToXml.xml("GetPriceList",getxml(xsldoc)+getxml(priceGroup)+getxml(discountGroup)+getxml(CurrencyCode));
	co=getRemoteCust("/RemotFunctionPage.aspx","doStuf",theXML);
	if (co!="") {
		document.getElementById('distributor').innerHTML=co;
		//updateContentHeadings();
	} else {
		window.location="/distributornet/Default.aspx?mode=logout";
	}
	var priceList=document.getElementById('priceList');
	tableRows=priceList.getElementsByTagName('tr');
	for (i=0; i<tableRows.length; i++) {
		tableRows[i].getElementsByTagName('td')[4].style.textAlign='right';
		if (i%2) {
			tableRows[i].className='even';
		} else {
			tableRows[i].className='odd';
		}
	}
	document.getElementById('content').style.height=(document.getElementById('priceList').offsetHeight+40)+"px";
}
function GetCountriesList(mode,id) {
	xsldoc="configuration\\Layout\\System\\Countrylist.xsl";
	var ToXml=new MyXml  ;
	var theXML=ToXml.xml("GetCountryList",getxml(xsldoc)+getxml(mode)+getxml(id));
	co=getRemoteCust("/RemotFunctionPage.aspx","doStuf",theXML);
	document.getElementById('CountryList').innerHTML="";
	document.getElementById('CountryList').innerHTML=co;
}

function AddDistributor(countryId) {
	xsldoc="configuration\\Layout\\System\\NewDistributor.xsl";
	var ToXml=new MyXml  ;
	var theXML=ToXml.xml("GetDistributorbutton",getxml(xsldoc)+getxml(countryId));
	co=getRemoteCust("/RemotFunctionPage.aspx","doStuf",theXML);
	document.getElementById('butt').innerHTML="";
	document.getElementById('butt').innerHTML=co;
}

function DiplayFrontPageNews() {
	xsldoc="Configuration/Layout/System/DisplayNews.xsl";
	var ToXml=new MyXml  ;
	var theXML=ToXml.xml("DiplayFrontPageNews",getxml(xsldoc));
	co=getRemoteCust("/RemotFunctionPage.aspx","doStuf",theXML);
	document.getElementById('news').innerHTML=co.split('&amp;shy;').join('&shy;');;
}
function DiplayDistributorFrontPageNews() {
	xsldoc="Configuration/Layout/System/DisplayNews.xsl";
	var ToXml=new MyXml  ;
	var theXML=ToXml.xml("DiplayDistributorFrontPageNews",getxml(xsldoc));
	co=getRemoteCust("/RemotFunctionPage.aspx","doStuf",theXML);
	document.getElementById('news').innerHTML="";
	document.getElementById('news').innerHTML=co;
}
function GetConnect() {
	window.location="/distributornet/products/Default.aspx";
	return false;
}
function NavisionRemoteDesktopConnection() {
	var ToXml=new MyXml  ;
	xsldoc="configuration\\Layout\\System\\NavisionRemoteDesktopLogin.xsl";
	var theXML=ToXml.xml("NavisionRemoteDesktopConnection",getxml(xsldoc));
	co=getRemoteCust("/RemotFunctionPage.aspx","doStuf",theXML);
	if (co!="") {
		document.getElementById('distributor').innerHTML="";
		document.getElementById('distributor').innerHTML=co;
	}

}
