﻿
	// 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);
}
