﻿
	// These variables are global to the included page
	var bMSIE = false;
	var bMSIE3 = false, bMSIE4 = false, bMSIE5 = false, bMSIE55 = false;
	var bNetscape = false;
	var bNetscape_2 = false, bNetscape_3 = false, bNetscape_4 = false, bNetscape_6 = false;

	function browser()
	{
	    var ua = navigator.userAgent;
	    var an = navigator.appName;

	    // Is it IE?
	    bMSIE = (ua.indexOf("MSIE")>=1);
	    
	    // NS 6 supports the userAgent property:
	    bNetscape_6 = (ua.indexOf("Netscape6") >= 1);
			
	    if (bMSIE)
	    {
	        // IE3
	        bMSIE3 = (ua.indexOf("MSIE 3.0")>=1);

	        // IE4
	        var iMSIE4 = ua.indexOf("MSIE 4.0");

	        // IE5
	        bMSIE5 = (ua.indexOf("MSIE 5.0")>=1);

	        // IE5.5
	        bMSIE55 = (ua.indexOf("MSIE 5.5")>=1);
	    }
	    else if (an == "Netscape")
	    {
	        bNetscape = true;
	        appVer = parseInt(navigator.appVersion);
	        if (appVer == 4)
	            bNetscape_4 = true;
	        else if (appVer >= 3)
	            bNetscape_3 = true;
	        else
	            bNetscape_2 = true;
	    }
//	    alert( " ie3: " + bMSIE3 + " ie4:" + bMSIE4 + " ie5:" + bMSIE5 + " ie55:" + bMSIE55 + " ns4: " + bNetscape_4 + " ns6: " + bNetscape_6 );
	}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapBGImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.obackgroundImage;i++){ x.style.backgroundImage=x.obackgroundImage;}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapBGImage() { //v3.0
  var i,j=0,x,a=MM_swapBGImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.obackgroundImage) x.obackgroundImage=x.style.backgroundImage; x.style.backgroundImage=a[i+2];}
}

function SetText(obj, text)
{
	var tmpEl = getObj(obj);
	if (!tmpEl)
		return;
	if(document.all){
		tmpEl.innerText = text;
	} else{
		tmpEl.textContent = text;
	}
}

function SetImage(obj, image)
{
	var tmpEl = getObj(obj);
	if (!tmpEl)
		return;
	if(document.all){
		tmpEl.src = image;
	} else{
		tmpEl.src = image;
	}
}

function addDOMLoadEvent(func) {
   if (!window.__load_events) {
      var init = function () {
          // quit if this function has already been called
          if (arguments.callee.done) return;
      
          // flag this function so we don't do the same thing twice
          arguments.callee.done = true;
      
          // kill the timer
          if (window.__load_timer) {
              clearInterval(window.__load_timer);
              window.__load_timer = null;
          }
          
          // execute each function in the stack in the order they were added
          for (var i=0;i < window.__load_events.length;i++) {
              window.__load_events[i]();
          }
          window.__load_events = null;

          // clean up the __ie_onload event
          /*@cc_on @*/
          /*@if (@_win32)
              document.getElementById("__ie_onload").onreadystatechange = "";
          /*@end @*/
      };
   
      // for Mozilla/Opera9
      if (document.addEventListener) {
          document.addEventListener("DOMContentLoaded", init, false);
      }
      
      // for Internet Explorer
      /*@cc_on @*/
      /*@if (@_win32)
          document.write("<scr"+"ipt id=__ie_onload defer src=javascript:void(0)><\/scr"+"ipt>");
          var script = document.getElementById("__ie_onload");
          script.onreadystatechange = function() {
              if (this.readyState == "complete") {
                  init(); // call the onload handler
              }
          };
      /*@end @*/
      
      // for Safari
      if (/WebKit/i.test(navigator.userAgent)) { // sniff
          window.__load_timer = setInterval(function() {
              if (/loaded|complete/.test(document.readyState)) {
                  init(); // call the onload handler
              }
          }, 10);
      }
      
      // for other browsers
      window.onload = init;
      
      // create event function stack
      window.__load_events = [];
   }
   
   // add function to event stack
   window.__load_events.push(func);
}

function getObj(id)
{
    if(document.layers)	   //NN4+
    {
		alert(id);
       if (document.layers[id])
          return document.layers[id];
       else
          return null;  
    }
    else if (document.getElementById)	  //gecko(NN6) + IE 5+
    {
        if (document.getElementById(id)) 
            return document.getElementById(id);
        else
            return null;
    }
    else if (document.all)	// IE 4
    {
        if (document.all[id].style) 
            return document.all[id].style;
        else
            return null;
    }
}

function InitProfileCountrySelect(){
//	alert("OnLoad");	var tmpEl = document.getElementById('txtCountry');
//	alert("txtCountry: " + tmpEl);
	browser();
	if (tmpEl != null){
		var tmpElSel = document.getElementById('txtCountrySelect');
//		alert("txtCountrySelect: " + tmpElSel);
		if (tmpElSel != null){
			if (bMSIE){//				alert("IExplorer");				var myValue=tmpEl.value;
//				alert("txtCountry value: " + myValue);
				if (myValue && myValue != ""){
					for (i = 0; i < tmpElSel.length; i++){
						var myOtherValue=tmpElSel[i].text;
						if (myOtherValue == myValue){
							tmpElSel[i].selected = true;
							break;
						}
					}
				} else {
//					alert("set txtCountry value: " + tmpElSel[tmpElSel.selectedIndex].text);
					tmpEl.value = tmpElSel[tmpElSel.selectedIndex].text;
				}
			} else {
//				alert("not IExplorer");				var myValue=tmpEl.value;
//				alert("txtCountry value: " + myValue);
				if (myValue && myValue != ""){
					for (i = 0; i < tmpElSel.length; i++){
						var myOtherValue=tmpElSel[i].text;
						if (myOtherValue == myValue){
							tmpElSel.selectedIndex = i;
							break;
						}
					}
				} else {
//					alert("set txtCountry value: " + tmpElSel[tmpElSel.selectedIndex].text);
					tmpEl.setAttribute("value", tmpElSel[tmpElSel.selectedIndex].text);
				}
			}
		}
	}
	
	return false;
}

function GetRandom(range)
{
	return Math.floor(Math.random()*range);
}

function CheckBlank(elem, text)
{
//alert("CheckBlank:" + text);
	if (elem.value == text)
	{
		elem.value = "";
		elem.select();
	}
}

function CheckRestore(elem, text)
{
//alert("CheckRestore:" + text);
	if (elem.value == "")
		elem.value = text;
}

function check_int(field)
{
    var s = field.value;
    if (isInteger(s)) return true;
    else 
    {
//        field.value = "0";
        return false;
    }
}

function Validate(field, valmin, valmax, valerror)
{
    var s = parseInt(field.value);
    
    if (s < valmin) 
    {
        alert(valerror);
        field.value = valmin;
        return false;
    } 
    if (s > valmax)
    {
        alert(valerror);
        field.value = valmax;
        return false;
    }
}

function isInteger(val){
if (isBlank(val)){return false;}
for(var i=0;i<val.length;i++){
	if(!isDigit(val.charAt(i))){return false;}
	}
return true;
}

function isBlank(val){
if(val==null){return true;}
for(var i=0;i<val.length;i++) {
	if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
	}
return true;
}

function isDigit(num) {
if (num.length>1){return false;}
var string="1234567890";
if (string.indexOf(num)!=-1){return true;}
return false;
}


function check_date(field){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = ".";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField.value;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      alert("Date is incorrect!");
      DateField.select();
	  DateField.focus();
   }
}

