/**
 * Open a pop up window
 **/
function popUp(url,id,w,h,r,s)
	{
	if(!id) id = 'popup';
	if(!w) w = 400;
	if(!h) h = 300;
	if(!r) r = '0';
	if(!s) s = '0';
    r = window.open(url,id,'width='+w+',height='+h+',menubar=0,statusbar=0,status=0,location=0,scrollbars='+s+',resizable='+r);
	}
/**
 * delete alert
 * @param string url of the page
 */
function del(pg) {
	// todo : lang replacement !!
	msg = "Etes-vous sûr de vouloir effacer cet élément ?";
	if(confirm(msg))
		location.href = pg;
	}
/**
 * change client in contact form
 */
function change_client(t)
	{
	sel = t.options[t.selectedIndex].value;
	if(sel=='etudiant')
		showdiv('div_etudiant');
	else
		hidediv('div_etudiant');
	}
/**
 * get element
 */
function get_element(n)
	{
	if (document.getElementById) { // DOM3 = IE5, NS6 
		return document.getElementById(n); 
		} 
	else if (document.layers) { // Netscape 4 
			return document[n]; 
		} 
	else { // IE 4 
		return document.getElementById(n); 
		} 
	} 
/**
 * change client in contact form
 */
function showhide(div)
	{
	if (document.getElementById) { // DOM3 = IE5, NS6 
		var onoff = document.getElementById(div).style.visibility=='visible'; 
		} 
	else { 
		if (document.layers) { // Netscape 4 
			var onoff = document[div].visibility=='visible'; 
			} 
		else { // IE 4 
			var onoff = document.getElementById(div).style.visibility=='visible'; 
			} 
		} 

	if(onoff)
		hidediv(div);
	else
		showdiv(div);
	}
/**
 * submit the form to the specified page
 * @param string page to go
 */
function formback(pg) {
	document.checkoutadrform.action = pg;
	document.checkoutadrform.submit();
	}
/**
 * submit the product top the wishlist
 * @param object form object
 **/
function submit_wishlist(f) {
	frm = get_element(f);
	frm.mod.value='wishlist_add';
	frm.submit();	
	}
/**
 * use to update image for all product
 **/
function toupdate(t)
	{
	if(t.checked)
		{
		document.toupdateform.toupdate.value += '|'+t.value;
		}
	else {
		var v = document.toupdateform.toupdate.value;
		document.toupdateform.toupdate.value = v.replace(eval('/\\|'+t.value+'/g'),'');
		}
	}
/**
 *
 **/
function validateshippingForm(t)
	{
	var newadr = false;
	var o = document.shippingform.ship_same_billing;
	// find the good one
	for(var i=0;i<o.length;i++) {
		if(o[i].value=="no" && o[i].checked) {
			newadr = true;
			}
		}

	if(newadr){
		return validateForm(t);
		}
	else{
		return true;
		}
	}

/**
 *
 **/
function validateSchoolShippingForm(t)
	{
	var newadr = false;
	var o = document.shippingform.ship_mode;
	// find the good one
	for(var i=0;i<o.length;i++) {
		if(o[i].value=="ship_post" && o[i].checked) {
			newadr = true;
			}
		}

	if(newadr){
		return validateForm(t);
		}
	else{
		return true;
		}
	}

/**
 *
 **/
function validateCheckout(){
	if(document.validate_order.check_conditions.checked){
		return validateForm(document.validate_order);
	}else{
		//alert('<?=$trs->get("check_condition")?>');
		alert('Veuillez accepter les conditions générales');
		//alert(pas bon);
		return false;
	}
}

/******************************************************************************
 * generic
 *****************************************************************************/

/**
 * hide a layer
 */
function hidediv(pi_layerName)
	{
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById(pi_layerName).style.visibility = 'hidden'; 
		document.getElementById(pi_layerName).style.position = 'absolute'; 
		} 
	else { 
		if (document.layers) { // Netscape 4 
			document[pi_layerName].visibility = 'none'; 
			} 
		else { // IE 4 
			document.all.pi_layerName.style.visibility = 'hidden'; 
			document.getElementById(pi_layerName).style.position = 'absolute'; 
			} 
		} 
	} 

/**
 * show a layer
 */
function showdiv(pi_layerName)
	{ 
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById(pi_layerName).style.position = 'static'; 
		document.getElementById(pi_layerName).style.visibility = 'visible'; 
		} 
	else { 
		if (document.layers) { // Netscape 4 
			document[pi_layerName].visibility = 'visible'; 
			} 
		else { // IE 4 
			document.getElementById(pi_layerName).style.position = 'static'; 
			document.all.pi_layerName.style.visibility = 'visible'; 
			} 
		} 
	}