/*
	//Opens the window where the customer can select what he/she are intereseted in.
	function OpenFreeWindow(moreInfoType)
	{
		var parameters = "";
		var url = "";
		
		if (moreInfoType == "lego")
			url = "http://www.reedbusiness.nu/rbiweb/pages/FeedBackFIABLegoInfo.aspx?country=sv&language=sv";
		else
			url = "http://www.reedbusiness.nu/rbiweb/pages/FeedBackFIABMaskinInfo.aspx?country=sv&language=sv";
		
		window.open(url, '','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=1,width=810,height=550');
	}
*/

	//Opens a new window and shows the company information.
	function OpenPrintWindow(winType, path)
	{
		var url = path;
		
		if (winType == "company")
			url += "PrintCompanyWindow.aspx";
		else
			url += "PrintInvestmentWindow.aspx";
			
		var cwin = window.open(url, 'PrintWindow', 'toolbar=no, location=no, directories=no, status=no, menubar=yes, resizable=yes, scrollbars=yes, height=450, width=520');
		cwin.focus();
	}


	function OpenCreateNewSupplierWindow(path)
	{
		var url = path + "NewSupplier.aspx";
		var cwin = window.open(url, 'NewSupplier', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, height=700, width=650');
		cwin.focus();
	}

	function OpenTryForFreeWindow(path)
	{
		var url = path + "TryForFree.aspx";
		var cwin = window.open(url, 'TryForFree', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, height=540, width=480');
		cwin.focus();
	}

	function OpenCreateNewInvestmentWindow(path)
	{
		var url = path + "NewBuySell.aspx";
		var cwin = window.open(url, 'NewBuySell', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, height=590, width=650');
		cwin.focus();
	}
	
	function OpenCreateNewCompanyWindow(path)
	{
		var url = path + "NewCompany.aspx";
		var cwin = window.open(url, 'NewCompany', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, height=600, width=650');
		cwin.focus();
	}
	
	function OpenEditCompanyWindow(path, companyId)
	{
		var url = path + "NewCompany.aspx?cid=" + companyId;
		var cwin = window.open(url, 'NewCompany', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, height=560, width=650');
		cwin.focus();
	}
	
	function OpenSendMailWindow(path, contactId)
	{
		var url = path + "SendMailToContact.aspx?cid=" + contactId;
		var cwin = window.open(url, 'SendMail', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, height=350, width=500');
		cwin.focus();
	}
	
		
	var downImg = new Image();
	downImg.src = "images/down_btn.gif";
	
	var upImg = new Image();
	upImg.src = "images/up_btn.gif";


	var animOpenListPanel;
	var animOpenSubListPanel;

	var animCloseListPanel;
	var animCloseSubListPanel;
	
	var dx = 1;
	var openSteps = 1;
	var closeSteps = 1;
	var isRunning = 0;

	var openAnimPanel;
	var openSubAnimPanel;
	var closeAnimPanel;
	var closeSubAnimPanel;
	
	var isAdvancedPanelAnim = false;


	function ShowAdvancedPanel()
	{
		if (isRunning == 1)
			return;

		isRunning = 1;
		isAdvancedPanelAnim = true;
		
		openAnimPanel = new MakeObject("advancedListPanel");
		openSubAnimPanel = new MakeObject("advancedSubListPanel");
		//panelImgObj = new MakeObject("imgAdvancedListPanel");

		openSteps = 1;
		closeSteps = 1;

		if (openAnimPanel.css.display == 'block')
		{
			//panelImgObj.el.src = downImg.src; //changes the image
			
			closeAnimPanel = openAnimPanel;
			closeSubAnimPanel = openSubAnimPanel;
			closeAnimPanel.css.overflow = "hidden";
			CloseListPanel();
		}
		else
		{
			//panelImgObj.el.src = upImg.src; //changes the image.

			openAnimPanel.css.display = "block"; 
			OpenListPanel();
		}
	}


	//
	//
	//	
	function ShowListPanel(panelId, imgId)
	{
		if (isRunning == 1)
			return;

		isRunning = 1;
		isAdvancedPanelAnim = false;					

		var panelImgObj;
		var panelsArray = new Array(3);

		panelsArray[0] = new Array(new MakeObject("geographyListPanel"), 
									new MakeObject("geographySubListPanel"), 
									new MakeObject("imgGeographyListPanel")); 

		panelsArray[1] = new Array(new MakeObject("machineListPanel"), 
									new MakeObject("machineSubListPanel"),
									new MakeObject("imgMachineListPanel")); 

		panelsArray[2] = new Array(new MakeObject("legoListPanel"), 
									new MakeObject("legoSubListPanel"), 
									new MakeObject("imgLegoListPanel")); 


		for(i = 0; i < panelsArray.length; i++)
		{
			if (panelId == panelsArray[i][0].el.id)
			{
				openAnimPanel = panelsArray[i][0];
				openSubAnimPanel = panelsArray[i][1];
				panelImgObj = panelsArray[i][2];
				break;
			}
		}
		
		openSteps = 1;
		closeSteps = 1;

		if (openAnimPanel.css.display == 'block')
		{
			panelImgObj.el.src = downImg.src; //changes the image
			
			closeAnimPanel = openAnimPanel;
			closeSubAnimPanel = openSubAnimPanel;
			CloseListPanel();
		}
		else
		{
			panelImgObj.el.src = upImg.src; //changes the image.
			
			for(i = 0; i < panelsArray.length; i++)
			{
				if (panelId != panelsArray[i][0].el.id && panelsArray[i][0].css.display == "block")
				{
					closeAnimPanel = panelsArray[i][0];
					closeSubAnimPanel = panelsArray[i][1];
					panelsArray[i][2].el.src = downImg.src;

					CloseListPanel();
					break;
				}
			}

			openAnimPanel.css.display = "block"; 
			OpenListPanel();

		}
	}


	/*
	 *
	 */	
	function OpenListPanel()
	{
		var panelHeight = parseInt(openAnimPanel.css.height);
		var subPanelTop = parseInt(openSubAnimPanel.css.top);

		if (panelHeight < 120)
			openSteps = openSteps + dx;
		else
		{
			openSteps = openSteps - dx;

			if (openSteps < 1)
				openSteps = 1;
		}

		panelHeight = panelHeight + openSteps;
		subPanelTop = subPanelTop + openSteps;
		
		openAnimPanel.css.height = panelHeight + "px";
		openSubAnimPanel.css.top = subPanelTop + "px";

		if (panelHeight < 215)
			setTimeout("OpenListPanel()", 20);
		else
		{
			isRunning = 0;
			
			if (isAdvancedPanelAnim)
				openAnimPanel.css.overflow = "visible";
		}
	}
	

	function CloseListPanel()
	{
		var panelHeight = parseInt(closeAnimPanel.css.height);
		var subPanelTop = parseInt(closeSubAnimPanel.css.top);


		if (panelHeight > 100)
			closeSteps = closeSteps + dx;
		else
		{
			closeSteps = closeSteps - dx;
			
			if (closeSteps < 1)
				closeSteps = 1;
		}

		panelHeight = panelHeight - closeSteps;
		subPanelTop = subPanelTop - closeSteps;
		
		closeAnimPanel.css.height = panelHeight + "px";
		closeSubAnimPanel.css.top = subPanelTop + "px";


		if (panelHeight > 1)
			setTimeout("CloseListPanel()", 20);
		else
		{
			isRunning = 0;
			closeAnimPanel.css.display = "none";
		}
	}
	
	
	function UpdateCounter(id, value, txt)
	{
		var valuePanel = new MakeObject(id);
		
		if (value > 0)
			valuePanel.el.innerText = "(" + txt + ")";
		else
			valuePanel.el.innerText = "";
	}
	
	
	// Removes leading whitespaces
	function LTrim( value ) {
		
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
		
	}

	// Removes ending whitespaces
	function RTrim( value ) {
		
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");
		
	}

	// Removes leading and ending whitespaces
	function trim( value ) {
		
		return LTrim(RTrim(value));
		
	}

	
	
