
/*********************************
 * PEM EFFECTS @ 2008
 *********************************/
var BgOpacity = 60;
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

var myBrowser = BrowserDetect.browser;
var myBrowserVersion = BrowserDetect.version;

/*********************************************
*   FONCTION loadPageContent()
**********************************************/
var loadPageContent = function ( PageContent, MyDiv, ActionType ){

  // on appelle l'ajax
  var zeUrl = ASSurl + '?ActionType='+ActionType+'&PageContent='+PageContent;

  if ( MyDiv == '' ) MyDiv = 'modal_popup';
  AjaxRequest( zeUrl, MyDiv );
}

var	addMultProducts = function ( PageContent, MyDiv, ActionType1, ActionType2 , ActionType3, ActionType4, lang)
{
	var aAction = new Array();

	if(ActionType1 != '')
		aAction.push(ActionType1);
	if(ActionType2 != '')
		aAction.push(ActionType2);
	if(ActionType3 != '')
		aAction.push(ActionType3);
	if(ActionType4 != '')
		aAction.push(ActionType4);
	AjaxRequestDerma(aAction, lang);
}



function AjaxRequestDerma(paAction, lang) {

	if(paAction.length == 0)
	  return false;

	var myUrl = ASSurl + '?ActionType=' + paAction[0] + "&PageContent=''";

	var http_request = false;

	  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	      http_request = new XMLHttpRequest();
	      if (http_request.overrideMimeType) {
	          http_request.overrideMimeType('text/xml; charset=ISO-8859-1');
	      }
	  }else if (window.ActiveXObject) { // IE
	      try {
	          http_request = new ActiveXObject("Msxml2.XMLHTTP");
	      } catch (e) {
	          try {
	              http_request = new ActiveXObject("Microsoft.XMLHTTP");
	          } catch (e) {}
	      }
	  }

	  if (!http_request) {
	      alert('Giving up :( Cannot create an XMLHTTP instance');
	      return false;
	  }
	http_request.aAction = paAction;
	http_request.onreadystatechange = function() {
	  if(http_request.readyState == 4)
	  {
	    var laAction = http_request.aAction;
	    laAction.shift();
	    if(laAction.length > 0)
	    {
	      AjaxRequestDerma(laAction, lang);
	    }
	    else
	    {
	      MyDiv = 'modal_popup';
	      var oDiv = document.getElementById(MyDiv);

	      Pop = "<div style='background-color:#000; border:solid 3px #FFF; text-align:center; padding:20px; font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#FFF;'>";
	      if (lang == 'french')
		{
		  Pop += "Vos produits ont été correctement ajoutés à votre panier<br />";
		  Pop += "<br /><img src='http://www.comptoirdelhomme.com/templates/Original/images/buttons/french/continue_shopping.gif' style='cursor:pointer;' onclick='hideModalPopup(); document.location = \"index.php\";'>&nbsp;&nbsp;<img src='http://www.comptoirdelhomme.com/templates/Original/images/buttons/french/goto_order.gif'style='cursor:pointer;' onclick='hideModalPopup(); document.location = \"shopping_cart.php\";'></div>";
		}
	      else
		{
		  Pop += "Your products were correctly added to your basket";
		  Pop += "<br /><img src='http://www.comptoirdelhomme.com/templates/Original/images/buttons/english/continue_shopping.gif' style='cursor:pointer;' onclick='hideModalPopup(); document.location = \"index.php\";'>&nbsp;&nbsp;<img src='http://www.comptoirdelhomme.com/templates/Original/images/buttons/english/goto_order.gif'style='cursor:pointer;' onclick='hideModalPopup(); document.location = \"shopping_cart.php\";'></div>";
		}
	      oDiv.innerHTML = Pop;
	      showModal(oDiv);
	    }
	  }
	    };


	var zeUrl = myUrl.substring(0, myUrl.indexOf('?'));
	var zeQuery = myUrl.substring( myUrl.indexOf('?')+1, myUrl.length );
	http_request.open('POST', zeUrl, true);
	http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	http_request.setRequestHeader("If-Modified-Since", "Mon, 26 Jul 1997 05:00:00 GMT");
	http_request.setRequestHeader("Cache-Control", "no-cache, must-revalidate");
	http_request.setRequestHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
	http_request.send(zeQuery);



	zeUrl 		= null;
	zeQuery 	= null;

}



/*********************************************
*   FONCTION hideModalPopup()
**********************************************/
function hideModalPopup(){

  var zePopup = document.getElementById('modal_popup');
  var zeModal = document.getElementById('modal_bg');

  hideMe( zeModal );
  hideMe( zePopup );
/*  fadeElement( 'modal_bg' );*/
}


/*********************************************
*   FONCTION showModal()
**********************************************/
function showModal( zePopup ){
  var myel = document.getElementById( 'modal_bg' );
  myel.style.display="block";
  // en fonction du navigateur, la transparence n'est pas gérée de la même façon

  if ( myBrowser == 'Safari' || myBrowser == 'Konqueror' ){
    myel.style.opacity = ( BgOpacity / 100 );
    myel.style.KhtmlOpacity = (BgOpacity / 100);
  }else{
    if( myBrowser == 'Explorer' ){
      myel.style.filter = "alpha(opacity=" + BgOpacity + ")";
    }else{
      myel.style.MozOpacity = ( BgOpacity / 100 );
      myel.style.opacity = ( BgOpacity / 100 );
    }
  }


/*
  if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5){
    myel.style.MozOpacity = ( BgOpacity / 100 );
    myel.style.opacity = ( BgOpacity / 100 );
    myel.style.KhtmlOpacity = (BgOpacity / 100);
  }else{
    myel.style.filter = "alpha(opacity=" + BgOpacity + ")";
  }
*/
	array_page_size = getPageSize();
	array_page_scroll = getPageScroll();

//	myel.style.width = '100%';
  myel.style.width  = array_page_size[0]+'px';
	myel.style.height = array_page_size[1]+'px';

//  var zeEls = document.getElementsByTagName('body');
//	var bdHeight = zeEls[0].offsetHeight;

  zePopup.style.visibility = 'hidden';
  zePopup.style.display = 'block';

	var middleHeight = ( ( array_page_size[3] * 1 ) / 2 ) - ((zePopup.offsetHeight * 1)/1.5);
//  alert( middleHeight +'\n'+ array_page_scroll[1] + '\n'+ ((zePopup.offsetHeight * 1)/1.5) );
	zePopup.style.top = array_page_scroll[1]+middleHeight+'px';// 200 pour la marge top
	zePopup.style.left = array_page_size[0]/2-((zePopup.offsetWidth * 1)/2)+'px';
  zePopup.style.visibility = 'visible';
//  zePopup.style.display = 'block';
}

function checkAddAddressForm(){

  if ( document.getElementById('gender_m').checked == false && document.getElementById('gender_f').checked == false ){
    alert( 'La civilité doit être renseignée' );
    return false;
  }

  if ( document.getElementById('firstname').value == "" ){
    alert( 'Le prénom doit être renseigné' );
    return false;
  }

  if ( document.getElementById('lastname').value == "" ){
    alert( 'Le nom doit être renseigné' );
    return false;
  }

  if ( document.getElementById('street_address').value == "" ){
    alert( 'L\'adresse doit être renseignée' );
    return false;
  }

  if ( document.getElementById('postcode').value == "" ){
    alert( 'Le code postal doit être renseigné' );
    return false;
  }

  if ( document.getElementById('city').value == "" ){
    alert( 'La ville doit être renseignée' );
    return false;
  }

  if ( document.getElementById('country').options[document.getElementById('country').selectedIndex].value == "" ){
    alert( 'Le pays doit être renseigné' );
    return false;
  }

  document.getElementById('checkout_address').submit();

}

function checkFriendForm(){

  if ( document.getElementById('from_email_address').value == "" ){
    alert( 'L\'adresse mail doit être renseigné' );
    return false;
  }

  if ( document.getElementById('from_name').value == "" ){
    alert( 'Le nom doit être renseigné' );
    return false;
  }

  if ( document.getElementById('to_name').value == "" ){
    alert( 'Le nom de votre ami doit être renseignée' );
    return false;
  }

  if ( document.getElementById('to_email_address').value == "" ){
    alert( 'L\'adresse mail de votre ami doit être renseigné' );
    return false;
  }

  if ( document.getElementById('message').value == "" ){
    alert( 'Le message doit être renseignée' );
    return false;
  }

  document.getElementById('email_friend').submit();

}
