// standard.js JavaScript Document

//------------------------------------ function switch language page
function switch_Lang(e, r){
	top.location.href = replaceSubstring(location.href, e, r);
}
//------------------------------------ function switch language page

//------------------------------------ function replace substring
function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
}
//------------------------------------ function replace substring

//------------------------------------ function window opener
function windowOpener(url, name, args) {
if (typeof(popupWin) != "object"){
	popupWin = window.open(url,name,args);
} else {
if (!popupWin.closed){ 
	popupWin.location.href = url;
} else {
	popupWin = window.open(url, name,args);
}
}
	popupWin.focus();
}
//------------------------------------ function window opener

//------------------------------------ function valid email
function emailCheck (checkThisEmail) {

var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;
var msgfr = "E-mail not valid";
var msgen ="E-mail not valid";

if (myAtSymbolAt < 1 )
{
	alert(msgfr);
	return false;
}

if (myLastDotAt < myAtSymbolAt)
{
	alert(msgfr);
	return false;
}

if (myLength - myLastDotAt <= 2)
{
	alert(msgfr);
	return false;
}

if (mySpaceAt != -1)
{
	alert(msgfr);
	return false;
}

if (myEMailIsValid == true)
{
	return true;
}
}
//------------------------------------ function valid email

//------------------------------------ dreamweaver image function
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//------------------------------------ dreamweaver image function

//------------------------------------ extraction to the right function
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
//------------------------------------ extraction to the right function

//------------------------------------ extraction to the left function
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

//------------------------------------ extraction to the left function

//
//
// CATALOG FUNCTIONS
//------------------------------------ calcul output price for many size available
function final_price(pricepay, addamount){
	var mt = "";
	var pos = addamount.indexOf("+");	
	var total = pricepay;
		
	if( pos != -1){
		pos = pos + 1;
		mt = Right(addamount, addamount.length - pos);
		price = Left(mt , mt.length-1);
		total = parseFloat(pricepay) + parseFloat(price);
	}
	
	document.item.amount.value = total;
	document.item.submit();
		
		
}
//------------------------------------ calcul output price for many size available

//
//
// SPOT GUIDE ENGLISH VALIDATION
//------------------------------------ validation
function spotguide( form ){
	if( form.name.value == "" ){
			alert( "Your name is mandatory");
			form.name.focus();
			return false;
	}
	
	if( form.email.value == "" ){
			alert( "Your email is mandatory");
			form.email.focus();
			return false;
	}

	if( !(emailCheck( form.email.value )) ){
			return false;
	}
	
	if( form.spotname.value == "" ){
			alert( "The spot name is mandatory");
			form.spotname.focus();
			return false;
	}
	
	if( form.city.value == "" ){
			alert( "The name of city is mandatory");
			form.city.focus();
			return false;
	}
	
	if( form.provincekey.value == "" ){
			alert( "The province is mandatory");
			form.country.focus();
			return false;
	}
	
	if( !(isValidExtension( form.fileupload.value )) ){
			return false;
	}
	
	
	form.submit();
}
//------------------------------------ validation

//------------------------------------ image upload validation
function isValidExtension( ext ){
	if( ext != ""){
		if( Right(ext,4).toLowerCase() != ".gif" && Right(ext,4).toLowerCase() != ".jpg" && Right(ext,5).toLowerCase() != ".jpeg" ){
			alert("Seulement les extensions .gif, .jpg ou .jpeg sont permis")
			return false;
		}
	}
	return true;
}
//------------------------------------ image upload validation
