﻿// JScript File

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_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_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];}
}

var ShippingAddressLine1 = "";
var ShippingAddressLine2 = "";
var ShippingCity = "";
var ShippingState = "";
var ShippingStateIndex = 0;
var ShippingCountry = "";
var ShippingCountryIndex = 0;
var ShippingZipcode = "";


function InitSaveVariables(form) 
{
    ShippingAddressLine1 = form.ShippingAddressLine1.value;
    ShippingAddressLine2 = form.ShippingAddressLine2.value;
    ShippingCity = form.ShippingCity.value;
    ShippingZipcode = form.ShippingZipcode.value;
    ShippingStateIndex = form.ShippingState.selectedIndex;
ShippingState = form.ShippingState[ShippingStateIndex].value;
ShippingCountryIndex = form.ShippingCountry.selectedIndex;
ShippingCountry = form.ShippingCountry[ShippingCountryIndex].value;

}

function ShipToBillPerson(form) 
{
    if (form.copy.checked) 
    {
        InitSaveVariables(form);
        form.ShippingAddressLine1.value = form.BillingAddressLine1.value;
        form.ShippingAddressLine2.value = form.BillingAddressLine2.value;
        form.ShippingCity.value = form.BillingCity.value;
        form.ShippingZipcode.value = form.BillingZipcode.value;
        form.ShippingState.selectedIndex = form.BillingState.selectedIndex;
        form.ShippingCountry.selectedIndex = form.BillingCountry.selectedIndex;
    }
    else 
    {
        form.ShippingAddressLine1.value = '';//ShippingAddressLine1;
        form.ShippingAddressLine2.value = '';// ShippingAddressLine2;
        form.ShippingCity.value = '';// ShippingCity;
        form.ShippingZipcode.value =  '';//ShippingZipcode;       
        form.ShippingState.selectedIndex = '';// ShippingStateIndex;
        form.ShippingCountry.selectedIndex = 'test';// ShippingCountryIndex;
    }
}
function show(which)
{
    var dv = document.getElementById("Q"+which)
    dv.style.visibility = "visible";
}
function DisplayMe()
{
    show(1)
}
function hide(which)
{
    var dv = document.getElementById("Q"+which)
    dv.style.visibility = "hidden";
}
function  HideMe()
{
    hide(1)
}


	
	function formatCurrency(num) {
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
		return (((sign)?'':'-') + num + '.' + cents);
	}
	
		function updateTotal() {
		
			extraCost = 0;
			pageCost = parseFloat(document.getElementById('PageCost').value) * (parseFloat(document.getElementById('ExtraPages').value) + parseFloat(document.getElementById('selAddPages').value));
			albumCost = parseFloat(document.getElementById('BasePrice').value) + parseFloat(pageCost) + parseFloat(document.getElementById('PageTypeCost').value);
			if (document.getElementById('chkDigitalProof').checked)
				extraCost = parseFloat(extraCost) + parseFloat(document.getElementById('DigitalProofCost').value)
			if (document.getElementById('chkMystyle').checked)
				extraCost = parseFloat(extraCost) + parseFloat(document.getElementById('MyStyleCost').value);
			addedCost = parseFloat(document.getElementById('AddedCost').value);
			copiesCost = (parseFloat(document.getElementById('Quantity').value)-1) * (parseFloat(albumCost) - parseFloat(document.getElementById('Discount').value));
			if (copiesCost < 0) copiesCost = 0;
		
			document.getElementById('SubTotal').innerHTML = formatCurrency(albumCost);
			document.getElementById('AddedTotal').innerHTML = formatCurrency(addedCost);
			document.getElementById('ExtraFeaturesCost').innerHTML = formatCurrency(extraCost);
			document.getElementById('CopiesTotal').innerHTML = formatCurrency(parseFloat(copiesCost));
			document.getElementById('TotalAmount').innerHTML = formatCurrency(albumCost + addedCost + extraCost + copiesCost);
			document.getElementById('TotalOrderAmount').value = document.getElementById('TotalAmount').innerHTML
		
			document.getElementById('AlbumCost').value = formatCurrency(albumCost + addedCost);
		
			document.getElementById('copyPrice').innerHTML = formatCurrency(albumCost - parseFloat(document.getElementById('Discount').value));
		}
	
	

//IFrame selection update to hidden parent field 'iframevalues'
function updateIframeSelection(obj) {
		
		optID = obj.value;
		currIDs = parent.document.getElementById('iframevalues').value;
				
		//if this selection was added
		if (obj.checked) {
			//alert('add ' + optID);
			//if the selection doesn't already exists, add it
			if (currIDs.indexOf(',' + optID + ',') == -1) {
				parent.document.getElementById('iframevalues').value = currIDs + optID + ',';
			}
			
		// otherwise the selection was removed	
		} else {
			//alert('remove ' + optID);
			//if the selection dexists, remove it
			if (currIDs.indexOf(',' + optID + ',') > -1) {
				parent.document.getElementById('iframevalues').value = currIDs.replace(',' + optID + ',', ',');
			}
		
		
		}
		//alert(parent.document.getElementById('iframevalues').value);
	
	}


	function goStep(step,substep) {
		document.getElementById('nextStep').value = step;
		document.getElementById('nextSubstep').value = substep;
		
		document.frmstep.submit();
	}

function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var win = null;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes'
	win = window.open(mypage,myname,settings)
}
function changeStat()
{
    document.form1.submit();
    }
function FreezeScreen(msg) 
{
      scroll(0,0);
      //msg='<object type="application/x-shockwave-flash" data="loader_1_2.swf" width="300"><param name="movie" value="loader_1_2.swf"></object>';
      var outerPane = window.parent.document.getElementById('FreezePane');
      var innerPane = window.parent.document.getElementById('InnerFreezePane');
      if (outerPane) outerPane.className = 'FreezePaneOn';
      //if (innerPane) innerPane.innerHTML = msg;
     
      
   
      
      
      
      
   }
   
   function showMe()
{
    var val=document.forms[0].imageHandling[0].checked;

    if(document.forms[0].imageHandling[0].checked)
    {
        imageHandling="upload";
    }
    else // if(document.forms[0].imageHandling[1].checked)
    {
        imageHandling="CD";
    }
	
    var stepIndex;
	if (document.getElementById('step') != null) 
		stepIndex = document.getElementById('step').value;
	else
		stepIndex = document.forms[0].step.value;
		
    var substepIndex;
	if (document.getElementById('substep') != null)
		substepIndex=document.getElementById('substep').value;
	else
		substepIndex= document.forms[0].substep.value;

    location.href="steps.asp?step="+stepIndex+"&substep="+substepIndex+"&imageHandling="+imageHandling;
}
    
/*
<script>
function show(which)
{
    var dv = document.getElementById("Q"+which)
    dv.style.visibility = "visible";
    dv.style.display="block";
}
function DisplayMe()
{
    show(1)
}
function hide(which)
{
    var dv = document.getElementById("Q"+which)
    dv.style.visibility = "hidden";
    dv.style.display="none";
    
}
function  HideMe()
{
    document.form.submit;
}
</script>*/
