var isIE6 = false;
function isIExplorer6(){
	var version=0;
	var isIE = navigator.appVersion.indexOf("MSIE");
	if(isIE > 0){
		version = navigator.appVersion.substr(isIE + 5, 1);
	} 
	return(isIE>0 && version==6);			
}

function dropdownAction(){
		if (isIE6){
			document.getElementById('lang').onchange = function (){
					document.getElementById('language_form').submit();
				}
			document.getElementById('lang').className = "dont_replce";
		}else{
			document.getElementById('lang').style.visibility = 'hidden';
		}
}

		function change_language(){
            var lang = replaced_obj_backup.value;
            var xss_elem = document.getElementById('xss');
            if(xss_elem && xss_elem.value) {
                location=azBase + "&lang=" + lang + "&xss=" + xss_elem;
            }else {
                location=azBase + "&lang=" + lang;
            }
        }
		
		function set_sfx_menu_language(lang){
			//---------------------------------------------------------
			// Responds to a user selecting a language
			//---------------------------------------------------------
		    var lng = lang;
		
		    var nextyear=new Date();
		    nextyear.setFullYear(nextyear.getFullYear()+1);
		    var cookie_name = 'user-Profile';
		
		    // default if there is no cookie already set
		    var new_cookie = cookie_name + "=+++" + lng + ";path=/;expires=" + nextyear.toGMTString();
		
		    // check if we need to modify an existing cookie
		    var start = document.cookie.indexOf(cookie_name + '=');
		    if (start != -1) {
		        //ignore 'name=' portion
		        start += cookie_name.length + 1;
		        // find end of value
		        var end = document.cookie.indexOf(';', start);
		        if (end == -1) end = document.cookie.length;
		        var cookie_val = unescape(document.cookie.substring(start, end));
		        // change language portion
		        var values = cookie_val.split('+');
		        values[3] = lng;
		        // set new cookie value
		        new_cookie = cookie_name + "=" + values.join('+') + ";path=/;expires=" + nextyear.toGMTString();
		    }
		
		    document.cookie = new_cookie;		
		}
	
    
// -----------------------------------------
//Functions for Language select box
	var replaced_obj_backup = null;
    function selectReplacement(obj) {

      var ul = document.createElement('ul');
      ul.id = obj.id + '_replaced';
      ul.style.position = 'absolute';
      ul.style.top = getAbsoluteTop(obj);
	  ul.style.left = getAbsoluteLeft(obj);

      obj.className += ' replaced';
		
          
      ul.className = 'selectReplacement';
      var opts = obj.options;
      var selectedOpt = (!obj.selectedIndex) ? 0 : obj.selectedIndex;

	  var firstLi = document.createElement('li');
	  firstLi.selIndex = 0;
	  firstLi.className = 'firstOption';

  	  firstLi.innerHTML = opts[selectedOpt].innerHTML;
	  firstLi.onclick = function() {
	  	selectMe(getSelected(this.parentNode));
      }; 	  
	  ul.appendChild(firstLi);
      	  
      for (var i=0; i<opts.length; i++) {
        var li = document.createElement('li');
        var txt = document.createTextNode(opts[i].text);
        li.appendChild(txt);
        li.selIndex = i;
        li.selectID = obj.id;
        li.onclick = function() {
          selectMe(this);
        };
        if (i == selectedOpt) {
          li.className = 'selected';
          
          li.onclick = function() {
            openSelect(this.parentNode);
            this.onclick = function() {
              selectMe(this);
            };
          };
        }
		
		addEvent(li,"mouseover", onHoverIn, false);
		addEvent(li,"mouseout", onHoverOut, false);

        ul.appendChild(li);
      }
      obj.onchange = function() {
        var idx = this.selectedIndex;
        selectMe(ul.childNodes[idx]);
      };
      obj.onkeypress = obj.onchange;
    
      obj.parentNode.insertBefore(ul,obj);
      replaced_obj_backup = obj;
      obj.parentNode.removeChild(obj);
    }
    
	function getSelected(ul){
		var lis = ul.getElementsByTagName('li');
	    for (var i=1; i<lis.length; i++) {
	    	if (lis[i].className=='selected') return lis[i];
		}
		return null;
    }
	function onHoverIn(){
		var li; 
		if (this.event) { // IE
			li = this.event.srcElement;
		} else {
			li = this;
		}
		if (li.parentNode.className == 'selectReplacement')  // the select box is not opened
			return;

        li.style.background = "#ebebeb";
	}
	function onHoverOut(){
		var li; 
		if (this.event) { // IE
			li = this.event.srcElement;
		} else {
			li = this;
		}
		if (li.parentNode.className == 'selectReplacement')  // the select box is not opened
			return;

        li.className = li.className;
        li.style.background = "white";
	}
			

    function selectMe(obj) {
      var lis = obj.parentNode.getElementsByTagName('li');
      lis[0].innerHTML =  obj.innerHTML;
	
      for (var i=1; i<lis.length; i++) {
        if (lis[i] != obj) {
          lis[i].className='';
          lis[i].onclick = function() {
            selectMe(this);
          };
       } else {
          setVal(obj.selectID, obj.selIndex);
          obj.className='selected';
          closeSelect(obj.parentNode);
          obj.onclick = function() {
          	openSelect(obj.parentNode);
            this.onclick = function() {
              selectMe(this);
            };
          };
        }
      }
    }
    var skipCloseEvent = false;
    function openSelect(ul){
	    if (ul.className != 'selectReplacement')  // the select box is opened
			return;
    
	    skipCloseEvent = true;
	    ul.className += ' selectOpen';
		var lis = ul.parentNode.getElementsByTagName('li');
		var lastNode = lis[lis.length-1];
		lastNode.style.borderBottom = "2px solid #808080";

		getSelected(ul).style.background = "white";		
	}
	
    function closeSelect(ul){
    	if (skipCloseEvent) { 
	   	    skipCloseEvent = false;
	   	    return;
	   	}
        ul.className = ul.className.replace(new RegExp(" selectOpen\\b"), '');	    
        
		var lis = ul.parentNode.getElementsByTagName('li');
		var lastNode = lis[lis.length-1];
		lastNode.style.borderBottom = "0px solid #808080";
		
		getSelected(ul).style.backgroundImage = "url(" + imageBase +"/azlist_ver3/select_top.gif)";
	}	
    function setVal(objID,val) {
      var obj = replaced_obj_backup;
      if (obj.selectedIndex!=val)  {
	      obj.selectedIndex = val;
    	  change_language(val);     
   	  }
    }
    function setForm() {
      var s = document.getElementsByTagName('select');
      for (var i=0; i<s.length; i++) {
        if (s[i].className=='replace') selectReplacement(s[i]);
      }
    }
    window.onload = function() {
      (document.all && !window.print) ? null : setForm();
    };
    
    /**
     * Returns the absolute left position of an element.
     * @param element the element
     * @return the absolute left position
     */
    function getAbsoluteLeft( element )
    {
        if ( element.offsetParent )
        {
            return element.offsetLeft + getAbsoluteLeft( element.offsetParent ) + 10;
        }
        return element.offsetLeft;
    }

    /**
    * Returns the absolute top position of an element.
    * @param the element
    * @return the absolute top position
    */
    function getAbsoluteTop( element )
    {
        if ( element.offsetParent )
        {
            return element.offsetTop + getAbsoluteTop( element.offsetParent );
        }
        return element.offsetTop;
    }

	function addEvent(elm, evType, fn, useCapture) {
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return true;
		}
		else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		}
		else {
			elm['on' + evType] = fn;
		}
	}    

//---------------------------------------------------------
// This function generates HTML for Go Button
// Thid function is copied from common.js file 
// for the customers that have custom.js customized
// 
//---------------------------------------------------------
function go_button(caption){
	return '<table border="0" cellspacing="0" cellpadding="0" style="cursor: pointer" onclick="document.forms.az_user_form.submit()">' +
'        <tr>'+
'          <td width="18px" style="height: 36px"><img src="' + imageBase + '/azlist_ver3/go_button_left.gif" alt="' + caption + '" width="18px" style="height: 36px"></td>'+
'          <td class="GoButton" style="height: 36px" nowrap>' + caption + '</td>'+
'          <td width="18px" style="height: 36px"><img src="' + imageBase + '/azlist_ver3/go_button_right.gif" alt="' + caption + '" width="18px" style="height: 36px"></td>'+
'        </tr>'+
'      </table>';
}
