/*
===================================================
By Xploïse,  http://www.xploise.nl

getObj from: http://www.quirksmode.org/js/dhtmloptions.html
===================================================
*/

var DHTML = (document.getElementById || document.all || document.layers);
var menu=new Array();
var idle=new Array();
var thepayment='order_vooraf.php';
var kadootjes=0;
var produkt=0;
var couponURL = "../includes/checkCoupon.php"; // The server-side script
var url = "../includes/checkProduct.php?id="; // The server-side script
var http = getHTTPObject();
var d = new Date();
var copy = 'Copyright &copy; 2005 - '+d.getFullYear()+' Juwelier Ed Oorebeek&nbsp;|&nbsp;Ontwikkeld door <a class="footer" href="http://www.xploise.nl" target="_new">Xplo&iuml;se</a>, <span style="font-style:italic;color:rgb(200,200,200)">webpages made easy</span>';

function checkLen(y,z,i)
{
	document.getElementById('couponCheck').innerHTML='<img src="images/'+i+'/wait.gif" alt="wait" />';
if (y.length==32)
  {
  checkCoupon(y,z);
  }
}

function bounceUp(element,sy,dy){
	if(sy>dy){
	sy--;
	document.getElementById(element).style.top=sy+'px';
	bounceUp(element,sy,dy);
	}
}

function bounceDown(element,sy,dy){
	if(sy<dy){
	sy++;
	document.getElementById(element).style.top=sy+'px';
	bounceDown(element,sy,dy);
	}
}

function getColor(page, color, language){
	althref(page+'?color='+color+'&language='+language);
}

function getLanguage(page, language, color){
	althref(page+'?language='+language+'&color='+color);
}

function del_cookie(name) {
	var date = new Date();
	document.cookie = name + '=; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/';
}

function is_child_of(parent, child) {
	if( child != null ) {
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}

function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {				
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}
	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		eval(JavaScript_code);
	}
}

function verstoppen(layer,button,style){
	get_object(layer).style.display='none';
	get_object(button).style.backgroundImage="url('images/"+style+"/kruimelpadKnop.png')";
}

function checkProduct(right,id) {
    
    http.open("GET", url + escape(id), true);
    http.onreadystatechange = function() {
    if (http.readyState == 4) {
    results = http.responseText;
        if(results!=0){
            if(confirm('Aan dit menu-item zijn produkten gekoppeld!\nIndien u dit menu-item verwijderd, moet u er rekening mee houden de produkten aan een ander menu-item te koppelen.\nMenu-item verwijderen?')){
                window.location=('<?=$_SERVER[\'PHP_SELF\'];?>?id='+id+'&right='+right);
            }
        }else{
            if(confirm('Weet u zeker dat u dit menu-item wilt verwijderen?')){
                window.location=('<?=$_SERVER[\'PHP_SELF\'];?>?id='+id+'&right='+right);
            }
        }
    }
}
    http.send(null);
 }

function checkCoupon(coupon,id) {
    
    http.open("GET", couponURL + '?coupon=' + escape(coupon) + '&id=' + escape(id), true);
    http.onreadystatechange = function() {
    if (http.readyState == 4) {
    results = http.responseText;
        if(results!=0){
        	if(results.substring(1,27)=='img src="../images/no.png"'){
        		document.getElementById('couponCheck').className='couponFalse';
        		document.getElementById('couponCheck').innerHTML=results;
            	document.getElementById('coupon').value='';
            	document.getElementById('coupon').focus();
            }else{
            	document.getElementById('couponCheck').className='couponValid';
            	document.getElementById('couponCheck').innerHTML=results;
            	document.getElementById('coupon').value='';
            	document.getElementById('remark').focus();
            }
        }
    }
}
    http.send(null);
 }
 
function getHTTPObject() {

  var xmlhttp;

  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

    try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

    }

  }

  return xmlhttp;

}

/* 
general function to get object and style info of a layer
*/

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function get_object(id) {
	var object = null;
	if( document.layers )	{
		object = document.layers[id];
	} else if( document.all ) {
		object = document.all[id];
	} else if( document.getElementById ) {
		object = document.getElementById(id);
	}
		return object;
	}

if(!window.MM_findObj){
	function MM_findObj(n, d) {
	  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 addRelation(idx){
	fromObj = MM_findObj("unassigned[]");
	toObj = MM_findObj("assigned[]");
	if(!idx){
		idx = fromObj.selectedIndex;
	}
	if(idx >= 0 && fromObj && toObj){
		for(i=idx;i<fromObj.length;i++){
			if(fromObj.options[i].selected){
				toObj.options[toObj.options.length] = new Option(fromObj.options[i].text,fromObj.options[i].value);
				fromObj.options[i] = null;
				i--;
			}
		}
		sortSelect(toObj);
		//sortSelect(fromObj);
	}
}

function disableUnrelated(){
	obj = MM_findObj("unassigned[]");
	obj.disabled = true;
}

function selectAll(name){
	obj = MM_findObj("assigned[]");
	obj.focus();
	for(i=0;i<obj.length;i++){
		obj.options[i].selected = true;
	}
}

function removeRelation(idx){
	fromObj = MM_findObj("assigned[]");
	toObj = MM_findObj("unassigned[]");
	if(!idx){
		idx = fromObj.selectedIndex;
	}
	if(idx >= 0 && fromObj && toObj){
		for(i=idx;i<fromObj.length;i++){
			if(fromObj.options[i].selected){
				toObj.options[toObj.options.length] = new Option(fromObj.options[i].text,fromObj.options[i].value);
				fromObj.options[i] = null;
				i--;
			}
		}
		sortSelect(toObj);
		//sortSelect(fromObj);
	}
}

function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
}

function sortSelect(obj) {
	var o = new Array();
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort(
		function(a,b) {
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			}
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	}
}


function setQuery(){
var query = document.group.product_menu.options[document.group.product_menu.selectedIndex].value;
document.cookie="query="+query;
window.location.href = "koppelen.php";
}

function althref(link) {
window.location=link;
}

function expand(id,status){
		if (!DHTML) return;
		var x = new getObj(''+id+'');
         if(status == 'show')
 {
  x.style.display = 'block';
 }else
 {
   x.style.display = 'none';
   }
}

function timer(id,status) {
idle[id]=setTimeout("expand('"+id+"','"+status+"')",10);
}

function swap(element,value){
    if (element.value==0){
        element.value=value;
        kadootjes=1;
    }else{
    element.value=0;
    kadootjes=1;
    }
}

function setGoal(goal){
  thepayment=goal;
}

function check_kado(kado,produkt){
	if (kado==1 || produkt==1){
	  var answer=confirm('U heeft een wijziging aangebracht in de bestelling en vervolgens niet op \'bijwerken\' geklikt!\nKlik \'OK\' om alsnog op \'bijwerken\' te klikken, of \'Annuleren\' om de wijzigingen te negeren en door te gaan met de bestelling');
	  if(answer){
	    return;
	  }else{
	    window.location='order_1.php';  
	  }
	}else{
	    window.location='order_1.php';  
}
}

activateMenu = function(nav) {

    /* currentStyle restricts the Javascript to IE only */
	if (document.all && document.getElementById(nav).currentStyle) {  
        var navroot = document.getElementById(nav);
        
        /* Get all the list items within the menu */
        var lis=navroot.getElementsByTagName("LI");  
        for (i=0; i<lis.length; i++) {
        
           /* If the LI has another menu level */
            if(lis[i].lastChild.tagName=="UL"){
            
                /* assign the function to the LI */
             	lis[i].onmouseover=function() {	
                
                   /* display the inner menu */
                   this.lastChild.style.display="block";
                   this.style.backgroundColor="rgb(200,200,200)";
                }
                lis[i].onmouseout=function() {                       
                   this.lastChild.style.display="none";
                   this.style.backgroundColor="rgb(153,153,153)";
                }
            }
        }
    }
}

activateAccessMenu = function(nav) {

    /* currentStyle restricts the Javascript to IE only */
	if (document.all && document.getElementById(nav).currentStyle) {  
        var navroot = document.getElementById(nav);
        
        /* Get all the list items within the menu */
        var lis=navroot.getElementsByTagName("LI");  
        for (i=0; i<lis.length; i++) {
        
           /* If the LI has another menu level */
            if(lis[i].lastChild.tagName=="UL"){
            
                /* assign the function to the LI */
             	lis[i].onmouseover=function() {	
                
                   /* display the inner menu */
                   this.lastChild.style.display="block";
                   this.style.backgroundColor="rgb(200,200,200)";
                }
                lis[i].onmouseout=function() {                       
                   this.lastChild.style.display="none";
                   this.style.backgroundColor="rgb(153,153,153)";
                }
            }
        }
    }
}

function toggle(obj) {

	var el = document.getElementById(obj);

	el.style.display = (el.style.display != 'none' ? 'none' : '' );

}
