﻿
function windowopen(url,target,options){

    var docWindow = window.open(url,target,options);
    //var docWindow = window.open("blank.htm",target,options);
    if(docWindow==undefined)
      {
      window.alert("A pop-up blocker has prevented to open the document.");
      }
    else {
      //docWindow.document.write('<a href=\''+url+'\'>Download bestand</a>');
      //docWindow.location = url
    }
}
function SetValue(ObjectName, sValue)
{
    var MyObject;
    MyObject = findKid(document,ObjectName);
    if(typeof(MyObject) != 'undefined') {
        MyObject.value = sValue;
       }   
}
function GetValue(ObjectName)
{
    var MyObject;
    MyObject = findKid(document,ObjectName);
    if(typeof(MyObject) != 'undefined') {
        return MyObject.value;
       }   
}

function SetFocus(ObjectName)
{
    var MyObject;
    MyObject = findKid(document,ObjectName);
    if(typeof(MyObject) != 'undefined') {
        MyObject.focus();
       }   
}

function climbTo(element, tagname) {
	tagname = tagname.toLowerCase();
	var parentElement;
	while((element = element.parentNode) && !parentElement) {
		if (element.tagName.toLowerCase() == tagname) {
			
			return element
		}
	}
}
function findKid(pObject, MyID){
	var mResult, i,j,x,aObjKids;
	aObjKids = pObject.childNodes;
	//alert('findkid'); 
	// Now do the class-hunting bit...
	for ( i=0, j=aObjKids.length; i<j; ++i){
		x = aObjKids[i];

		if(typeof(x) != 'undefined') {
			//alert(x + x.className);

			mResult = findKid(x,MyID);
			
			if(typeof(mResult) != 'undefined'){
				
				return mResult;
			}
			
			if(typeof(x.id) != 'undefined') {
				if (MyID.toLowerCase() == x.id.toLowerCase()){ // exact match
					//alert('found'+ x.className);
					return x;
				}
				if (MyID.match('\\.\\*') != null && x.id.match(MyID) != null){ // contains regex and matches
					//alert('found'+ x.className);
					return x;
				}
			}
		}
	}
}
  function Show(id)
  {
    showHideContent(id, true)

    }
      function Hide(id)
  {
    showHideContent(id, false)

    }

  function showHideContent(id, show)
  {
    var elem = document.getElementById(id);
    if (show) 
      {
        elem.style.display = 'block';
        elem.style.visibility = 'visible';
      } 
      else
      {
        elem.style.display = 'none';
        elem.style.visibility = 'hidden';
      }
  }        


  function ToggleDisplay(id)
  {
    var elem = document.getElementById(id);
    if (elem) 
    {
      if (elem.style.display != 'block') 
      {
       showHideContent(id, true)
      } 
      else
      {
        showHideContent(id, false)
      }
    }
  }
var FirstBusy;
 var NoBusy;
 FirstBusy =1;
 NoBusy = 0
function UpdateBusyImg() {
    if(NoBusy == 0){
        showHideContent('ctl00_WaitImg',true);
    }
    var img = document.getElementById('ctl00_WaitImg');
	img.src = 'images/icons/indicator.gif';
}
function BusyImage() {
    if(FirstBusy == 1) {
        setTimeout("UpdateBusyImg();",1000);
        FirstBusy = 0;
    } else {
        if(NoBusy == 0){
            setTimeout("UpdateBusyImg();",2500);
        } else {
            showHideContent('ctl00_WaitImg',false);
        }
    }
    return true;
}
function postwith (to,fieldname, text) {
  var myForm = document.createElement("form");
  myForm.style.display = 'none';
  myForm.target = 'Excel_Export';
  myForm.method="post" ;
  myForm.action = to ;

  var myInput = document.createElement("input") ;
  myInput.setAttribute("name", fieldname) ;
  myInput.setAttribute("value", text);
  myForm.appendChild(myInput) ;

  document.body.appendChild(myForm) ;
  myForm.submit() ;
  document.body.removeChild(myForm) ;
}
function ClipboardTable(tableID) {
    var i;
    var j;
    var mycell;
    var table_txt;
    table_txt = '';
    tableObject = document.getElementById(tableID)
  
    for (i=0; i < tableObject.rows.length; i++)
    {
        for (j=0; j < tableObject.rows(i).cells.length; j++)
        {
            if(j > 0) table_txt = table_txt + '\t';
            mycell = tableObject.rows(i).cells(j)
            table_txt = table_txt + mycell.innerText
        }
        table_txt = table_txt + '\r\n';
    }


    CopyClipBoard(table_txt);

    alert('Copied to clipboard');
}
function ExcelTable(tableID) {
    var i;
    var j;
    var mycell;
    var table_txt;
    table_txt = '';
    tableObject = document.getElementById(tableID)
    table_txt = table_txt + '<table>';

    table_txt = table_txt + tableObject.innerHTML;
    table_txt = table_txt + '</table>';

   postwith('TemplateDocs/export.aspx','excel',table_txt);
   
}


function CopyClipBoard(copyText) {

      if (window.clipboardData) { // IE send-to-clipboard method.
            window.clipboardData.setData('Text', copyText);
            
      } else if (window.netscape) {
       
            // You have to sign the code to enable this or allow the action in about:config by changing user_pref("signed.applets.codebase_principal_support", true);
            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
            
            // Store support string in an object.
            var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
            if (!str) return false;
            str.data=copyText;
            
            // Make transferable.
            var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
            if (!trans) return false;
            
            // Specify what datatypes we want to obtain, which is text in this case.
            trans.addDataFlavor("text/unicode");
            trans.setTransferData("text/unicode",str,copyText.length*2);
            
            var clipid=Components.interfaces.nsIClipboard;
            var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid);
            if (!clip) return false;
            
            clip.setData(trans,null,clipid.kGlobalClipboard);
      }
}


function createCookie(name,value,days) {
    var expires = "";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}

	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function PNGFix(){
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])

    if ((version >= 5.5) && (document.body.filters)) 
    {
       var i;
       for(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")
          {
             var imgID = (img.id) ? "id='" + img.id + "' " : ""
             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
             var imgStyle = "display:inline-block;" + img.style.cssText 
             if (img.align == "left") imgStyle = "float:left;" + imgStyle
             if (img.align == "right") imgStyle = "float:right;" + imgStyle
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
             var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
             img.outerHTML = strNewHTML
             i = i-1
          }
       }
    }
}
