﻿var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);

var disabledElement = null;

function beforeSubmit()
{
	if(typeof(window['Page_IsValid']) != "undefined" && !Page_IsValid)
	{
		edc();
	}
}

/**************Disable Double Click**************/
function ddc(e) {
	var targ;
	if (!e) {
		var e = window.event;
	}
	if (e.target) {
		targ = e.target;
	}
	else if (e.srcElement) {
		targ = e.srcElement;
	}
	if (targ.nodeType == 3) // defeat Safari bug
	{
		targ = targ.parentNode;
	}
	if (targ.tagName.toLowerCase() == "input") {
		return true;
	}else{
		if (targ.disabled) {
			return false;
		}
		else {
			disabledElement = targ;
			targ.disabled = true;
			return true;
		}
	}
}

/**************Enable (Double) Click**************/
function edc() {
	if(disabledElement != null){
		disabledElement.disabled = false;
	}
}

function isChar(Data)
{
	varChars = "æøåéèàùûôoöëabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var isChar = true;
	var index = 0;
	while((index < Data.length) && (isChar))
	{
		isChar = (varChars.indexOf(Data.charAt(index)) != -1);
		index++;
	}
	return isChar;
}

function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}

function printPage()
{
	window.print();
}

function viewRapport(id, vars)
{
	showPopup("/m/Report/Viewer.aspx?id=" + id + "&" + vars, "print", "840", "650")
}

function openUrl(strUrl)
{
	document.location = strUrl;
}

function showModal(url, windowName, width, height, options)
{
	if(window.showModalDialog)
  {
		var features;
		features += "center:yes;";
		features += "status:no;";
		features += "scroll:no;";
		features += "dialogWidth:" + width + "px;";
		features += "dialogHeight:" + height + "px;";
		window.showModalDialog(url, null, features);
  }
  else
  {
    showPopup(url, windowName, width, height, {modal:true});
  }
}

function showPopup(url, windowName, width, height, options)
{
	var windowArgs;
	var top = (screen.height/2) - (height/2);
	var left = (screen.width/2) - (width/2);
	
	windowArgs = 'width=' + width;
	windowArgs += ',height=' + height;
	windowArgs += ',top=' + top;
	windowArgs += ',left=' + left;
	if (options == undefined || !options.scrollbars) {
		windowArgs += ',scrollbars=no';
	} else {
	  windowArgs += ',scrollbars=yes';
	}
	if (options == undefined || !options.resizable) {
		windowArgs += ',resizable=no';
	} else {
	  windowArgs += ',resizable=yes';
	}
	if (options == undefined || !options.modal) {
		windowArgs += ',modal=no';
	} else {
	  windowArgs += ',modal=yes';
	}

	windowArgs += ',toolbar=no,location=no,directories=no,status=no,menubar=no';
	
	var win = window.open(url, windowName, windowArgs);
	if(win)
	{
		win.focus();
	}
	else
	{
		alert("Error opening popup!");
	}
}

function showHelp(guid)
{
	showPopup("/m/Help/default.aspx?guid=" + guid, "helpWindow", 700, 585);
}

function CheckNoHtml(val) 
{
  var inputValue = document.getElementById(val.getAttribute('controltovalidate')).value;
  var re = new RegExp('<[a-zA-Z]|<$');
  var m = re.exec(inputValue);
	if (m == null) {
		return true;
	}
	else 
	{
		return false;
	}
}

function zipCodeChanged(city, context) {
	var inputCity = $get(context);
	inputCity.value = city;
	inputCity.select();
}

function ieAjaxBeginRequest(sender, args)
{
	setTimeout('showLoading()', 500);
}

function showLoading(overrideStatus)
{
	var status = Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack();
	if (status || overrideStatus) {
		var loadingDiv = getLoadingDiv();
		loadingDiv.style.display = "block";
		loadingDiv.style.zIndex = 10000;
		var topPos = top.page.scrollTop() + ((top.page.offsetHeight() / 2) - 60);
		var leftPos = top.page.scrollLeft() + ((top.page.offsetWidth() / 2) - 150);
		loadingDiv.style.top = topPos + "px";
		loadingDiv.style.left = leftPos + "px";
		window.status = "Please wait...";
		top.document.body.style.cursor = "wait";
	}
}

function ieAjaxPageLoaded(sender, args) {
	hideLoading();
}

function hideLoading()
{
	var loadingDiv = getLoadingDiv();
	window.status = "Done";
	top.document.body.style.cursor = "default";
	loadingDiv.style.display = "none";
	fader();
	if (disabledElement != null)
	{
		disabledElement.disabled = false;
		disabledElement = null;
	}
}

function getLoadingDiv() {
	return top.document.getElementById("loading");
}

function ChangeCountryCode(id)
{
	var labelTelephone = $get(id);
	alert(labelTelephone);
}

function fixPNG()
{
	if ((version >= 5.5) && (version < 7.0) &&(document.body.filters)) 
	{
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i];
			var imgName = img.src.toUpperCase();
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src + "',sizingMethod='scale')";
				var width = img.width > 0 ? img.width : 24;
				var height = img.height > 0 ? img.height : 24;
				img.width = width;
				img.height = height;
				img.src = "/images/blank.gif";
				i = i - 1;
			}
		}
	}
}

function initPNG()
{
	if ((version >= 5.5) && (version < 7.0) &&(document.body.filters)) 
	{
		Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(fixPNG);
	}
}

/* tristate var 0=nothing requested, 1=fade requested, 2=unfade requested */
var fade = 0;
var onlyFadeIframe = false;
function fader() {
    switch(fade) {
        case 1:
            page.fade(onlyFadeIframe);
            fade = 0;
            break;
          case 2:
            page.unFade();
            fade = 0;
            onlyFadeIframe = false;
            break;
          default: fade = 0;
            onlyFadeIframe = false;
            break;
    }
}

function requestFade() 
{
  fade = 1;
  onlyFadeIframe = true;
}

function requestUnfade() 
{
	if (fade == 0) 
	{
		fade = 2;
	}
}

function init()
{
	initPNG();
	copyImgAltToTitle();
}

function copyImgAltToTitle()
{
	$("img:not([title])").each(function() {
	 $(this).attr("title", $(this).attr("alt"))
	})
}

function showHideCalendar(id)
{
    var datepicker = $find(id);

    // Update the min date for the calendar from the date(time)picker
    var cal = datepicker.get_calendar();

    var dpMinDate = datepicker.get_minDate();
    var dpMaxDate = datepicker.get_maxDate();

    var minDateTriplet = [dpMinDate.getFullYear(), (dpMinDate.getMonth() + 1), dpMinDate.getDate()];
    cal.SetRangeMinDate(minDateTriplet);

    if (dpMaxDate > dpMinDate) {
        var maxDateTriplet = [dpMaxDate.getFullYear(), (dpMaxDate.getMonth() + 1), dpMaxDate.getDate()];
       cal.SetRangeMaxDate(maxDateTriplet);
    }
    

	var textBox = datepicker.get_textBox();
	var popupElement = datepicker.get_popupContainer();
	var dimensions = datepicker.getElementDimensions(popupElement);
	var position = datepicker.getElementPosition(textBox);
	if ((position.y + dimensions.height) > page.scrollHeight())
	{
		datepicker.showPopup(position.x, position.y - dimensions.height-2);
	}
	else 
	{
		datepicker.showPopup();
	}
}

function showHideCalendarTime(id) {
	var timePicker = $find(id);
	timePicker.showTimePopup();
}


function openCloseBox(img, strId)
{
	var boolOpen = false;
	var contentObj = img.parentNode.parentNode.nextSibling;
	if(contentObj.style.display == "none")
	{
		contentObj.style.display = "";
		img.src = "/images/box/hide.gif";
		boolOpen = true;
	}else{
		contentObj.style.display = "none";
		img.src = "/images/box/show.gif";
		boolOpen = false;
	}
	document.getElementById(strId).value = boolOpen;
}

function newEmail(d, a, s)
{
	if(s)
	{
		document.location = "mail" + "to:" + a + "@" + d + "?subject=" + s;
	}
	else
	{
		document.location = "mail" + "to:" + a + "@" + d;
	}
}

function writeEmail(d, a)
{
	document.write(a + "&#64;" + d);
}

function nextRotator(id)
{
	var oRefs = document.getElementById(id);
	if(oRefs.attributes["stopped"].value == "false")
	{
		var x = 0;
		var arrChildNodes = getChildNodes(oRefs);
		if(oRefs.filters)
		{
			if(oRefs.filters.length == 0)
			{
				oRefs.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=1)";
			}
			if(oRefs.filters.length > 0)
			{
				oRefs.filters[0].Apply();
			}
		}
		for(var i=0; i<arrChildNodes.length; ++i)
		{
			var oItem = arrChildNodes[i];
			if(oItem.style)
			{
				if(oItem.style.display == "")
				{
					x = i + 1;
				}
				oItem.style.display = "none";
			}
		}
		if(x >= arrChildNodes.length)
		{
		 x = 0;
		}
		if(arrChildNodes.length > 0)
		{
			arrChildNodes[x].style.display = "";
		}
		if(oRefs.filters)
		{
			if(oRefs.filters.length > 0)
			{
				oRefs.filters[0].Play();
			}
		}
	}
	window.setTimeout("nextRotator('" + id + "')", 8000);
}

function stopRotator(id)
{
	var oRefs = document.getElementById(id);
	oRefs.setAttribute("stopped", "true");
}

function startRotator(id)
{
	var oRefs = document.getElementById(id);
	if(!oRefs.attributes["stopped"])
	{
		oRefs.style.display = "";
		oRefs.setAttribute("stopped", "false");
		nextRotator(id);
		oRefs.onmouseover = function(){ stopRotator(id); };
		oRefs.onmouseout = function(){ startRotator(id); };
	}else{
		oRefs.setAttribute("stopped", "false");
	}
}

function searchSite()
{
	location.href = "/m/search/default.aspx?q=" + document.aspnetForm.searchSiteInput.value;
}

function enterPressed(e)
{
	var keyNum;
	
	if (window.event) 
	{
		keyNum = e.keyCode;
	}
	else if (e.which)
	{
		keyNum = e.which;
	}

	if (keyNum == 13)
	{
		return true;
	}
}

function changeCbb(e)
{
	var obj = null;
	if (document.all)
	{
		obj = window.event.srcElement;
	}
	else
	{
		obj = e.target;
	}
	if(obj.tagName != "INPUT")
	{
		var tableRow = getParentByTypeName(obj, "tr");
		var cbb = tableRow.getElementsByTagName("input")[0];
		//cbb.checked = !cbb.checked;
		cbb.click();
	}
}

function changeRadio(e)
{
	var obj = null;
	if (document.all)
	{
		obj = window.event.srcElement;
	}
	else
	{
		obj = e.target;
	}
	if (obj.tagName != "INPUT")
	{
		var tableRow = getParentByTypeName(obj, "tr");
		var radio = tableRow.getElementsByTagName("input")[0];
		var disableValue = radio.getAttribute("disabled");

		if ($.browser.msie && disableValue == false)
		{
			radio.checked = true;
		}
		else if (disableValue == null)
		{
			radio.checked = true;
		}
	}
}

function getParentByTypeName(obj, tagName)
{
	if(obj.parentNode)
	{
		if(obj.parentNode.tagName == tagName.toUpperCase())
		{
			return obj.parentNode;
		}else{
			return getParentByTypeName(obj.parentNode, tagName);
		}
	}
	return null;
}

function inputStdValueBlur(e, obj)
{
	if(obj.value == "")
	{
		obj.value = obj.val;
		if(obj.type == "password")
		{
			obj = changeInputType(obj, "text");
			var target = e.explicitOriginalTarget || document.activeElement;
			setTimeout(function(){target.focus();}, 200);
		}
	}
}

function inputMinMaxValueBlur(obj, min, max, defVal) 
{
	if (obj.value != "") 
	{
		var numb = parseInt(obj.value);
		if (isNaN(numb))
		{
			obj.value = defVal;
		}
		else
		{
			if (numb < min)
			{
				obj.value = min;
			}
			else if (numb > max)
			{
				obj.value = max;
			}
		}
	}
}

function inputStdValueFocus(obj, passwordField)
{
	if (passwordField && obj.type == "text")
	{
		obj = changeInputType(obj, "password");
		obj.focus();
	}

	if(!obj.val)
	{
		obj.val = obj.value;
	}
	if(obj.val == obj.value)
	{
		obj.value = "";
	}
	
	obj.select();
}

function trim(s) {
  var l = 0; var r = s.length - 1;
  while (l < s.length && s[l] == ' ')
  { l++; }
  while (r > l && s[r] == ' ')
  { r -= 1; }
  return s.substring(l, r + 1);
}

function getChildNodes(oObject)
{
	var arrChildren = new Array();
	for(var i = 0; oObject.childNodes.length > i; ++i)
	{
		var oNode = oObject.childNodes[i];
		if(oObject.childNodes[i].nodeType == 1){
			arrChildren.push(oNode);
		}
	}
	
	return arrChildren;
}

var Modal = {
	show: function(url, name, width, height) {
		var win;
		if (Modal.supported) {
			win = window.showModalDialog(url, name,
				"dialogWidth:" + width + "px;dialogHeight:" + height + "px");
		} else {
			win = window.open(url, name,
				"width=" + width + ",height=" + height + ",toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes");
		}
		
		return win;
	},

	supported: function() {
		if (window.showModalDialog) {
			return true;
		} else {
			return false;
		}
	}
};

var Popup = {
	Show: function(url, name, width, height) {
		var newWindow = window.open(url, name, 'width=' + width + ',height=' + height);

		if (window.focus) {
			newWindow.focus();
		}

		return newWindow;
	},
	
	ShowElement: function(elementId, name, width, height) {
		var element = document.getElementById(elementId);
		var newWindow = Popup.Show('', name, width, height);
		
		// Copy content from the specified element
		newWindow.document.write(element.innerHTML);
		
		return newWindow;
	},
	
	Close: function() {
		window.close();
	}
};

var CpvPicker = {
	SetValue: function(elementId, csv, prettyPrint, primaryCpvCode) {
		// Set CSV-values
		var csvElement = document.getElementById(elementId + '_csv');
		csvElement.value = csv;
		
		// Set pretty-print form element
		var prettyPrintElement = document.getElementById(elementId + '_pp');
		prettyPrintElement.value = prettyPrint.replace(/¤/g, "\n");
		
		var primaryCpvCodeElement = document.getElementById(elementId + '_primary');
		primaryCpvCodeElement.value = primaryCpvCode;
	}
};

var CopyTextBox = {
	Register: function(checkBoxId, textBoxId, value) {
		var checkBox = document.getElementById(checkBoxId);
		checkBox.textBox = document.getElementById(textBoxId);
		checkBox.copyValue = value;
		checkBox.textBox.disabled = checkBox.checked;
		checkBox.onclick = function() {
			if (this.checked) {
				this.originalValue = this.textBox.value;
				this.textBox.value = this.copyValue;
				this.textBox.disabled = true;
			} else {
				if (this.originalValue !== undefined) {
					this.textBox.value = this.originalValue;
				} else {
					this.textBox.value = "";
				}
				this.textBox.disabled = false;
			}
		};
	},

	RegisterDate: function(checkBoxId, textBoxId, datePickerId, defaultDateString) {
		var checkBox = document.getElementById(checkBoxId);
		checkBox.textBox = document.getElementById(textBoxId);
		checkBox.defaultDateString = defaultDateString;
		checkBox.textBox.disabled = checkBox.checked;
		checkBox.onclick = function()
		{
			checkBox.InProgress = true;
			var datePicker = $find(datePickerId);
			if (this.checked) 
			{
				this.originalValue = datePicker.get_selectedDate();
				defaultDate = new Date();
				var arrDate = this.defaultDateString.split('-');
				//month in javascript is zero based, therefore substract 1 from month when setting date
				defaultDate.setFullYear(arrDate[0], arrDate[1] - 1, arrDate[2]);
				defaultDate.setHours(arrDate[3], arrDate[4], 0, 0);
				datePicker.set_selectedDate(defaultDate);
				this.textBox.disabled = true;
			} 
			else 
			{
				if (this.originalValue !== undefined) 
				{
					datePicker.set_selectedDate(this.originalValue);
				} 
				else 
				{
					datePicker.clear();
				}
				this.textBox.disabled = false;
			}
			checkBox.InProgress = false;
		};
	}
};

function CopyDateControlUpdateCheckbox(datePickerId, textBoxId, checkBoxId, defaultDateString) {
		var checkBox = document.getElementById(checkBoxId);
		if (!checkBox.InProgress) 
		{
			var textBox = document.getElementById(textBoxId);
			var datePicker = $find(datePickerId);
			var selectedDate = datePicker.get_selectedDate();
			defaultDate = new Date();
			var arrDate = defaultDateString.split('-');

			//month in javascript is zero based, therefore substract 1 from month when setting date
			defaultDate.setFullYear(arrDate[0], arrDate[1] - 1, arrDate[2]);
			defaultDate.setHours(arrDate[3], arrDate[4], 0, 0);
			if (selectedDate.toString() != defaultDate.toString()) {
				checkBox.checked = false;
				textBox.disabled = false;
			}
			else {
				checkBox.checked = true;
				textBox.disabled = true;
			} 
		}
  }

function getY( oElement )
{
	var iReturnValue = 0;
	while( oElement != null )
	{
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX( oElement )
{
	var iReturnValue = 0;
	while( oElement != null )
	{
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function showHideCompareItem(item)
{
	var table = item.parentNode;
	var minimizer = getChildNodes(getChildNodes(item)[0])[0];
	var found = false;
	var maximized = minimizer.className == "maximize";
	
	minimizer.className = maximized ? "minimize" : "maximize";
	for(var i = 0; i < table.rows.length; ++i)
	{
		var row = table.rows[i];
		if(found)
		{
			row.style.display = maximized ? "" : "none";
			if(row.className == "itemBottom")
			{
				break;
			}
		}
		if(row == item)
		{
			found = true;
		}
	}
}

function ieAjaxErrorHandler(sender, args) 
{
	if (args.get_error() != undefined && args.get_error().httpStatusCode == '500') {
    var errorMessage = args.get_error().message
    errorMessage = errorMessage.replace(args.get_error().name + ":", "");
    args.set_errorHandled(true);
		alert(errorMessage);
	}
}

/************************ PAGE OBJECT ************************************/
var page = {
  fadeDiv: null,
  iebody: document.compatMode && document.compatMode != 'BackCompat' ? document.documentElement : document.body,

  height: function() {
    return Math.max(document.body.scrollHeight, document.body.clientHeight);
  },

  width: function() {
    return Math.max(document.body.scrollWidth, document.body.clientWidth);
  },

  scrollHeight: function() {
    return (window.innerHeight && window.scrollMaxY) ? window.innerHeight + window.scrollMaxY : Math.max(document.body.scrollHeight, document.body.offsetHeight);
  },

  scrollWidth: function() {
    return (window.innerWidth && window.scrollMaxX) ? window.innerWidth + window.scrollMaxX : Math.max(document.body.scrollWidth, document.body.offsetWidth);
  },

  scrollLeft: function() {
    return browser.ie ? page.iebody.scrollLeft : window.pageXOffset;
  },

  scrollTop: function() {
    return browser.ie ? page.iebody.scrollTop : window.pageYOffset;
  },

  offsetHeight: function() {
    return browser.ie ? page.iebody.offsetHeight : document.body.parentNode.clientHeight;
  },

  offsetWidth: function() {
    return browser.ie ? page.iebody.offsetWidth : document.body.parentNode.clientWidth;
  },

  fade: function(onlyIframe) {
    if (typeof (fadeDiv) == "undefined" || fadeDiv == null) {
      if (onlyIframe && top.document != null) {
        fadeDiv = document.createElement("div");
        fadeDiv.style.width = page.offsetWidth() + "px";
        fadeDiv.style.height = page.offsetHeight() + "px";
      }
      else {
        fadeDiv = top.document.createElement("div");
        fadeDiv.style.width = top.page.offsetWidth() + "px";
        fadeDiv.style.height = top.page.offsetHeight() + "px";
      }
      fadeDiv.style.top = top.page.scrollTop() + "px";
      fadeDiv.style.left = 0;
      fadeDiv.style.position = "absolute";
      fadeDiv.style.zIndex = 8000;
      if (browser.ie) {
        fadeDiv.style.backgroundColor = "white";
        fadeDiv.style.filter = "alpha(opacity=60)";
      }
      else {
        fadeDiv.style.backgroundImage = "url(/images/popup/transparent.png)";
      }
      if (onlyIframe && top.document != null) {
        document.body.appendChild(fadeDiv);
      }
      else {
        top.document.body.appendChild(fadeDiv);
      }
    }
  },

  unFade: function() {
    if (typeof (fadeDiv) != "undefined" && fadeDiv != null) {
      if (fadeDiv.parentNode == document.body) {
        document.body.removeChild(fadeDiv);
        fadeDiv = null;
      }
    }
  }
}

var browser = {
	ie: (document.all && !window.opera)
}

function SetIframeHeight(iframeId)
{
    var iframe = document.getElementById(iframeId);
    if (iframe == null)
	{
		iframe = parent.document.getElementById(iframeId);
    }
    
    if (iframe != null && iframe.contentWindow != null && iframe.contentWindow.document != null && iframe.contentWindow.document.body != null)
    {
        iframe.height = iframe.contentWindow.document.body.clientHeight + 1 + "px";
        iframe.style.height = iframe.height;
	}
}

function showTimeZoneWarning(ele) {
	var title = ele.title;
	ele.title = "";
	var id = "__showTimeZoneWarning";
	var img = $(ele);
	var span = $("#" + id);
	
	if (span.size() == 0) {
		span = document.createElement("span");
		span.id = id;
		span.innerHTML = "<img src='/images/icons/TimeZone-48.png' align='absmiddle' />" + title;
		$(document.body).append(span);
		span = $(span);
		span.css("position", "absolute");
		span.css("background-color", "white");
		span.css("padding", "5px");
		span.addClass("borderLRTB");
	}
	
	span.css("left", $(ele).position().left + 20);
	span.css("top", $(ele).position().top + $(ele).height() + 6);
	span.show(200);
	img.bind("mouseleave", function() { span.hide(200); ele.title = title; });
}

function FormatNumber(txtControl, formatDecimal)
{
	var numbVal = Number.parseLocale(txtControl.value);
	if (isNaN(numbVal))
	{
		return;
	}
	
	var value = parseFloat(numbVal);	
	var pattern = formatDecimal ? "N" : "N0";
	txtControl.value = value.localeFormat(pattern);
}	

function LogOn(userName, password, rememberUsername, redirect, https)
{
	if(!Page_ClientValidate())
	{
		return;
	}
	if(!$get("LogOnUsername"))
	{
		var action = (https ? "https://" : "http://") + location.host + "/m/Logon/default.aspx";
		$("body").append("<form method='post' action='" + action + "' id='loginForm'></form>");
		$("#loginForm").append("<input type='hidden' name='LogOnUsername' id='LogOnUsername' />");
		$("#loginForm").append("<input type='hidden' name='LogOnPassword' id='LogOnPassword' />");
		$("#loginForm").append("<input type='hidden' name='LogOnRememberUsername' id='LogOnRememberUsername' />");
		$("#loginForm").append("<input type='hidden' name='LogOnRedirectUrl' id='LogOnRedirectUrl' />");
	}
	$get("LogOnUsername").value = userName;
	$get("LogOnPassword").value = password;
	$get("LogOnRememberUsername").value = rememberUsername;
	if (redirect)
	{
		$get("LogOnRedirectUrl").value = document.location;
	}
	$("#loginForm").submit();
}

function changeInputType(obj, oType) {
	var newObject = document.createElement('input');
	newObject.type = oType;
	for(var i = 0; i < obj.attributes.length; ++i)
	{
		if(obj.attributes[i].value != 'null' && obj.attributes[i].value != '' && obj.attributes[i].name != 'type')
		{
			newObject.setAttribute(obj.attributes[i].name, obj.getAttribute(obj.attributes[i].name));
		}
	}
	if(obj.onfocus) newObject.onfocus = obj.onfocus;
	if(obj.onblur) newObject.onblur = obj.onblur;
	if(obj.onchange) newObject.onchange = obj.onchange;
	obj.parentNode.replaceChild(newObject, obj);
	
	return newObject;
}

// To know more about this you can go to
// http://www.codeproject.com/KB/aspnet/pendingcallbacks.aspx
//<![CDATA[
var GlvDelayedNextPageNo;

function WebForm_CallbackComplete_SyncFixed() 
{
	// the var statement ensure the variable is not global
	for (var i = 0; i < __pendingCallbacks.length; i++) 
	{
		callbackObject = __pendingCallbacks[i];
		if (callbackObject && callbackObject.xmlRequest && (callbackObject.xmlRequest.readyState == 4)) 
		{
			// SyncFixed: line move below // WebForm_ExecuteCallback(callbackObject);
			if (!__pendingCallbacks[i].async)
			{ 
				__synchronousCallBackIndex = -1;
			}
			
			__pendingCallbacks[i] = null;
			var callbackFrameID = '__CALLBACKFRAME' + i;
			var xmlRequestFrame = document.getElementById(callbackFrameID);
			if (xmlRequestFrame)
			{
					xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);
			}
			
			// SyncFixed: the following statement has been moved down from above;
			WebForm_ExecuteCallback(callbackObject);
		}
	}
}

var OnloadWithoutSyncFixed = window.onload;

window.onload = function Onload()
{
	if (typeof (WebForm_CallbackComplete) == 'function') 
	{
		// Set the fixed version
		WebForm_CallbackComplete = WebForm_CallbackComplete_SyncFixed;
		// CallTheOriginal OnLoad
	}
	else if (OnloadWithoutSyncFixed != null) 
	{
		OnloadWithoutSyncFixed();
	}
}
