// JavaScript Document

//VAR Declarations
var f1
var t1
var q1
var p1
var itemCount
var Alength
var j_format
var j_price
var j_title
var totalCost
// End Delcarations

function doAboutUs() {
document.getElementById('aboutUs').className='showDiv'
document.getElementById('aboutUs').style.height="36px"
document.getElementById('aboutUs').innerHTML="<a href=\"the_band.php\">The Band</a><br>"+
"<a href=\"biographies.php\">Biographies</a><br>"+
"<a href=\"instruments.php\">Instruments</a>"
}

function doSampleBuy() {
document.getElementById('sampleBuy').className='showDiv'
document.getElementById('sampleBuy').style.height="24px"
document.getElementById('sampleBuy').innerHTML="<a href=\"buy_CDs.php\">CD and DVD'S</a><br>"+
"<a href=\"sheet_music.php\">Sheet music</a>"
}

function hideSubs() {
document.getElementById('aboutUs').innerHTML=null
document.getElementById('aboutUs').style.height="0px"
document.getElementById('aboutUs').className='hideDiv'
document.getElementById('sampleBuy').innerHTML=null
document.getElementById('sampleBuy').style.height="0px"
document.getElementById('sampleBuy').className='hideDiv'
}

function introSrc() {
/*  np=Math.round(Math.random()*20)
if (np<10) {document.getElementById('introClip').src="sound/intro.mp3"}
if (np>10) {document.getElementById('introClip').src="sound/volte.mp3"} */

np=Math.round(Math.random()*30)
if (np<10) {document.getElementById('introClip').src="sound/hp1.mp3"}
if (np>10 && np<20) {document.getElementById('introClip').src="sound/hp2.mp3"}
if (np>20) {document.getElementById('introClip').src="sound/hp3.mp3"}
}

var emailRegExp=/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{1,4}$/i;
function msgvalidate(){
 if(trim(document.contactUs.email.value)==''){
   alert('Please enter your email address');
   document.contactUs.email.focus();
   return(false);
 }
   else if(!emailRegExp.test(document.contactUs.email.value)){
   alert('Sorry, your email address does not appear to be correctly formatted');
   document.contactUs.email.focus();
   return(false);
 }
 return(true);
}
function trim(input){
  var b=0;
  var e=input.length;
  while((b<e) &&(input.substr(b,1)==" ")){
    ++b;
  };
  while((e>b) &&(input.substr(e,1)==" ")){
    --e;
  }
  return input.substr(b,e);
}

function activateSubmit() {
if(document.contactUs.name.value!="" && document.contactUs.email.value!="" && document.contactUs.subject.value!="" && document.contactUs.content.value!="")
{document.contactUs.Submit.disabled=false}
}

function activateBooking() {
if(document.contactUs.name.value!="" &&
   document.contactUs.email.value!="" &&
   document.contactUs.tel.value!="" &&
   document.contactUs.date1xx.value!="" &&
   document.contactUs.venue.value!="" &&
   document.contactUs.venue_address.value!="")
{document.contactUs.Submit.disabled=false}
}

function delItem(v,w,x,y,z) {
document.getElementById(v).value=""
document.getElementById(w).value=""
document.getElementById(x).value=""
document.getElementById(y).value=""
document.getElementById(z).value=""
}

function calcCost(a,b,c) {
totalCost = parseFloat(document.getElementById(b).value)*parseFloat(document.getElementById(c).value)
//document.getElementById(a).value= totalCost
roundIt(a,totalCost)
}

function roundIt(a,amount)
{
var s = "";
var decimal;
amount = parseFloat(amount);
if (!(isNaN(amount))) {
// round to nearest cent
amount = Math.round(amount * 100);
amount = amount / 100;

// format the output
s = new String(amount);
decimal = s.indexOf(".");
if (decimal == -1) {
// whole number
s+= ".00";
} else {
if (decimal == (s.length - 2)) {
// needs a trailing zero
s+= "0";
}
}
} else {
// not a number so return zero
s = "0.00";
} 
//alert(s)
document.getElementById(a).value=s;
//calculate();
return s;
}


//--------------------------------------------------
function add2Order(t) {

document.getElementById('formatDIV').innerHTML=document.getElementById('formatDIV').innerHTML +
"<br><input ReadOnly style=\"width: 80px\" type=\"text\" name=\"format"+itemCount+"\" id=\"format"+itemCount+"\" class=\"item\">"

document.getElementById('titleDIV').innerHTML=document.getElementById('titleDIV').innerHTML +
"<br><input ReadOnly type=\"text\" name=\"title"+itemCount+"\" id=\"title"+itemCount+"\" class=\"item\" value=\""+t+"\">"

document.getElementById('priceDIV').innerHTML=document.getElementById('priceDIV').innerHTML +
"<br><input ReadOnly style=\"width: 50px\"  type=\"text\" name=\"price"+itemCount+"\" id=\"price"+itemCount+"\" class=\"item\">"

document.getElementById('quantDIV').innerHTML=document.getElementById('quantDIV').innerHTML +
"<br><input style=\"width: 60px; background-color:#FFEEEE\"  type=\"text\" name=\"quant"+itemCount+"\" id=\"quant"+itemCount+"\" class=\"item\" value=\"1\" onchange=\"calcCost('total"+itemCount+"','quant"+itemCount+"','price"+itemCount+"')\">"

document.getElementById('totalDIV').innerHTML=document.getElementById('totalDIV').innerHTML +
"<br><input ReadOnly style=\"width: 50px\" type=\"text\" name=\"total"+itemCount+"\" id=\"total"+itemCount+"\" class=\"item\">"

document.getElementById('removeDIV').innerHTML=document.getElementById('removeDIV').innerHTML +
"<br><input ReadOnly type=\"button\" class=\" tenpx input\" value=\"X\" onclick=\"delItem('format"+itemCount+"','title"+itemCount+"','price"+itemCount+"','quant"+itemCount+"','total"+itemCount+"')\">"

f1 = "format"+itemCount
t1 = "total"+itemCount
q1 = "quant"+itemCount
p1 = "price"+itemCount
Alength = j_title.length

for (place=0; place<=Alength; place++) 
{
	if(j_title[place]==t) {
		if(j_format[place]=='SM') {j_format[place] = 'Sheet Music'}
	document.getElementById(f1).value=j_format[place]
	document.getElementById(p1).value=j_price[place]
	break}
}

calcCost(t1,q1,p1)
document.getElementById('itemz').value=itemCount
itemCount=itemCount+1
}
//--------------------------------------------------

function theDate() {
day = new Array("Sun","Mon","Tues","Weds","Thurs","Fri","Sat")
month = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
today = new Date()
thisDay = day[today.getDay()]
thisDate = today.getDate()
thisMonth = month[today.getMonth()]
thisYear = today.getFullYear()
thisHour = today.getHours()
thisMin = today.getMinutes()
thisSec = today.getSeconds()
thisTime = today.getTime()
//document.dateDisplay.Date.value=thisDay+', '+thisDate+' '+thisMonth+' '+thisYear
alert(thisTime)
}

//--------------------------------------------------
function add2Cart(t) {
Alength = j_title.length
dbid = document.getElementById('orderNumber').value

for (place=0; place<=Alength; place++) 
{
	if(j_title[place]==t) {
		if(j_format[place]=='SM') {j_format[place] = 'Sheet Music'}
	window.location="cart.php?dbid="+dbid+"&format="+j_format[place]+"&title="+j_title[place]+"&price="+j_price[place]+"&status=new"
	break}
}

}
//--------------------------------------------------

function checkFields() {
compulsoryFields = new Array(document.printOrder.name,document.printOrder.add1,document.printOrder.town,document.printOrder.postcode,document.printOrder.email)
compFieldName = new Array("Name","Address, line 1","Town","Postcode","Email")
Loc=0
for (Loc=0; Loc<5; Loc++) {
	if (compulsoryFields[Loc].value=="")
		{alert('Please enter details in the '+compFieldName[Loc]+' field')
		compulsoryFields[Loc].focus()
		break}}
if (compulsoryFields[0].value!=""
		&&	 compulsoryFields[1].value!=""	
		&&	 compulsoryFields[2].value!=""	
		&&	 compulsoryFields[3].value!=""	
		&&	 compulsoryFields[4].value!="") 
	{document.printOrder.submit()	}
}
