// 
//These javascipts is created for orch portal
//Solution provided by:
//Rune Ørskov Christensen
//2007


function displayCalendar()
        {
            var datePicker = document.getElementById('datePicker');
            datePicker.style.display = 'block';
        }
function removeCalendar()
        {
            var datePicker = document.getElementById('datePicker');
            datePicker.style.display = 'none';
        }
function setHdnVal()
{
document.getElementById(_ctl0_contentPlace1_hdnLnkButPress).value = 1;
}
//finds the position of an element
function getPos(obj)
{
    var leftPos = 0;
    var topPos = 0;
    if(obj.offsetParent)
    {
        leftPos = obj.offsetLeft;
        topPos = obj.offsetTop;
        while(obj = obj.Parent)
        {
            leftPos += obj.offsetLeft;
            topPos += obj.offsetTop;
        }
    }
    return [leftPos,topPos];
}

//place an abselute element on the screen
function placeObj(objToPos, objRel, addl, addt)
{
    var relPos = getPos(document.getElementById(objRel));
    var lPos = relPos[0]+addl;
    var tPos = relPos[1]+addt;
    
    document.getElementById(objToPos).style.left = lPos + "px";
    document.getElementById(objToPos).style.top = tPos + "px";
    
}
function confirm_delete(){
  if (confirm("Confirm you want to delete this item!")==true)
    return true;
  else
    return false;
}

function confirm_delete_adv(confStr){
  if (confirm(confStr)==true)
    return true;
  else
    return false;
}

 function clearField(txtbx, defVal) {
     if (txtbx.value == defVal) {
         txtbx.value = ""
     }
 }
 function clearFieldDef(txtbx) {
     if (txtbx.value == txtbx.defaultValue) {
         txtbx.value = ""
     }
 }
 
 // For opening popup window
function openPop(mypage,myname,w,h,scroll,pos){
	if(pos=="center")
	{
	LeftPosition=(screen.width)?((screen.width-w)-15)/2:100;TopPosition=(screen.height)?((screen.height-h)-50)/2:100;
	}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=open(mypage,myname,settings);
	win.opener=self;
	    if(win.focus)
	    {
	    win.focus();
	    }
	}
	//For the download section. Windows is resizable
	function downloadWindow(mypage,myname,w,h,scroll,pos){
	if(pos=="center")
	{
	LeftPosition=(screen.width)?((screen.width-w)-15)/2:100;TopPosition=(screen.height)?((screen.height-h)-50)/2:100;
	}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	win=open(mypage,myname,settings);
	win.opener=self;
	    if(win.focus)
	    {
	    win.focus();
	    }
	}
// For AJAX control
var xmlHttp;
function showSearch(str)
{
xmlHttp = GetXmlHttpObject();
if(xmlHttp==null)
    {
    alert("your browser does not support AJAX!");
    return;
    }

    str = Url.encode(str);
    var url = "ajaxReturn.aspx";
    url=url+"?searchString="+str;
    url=url+"&sid="+Math.random();

xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}
myTimer = null;
function stateChanged()
{
placeObj("AjaxLayer","Holder",660,117);
if(xmlHttp.readyState==4)
{
    if(xmlHttp.responseText != "")
    {
    MM_showHideLayers('AjaxLayer','','show');
    document.getElementById("hidtext").innerHTML = xmlHttp.responseText;
    clearTimeout(myTimer); 
    myTimer = setTimeout("MM_showHideLayers('AjaxLayer','','hide');;",5000);
    }
    else
    MM_showHideLayers('AjaxLayer','','hide');
   
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
    {
    //fireFox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
    }
catch(e)
    {
    //IE
    try
        {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
    catch(e)
        {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
return xmlHttp;
}


var Url = {

	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}
    function CopyDivtag(divtag)
{
	var divElements = document.getElementsByTagName("div");
	var i;
	for(i = 0; i < divElements.length; ++i)
	{
		if(divtag.parentNode.parentNode.parentNode == divElements[i].parentNode)
		{
			window.clipboardData.setData("Text", divElements[i].innerText);
		}
	}
}