// ----------------- Main menu -----------------//

/**************************************
/kindly taken from http://www.alistapart.com/articles/dropdowns
/adds over class to appropriate classe, as IE doesnt support li:hover
/**************************************/
IEhoverBug = function() {
  if(!browserIsIE())  //if not Internet explorer which is the only browser where the problem occurs
    return false;

  if (document.all&&document.getElementById) {
	  navRoot = document.getElementById("mainmenunav");
	  if (navRoot == null)
	    return false;
	  addHoverClassToLIs(navRoot,1);
	}

  function addHoverClassToLIs(navRoot, level)
  {
    if (navRoot.childNodes.length == 0)
      return false;

	  var i;  //must be declared because it is called recursive (javascript..!)
    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.nodeName=="LI" || node.nodeName=="li") {
        node.onmouseover=function() {
	        this.className+=" over"+level;
        }
        node.onmouseout=function() {
	        this.className=this.className.replace(" over"+level, "");
        }
      }

      if (node.childNodes.length > 0)
      {
        var j;
        for (j=0; j<node.childNodes.length; j++) {

          // traverse subtree
          subTree = node.childNodes[j];

          if (subTree != null)
            if (subTree.nodeName=="UL" || subTree.nodeName=="ul") {
              addHoverClassToLIs(subTree,level+1);
            }
        }     
      }
    }
  }
}
if (window.attachEvent) window.attachEvent('onload', IEhoverBug);

/*--------------------------------------------------*/
//Internet explorer detect
function browserIsIE()
{
  var detect = navigator.userAgent.toLowerCase();
  if (checkIt('msie'))
    return true;  
  return false;
  
  function checkIt(string)
  {
	  if ((detect.indexOf(string) + 1) && !(detect.indexOf('opera') + 1)) //hvis msie og ikke opera!!! :-)
	    return true;
	  return false;
  }
}

// ----------------- Text box -----------------//

function ClickDefaultButton(buttonID, e)
{
    var ev = e;
    var code;
    
    if(ev == null)
        ev = windows.event;
        
    
    if(ev.keyCode)
        code = ev.keyCode;
    else
        if(ev.which) code = e.which;
        
    if(code == 13)
    {
        var control = document.getElementById(buttonID);
        if(control)
        {
           // link doesn't have click method in FF, add it
           if(typeof(control.click) == "undefined" && control.tagName == "A")
              expandLink(control);
               
           if(control.click)
           {
               control.click();
               ev.cancelBubble = true;
               if (ev.stopPropagation) ev.stopPropagation();
               return false;              
           }
        }
    }
    
    return true;
}

function expandLink(control)
{
   if(typeof (control.click) == "undefined")
   {
      control.click = function() { 
                        var result = null;
                        if(this.onclick != null) {
                           result = this.onclick();
                        }
                        
                        if(typeof(result) == "undefined" || result != false) {
                           eval(decodeURI(this.href));
                        }
                     }
   }
}

function TextBoxOnFocus(c, defaultText)
{
    if(c.type == "text")
    {
        if(defaultText == null)
            defaultText = c.defaultValue;
            
        if(c.value == defaultText)
            c.value = '';            
    }
    else if(c.type == "textarea")
    {
        c.select();
    }
}

// -----------------  -----------------//

function FixIeImageTransparent()
{   
   if(navigator.userAgent.toLowerCase().indexOf('msie')>0){ // detect for IE (could be more specific to PC and version, but this works for the test)
   
      var version = 0.0;
      if (navigator.appVersion.indexOf("MSIE")!=-1){
         temp=navigator.appVersion.split("MSIE")
         version=parseFloat(temp[1])
      }

      if (version>=5.5 && version < 7)
      {	      	      
	      is = document.getElementsByTagName('IMG'); // get all images
	      for(x=0; x<is.length; x++){ // cycle through those images	   
		      var src = is[x].src;
		      if((src.indexOf('.ashx') >=0 && src.indexOf('thn=1') >=0) || ( src.length > 4 && src.substring(src.length - 4) == '.png')){ // only do this to png files or sitecore thubnails			   			   
			      // Fix only thumbnail for ie
			      is[x].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"');"; // apply the filter stuff that makes IE do it's magic			   		 
			      is[x].src = "/sitecore/images/blank.gif"; // replace the image with a clear gif so that the filter can show through   			   
		      }
	      }      
      }
   }
}

// ----------------- MSS RequiredFieldValidator ----------------- //
function MssRequiredFieldValidatorIsValid(val)
{
   var validatorValue = ValidatorGetValue(val.controltovalidate);
   return (validatorValue.length > 0 && ValidatorTrim(validatorValue) != ValidatorTrim(val.initialvalue))
}