// JavaScript Document
var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;

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_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_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_validateContactForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateContactForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if (nm == "cFirstName" && val.value == 'First Name') { val.value = "";} else { if (nm == "cLastName" && val.value == 'Last Name') { val.value = "";}  else { if (nm == "cPhone" && val.value == 'Phone') { val.value = "";}}}if ((vVal=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=vVal.indexOf('@');
        if (p<1 || p==(vVal.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(vVal);
        if (isNaN(vVal)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; 
	if ( nm == "cFirstName" && val.value == '') {val.value = "First Name";} if (nm == "cLastName" && val.value == '') { val.value = "Last Name";} if (nm == "cPhone" && val.value == '') { val.value = "Phone";} }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
 	document.MM_returnValue = (errors == '');
  	document.cForm.action = "http://www.summersmashgala.com/contact.cfm?sID=1";
}

function MM_validateOrderForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateOrderForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  document.oForm.action = "https://www5677.ssldomain.com/summersmashgala/submitOrder.cfm?sID=1";
}

function MM_validateDonationForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateDonationForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  document.dForm.action = "https://www5677.ssldomain.com/summersmashgala/submitDonation.cfm?sID=1";
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

var thisPage = document.URL.substring(document.URL.lastIndexOf("/")+1 ,document.URL.length);
thisPage = thisPage.substring(0 ,thisPage.lastIndexOf("."));

function setPrice(r,t) {
	if(thisPage == "buy-tickets" || thisPage == "submitOrder") {
		var q = MM_findObj('pQty' + r);
		var qf = MM_findObj('qty' + r);
		qf.value = q.value;
		if(qf.value > 0) {
			MM_findObj('tRow' + r).style.display = 'block';
		} else {
			MM_findObj('tRow' + r).style.display = 'none';
		}
		
		for (i=1;i<=t;i++) {
			MM_findObj('qty'+ i).value = MM_findObj('pQty' + i).value;
			MM_findObj('itemSub'+ i).value = MM_findObj('pItemSub' + i).value;
		}
		
		var u = MM_findObj('pUnit'+ r);
		var s = MM_findObj('pItemSub'+ r);
		var sf = MM_findObj('itemSub'+ r);
		s.value = (q.value * u.value).toFixed(2);
		sf.value = (q.value * u.value).toFixed(2);
		MM_findObj('subTotal').value = 0.00;
		
		for (i=1;i<=t;i++) {
			s = MM_findObj('itemSub'+ i);
			MM_findObj('subTotal').value = (parseFloat(MM_findObj('subTotal').value) + parseFloat(s.value)).toFixed(2);
		}
		
		
		MM_findObj('total').value = MM_findObj('subTotal').value;
	} else {
		var d = MM_findObj('Donation Amount');
		var f = MM_findObj('fda');
		f.value = d.value;
	}
}

function setConf() {
	var confBText = '<div class="cHeader">Billing Details</div>' +
	MM_findObj('First Name').value + ' ' + MM_findObj('Last Name').value + '<br />' +
	MM_findObj('Address') .value+ '<br />' +
	MM_findObj('City').value + ', ' + MM_findObj('State').value + ' ' + MM_findObj('Zip').value + '<br />' +
	'Phone: ' + MM_findObj('Phone').value + '<br />' +
	'Email: ' + MM_findObj('Email').value + '<br />';
	
	var confCText = '<div class="cHeader">Credit Card Details</div>' +
	 MM_findObj('ccType').value.toUpperCase() + ' ending in: ' + MM_findObj('ccNumber').value.substring(MM_findObj('ccNumber').value.length-4) + '<br />' +
	'Expiration Date: ' + MM_findObj('ccMonth').value + '/' + MM_findObj('ccYear').value + '<br />';
	MM_findObj('confB').innerHTML = confBText;
	MM_findObj('confC').innerHTML = confCText;
	Nifty("div#confB,div#confC", "none same-height");
	setPrice(1,7);
}

function testCreditCard () {
  var myCardNo = MM_findObj('ccNumber').value;
  var myCardType = MM_findObj('ccType').value;
  if (checkCreditCard(myCardNo,myCardType)) {
    $(MM_findObj('ccNumber')).removeClass("error");
  } 
  else {
	 alert (ccErrors[ccErrorNo]);
  	$(MM_findObj('ccNumber')).addClass("error");
  }
}



$(document).ready(function(){

	Nifty("div#fsbtLeft,div#fsbtRight", "none same-height");
	Nifty("div#fsbbLeft,div#fsbbRight", "none same-height");

	if(thisPage  == "index" || thisPage == '') {
		$(".mapBox").colorbox({iframe:true, innerWidth:500, innerHeight:400});
		$(".musicBox").colorbox();
	}

	if(thisPage == "contact") {
		setTimeout("initialize()",500);
	}
	
	if(thisPage == "eventMap") {
		setTimeout("initialize()",500);
	}
	
	if(thisPage == "past-events") {
		$(".slideshow").colorbox({iframe:true, innerWidth:700, innerHeight:600});
	}
	
	if(thisPage == "hotelMap") {
		setTimeout("initialize()",500);
	}
	
	if(thisPage == "prizes") {
		$(".tabNav").tabs(".panes > .pane", { effect: 'fade', fadeOutSpeed: 400, onBeforeClick: function(event, tabIndex) { $("#fsbtLeft .panes").animate({ height: $(".panes .pane").eq(tabIndex).height() + "px" }) } });
	}
	

	
	if(thisPage == "buy-tickets" || thisPage == "submitOrder" || thisPage == "donations" || thisPage == "submitDonation") {
		Nifty("div#orderError", "top transparent");
		if(!ie7) {
			Nifty("div#status li", "transparent");
		}
		
		var root = $("#orderForm").scrollable();
		
		// some variables that we need
		var api = root.scrollable(), drawer = $("#drawer");
		
		if(thisPage == "submitOrder") { api.move(2, 0); }
		
		// validation logic is done inside the onBeforeSeek callback
		api.onBeforeSeek(function(event, i) {
		
			// we are going 1 step backwards so no need for validation
			if (api.getIndex() < i) {
		
				// 1. get current page
				var page = root.find(".page").eq(api.getIndex()),
		
					 // 2. .. and all required fields inside the page
					 inputs = page.find(".required :input").removeClass("error"),
		
					 // 3. .. which are empty
					 empty = inputs.filter(function() {
						return $(this).val().replace(/\s*/g, '') == '';
					 });
		
				 // if there are empty fields, then
				if (empty.length) {
		
					// slide down the drawer
					drawer.slideDown(function()  {
		
						// colored flash effect
						drawer.css("backgroundColor", "#900");
						setTimeout(function() { drawer.css("backgroundColor", "#fff"); }, 1000);
					});
		
					// add a CSS class name "error" for empty & required fields
					empty.addClass("error");
		
					// cancel seeking of the scrollable by returning false
					return false;
		
				// everything is good
				} else {
		
					// hide the drawer
					drawer.slideUp();
				}
		
			}
		
			// update status bar
			$("#status li").removeClass("active").eq(i).addClass("active");
		
		});
		
		
		
		// if tab is pressed on the next button seek to next page
		root.find("button.next").keydown(function(e) {
			if (e.keyCode == 9) {
		
				// seeks to next tab by executing our validation routine
				api.next();
				e.preventDefault();
			}
		});
	}
	
	$("#fsNavigation .topNavBtns").each(function(){
        if($(this).children('a').hasClass('current')) { 
			var bPos = $(this).children('.current').css('background-position');
       		var bPos = bPos.replace(/px/g, '').split(' ');
        	var bPosN = bPos[0] + 'px' + ' -38px';
			$(this).children('.current').css('background-position', bPosN);
		}
    });

	
	MM_preloadImages('images/spacer.gif','images/btn-details-on.png','images/btn-prizes-on.png','images/btn-vip-seating-on.png','images/btn-donors-on.png','images/btn-buy-tickets-on.png','images/btn-past-events-on.png','images/btn-what-is-summer-smash-on.png');

});

