// JavaScript Document
<!--
arrList = new Array();
var price = 2.95;
var nprice = 3.50;

function determineGST() {
   switch (document.form2.state.value) {
   case "Ontario":
      var GST = 1.13;
      break;
   case "British Columbia":
      var GST = 1.12;
      break;
   case "Nova Scotia":
      var GST = 1.15;
      break;
   case "New Brunswick":
      var GST = 1.13;
      break; 
   case "Newfoundland":
      var GST = 1.13;
      break;   
   default:
   var GST = 1.05;
   }
   return GST;
}

function determineInvGST() {
   switch (document.form2.state.value) {
   case "Ontario":
      var InvGST = 0.13;
      break;
   case "British Columbia":
      var InvGST = 0.12;
      break;
   case "Nova Scotia":
      var InvGST = 0.15;
      break;
   case "New Brunswick":
      var InvGST = 0.13;
      break; 
   case "Newfoundland":
      var InvGST = 0.13;
      break;   
   default:
   var InvGST = 0.05;
   }
   return InvGST;
}

var theprice = 0;

function add2List(inName, inGroup, inParty)
{
    var GST = determineGST();
	if(arrList[inParty])
	{
		//It's in the List, we need to message the user.
		alert ("That destination already exists in the destination list.");
	} else {
		//It's not in the List, we should add it
		var Group = '';
		if(inGroup.length > 0)
		{
			Group = ' in (' + inGroup.replace('||',' in ') + ')';
		}
		document.getElementById("TheList").innerHTML = document.getElementById("TheList").innerHTML + '<div id="item' + inParty + '" onClick="javascript:removeFromList(' + inParty + ')" class="fd">' + inName + Group + '</div>';
		arrList[inParty] = inName + Group;
		var intTotal = parseInt(document.getElementById("Total").innerHTML) + 1;
		document.getElementById("Total").innerHTML = intTotal;
		document.getElementById("Total2").innerHTML = intTotal;
		if (document.form2.cirpa_member.value == 'yes')
		{
			theprice = price;
		} else {
			theprice = nprice;
		}
		var vprice = (intTotal * theprice) * GST;
		vprice = formatCurrency(vprice);
		document.getElementById("Price").innerHTML = vprice;
		document.getElementById("Price2").innerHTML = vprice;
	}
}
function removeFromList(inParty)
{
    var GST = determineGST();
	if(arrList[inParty].length>0)
	{
		document.getElementById("item" + inParty).innerHTML = '';
		document.getElementById("item" + inParty).outerHTML = '';
		arrList[inParty] = '';
		var intTotal = parseInt(document.getElementById("Total").innerHTML) - 1;
		document.getElementById("Total").innerHTML = intTotal;
		document.getElementById("Total2").innerHTML = intTotal;
		if (document.form2.cirpa_member.value == 'yes')
		{
			theprice = price;
		} else {
			theprice = nprice;
		}
		var vprice = (intTotal * theprice) * GST;
		vprice = formatCurrency(vprice);
		document.getElementById("Price").innerHTML = vprice;
		document.getElementById("Price2").innerHTML = vprice;
	}
}
function sub_form()
{
	if(parseInt(document.getElementById("Total").innerHTML) >0 )
	{
		var strHTML = "";
		var strHTML2 = "";
		var strParties = "";
		for (var i in arrList)
		{
			if(arrList[i].length >0)
			{
				strHTML = strHTML + arrList[i] + "|";
				strParties = strParties + i + "|";
				strHTML2 = strHTML2 + i + "|" + arrList[i] + "||";
			}
		}
		//alert ("Selected Destinations:\n" + strParties);
//		document.getElemnetById("destinations").value=strHTML;
		document.form2.parties.value = strParties;
		document.form2.destinations.value = strHTML;
		document.form2.rawdestinations.value = strHTML2;
		document.form2.totaldestinations.value = document.getElementById("Total").innerHTML;
		var intTotal = parseInt(document.getElementById("Total").innerHTML);
		if (document.form2.cirpa_member.value == 'yes')
		{
			theprice = price;
		} else {
			theprice = nprice;
		}
		var vprice = (intTotal * theprice);
		document.form2.subtotal.value = vprice;
		// subgst value needs to be calculated here
		//alert(document.form2.state.value);
		var InvGST = determineInvGST();
		//alert(InvGST);
	    // CS
		//var subgst = (vprice * 0.05);	
		var subgst = (vprice * InvGST);	
		document.form2.gst.value = subgst;
		//alert("intTotal: " + intTotal);
		alert('We will now transfer your data to DMDS. This may take a moment or two. Please do not reload the page.')
		document.form2.submit.disabled = true;
		document.form2.submit();
	} else
	{
		alert ("Select Some Destinations First!");
	}
}
function roundNumber(origNum)
{
        var rlength = 2; // The number of decimal places to round to
        var newnumber = Math.round(origNum.value*Math.pow(10,rlength))/Math.pow(10,rlength);
        roundNumber = newnumber;
}
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 doImg(mytype, myvalue) {
	if (myvalue.length > 0) {
		document.getElementById( mytype + '_art_disp').src = myvalue;
		document.getElementById( mytype + '_art_file').innerHTML = 'File Selected';
	}
	else {
		document.getElementById(mytype + '_art_disp').src = "/modules/cirpa/images/blank_img.jpg";
	}
}

function image_reload(name1,imgBac)
{
	name1.src = imgBac;
	return;
}

function form1_submit()
{
	if (document.getElementById('logo_art').value.length > 0 || document.getElementById('cover_art').value.length > 0 || document.getElementById('alt_art').value.length > 0 || document.getElementById('track').value.length > 0 ) {
		alert('The time it takes to upload files is dependant on your internet connection.')
	}
	document.getElementById('form1').submit.disabled = true;
}

function showhide(obj1, obj2)
{
	//alert(obj2)
	if (document.getElementById(obj1).style.display == '')
	{
		document.getElementById(obj1).style.display = 'none';
		document.getElementById(obj2).src = '/modules/cirpa/images/plus.gif';
	} else
	{
		document.getElementById(obj1).style.display = '';
		document.getElementById(obj2).src = '/modules/cirpa/images/minus.gif';
	}
}

//-->