
function doUnload(orderid, userid, osample, nopop, nopop2) {


    var browser = navigator.appName;
    var b_version = navigator.appVersion;
    var version = parseFloat(b_version);

    //ORDERS

    if ((browser == "Microsoft Internet Explorer") && (version == 4)) {
        if (nopop2 == 0) {
            if (orderid > 0 && userid == 0) {
                var n = window.event.screenX - window.screenLeft;
                var b = n > document.documentElement.scrollWidth - 20;
                if (b && window.event.clientY < 0 || window.event.altKey) {
                    window.event.returnValue = "";
                    popUpWin('http://www.StoresSelectsCanada.ca/back.aspx?oid=' + orderid + '&src=ISawPopUp5Per', 390, 570);
                }
            }
        }
    }
    else {

        if (nopop2 == 0) {
            if (orderid > 0 && userid == 0) {

                if (window.event && window.event.clientX < 0 && window.event.clientY < 0) {
                    popUpWin('http://www.StoresSelectsCanada.ca/back.aspx?oid=' + orderid + '&src=ISawPopUp5Per', 475, 650);

                }
            }
        }

    }



    //SAMPLES


    if ((browser == "Microsoft Internet Explorer") && (version == 4)) {

        var n = window.event.screenX - window.screenLeft;
        var b = n > document.documentElement.scrollWidth - 20;
        if (b && window.event.clientY < 0 || window.event.altKey) {
            window.event.returnValue = "";
            popUpWin('http://www.StoresSelectsCanada.ca/Back2SamplesPlus50First.aspx?oid=' + orderid + '&src=ISawPopUpSamples', 475, 650);
        }
    }
    else {

        //if(nopop == 0)
        //{
        if (orderid == 0 && userid == 0 && osample == 0) {
            if (window.event && window.event.clientX < 0 && window.event.clientY < 0) {
                popUpWin('http://www.StoresSelectsCanada.ca/Back2SamplesPlus50First.aspx?oid=' + orderid + '&src=ISawPopUpSamples', 375, 550);
                
            }
        }
        //} 


    }


} 




function submit_helpfullink(obj,selected) {

	if(selected == 1)
	{ var y = parseInt(document.getElementById(obj).helpful.value);
	  document.getElementById(obj).helpful.value = y+1;
	}	
	if(selected == 0)
	{ var y = parseInt(document.getElementById(obj).nothelpful.value);
	  document.getElementById(obj).nothelpful.value =  y+1;
	}
	document.getElementById(obj).submit();
}
function submit_revpaging(selected) {
	var y = parseInt(document.all.listpage.value);
	if(selected == 'next')
		{document.all.listpage.value = y + 1;}
	if(selected == 'prev')
		{document.all.listpage.value = y - 1;}
	document.reviewpaging.submit();
	
}


function validateRemove(frmEle)
{
if(frmEle.Email)
{
		if(frmEle.Email.value == "")
		{
			alert("Veuillez entrer votre Adresse de Courriel");
			frmEle.Email.focus();
			return false;
		}
		
		var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
		var check=/@[\w\-]+\./;
		var checkend=/\.[a-zA-Z]{2,4}$/;
		
		emailad = frmEle.Email.value;
		
		if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1))
		{
	  		alert("Adresse de courriel incorrecte!  Veuillez apporter les changements n\351cessaires.");
			frmEle.Email.focus();
			return false;
		}
}


if(frmEle.Frequency7.checked == false && frmEle.Frequency14.checked == false  && frmEle.Frequency30.checked == false  && frmEle.Frequency128.checked == false  && frmEle.Frequency365.checked == false  && frmEle.Frequency0.checked == false)
{
alert("Veuillez svp nous signaler \u00E0 quelle fr\351quence vous souhaitez recevoir notre newsletter en cliquant sur l'une des options.");
return false;
}

}


function validateEmailAlerts(frmEle)
	{
	

	
		// Primary
		
		if(frmEle.Email){
			if(frmEle.Email.value == "")
			{
				alert("Veuillez entrer votre Adresse de Courriel");
				frmEle.Email.focus();
				return false;
			}
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frmEle.Email.value))
			{
				//return (true)
			}
			else
			{
			alert("Adresse de courriel incorrecte!  Veuillez apporter les changements n\351cessaires.");
			frmEle.Email.focus();
			return false;
			}
		}	
	
		if(frmEle.FirstName.value == ""){
		alert("Veuillez entrer votre Prenom");
		frmEle.FirstName.focus();
		return false;
		}
		if(frmEle.LastName.value == ""){
		alert("Veuillez entrer votre Nom de Famille");
		frmEle.LastName.focus();
		return false;
		}

		if(frmEle.Province.value == "" || frmEle.Province.value == "0"){
		alert("Veuillez entrer votre province");
		frmEle.Province.focus();
		return false;
		}
		
if(frmEle.Frequency7.checked == false && frmEle.Frequency14.checked == false  && frmEle.Frequency30.checked == false  && frmEle.Frequency128.checked == false  && frmEle.Frequency365.checked == false  && frmEle.Frequency0.checked == false)
{
alert("Veuillez svp nous signaler \u00E0 quelle fr\351quence vous souhaitez recevoir notre newsletter en cliquant sur l'une des options.");
return false;
}		
		
}


function clearEmailForm(frmEle){

//Clear the email form if customer clicks in the box
	if (frmEle.value == "Inscrire le courriel")
	{
		frmEle.value = "";
	}
}

function clearSearchTip(frmEle){

//Clear the email form if customer clicks in the box
	if (frmEle.value.replace(/^\s+/,"") == "Chercher un conseil..."){
		frmEle.value = "";
	}
}
function PricePer(width,PricePercentage){
		this.MaxWidth = width;
		this.PricePercentage = PricePercentage;
	}

function Pricing(width,height,price,dualBlinds){
		this.width = width;
		this.height = height;
		this.price = price;
		this.dualBlinds = dualBlinds;
	}
function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}
function tmt_findObj(n){
	var x,t; if((n.indexOf("?"))>0&&parent.frames.length){t=n.split("?");
	x=eval("parent.frames['"+t[1]+"'].document.getElementById('"+t[0]+"')");
	}else{x=document.getElementById(n)}return x;
}
function MM_showHideLayers() { 
  var i,p,v,obj,args=MM_showHideLayers.arguments;if(document.getElementById){
   for (i=0; i<(args.length-2); i+=3){ obj=tmt_findObj(args[i]);v=args[i+2];
   v=(v=='show')?'visible':(v='hide')?'hidden':v;
   if(obj)obj.style.visibility=v;}} else{
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }}
}


function MM_showHideLayersWithWidth() { 

MM_showHideLayers('feature69','','hide');	
MM_showHideLayers('feature70','','hide');		
MM_showHideLayers('feature71','','hide');
MM_showHideLayers('feature72','','hide');
MM_showHideLayers('feature73','','hide');
MM_showHideLayers('feature76','','hide');
MM_showHideLayers('feature77','','hide');
MM_showHideLayers('feature82','','hide');
MM_showHideLayers('feature83','','hide');
MM_showHideLayers('feature84','','hide');
MM_showHideLayers('feature88','','hide');
MM_showHideLayers('feature93','','hide');

MM_showHideLayers('optionLayer132','','hide');
MM_showHideLayers('optionLayer133','','hide');
MM_showHideLayers('optionLayer134','','hide');
MM_showHideLayers('optionLayer130','','hide');
MM_showHideLayers('optionLayer138','','hide');
MM_showHideLayers('optionLayer141','','hide');
MM_showHideLayers('optionLayer142','','hide');
MM_showHideLayers('optionLayer143','','hide');
MM_showHideLayers('optionLayer146','','hide');
MM_showHideLayers('optionLayer147','','hide');
MM_showHideLayers('optionLayer148','','hide');
MM_showHideLayers('optionLayer149','','hide');
MM_showHideLayers('optionLayer151','','hide');


  var i,p,v,obj,args=MM_showHideLayersWithWidth.arguments;
  				var chag = 100;
  if(document.getElementById)
	{
		for (i=0; i<(args.length-2); i+=3)
			{ 
			obj=tmt_findObj(args[i]);
			v=args[i+2];
			v=(v=='show')?'visible':(v='hide')?'hidden':v;
			if(obj)
				{
				var winX = screen.width;
				if (winX == '1600') obj.style.left = 395 - chag;
				if (winX == '1440') obj.style.left = 315 - chag;
				if (winX == '1400') obj.style.left = 295 - chag;
				if (winX == '1280') obj.style.left = 233 - chag;
				if (winX == '1152') obj.style.left = 170 - chag;
				if (winX == '1024') obj.style.left = 105 - chag;
				if (winX == '800') obj.style.left = 75 - chag;	
				obj.style.visibility=v;
				}
			}
	} 
	else
	{
		for (i=0; i<(args.length-2); i+=3) 
			if ((obj=MM_findObj(args[i]))!=null) 
				{ 
				v=args[i+2];
				if (obj.style) 
					{ 
						obj=obj.style;
						v=(v=='show')?'visible':(v='hide')?'hidden':v; 
					}
				var winX = screen.width;
				if (winX == '1600') obj.style.left = 385 - chag;
				if (winX == '1440') obj.style.left = 305 - chag;
				if (winX == '1400') obj.style.left = 285 - chag;
				if (winX == '1280') obj.style.left = 223 - chag;
				if (winX == '1152') obj.style.left = 160 - chag;
				if (winX == '1024') obj.style.left = 95 - chag;
				if (winX == '800') obj.style.left = 65 - chag;					
				obj.visibility=v; 
				}
	}

}




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];}
}
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;
}

var nPlus = 5   //the % of fading for each step
var speed = 100  //the speed
function FadeLayer(){
	var ie5=(document.getElementById && document.all);
	var ns6=(document.getElementById && !document.all);
    if(document.getElementById){
        var objLayer = document.getElementById('WelcomeDiv');
        if(iOpacity == 0 && isShow == 1){
			MM_showHideLayers('WelcomeDiv','','show');
		}		
        if(isShow == 1){//Add to opacity
			iOpacity+=nPlus;
		}
		else{//Remove from opacity
			iOpacity-=nPlus;
		}
		if(ie5){
			objLayer.style.filter="alpha(iOpacity = 0)";
			objLayer.filters.alpha.opacity = iOpacity;
		}
		if(ns6){
			objLayer.style.MozOpacity = 0 + '%';
			objLayer.style.MozOpacity = iOpacity + '%';
		}
		if(iOpacity < 100 && iOpacity > 0){
			setTimeout('FadeLayer();',speed);
		}
		if(iOpacity == 0 && isShow == 0){
			MM_showHideLayers('WelcomeDiv','','hide');
		}
		if(iOpacity == 100){
			isShow = 0 
		}
	}
}
function validKey(theEle,typeHex){ //1 Nav(Tab, enter, arrows, etc.), 2 Numbers, 4 decimal, 8 hypen, 16 letters, 32 space
	if((typeHex & 1) == 1){ //9-8,13,37-40,45-46,112-123
		if(
			(
				(event.keyCode >= 8 && event.keyCode <= 9) || //  and Tab
				(event.keyCode == 13) || //Return
				(event.keyCode == 16) || //Shift
				(event.keyCode >= 37 && event.keyCode <= 40) || //arrows
				(event.keyCode >= 45 && event.keyCode <= 46) ||
				(event.keyCode >= 112 && event.keyCode <= 123) //Function Keys
			)
		  ) return true
	}
	if((typeHex & 2) == 2){ //Numbers
		if(
			(
				(event.keyCode >= 48 && event.keyCode <= 57) ||
				(event.keyCode >= 96 && event.keyCode <= 105)
			) && !event.shiftKey
		  ) return true
	}
	if((typeHex & 4) == 4){ //Decimal
		if((event.keyCode == 110 || event.keyCode === 190) && theEle.value.search(/\./) < 0) return true 
	}
	if((typeHex & 8) == 8){  //Hypen
		if(event.keyCode == 109 || event.keyCode === 189) return true
	}
	if((typeHex & 16) == 16){  //Letters
		if(event.keyCode >= 65 && event.keyCode <= 90) return true
	}
	if((typeHex & 32) == 32){
		if(event.keyCode >= 32) return true
	}
	return false;
}
function isDate(formEle,page) {
    var pg = page;
    var mf = "";               // Month Formatted
    var df = "";               // Date Formatted
    var ds = formEle.value;    // Date Value
	var nd = new Date(ds);
	var td = 0;
	var i = 0;
	var ID = 0;
	//alert(ds);
  if(formEle.value.length > 0){
	if(pg == 1){NotNewCompany(ds);}		
			
	if (ds == ""){return true;}
	  	
	if(!isNaN(nd.getDate())) {
			
	for(i=0;i<12;i++)
		{
			td = nd.getMonth();
			if (i == td)
			{mf = m[i];} 
		}	
	      
		if (formEle.value.length <= 8){
		var SplitWak = formEle.value.split('/');
		var SplitDash = formEle.value.split('-');
		if ((SplitWak[2] != null && SplitWak[2].length == 2) || (SplitDash[2] != null && SplitDash[2].length == 2)){
			if(SplitWak[2] == null && SplitDash[2] != null){YearVal = SplitDash[2];}
			else if(SplitDash[2] == null && SplitWak[2] != null){YearVal = SplitWak[2];}
			else {YearVal = nd.getFullYear;}
   			if (YearVal <= 50){nd.setFullYear(eval("20" + YearVal));}
   		} 
		}  
			
		if (nd.getDate() < 10){
		df = mf + "  " + nd.getDate() + " " + nd.getFullYear(); formEle.value = df;}
		else{
		df = mf + " " + nd.getDate() + " " + nd.getFullYear(); formEle.value = df;}
		   
		if(pg > 0){
		////////////////////////////
		// Start Date vs. End Date   
		////////////////////////////
		var StartDate = new Array();
		var EndDate = new Array();
		var LHID = new Array();
		var msg = "";
		var err = 0;
		var count = 0;
		var max = 1;
		

	}
		if (err > 0){
		formEle.value = "";
		msg = "The End Date cannot be earlier then the Start Date!";
		alert(msg);
		return false;
		}
		else{      
		formEle.value = df;
		formEle.focus();
		return true; // date is valid
		}
		}else{
			formEle.value = "";
			alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
			return true;
		}	
  }
}
// Format Masked field
function formatValue(formEle, sMask){
	//date(mm/dd/yyyy), Alpha, Numeric, %,$
	var k = event.keyCode;
	switch (sMask){
		case "Alpha":
			break
		case "$":
		    //CHECKING FOR $-SIGN AND ADDING IT IF IT DOESN'T EXIST
		    var re = /\$/g;
		    var dollarKiller = formEle.value.replace(re,'');
		  if(formEle.value.indexOf("$") > 0 || (dollarKiller.length > 0 && formEle.value.indexOf("$") != 0)){
		    if (formEle.value == "$" || formEle.value == "" || dollarKiller == "")
		       {formEle.value = "" ;}
		    else {formEle.value = "$" + dollarKiller ;}
		  }  
		case "%":
		case "Numeric":
			if((k>= 48 && 57 >= k) || (k>= 96 && 105 >= k) || k==8 || k==109 || k==189){
				var sn = new String(formEle.value.replace(/,/ig,""));
				var y = 0;
				var cn = new String("");
				var dec = (sn.indexOf("."));
				var usecomma = true;
					if(dec > -1) usecomma=false ;
				for(x=sn.length-1;x>=0;x--){
					if ( x == dec){
						usecomma=true;
						y = -1;
					}	
					if(y%3 == 0 && y!=0 && usecomma && sn.charAt(x)!="-" && sn.charAt(x)!="$" ) cn = "," + cn;
					if(sn.charAt(x)!="-" || x==0 || sn.charAt(x)!="$"){
						cn = sn.charAt(x) + cn;
						y++;
					}
				}
				formEle.value = (cn);
				y=null;
			}	
			break;
		case "MM/DD/YYYY":
			if(formEle.value.length > 9){
				if(!checkDate(formEle)){
					alert("Invalid Date:\nPlease use (MM/DD/YYYY) ");
				}
			}
			break
		default:
	}		
}
function showWelcome(sMethod){
	var bVisible = 'show';
	var ie5=(document.getElementById && document.all);
	var ns6=(document.getElementById && !document.all);
	
	MM_showHideLayers('WelcomeDiv','',sMethod);
	if (sMethod == 'show'){
		bVisible = 'none';
		var objLayer = document.getElementById('WelcomeDiv');
		if(ie5){
			objLayer.style.filter="alpha(iOpacity = 0)";
			objLayer.filters.alpha.opacity = 100;
		}
		if(ns6){
			objLayer.style.MozOpacity = 100 + '%';
		}
	}
	else
	{
	}
	MM_showHideLayers('theDrops','',bVisible);
}
function popUpWin(url, h, w){
	var scroll = "yes";
	if(popUpWin.arguments[3] != null){
		scroll = popUpWin.arguments[3]
	}
	newWindow = window.open(url,"pop","resizable=yes,toolbar=no,scrollbars=" + scroll + ",width="+w+",height="+h);
	
	
	newWindow.focus();
}
function showMenu(DivID){
	hideMenu();
		if(DivID == "verticalblinds_nav" || DivID == "honeycombshades_nav" || DivID == "rollershades_nav" || DivID == "bambooshades_nav")
		{
		hideT();
		}
		if(DivID == "verticalblinds_nav" || DivID == "honeycombshades_nav")
		{
		hideT2();
		}
	MM_showHideLayers(DivID,'','show');
}




function hideT()
		{
if (document.shopcart)
{
		if (document.shopcart.WidthInches)
		{
	  document.shopcart.WidthInches.style.visibility="hidden";
	  document.shopcart.Width8ths.style.visibility="hidden";
	  document.shopcart.HeightInches.style.visibility="hidden";
	  document.shopcart.Height8ths.style.visibility="hidden";
		}	  
	  if (document.shopcart.WidthInchesDisplay)
		{		
	  document.shopcart.WidthInchesDisplay.style.visibility="hidden";
	  document.shopcart.HeightInchesDisplay.style.visibility="hidden";
	  document.shopcart.Height8thsDisplay.style.visibility="hidden";
	  document.shopcart.Width8thsDisplay.style.visibility="hidden";
	    }
}

		}
function showT()
	  {
if (document.shopcart)
{	  
		if (document.shopcart.WidthInches)
		{
	  document.shopcart.WidthInches.style.visibility="visible";
	  document.shopcart.Width8ths.style.visibility="visible";
	  document.shopcart.HeightInches.style.visibility="visible";
	  document.shopcart.Height8ths.style.visibility="visible";
	  	}
	  if (document.shopcart.WidthInchesDisplay)
		{
	  document.shopcart.WidthInchesDisplay.style.visibility="visible";
	  document.shopcart.HeightInchesDisplay.style.visibility="visible";
	  document.shopcart.Height8thsDisplay.style.visibility="visible";
	  document.shopcart.Width8thsDisplay.style.visibility="visible";
		}
}			
	  }



function showT2()
	  {
if (document.shopcartiee)
{	  
		if (document.shopcartiee.WidthInches)
		{
	  document.shopcartiee.WidthInches.style.visibility="visible";
	  document.shopcartiee.Width8ths.style.visibility="visible";
	  document.shopcartiee.HeightInches.style.visibility="visible";
	  document.shopcartiee.Height8ths.style.visibility="visible";
	  	}

}			
	  }
	  
	  
function hideT2()
		{
if (document.shopcartiee)
{
		if (document.shopcartiee.WidthInches)
		{
	  document.shopcartiee.WidthInches.style.visibility="hidden";
	  document.shopcartiee.Width8ths.style.visibility="hidden";
	  document.shopcartiee.HeightInches.style.visibility="hidden";
	  document.shopcartiee.Height8ths.style.visibility="hidden";
		}	  
	 
}

		}	  



function hideMenu(){
	showT();showT2();
	MM_showHideLayers('woodblinds_nav','','hide');
	MM_showHideLayers('fauxwoodblinds_nav','','hide');
	MM_showHideLayers('honeycombshades_nav','','hide');
	MM_showHideLayers('miniblinds_nav','','hide');
	MM_showHideLayers('verticalblinds_nav','','hide');
	MM_showHideLayers('bambooshades_nav','','hide');
	MM_showHideLayers('rollershades_nav','','hide');
	MM_showHideLayers('romanshades_nav','','hide');
	MM_showHideLayers('suncontrolshades_nav','','hide');
	MM_showHideLayers('brand_nav','','hide');
}
function change_class(obj,className) {
	//alert(obj + " " + className);
	obj.className = className;
}

function validateEmailHP(frmEle){



		if (frmEle.YourEmail.value == "" || frmEle.YourEmail.value == "Inscrire le courriel"){
			alert("Veuillez entrer votre Adresse de Courriel");
			frmEle.YourEmail.focus();
			return false;
		}
		
		if (frmEle.YourEmail.value != "" && frmEle.YourEmail.value != "Inscrire le courriel")
		{

		var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
		var check=/@[\w\-]+\./;
		var checkend=/\.[a-zA-Z]{2,4}$/;
		
		emailad = frmEle.YourEmail.value;
		if(((emailad.search(exclude) != -1)||(emailad.search(check))== -1)||(emailad.search(checkend) == -1))
		{
	  		alert("L'adresse \351lectronique que vous avez entr\351e n'est pas valide. Veuillez entrer \340 nouveau votre adresse electronique compl\350te.");
			frmEle.email.focus();
			return false;
		}
		
		}
	
	
	
}

function CreateBookmarkLink() 
{ 

    title = "StoresSelectsCanada.ca";   // Blogger - Replace with <$BlogItemTitle$>   // MovableType - Replace with <$MTEntryTitle$> 
    url = "http://www.storesselectscanada.ca";  // Blogger - Replace with <$BlogItemPermalinkURL$>   // MovableType - Replace with <$MTEntryPermalink$>  // WordPress - <?php bloginfo('url'); ?>	
    if (window.sidebar) 
    { 
        // Mozilla Firefox Bookmark		
        window.sidebar.addPanel(title, url,"");	
    } 
    else if( window.external ) 
    { 
        // IE Favorite		
        window.external.AddFavorite( url, title); 
    }	
    else if(window.opera && window.print) 
    { 
        // Opera Hotlist		
        return true; 
    }
}

function calculateMeasureInstallation()
{
    calculateMeasuring();
    calculateInstallation();
}
function calculateMeasuring()
{

    var selectMeasure = document.getElementById('Measure');
    var totalMeasuring = document.getElementById('totalMeasuring');
    var measurementP = document.getElementById('measurementP');
    var measurementCost = document.getElementById('measurementCost');
    
    var total = 0;
    var totalCost = 0;
    var upto = measure_upto;
    var uptoPrice = measure_price;
    var additional = measure_additional;
    var uptoCost = cost_measure_price;
    var cost_additional = cost_measure_additional;

    if(selectMeasure.value > 0)
    {
        total = uptoPrice + (additional * (selectMeasure.value-upto))
        totalCost = uptoCost + (cost_additional * (selectMeasure.value-upto))
        
        setInnerText(totalMeasuring,"$" + total.toFixed(2));
        measurementP.value = total;
        measurementCost.value = totalCost;
    }
    else
    {
        setInnerText(totalMeasuring,"$0.00");
        measurementP.value = 0;
        measurementCost.value = 0;
    }
 
}

function calculateInstallation()
{
    var installation_total = 0;
    var cost_installation_total = 0;
    
    vertical_total = 0;
    cost_vertical_total = 0;

    horizontal_total = 0;
    cost_horizontal_total = 0;
    
    var installationP = document.getElementById('installationP');
    var installationCost = document.getElementById('installationCost');
    var installH = document.getElementById('Install_horizontal');
    var InstallV = document.getElementById('Install_vertical');
    

    if(installH.value > 0 || InstallV.value > 0)
    {

        calculateVertical();
        calculateHorizontal();
        
        installation_total = horizontal_total + vertical_total;
        cost_installation_total = cost_horizontal_total + cost_vertical_total;
        
        
       setInnerText(totalInstallation,"$" + installation_total.toFixed(2));
       installationP.value = installation_total;
       installationCost.value = cost_installation_total;
    }
    else
    {
        setInnerText(totalInstallation,"$0.00");
        installationP.value = 0;
        installationCost.value = 0;
    }
}
function calculateVertical()
{
    var vertical_total_no = 0;
    var vertical_concrete = 0;
    var vertical_nonconcrete = 0;
    var vertical_concrete_wide = 0;
    var vertical_concrete_nonwide = 0;
    var vertical_nonconcrete_wide = 0;
    var vertical_nonconcrete_nonwide = 0;
    var countFirstX = 0;
    var vertical_uptoX = vertical_upto;
    
    var Install_vertical = document.getElementById('Install_vertical');
    var vertical_concrete = document.getElementById('vertical_concrete');
    var verConcreteWide = document.getElementById('verConcreteWide');
    var verNonConcreteWide = document.getElementById('verNonConcreteWide');
    
    if(Install_vertical.value > 0)
    {
        vertical_total_no = Install_vertical.value;
        vertical_concrete = vertical_concrete.value;
        vertical_nonconcrete = vertical_total_no - vertical_concrete;
        
        vertical_concrete_wide = verConcreteWide.value;
        vertical_concrete_nonwide = vertical_concrete - vertical_concrete_wide;
        vertical_nonconcrete_wide = verNonConcreteWide.value;
        vertical_nonconcrete_nonwide = vertical_nonconcrete - vertical_nonconcrete_wide;
        
        if(Install_vertical.value > 0)
        {
            if(vertical_concrete_wide > 0)
            {
                if(vertical_concrete_wide >= vertical_uptoX)
                {
                    vertical_total += vertical_uptoX * (price_vertical_firstX_concrete/vertical_upto) * 2;
                    vertical_total += (vertical_concrete_wide - vertical_uptoX) * price_vertical_additional_concrete * 2;
                    
                    cost_vertical_total += vertical_uptoX * (cost_vertical_firstX_concrete/vertical_upto) * 2;
                    cost_vertical_total += (vertical_concrete_wide - vertical_uptoX) * cost_vertical_additional_concrete * 2;
                    
                    //count the remaining for the first X
                    vertical_uptoX = 0;
                }
                else
                {
                    vertical_total += vertical_concrete_wide * (price_vertical_firstX_concrete/vertical_upto) * 2;
                    
                    cost_vertical_total += vertical_concrete_wide * (cost_vertical_firstX_concrete/vertical_upto) * 2;
                    
                    //count the remaining for the first X
                    vertical_uptoX = vertical_uptoX - vertical_concrete_wide;
                }
            }
            
             if(vertical_nonconcrete_wide > 0)
            {
                if(vertical_nonconcrete_wide >= vertical_uptoX)
                {
                    vertical_total += vertical_uptoX * (price_vertical_firstX_nonconcrete/vertical_upto) * 2;
                    vertical_total += (vertical_nonconcrete_wide - vertical_uptoX) * price_vertical_additional_nonconcrete * 2;
                    
                    cost_vertical_total += vertical_uptoX * (cost_vertical_firstX_nonconcrete/vertical_upto) * 2;
                    cost_vertical_total += (vertical_nonconcrete_wide - vertical_uptoX) * cost_vertical_additional_nonconcrete * 2;
                    
                    //count the remaining for the first X
                    vertical_uptoX = 0;
                }
                else
                {
                    vertical_total += vertical_nonconcrete_wide * (price_vertical_firstX_nonconcrete/vertical_upto) * 2;
                
                    cost_vertical_total += vertical_nonconcrete_wide * (cost_vertical_firstX_nonconcrete/vertical_upto) * 2;
                    
                    //count the remaining for the first X
                    vertical_uptoX = vertical_uptoX - vertical_nonconcrete_wide;
                }
            }
            
             if(vertical_concrete_nonwide > 0)
            {
                if(vertical_concrete_nonwide >= vertical_uptoX)
                {
                    vertical_total += vertical_uptoX * (price_vertical_firstX_concrete/vertical_upto);
                    vertical_total += (vertical_concrete_nonwide - vertical_uptoX) * price_vertical_additional_concrete;
                    
                    cost_vertical_total += vertical_uptoX * (cost_vertical_firstX_concrete/vertical_upto);
                    cost_vertical_total += (vertical_concrete_nonwide - vertical_uptoX) * cost_vertical_additional_concrete;
                    
                    //count the remaining for the first X
                    vertical_uptoX = 0;
                }
                else
                {
                    vertical_total += vertical_concrete_nonwide * (price_vertical_firstX_concrete/vertical_upto);
                    
                    cost_vertical_total += vertical_concrete_nonwide * (cost_vertical_firstX_concrete/vertical_upto);
                    
                    //count the remaining for the first X
                    vertical_uptoX = vertical_uptoX - vertical_concrete_nonwide;
                }
            }
            
            if(vertical_nonconcrete_nonwide > 0)
            {
                if(vertical_nonconcrete_nonwide >= vertical_uptoX)
                {
                    vertical_total += vertical_uptoX * (price_vertical_firstX_nonconcrete/vertical_upto);
                    vertical_total += (vertical_nonconcrete_nonwide - vertical_uptoX) * price_vertical_additional_nonconcrete;
                    
                    cost_vertical_total += vertical_uptoX * (cost_vertical_firstX_nonconcrete/vertical_upto);
                    cost_vertical_total += (vertical_nonconcrete_nonwide - vertical_uptoX) * cost_vertical_additional_nonconcrete;
                    
                    //count the remaining for the first X
                    vertical_uptoX = 0;
                }
                else
                {
                    vertical_total += vertical_nonconcrete_nonwide * (price_vertical_firstX_nonconcrete/vertical_upto);
                    
                    cost_vertical_total += vertical_nonconcrete_nonwide * (cost_vertical_firstX_nonconcrete/vertical_upto);
                    
                    //count the remaining for the first X
                    vertical_uptoX = vertical_uptoX - vertical_nonconcrete_nonwide;
                }
            }
        
        }
        else
        {
            vertical_total = 0;
            cost_vertical_total = 0;
        }
        
        
    }
}
function calculateHorizontal()
{
    var horizontal_total_no = 0;
    var horizontal_concrete = 0;
    var horizontal_nonconcrete = 0;
    var horizontal_concrete_wide = 0;
    var horizontal_concrete_nonwide = 0;
    var horizontal_nonconcrete_wide = 0;
    var horizontal_nonconcrete_nonwide = 0;
    var horizontal_uptoX = horizontal_upto;
    
    var Install_horizontal = document.getElementById('Install_horizontal');
    var horizontal_concrete = document.getElementById('horizontal_concrete');
    var horConcreteWide = document.getElementById('horConcreteWide');
    var horNonConcreteWide = document.getElementById('horNonConcreteWide');
    
    if(Install_horizontal.value > 0)
    {
        horizontal_total_no = Install_horizontal.value;
        horizontal_concrete = horizontal_concrete.value;
        horizontal_nonconcrete = horizontal_total_no - horizontal_concrete;
        
        horizontal_concrete_wide = horConcreteWide.value;
        horizontal_concrete_nonwide = horizontal_concrete - horizontal_concrete_wide;
        horizontal_nonconcrete_wide = horNonConcreteWide.value;
        horizontal_nonconcrete_nonwide = horizontal_nonconcrete - horizontal_nonconcrete_wide;
   
        if(Install_horizontal.value > 0)
        {
            if(horizontal_concrete_wide > 0)
            {
                if(horizontal_concrete_wide >= horizontal_uptoX)
                {
                    horizontal_total += horizontal_uptoX * (price_horizontal_firstX_concrete/horizontal_upto) * 2;
                    horizontal_total += (horizontal_concrete_wide - horizontal_uptoX) * price_horizontal_additional_concrete * 2;
                    
                    cost_horizontal_total += horizontal_uptoX * (cost_horizontal_firstX_concrete/horizontal_upto) * 2;
                    cost_horizontal_total += (horizontal_concrete_wide - horizontal_uptoX) * cost_horizontal_additional_concrete * 2;
                    
                    //count the remaining for the first X
                    horizontal_uptoX = 0;
                }
                else
                {
                    horizontal_total += horizontal_concrete_wide * (price_horizontal_firstX_concrete/horizontal_upto) * 2;
                    
                    cost_horizontal_total += horizontal_concrete_wide * (cost_horizontal_firstX_concrete/horizontal_upto) * 2;
                    
                    //count the remaining for the first X
                    horizontal_uptoX = horizontal_uptoX - horizontal_concrete_wide;
                }
            }

            
             if(horizontal_nonconcrete_wide > 0)
            {
                if(horizontal_nonconcrete_wide >= horizontal_uptoX)
                {
                    horizontal_total += horizontal_uptoX * (price_horizontal_firstX_nonconcrete/horizontal_upto) * 2;
                    horizontal_total += (horizontal_nonconcrete_wide - horizontal_uptoX) * price_horizontal_additional_nonconcrete * 2;
                    
                    cost_horizontal_total += horizontal_uptoX * (cost_horizontal_firstX_nonconcrete/horizontal_upto) * 2;
                    cost_horizontal_total += (horizontal_nonconcrete_wide - horizontal_uptoX) * cost_horizontal_additional_nonconcrete * 2;
                    
                    //count the remaining for the first X
                    horizontal_uptoX = 0;
                }
                else
                {
                    horizontal_total += horizontal_nonconcrete_wide * (price_horizontal_firstX_nonconcrete/horizontal_upto) * 2;
                
                    cost_horizontal_total += horizontal_nonconcrete_wide * (cost_horizontal_firstX_nonconcrete/horizontal_upto) * 2;
                    
                    //count the remaining for the first X
                    horizontal_uptoX = horizontal_uptoX - horizontal_nonconcrete_wide;
                }
            }


            if(horizontal_concrete_nonwide > 0)
            {
                if(horizontal_concrete_nonwide >= horizontal_uptoX)
                {
                    horizontal_total = horizontal_total + horizontal_uptoX * (price_horizontal_firstX_concrete/horizontal_upto);
                    horizontal_total = horizontal_total + (horizontal_concrete_nonwide - horizontal_uptoX) * price_horizontal_additional_concrete;
                    
                    cost_horizontal_total = cost_horizontal_total + horizontal_uptoX * (cost_horizontal_firstX_concrete/horizontal_upto);
                    cost_horizontal_total = cost_horizontal_total + (horizontal_concrete_nonwide - horizontal_uptoX) * cost_horizontal_additional_concrete;
                    
                    //count the remaining for the first X
                    horizontal_uptoX = 0;
                }
                else
                {
                    horizontal_total += horizontal_concrete_nonwide * (price_horizontal_firstX_concrete/horizontal_upto);
                    
                    cost_horizontal_total += horizontal_concrete_nonwide * (cost_horizontal_firstX_concrete/horizontal_upto);
                    
                    //count the remaining for the first X
                    horizontal_uptoX = horizontal_uptoX - horizontal_concrete_nonwide;
                }
            }
            if(horizontal_nonconcrete_nonwide > 0)
            {
                if(horizontal_nonconcrete_nonwide >= horizontal_uptoX)
                {
                    horizontal_total += horizontal_uptoX * (price_horizontal_firstX_nonconcrete/horizontal_upto);
                    horizontal_total += (horizontal_nonconcrete_nonwide - horizontal_uptoX) * price_horizontal_additional_nonconcrete;
                    
                    cost_horizontal_total += horizontal_uptoX * (cost_horizontal_firstX_nonconcrete/horizontal_upto);
                    cost_horizontal_total += (horizontal_nonconcrete_nonwide - horizontal_uptoX) * cost_horizontal_additional_nonconcrete;
                    
                    //count the remaining for the first X
                    horizontal_uptoX = 0;
                }
                else
                {
                    horizontal_total += horizontal_nonconcrete_nonwide * (price_horizontal_firstX_nonconcrete/horizontal_upto);
                    
                    cost_horizontal_total += horizontal_nonconcrete_nonwide * (cost_horizontal_firstX_nonconcrete/horizontal_upto);
                    
                    //count the remaining for the first X
                    horizontal_uptoX = horizontal_uptoX - horizontal_nonconcrete_nonwide;
                }
            }
        
        }
        else
        {
            horizontal_total = 0;
            cost_horizontal_total = 0;
        }
        
        
    }
}
function validateInstallMeasure()
{
    var installHorizontal = document.getElementById('Install_horizontal');
    var Install_vertical = document.getElementById('Install_vertical');
    var Measure = document.getElementById('Measure');
    
    
    //just in case a user comes back from shopcart by back button and click Add to Cart again
    //recalculate totals.

    calculateMeasuring();
    calculateInstallation();
      
    if(Measure.value == -1)
    {
        alert("Veuillez choisir les fen\350tres devant \352tre mesur\351es.");
        return false;
    }
    
    if(installHorizontal.value == -1)
    {
        alert("Veuillez choisir les stores horizontaux devant \352tre install\351s.");
        return false;
    }
    
    if(Install_vertical.value == -1)
    {
        alert("Veuillez choisir les stores verticaux devant \352tre install\351s.");
        return false;
    }
    
    if(Measure.value + installHorizontal.value + Install_vertical.value <= 0)
    {
        alert("Veuillez choisir « Mesure » et/ou « Installation ».");
        return false;
    }

    
}
function setInnerText(obj, text)
 {
   if (document.all)
   {
     obj.innerText = text;
   }
   else
   {
     obj.textContent = text;
   }
}
function addOptions(obj,max)
{
    var i;

    obj.options[0] = new Option('0', 0)
    for(i=1;i<=max; i++) 
    {
        obj.options[obj.options.length] = new Option(i, i);
    }
}
function setHorizontalTotal(horList)
{

    var selectHorCon = document.getElementById("horizontal_concrete");
    var selectHorConWide = document.getElementById("horConcreteWide");
    var selectHorNonConWide = document.getElementById("horNonConcreteWide");
    
    selectHorCon.options.length = 1;
    selectHorConWide.options.length = 1;
    selectHorNonConWide.options.length = 1;

    if(horList.selectedIndex > 0)
    {
        addOptions(selectHorCon,horList.options[horList.selectedIndex].value);
    }
    addOptions(selectHorNonConWide, horList.options[horList.selectedIndex].value);
    
    calculateInstallation();
}
function setVerticalTotal(verList)
{

    var selectVerCon = document.getElementById("vertical_concrete");
    var selectVerConWide = document.getElementById("verConcreteWide");
    var selectVerNonConWide = document.getElementById("verNonConcreteWide");
    
    selectVerCon.options.length = 1;
    selectVerConWide.options.length = 1;
    selectVerNonConWide.options.length = 1;

    if(verList.selectedIndex > 0)
    {
        addOptions(selectVerCon,verList.options[verList.selectedIndex].value);
    }
    addOptions(selectVerNonConWide, verList.options[verList.selectedIndex].value);

    calculateInstallation();
}
function setHorConcrete(horConcrete)
{

    var tblWide = document.getElementById("tblHorWide");
    var selectConWide = document.getElementById("horConcreteWide");
    var selectNonConWide = document.getElementById("horNonConcreteWide");
    var selectInstallHor = document.getElementById("Install_horizontal");
    
    selectConWide.options.length = 1;
    selectNonConWide.options.length = 1;

    if(horConcrete.selectedIndex > 0)
    {
        tblWide.style.display = "inline";
        addOptions(selectConWide,horConcrete.options[horConcrete.selectedIndex].value);
    }
    else
    {
        tblWide.style.display = "none";
    }

    addOptions(selectNonConWide, selectInstallHor.options[selectInstallHor.selectedIndex].value - horConcrete.options[horConcrete.selectedIndex].value);
    calculateInstallation();
}

function setVerConcrete(verConcrete)
{

    var tblVerWide = document.getElementById("tblVerWide");
    var selectVerConWide = document.getElementById("verConcreteWide");
    var selectVerNonConWide = document.getElementById("verNonConcreteWide");
    var selectInstallVer = document.getElementById("Install_vertical");
    
    selectVerConWide.options.length = 1;
    selectVerNonConWide.options.length = 1;

    if(verConcrete.selectedIndex > 0)
    {
        tblVerWide.style.display = "inline";
        addOptions(selectVerConWide,verConcrete.options[verConcrete.selectedIndex].value);
    }
    else
    {
        tblVerWide.style.display = "none";
    }

    addOptions(selectVerNonConWide, selectInstallVer.options[selectInstallVer.selectedIndex].value - verConcrete.options[verConcrete.selectedIndex].value);
    calculateInstallation();
}
