var all_links = document.getElementsByTagName('a');
function doDisableSubmits(el){
	var el;
	//if(x)
	//	disFlag='FALSE';
	//else
	disFlag='TRUE';
	if(document.forms.length >0){
		for(f=0;f<document.forms.length;f++){
			for (i = 0; i < document.forms[f].length; i++) {
				var tempobj = document.forms[f].elements[i];
				if (tempobj.type.toLowerCase() == 'submit')
					var x;
				//tempobj.style.display = 'none';
			}
		}
	}
	doDisableLinks(el);
	//if(document.forms.length>0)
	//	document.forms[0].submit();
}

function doDisableLinks(el){
	var el;
	var clicked = new String(el);
	for(i=0;i<all_links.length;i++){
		if(all_links[i].getAttribute("href").toLowerCase().indexOf("javascript")== -1 &&
			all_links[i].getAttribute("href").toLowerCase().indexOf("mailto:")== -1){
			all_links[i].disabled = true;
			var link = new String(all_links[i]);
			if(link.toLowerCase() != clicked.toLowerCase()){
				all_links[i].removeAttribute('href');
			}else{
				window.location = clicked;
				//for some reason even if you call the location replace before you remove the 
				//href attribute the browser loses it. so we keep jus this one
				//all_links[i].removeAttribute('href');
			}
		}
	}
}
function doLink(e){// e = event
	var el;
	if(window.event && window.event.srcElement)
		el = window.event.srcElement;
	if(e && e.target)
		el = e.target;
	if(!el)
		return;
	//var link = ;
	doDisableSubmits(el);
}
function PageDisable(){//add event listeners to all submit buttons
	if(document.forms.length >0){
		for(f=0;f<document.forms.length;f++){
			 for (i = 0; i < document.forms[f].length; i++) {
				var tempobj = document.forms[f].elements[i];
				if (tempobj.type.toLowerCase() == 'submit'){
				addEvent(tempobj,'click',doDisableSubmits,false);
				}
			 }
		 }
	}
//	var all_links = document.getElementsByTagName('a');
	for(i=0;i<all_links.length;i++){
		if(all_links[i].getAttribute("href").toLowerCase().indexOf("javascript")== -1 &&
			all_links[i].getAttribute("href").toLowerCase().indexOf("mailto:")== -1)
		addEvent(all_links[i],'click',doLink,false);
	}
}
//add event to DOM object
//use for custom event listening.
//USAGE: addEvent(object, 'event[click,change,load,mouseOver...etc]', functionToCall, false);
function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : 
    oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}
//AJAX Functions
function makeAJAXRequest(url,returnFunctionCall){
	if (window.XMLHttpRequest) {
		   req = new XMLHttpRequest();	//req =Request Objects
		   req.onreadystatechange = returnFunctionCall;
		   req.open("GET", url, true);
		   req.send(null);
	// branch for IE/Windows ActiveX version
	    } else if (window.ActiveXObject) {
		   req = new ActiveXObject("Microsoft.XMLHTTP");
		   if (req) {
			  req.onreadystatechange = returnFunctionCall;
			  req.open("GET", url, true);
			  req.send();
		   }
	    }
}
function clearTable(tbody){
	for(i=0;i<tbody.rows.length;i++){
		row = tbody.getElementsByTagName("TR").item(i);
		tbody.removeChild(row);
	}
}
function addCell(row,cell){
	if(cell == 'none' || cell == ', ')
		cell=' ';
	mycurrent_cell=document.createElement("TD");
	currenttext=document.createTextNode(cell);
	mycurrent_cell.appendChild(currenttext);
	row.appendChild(mycurrent_cell);
}
// climb up the tree to the supplied tag.
function ascendDOM(e, target) {
  while (e.nodeName.toLowerCase() != target && 
      e.nodeName.toLowerCase() != 'html')
    e = e.parentNode;
  
  return (e.nodeName.toLowerCase() == 'html') ? null : e;
}

// turn on highlighting
function hi_cell(e) {
  var el;
  if (window.event && window.event.srcElement)
    el = window.event.srcElement;
  if (e && e.target)
    el = e.target;
  if (!el) return;

  el = ascendDOM(el, 'td');
  if (el == null) return;

  var parent_row = ascendDOM(el, 'tr');
  if (parent_row == null) return;

  var parent_table = ascendDOM(parent_row, 'tbody');
  if (parent_table == null) return;

  // row styling
  parent_row.className += ' hi';
/**
  // column styling
  var ci = -1;
  for (var i = 0; i < parent_row.cells.length; i++) {
    if (el === parent_row.cells[i]) {
      ci = i;
    }
  }
  if (ci == -1) return; // this should never happen

  for (var i = 0; i < parent_table.rows.length; i++) {
    var cell = parent_table.rows[i].cells[ci];
    cell.className += ' hi';
  }
*/
}

// turn off highlighting
function lo_cell(e) {
  var el;
  if (window.event && window.event.srcElement)
    el = window.event.srcElement;
  if (e && e.target)
    el = e.target;
  if (!el) return;

  el = ascendDOM(el, 'td');
  if (el == null) return;
  
  var parent_row = ascendDOM(el, 'tr');
  if (el == null) return;

  var parent_table = ascendDOM(parent_row, 'tbody');
  if (el == null) return;

  // row de-styling
  parent_row.className = parent_row.className.replace(/\b ?hi\b/, '');
/**
  // column de-styling
  var ci = -1;
  for (var i = 0; i < parent_row.cells.length; i++) {
    if (el === parent_row.cells[i]) {
      ci = i;
    }
  }
  if (ci == -1) return; // this should never happen

  for (var i = 0; i < parent_table.rows.length; i++) {
    var cell = parent_table.rows[i].cells[ci];
    cell.className = cell.className.replace(/\b ?hi\b/, '');
  }
  */
}
	var isOpera = navigator.userAgent.indexOf("Opera") > -1;
	var isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera;
	var isMoz = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !isOpera;

function textboxSelect (oTextbox, iStart, iEnd) {

   switch(arguments.length) {
       case 1:
           oTextbox.select();
           break;

       case 2:
           iEnd = oTextbox.value.length;
           /* falls through */
           
       case 3:          
           if (isIE) {
               var oRange = oTextbox.createTextRange();
               oRange.moveStart("character", iStart);
               oRange.moveEnd("character", -oTextbox.value.length + iEnd);      
               oRange.select();                                              
           } else if (isMoz){
               oTextbox.setSelectionRange(iStart, iEnd);
           }                    
   }

   oTextbox.focus();
}

function textboxReplaceSelect (oTextbox, sText) {

   if (isIE) {
       var oRange = document.selection.createRange();
       oRange.text = sText;
       oRange.collapse(true);
       oRange.select();                                
   } else if (isMoz) {
       var iStart = oTextbox.selectionStart;
       oTextbox.value = oTextbox.value.substring(0, iStart) + sText + oTextbox.value.substring(oTextbox.selectionEnd, oTextbox.value.length);
       oTextbox.setSelectionRange(iStart + sText.length, iStart + sText.length);
   }

   oTextbox.focus();
}

function autocompleteMatch (sText, arrValues) {

   for (var i=0; i < arrValues.length; i++) {
       if (arrValues[i].indexOf(sText) == 0) {
           return arrValues[i];
       }
   }

   return null;

}

function autocomplete(oTextbox, oEvent, arrValues) {

   switch (oEvent.keyCode) {
       case 38: //up arrow  
       case 40: //down arrow
       case 37: //left arrow
       case 39: //right arrow
       case 33: //page up  
       case 34: //page down  
       case 36: //home  
       case 35: //end                  
       case 13: //enter  
       case 9: //tab  
       case 27: //esc  
       case 16: //shift  
       case 17: //ctrl  
       case 18: //alt  
       case 20: //caps lock
       case 8: //backspace  
       case 46: //delete
           return true;
           break;

       default:
           textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode));
           var iLen = oTextbox.value.length;

           var sMatch = autocompleteMatch(oTextbox.value, arrValues);

           if (sMatch != null) {
               oTextbox.value = sMatch;
               textboxSelect(oTextbox, iLen, oTextbox.value.length);
           }  
           
           return false;
   }
} 

hex=210 // Initial color value.
function fadetext(el){ 
if(hex>0) { //If color is not black yet
hex-=11; // increase color darkness
	el.style.color="rgb("+hex+","+hex+","+hex+")";
setTimeout("fadetext(el)",30); 
}
else
hex=210 //reset hex value
}

function makeOption(display,value,selected){
	 var opt = new Option(display,value,selected,selected);
	 return opt;
}

//open rico utils...
function fixImage(img, width, height) {
   var isIE = navigator.userAgent.toLowerCase().indexOf("msie") >= 0;
   if (!isIE)
      return;

   var currentSrc = img.src;

   var imgStyle = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + currentSrc + "', sizingMethod='scale')";
   img.src = 'images/clearpixel.gif';
   img.style.width  = width + "px";
   img.style.height = height + "px";
   img.style.filter =  imgStyle;
}

var navigationPages = [ "home.page",  "demos.page", "docs.page",  "downloads.page" ];
var navigationLinks = [ "homeLink",  "demosLink", "resourcesLink", "downloadsLink" ];

function showMenuContext() {
   var currentLocation = document.location.href;
   for ( var i = 0 ; i < navigationPages.length ; i++ )
      if ( currentLocation.indexOf(navigationPages[i]) != -1 ) { setLinkStyle($(navigationLinks[i])); break; }
}

function setLinkStyle(link) {
   link.style.fontWeight = 'bold';
   var currentFontSize = parseInt(RicoUtil.getElementsComputedStyle(link, "fontSize", "font-size" ));
   link.style.fontSize = (currentFontSize+2) + "px";
   link.style.color    = 'white';
}



