
// pops up a window at the specified dimensions at the given url
function popupWindow(url, width, height, destination) {
	
	width = width;
	height = height;
	window.open(url, 0, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+width+',height='+height+',left=280,top=100,screenX=280,screenY=100');
}

// pops up a window at the specified dimensions at the given url
function popupScrollingWindow(url, width, height, destination) {
	
	width = width;
	height = height;
	window.open(url, 0, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width='+width+',height='+height+',left=280,top=100,screenX=280,screenY=100');
}

function modalPopupWindow(url, width, height, destination) {

	showModalDialog(url, '', 'dialogHeight:'+height+'px;dialogWidth:'+width+'px;center:1;resizable:0;scroll:0');
}

// modified from Spip /ecrire

var vis = new Array();

function MM_findObj(n) { //v4.0

	return document.getElementById(n);
}


function confirmAction(theAction)
{
    // Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (typeof(window.opera) != 'undefined')
	{
        return true;
    }

    var is_confirmed = confirm('Etes-vous sūr de vouloir : \n' + theAction);

    return is_confirmed;
}

// Check for null and for empty
function isFilled(elm)
{
	checkVal = elm.value;
	checkVal = trim(checkVal);
	
	if (checkVal == "" || checkVal == null) 
		return false;
	else
		return true;
}

// Check valid email address
function isValidEmail(str)
{

  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid

  if (!reg1.test(str) && reg2.test(str))
  {
    return true;
  }

  return false;
}

// Trim functions

function ltrim(str)
{
   var whitespace = new String(" \n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

function rtrim(str)
{
   var whitespace = new String(" \n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }

   return s;
}

function trim(str)
{
   return rtrim(ltrim(str));
}


// Form checking

function isContactFormReady(form) {

	if (isFilled(form.name) == false)
	{
		alert("Please supply a contact name.");
		form.name.focus();
		return false;
	}

	if (isFilled(form.email) == false)
	{
		alert("Please supply a contact email.");
		form.email.focus();
		return false;
	}
	if(!isValidEmail(form.email.value))
	{
		alert("Please check the format of your email address.");
		form.email.focus();
		return false;
	}
	if (isFilled(form.subject) == false)
	{
		alert("Please supply a subject.");
		form.subject.focus();
		return false;
	}
	if (isFilled(form.message) == false)
	{
		alert("Please supply a message.");
		form.message.focus();
		return false;
	}

	return true;
}

var rollovers = new Array();

function getRollovers()
{
	for (x=1; x<=7; x++) 
	{
		var pic = new Image(173,130);
    	pic.src = "site/img/furniture/rollover" + x + ".jpg";
		rollovers[x] = pic;
	} 
}

function showRollover(image)
{
	var pic = rollovers[image];
	var target = MM_findObj('rollover');
	target.src = pic.src;

	var targetlink = MM_findObj('rollover_link');
	targetlink.href = 'rubrique.php3?id_rubrique=5&category_id='+image;

}