﻿// JScript File

    function SetFocusOnControl(ctr){

        var ctrl = document.getElementById(ctr);
        if(ctrl){
            ctrl.focus();
		}
	}	
	
	function SetFocusOnLogin(){
		var ctrl = document.getElementById("txtUserName");
		var ctrl2 = document.getElementById("txtPassword");
		if (ctrl.value==""){
			ctrl.focus();	
		}
		else{
			ctrl2.focus();
		}
	}
                
	var submitcount=0;   
    function checkSubmit() 
    {     
    if (submitcount == 0) 
       { submitcount++; return true; }   
    else {return false; } 
    } 	
        
    function SetFocusOnRequireNewPW(){
        var ctrl = document.getElementById("txtUserName");
        ctrl.focus();
		}
				
    function confirm_delete(text){
	    if(confirm(text)==true){
    		return true;
	    }
	    else{
    		return false;
	    }
    }
      
    function SetFocusOnSearch(){
        var ctrl = document.getElementById("txtSearch");
        if(ctrl){
            ctrl.focus();
		}
	}	
		
    function SetFocusOnControl(ctr){

        var ctrl = document.getElementById(ctr);
        if(ctrl){
            ctrl.focus();
		}
	}				


    function confirm_clear(text){
        if(confirm(text)==true){
            return true;
            }
            else{
                return false;
			}
		}
			
			
	function ButtonClick(id){
		var OBJ = eval("document.getElementById('ucButtonMenu1_txtClickedButton')");
		OBJ.value=id;
	}

	function ShowCountries(i,x,y){//xy fir d'Positioun ze korrigéieren
		var ClickOBJ = document.getElementById("DropDownButton"+i);
		str = ClickOBJ.src;
		str = str.substr(str.length-8);
		if (str=="Down.gif"){
			HideListBoxes();
			ShowListBox(i,"Countries",x,y);
			ClickOBJ.src="images/DropDownButtonUp.gif";
		}
		if (str!="Down.gif"){
			HideListBoxes();
		}	
	}
		
	function ShowCities(i,x,y){
		var ClickOBJ = document.getElementById("DropDownButton"+i);
		str = ClickOBJ.src;
		str = str.substr(str.length-8);
		if (str=="Down.gif"){
			HideListBoxes();
			ShowListBox(i,"Cities",x,y);
			ClickOBJ.src="images/DropDownButtonUp.gif";
		}
		if (str!="Down.gif"){
			HideListBoxes();
		}	
	}	

	function ShowListBox(i,s,x,y){
		if (!x){
			x=0;
		}
		if (!y){
			y=0;
		}
		var ListOBJ = document.getElementById("cldList"+s);
			ListOBJ.onkeyup = new Function("selectItem("+i+",'"+s+"');");
			ListOBJ.onclick = new Function("selectItem("+i+",'"+s+"');");
			//ListOBJ.onclick = new Function("selectAndClose("+i+",'"+s+"');");
			ListOBJ.ondblclick = new Function("HideListBoxes();");
			ListOBJ.ondeactivate = new Function("HideListBoxes();");//IE
			ListOBJ.onblur = new Function("HideListBoxes();");//FireFox
			//ListOBJ.selectedIndex=0;
			
		var ClickOBJ = document.getElementById("DropDownButton"+i);	
			ListOBJ = document.getElementById("cldList"+s).style;
			ListOBJ.left = ((ClickOBJ.offsetLeft-180)+ClickOBJ.width+x)+"px";
			ListOBJ.top = (ClickOBJ.offsetTop+ClickOBJ.offsetHeight+y+5)+"px";
			ListOBJ.visibility = "visible";	
			//var ListOBJ = document.getElementById("ucListBoxes1_lbx"+s);
			//ListOBJ = document.getElementById("cldList"+s);
	}
		
	function HideListBoxes(){
		var ListOBJ = document.getElementById("cldListCities");
		if (ListOBJ){
			ListOBJ.style.visibility = "hidden";
		}
		var ListOBJ = document.getElementById("cldListCountries");
		if (ListOBJ){
			ListOBJ.style.visibility = "hidden";
		}
		for (i = 0 ; i < 12; i++){
			var ClickOBJ = document.getElementById("DropDownButton"+i);
			if (ClickOBJ){
				ClickOBJ.src="images/DropDownButtonDown.gif";
			}
		}
	}

	function selectItem(i,s){
		var objList = document.getElementById("ucListBoxes1_lbx"+s);
		//var theform = document.getElementById("Form1");
		//alert(theform.id);
		var objID = document.getElementById("txtIDBox"+i);
		//var objID = theform.getElementById(".txtIDBox"+i);
		//var objid="document.Form1.txtIDBox"+i;
//alert(objID);
		var objSelect = document.getElementById("txtSelectBox"+i);
//alert(objSelect);
		var ii = objList.selectedIndex;
		if (ii>=0){
//alert(objID.value);
			objID.value=objList.value;
//alert(objID.value);
			objSelect.value=objList.options[ii].text;
		}
	}	
	
	/*function selectAndClose(i,s){
		var objList = document.getElementById("ucListBoxes1_lbx"+s);
		var objID = document.getElementById("txtIDBox"+i);
		var objSelect = document.getElementById("txtSelectBox"+i);
		var ii = objList.selectedIndex;
		if (ii>0){
			objID.value=objList.value;
			objSelect.value=objList.options[ii].text;
		}
		HideListBoxes();
	}*/
		


	function UCaseAll(id){
		var f = document.getElementById(id);
		var str = trim(f.value);
		var ch = str.toUpperCase();
		f.value = ch;
	}
	
	function LCaseAll(id){
		var f = document.getElementById(id);
		var str = trim(f.value);
		var ch = str.toLowerCase();
		f.value = ch;
	}
	
	function UCaseFirst(id){
		var f = document.getElementById(id);
		var str = trim(f.value);
		var c = str.substring(0,1);
		c = c.toUpperCase();	
		str= c + str.substring(1);
		//alert(str);
		f.value = str;
	}
	
	function ValidateDate(id){	
		//alert(id);
		var f = document.getElementById(id);
		var str = f.value;
		str = trim(str);
		if (str !=""){
			str = str.replace(/\./g, "/");
			str = str.replace(/\-/g, "/");
			str = str.replace(/\,/g, "/");
			str = str.replace(/\s/g, "/");
			
			if (isDateElement(str)){
				str = str + "//";
				var arr = str.split("/");
				var dd = arr[0];
				var mm = arr[1];
				var yy = arr[2];
				ddN=dd;
				mmN=mm;
				yyN=yy;			
				MyDate = new Date();
				/*if (yyN.length == 4) {
					yyN = yyN.substr(2,2);
				}*/
				if (yyN.length == 2) {
					yyN = "20" + yyN;
				}				
				if (yyN.length == 1) {
					yyN = "200" + yyN;
				}
				if (yyN.length < 1){
					yyN = "dummy" + MyDate.getFullYear();
					yyN=yyN.substr(5,4);	
				}	
				if (mm.length < 2) {
					mmN = "0" + mm;
				}
				if (mm.length  < 1){
					mmN = MyDate.getMonth()+1;	
					mmN = "0" + mmN;
				}	
				if (dd.length < 2) {
					ddN = "0" + dd;
				}									
		
				if (dd.length  < 1){
					ddN = MyDate.getDate();
				}
				//alert(ddN+"/"+mmN+"/"+yyN);
				f.value=ddN+"/"+mmN+"/"+yyN;
			}
		}
	}		
	
	function trim(inputString) {
		if (typeof inputString != "string") { return inputString; }
		var retValue = inputString;
		var ch = retValue.substring(0, 1);
		while (ch == " ") {
			retValue = retValue.substring(1, retValue.length);
			ch = retValue.substring(0, 1);
		}
		ch = retValue.substring(retValue.length-1, retValue.length);
		while (ch == " ") { 
			retValue = retValue.substring(0, retValue.length-1);
			ch = retValue.substring(retValue.length-1, retValue.length);
		}
		while (retValue.indexOf("  ") != -1) {
			retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
		}
		return retValue; 
	}

	function isDateElement(str){
		var i;
		for (i = 0; i < str.length; i++){   
			var c = str.charAt(i);
			if (((c < "0") || (c > "9"))){
				if (c != "/"){
					return false
				}
			}
		}
		return true	
	}
	

	function SelectedIndexToHiddenTxt(id){
	
		var objList = document.getElementById(id);
		//alert(objList.selectedIndex);
		
		var objID = document.getElementById(id+"SelItem");
		var i = objList.value;
		//alert(i);
		//alert(objList.value);
		if (i>=0){
			objID.value=objList.value;
		}
	}

	function CheckAll( checkAllBox ){
		/*if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
			frm = document.Form1;
		}
		else {
			frm = document.forms["Form1"];
		}*/
		
		frm=document.getElementById("Form1");
		var actVar = checkAllBox.checked ;
		for(i=0;i< frm.length;i++){
			e=frm.elements[i];
			//alert(e.name);
			if ( e.type=='checkbox' && e.name.indexOf("checkOne") != -1 ){
				e.checked= actVar ;
			}
		}
	}

	function CheckAll2( checkAllBox ){
		/*if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
			frm = document.Form1;
		}
		else {
			frm = document.forms["Form1"];
		}*/
		
		frm=document.getElementById("Form1");
		var actVar = checkAllBox.checked ;
		for(i=0;i< frm.length;i++){
			e=frm.elements[i];
			//alert(e.name);
			if ( e.type=='checkbox' && e.name.indexOf("chk") != -1 ){
				e.checked= actVar ;
			}
		}
	}

	function UnCheck(){
		/*if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
			frm = document.Form1;
		}
		else {
			frm = document.forms["Form1"];
		}*/
		frm=document.getElementById("Form1");
		for(i=0;i< frm.length;i++)
		{
			e=frm.elements[i];
			if ( e.type=='checkbox' && e.name.indexOf("checkAll") != -1 )
			{
			e.checked= false ;
			break;
			}
		}
	}
	function Copy(){
		//method 1:
/*		var ob = document.getElementById("txtEmails");
		var s=ob.value;
		window.clipboardData.setData("Text",s);*/
		//method 2: todo FAQ works fine in IE6 but not in opera neither in firefox :-( may be due to their security settings
		var ob = document.getElementById("txtEmails");
		var Copied = ob.createTextRange();
		Copied.execCommand("Copy");
	}
	
	
    function InitTabDiv(){
	    var TabDiv = document.getElementById("tabDiv").style;
	    var TopMenu = document.getElementById("TopMenu");
	    /*if (TopMenu == "[object]"){//IE6
		    TabDiv.top="50px";
	    }
	    else{//[object HTMLDivElement] Opera, Firefox, IE7
	    //alert("ok2")
		    TabDiv.top="75px";
	    }*/
	    for (i = 0 ; i < 20; i++){
		    var TabOBJ = document.getElementById(i);
		    if (TabOBJ){
			    ShowTabPanel(i);
			    i=20;//exit
		    }
	    }
    }

    function ShowTabPanel(id){
	    HideListBoxes();
	    for (i = 0 ; i < 20; i++){
		    var TabOBJ = document.getElementById(i);
		    if (TabOBJ){
			    TabOBJ.style.backgroundColor="#DCDCDC";
			    TabOBJ.onmouseover =  new Function("this.style.backgroundColor='#F5F5DC'");
			    TabOBJ.onmouseout =  new Function("this.style.backgroundColor='#DCDCDC'");
			    TabOBJ.onclick =  new Function("ShowTabPanel('"+i+"')");
		    }
	    }
    	
	    TabOBJ = document.getElementById(id);
	    TabOBJ.style.backgroundColor="#F5F5DC";
	    TabOBJ.onmouseover = new Function("");
	    TabOBJ.onmouseout = new Function("");
	    TabOBJ.onclick = new Function("");
    	
	    for (i = 0 ; i < 20; i++){
		    var PanelOBJ = document.getElementById("tabPanel"+i);
		    if (PanelOBJ){
			    PanelOBJ.style.visibility = "hidden";	
		    }
	    }
	    /*
	    var TabDiv = document.getElementById("tabDiv").style;
	    PanelOBJ = document.getElementById("tabPanel"+id).style;
	    PanelOBJ.top=TabDiv.top+TabDiv.height;
	    PanelOBJ.visibility = "visible";
	    */
	    var TabDiv = document.getElementById("tabDiv");
	    PanelOBJ = document.getElementById("tabPanel"+id).style;
	    PanelOBJ.top=(TabDiv.offsetTop+TabDiv.offsetHeight)-6;//fir den ie6+ie7
	    //PanelOBJ.top=(TabDiv.offsetTop+TabDiv.offsetHeight);
	    PanelOBJ.visibility = "visible";
	    
	}

    function SelectedIndexToHiddenTxt(id){

	    var objList = document.getElementById(id);
	    //alert(objList.selectedIndex);
    	
	    var objID = document.getElementById(id+"SelItem");
	    var i = objList.value;
	    //alert(i);
	    //alert(objList.value);
	    if (i>=0){
		    objID.value=objList.value;
	    }
    }
