/******************************************************************************
Function for flashmap filtering
******************************************************************************/
function getQueryVariable(variable) {  
	var query = window.location.search.substring(1);  
	var vars = query.split("&");  
	for (var i=0;i<vars.length;i++) {    
		var pair = vars[i].split("=");    
		if (pair[0] == variable) {      
			return pair[1];    
		}  
	} 
}

/******************************************************************************
Toggle element.disabled
------------------------------
parameters:
elementName(string): the name of the element to enable/disable
disabled(bool): the state to set the element to.
******************************************************************************/
function toggleDisabledProp(elementName, disabled)
{
    var element = document.getElementById(elementName);
    
    element.disabled = disabled;
}


/******************************************************************************
Clear value of element
------------------------------
parameters:
elementName(string): the name of the element to enable/disable
******************************************************************************/
function clearElementValue(elementName)
{
    var element = document.getElementById(elementName);    
    
    element.value = "";
}


/******************************************************************************
Function for trygfonden.Form.Lifeuoy.ascx
-when the radiobutton "andet" is disabled, the associated textbox will be cleared
------------------------------
parameters:
elementName(string): the name of the element to enable/disable
******************************************************************************/
function disableUi_TbAndet(associatedTextBoxElementName)
{
    toggleDisabledProp(associatedTextBoxElementName, true);
    clearElementValue(associatedTextBoxElementName);
}

/******************************************************************************
Function for substituting the "browse" button image on a asp:FileUpload control
-The structure around the asp:FileUpload control should look like this:
    <div class="fileinputs">
        <asp:FileUpload runat="server" ID="uiFuFile" CssClass="file" size="1" />
    </div>
------------------------------
parameters:
None
******************************************************************************/
function initFileUploads() {
    var W3CDOM = (document.createElement && document.getElementsByTagName);
    
    if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='/gfx/trygfonden.dk/forms/btn_browse.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}
