/*
  $Id: general.js 1498 2007-03-29 14:04:50Z hpdl $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2005 osCommerce

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License v2 (1991)
  as published by the Free Software Foundation.
*/

function updateDatePullDownMenu(objForm, fieldName) {
  var pdmDays = fieldName + "_days";
  var pdmMonths = fieldName + "_months";
  var pdmYears = fieldName + "_years";

  time = new Date(objForm[pdmYears].options[objForm[pdmYears].selectedIndex].text, objForm[pdmMonths].options[objForm[pdmMonths].selectedIndex].value, 1);

  time = new Date(time - 86400000);

  var selectedDay = objForm[pdmDays].options[objForm[pdmDays].selectedIndex].text;
  var daysInMonth = time.getDate();

  for (var i=0; i<objForm[pdmDays].length; i++) {
    objForm[pdmDays].options[0] = null;
  }

  for (var i=0; i<daysInMonth; i++) {
    objForm[pdmDays].options[i] = new Option(i+1);
  }

  if (selectedDay <= daysInMonth) {
    objForm[pdmDays].options[selectedDay-1].selected = true;
  } else {
    objForm[pdmDays].options[daysInMonth-1].selected = true;
  }
}

function updateCart() {
	document.getElementById('shopping_cart').submit();
	}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function checkBox(object) {
  document.account_newsletter.elements[object].checked = !document.account_newsletter.elements[object].checked;
}

function popupWindow(url, name, params) {
  window.open(url, name, params).focus();
}


function size(id) {

	var inner_x,inner_y;
		if (self.innerHeight) // all except Explorer
		{
			inner_x = self.innerWidth;
			inner_y = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		{
			inner_x = document.documentElement.clientWidth;
			inner_y = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
			inner_x = document.body.clientWidth;
			inner_y = document.body.clientHeight;
		}
	
	var scroll_y;
		if (self.pageYOffset) // all except Explorer
		{
			scroll_y = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
			// Explorer 6 Strict
		{
			scroll_y = document.documentElement.scrollTop;
		}
		else if (document.body) // all other Explorers
		{
			scroll_y = document.body.scrollTop;
		}
	
	
	
	document.getElementById(id).style.left = eval(inner_x/2)+'px';
	document.getElementById(id).style.top = eval(scroll_y+inner_y/2)+'px';
}

function deschide(id) {
	size(id);
	document.getElementById(id).className = '';
}

function inchide(id){
	document.getElementById(id).className = 'ascuns';
}


function verify_payment(){
	var radio=document.getElementById("payment_method");
	var selected=-1;
	for (i=0;i<document.forms[0].payment_method.length;i++) {
	if (document.forms[0].payment_method[i].checked) {
		selected = document.forms[0].payment_method[i].value;
	}
}
	var cond_general=document.getElementById("cond_general").checked;
	var msg='';
	var error=0;
	if(selected==-1) {
		msg="Veuillez choisir une métode de paiement pour votre commande."+"\n";
		error=1;
	}
	if(cond_general==false) {
		msg+="Vous devez accepter les conditions génerales de vente pour passer commande."+"\n";
		error=1;
	}
	if(error==1) {
		alert(msg);
		return false;
	}
	else {
		document.getElementById("checkout_payment").submit();
	}
}
