<!--
// function to capture all onload events
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

//pop-up windows.
function popup(url,breedte,hoogte, naam)
{
	grootte="toolbar=no,location=no,menubar=no,scrollbars=yes,width="+breedte+",height="+hoogte+",resizeable=no,status=no";
	window.open(url,naam,grootte);
}

//confirms action triggered by user..
function confirmAction(infotext){
var agree=confirm(infotext);
if (agree)
	return true ;
else
	return false ;
}

//function to toggle visibility layers		
function toggleLayer(whichLayer) {
         if (document.getElementById)
     {
      // this is the way the standards work
       var style2 = document.getElementById(whichLayer).style;

             if( style2.diplay == "" || style2.display == "none" )
             {
                  style2.display = "block";
             }
             else
             {
                  style2.display = "none";
             }
     }
     else if (document.all)
     {
          // this is the way old msie versions work
          var style2 = document.all[whichLayer].style;
          style2.display = style2.display? "":"block";
     }
     else if (document.layers)
     {
          // this is the way nn4 works
          var style2 = document.layers[whichLayer].style;
          style2.display = style2.display? "":"block";
     }
}

//getvalue of dropdown
function get_item(val){
	alert(val);
}

//scroll to bottom of page
function scrollme(){
	ch=document.body.clientHeight
    window.scrollTo(0,ch)
}

//submit after the onsubmit
function submitform(i)
{
 if(document.forms[i].onsubmit())
 {//this check triggers the validations
    document.forms[i].submit();
 } else {
    scrollme()
 }
}

// place new files into teh head-section of teh page
function AddHeader(thetype, therel, thelink, themedia){
   var l=CreateEl("link");
   l.setAttribute("type",type);
   l.setAttribute("rel",therel);
   l.setAttribute("href",thelink);
   l.setAttribute("media",themedia); //screen
   document.getElementsByTagName("head")[0].appendChild(l);
}

// marketplace tenba-bv, build uri
function get_item(selval){
	window.location.href="./inventory.php?action=show&productid="+selval;
}

//tooltip
function enableTooltips(id){
var links,i,h;
if(!document.getElementById || !document.getElementsByTagName) return;

h=document.createElement("span");
h.id="btc";
h.setAttribute("id","btc");
h.style.position="absolute";
document.getElementsByTagName("body")[0].appendChild(h);

if(id==null) links=document.getElementsByTagName("p"); // the searched tags
else links=document.getElementById(id).getElementsByTagName("p");
for(i=0;i<links.length;i++){
    Prepare(links[i]);
    }
}

function Prepare(el){
	var tooltip,t,b,s,l;
	t=el.getAttribute("title");
	if(t==null || t.length==0){ 
	   exit();
	}else{;
		el.removeAttribute("title");
		tooltip=CreateEl("span","tooltip");
		s=CreateEl("span","top");
		s.appendChild(document.createTextNode(t));
		tooltip.appendChild(s);
		b=CreateEl("b","bottom");
		tooltip.appendChild(b);
		setOpacity(tooltip);
		el.tooltip=tooltip;
		el.onmouseover=showTooltip;
		el.onmouseout=hideTooltip;
		el.onmousemove=Locate;
	}
}

function showTooltip(e){
	document.getElementById("btc").appendChild(this.tooltip);
	Locate(e);
}

function hideTooltip(e){
var d=document.getElementById("btc");
if(d.childNodes.length>0) d.removeChild(d.firstChild);
}

function setOpacity(el){
	el.style.filter="alpha(opacity:90)";
	el.style.KHTMLOpacity="0.90";
	el.style.MozOpacity="0.90";
	el.style.opacity="0.90";
}

function CreateEl(t,c){
	var x=document.createElement(t);
	x.className=c;
	x.style.display="block";
	return(x);
}

function Locate(e){
var posx=0,posy=0;
if(e==null) e=window.event;
if(e.pageX || e.pageY){
    posx=e.pageX; posy=e.pageY;
    }
else if(e.clientX || e.clientY){
    if(document.documentElement.scrollTop){
        posx=e.clientX+document.documentElement.scrollLeft;
        posy=e.clientY+document.documentElement.scrollTop;
        }
    else{
        posx=e.clientX+document.body.scrollLeft;
        posy=e.clientY+document.body.scrollTop;
        }
    }
document.getElementById("btc").style.top=(posy+10)+"px";
document.getElementById("btc").style.left=(posx-20)+"px";
}


//check forms based on required field
function checkform(of,veldid)
{
	// Test if DOM is available and there is an element called required
	if(!document.getElementById || !document.createTextNode){return;}
	if(!document.getElementById(veldid)){return;}

	// Define error messages and split the required fields
	var errorID='errormsg';
	var errorClass='error'
	var errorMsg='Please fill in the required field ';
	var errorImg='../../images/icons/exclamation.gif';
	var errorAlt='Error';
	var errorTitle='This field is not filled properly!';
	var reqfields=document.getElementById(veldid).value.split(',');

	// if there is an old errormessage field, delete it
	if(document.getElementById(errorID))
	{
		var em=document.getElementById(errorID);
		em.parentNode.removeChild(em);
	}
	for(var i=0;i<reqfields.length;i++)
	{
		var f=document.getElementById(reqfields[i]);
		if(!f){continue;}
		if(f.previousSibling && /img/i.test(f.previousSibling.nodeName))
		{
			f.parentNode.removeChild(f.previousSibling);
		}
		f.className='';
	}

	for(var i=0;i<reqfields.length;i++)
	{
		// check if required field is there
		var f=document.getElementById(reqfields[i]);
		var e=document.getElementsByName(reqfields[i]);
		if(!f){continue;}
		
		// test if the required field has an error,
		switch(f.type.toLowerCase())
		{
			case 'text':
			case 'password':
			
				if(f.value=='' && (f.id!='contact_email' && f.id!='email' && f.id!='cemail')){cf_adderr(f)}									
				// email is a special field and needs checking
				if(f.id=='contact_email' && !cf_isEmailAddr(f.value)){cf_adderr(f)}
				if(f.id=='email' && !cf_isEmailAddr(f.value)){cf_adderr(f)}	
				if(f.id=='cemail' && !cf_isEmailAddr(f.value)){cf_adderr(f)}	
			break;
			case 'textarea':
				if(f.value==''){cf_adderr(f)}							
			break;
			case 'checkbox':
			   if(getSelectedCheckbox(e).length==0){cf_adderr(f)}
			break;
			case 'radio':
			   if(getSelectedRadio(e)<0){cf_adderr(f)}
			break;
			case 'select-one':
				if(!f.selectedIndex && f.selectedIndex==0){cf_adderr(f)}							
			break;
		}
	}
	return !document.getElementById(errorID);

	
	function getSelectedRadio(buttonGroup) {
		// returns the array number of the selected radio button or -1 if no button is selected
		if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
		  for (var i=0; i<buttonGroup.length; i++) {
			 if (buttonGroup[i].checked) {
				return i
			 }
		  }
		} else {
		  if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
		}
		// if we get to this point, no radio button is selected
		return -1;
	} // Ends the "getSelectedRadio" function
	
	function getSelectedCheckbox(buttonGroup) {
	   // Go through all the check boxes. return an array of all the ones
	   // that are selected (their position numbers). if no boxes were checked,
	   // returned array will be empty (length will be zero)
	   var retArr = new Array();
	   var lastElement = 0;
	   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
		  for (var i=0; i<buttonGroup.length; i++) {
			 if (buttonGroup[i].checked) {
				retArr.length = lastElement;
				retArr[lastElement] = i;
				lastElement++;
			 }
		  }
	   } else { // There is only one check box (it's not an array)
		  if (buttonGroup.checked) { // if the one check box is checked
			 retArr.length = lastElement;
			 retArr[lastElement] = 0; // return zero as the only array value
		  }
	   }
	   return retArr;
   } // Ends the "getSelectedCheckbox" function

	function cf_adderr(o)
	{
		var errorIndicator=document.createElement('img');
		errorIndicator.alt=errorAlt;
		errorIndicator.src=errorImg;
		errorIndicator.title=errorTitle;
		o.className=errorClass;
		o.parentNode.insertBefore(errorIndicator,o);

	    // Check if there is no error message
		if(!document.getElementById(errorID))
		{
		// create errormessage and insert before submit button
			var em=document.createElement('div');
			em.id=errorID;
			var newp=document.createElement('p');
			newp.appendChild(document.createTextNode(errorMsg))
			// clone and insert the error image
			newp.appendChild(errorIndicator.cloneNode(true));
			em.appendChild(newp);
			// find the hidden button 
			for(var i=0;i<of.getElementsByTagName('input').length;i++)
			{
				if(/reset/i.test(of.getElementsByTagName('input')[i].type))
				{
					var sb=of.getElementsByTagName('input')[i];
					break;
				}
			}
			if(sb)
			{
				sb.parentNode.insertBefore(em,sb);
			}	
		} 
	}
	function cf_isEmailAddr(str) 
	{
	    return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
	}
}
//-->
