// fix the transparent PNG bug in IE
// correctly handle PNG transparency in Win IE 5.5 & 6.
function correctPNG()
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "pointer:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

window.attachEvent("onload", correctPNG);

function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to ); 
        idx = str.indexOf( from );
    }
    return str;
}

function ToggleDependants(obj) {
//    if (DependantsArray != undefined) {
//        var currentID = replaceAll(obj.name, 'buyticket_', '');
//        var isEnabled = new Array(256);
//        var count = 0;
//        var doIndexReset = new Array(256);
//        var resetcount = 0;
//        var currentindex = 0;
//        for (var j = 0; j < DependantsArray.length; j++) {
//            // do each line, see if object that has a dependance has a value, if it does then enable the item
//            var Dependants = DependantsArray[j].split("|");
//            // Dependants[0] is the object to check the value of
//            // Dependants[1] is a : separated list of objects to trigger the enable/disable of
//            if (Dependants[1].indexOf(":") != -1) {
//                var triggers = Dependants[1].split(":");
//            } else {
//                triggers = new Array(1);
//                triggers[0] = Dependants[1];
//            }
//            // triggers is an array of objects that if they contain a value, enable an object
//            for (var i = 0; i < triggers.length; i++) {
//                // get object from the page
//                trigerobj = document.getElementById("buyticket_" + triggers[i]);
//                docobj = document.getElementById("buyticket_" + Dependants[0]);
//                if (docobj != null) {
//                    var objcount = 0;
//                    if (docobj.type == "select-one") {
//                        objcount = docobj.options[docobj.selectedIndex].value;
//                    }
//                    else {
//                        objcount = docobj.value;
//                    }
//                    var found = false;
//                    if (objcount > 0) {
//                        isEnabled[count] = triggers[i];
//                        count++;
//                        trigerobj.disabled = false;
//                        trigertable = document.getElementById("ticket_num_" + triggers[i]);
//                        trigertable.style.display = "";
//                    } else {
//                        for (var h = 0; h < isEnabled.length; h++) if (isEnabled[h] == triggers[i]) found = true;
//                        if (!found) {
//                            currentindex = trigerobj.selectedIndex;
//                            doIndexReset[resetcount] = triggers[i];
//                            resetcount++;
//                            trigerobj.disabled = true;
//                        }
//                    }
//                }
//            }
//        }

//        // check if we should reset the index
//        for (var j = 0; j < doIndexReset.length; j++) {
//            if (doIndexReset[j]) {
//                resetobj = document.getElementById("buyticket_" + doIndexReset[j]);
//                // check if object is disabled, if it is reset, else do nothing
//                if (resetobj.disabled == true) {
//                    resetobj.selectedIndex = 0;
//                    trigertable = document.getElementById("ticket_num_" + doIndexReset[j]);
//                    trigertable.style.display = "none";
//                }
//            }
//        }
//    }
}

function CheckTicketCount() {
	var itemList = document.getElementsByTagName("*");
	var ticketsSelected = false;
	for(i=0;i<itemList.length;i++) {
		if (itemList[i].id != undefined && itemList[i].id != "") {
			if (itemList[i].id.substr(0,10) == "buyticket_") {
				if (itemList[i].value > 0) ticketsSelected = true;
			}
		}
	}
	return ticketsSelected;
}

function UpdateSeatCount( seatObj, nameCounter ) {
	if (seatObj.checked == true) {
		if (document.getElementById(nameCounter).value == 0) {
			seatObj.checked = false;
			alert ('You have reached the maximum number of seats, remove one seat first.');	
		} else {
			document.getElementById(nameCounter).value--;
		}
	} else {
		document.getElementById(nameCounter).value++;
	}
}

function CheckSeatCount( nameCounter ) {
	if (document.getElementById(nameCounter).value != 0) {
		alert ('You have not select all the seats required, please select all seats first.');
		return false;
	} else {
		return true;
	}
}

function UpdateReusableTickets( baseConvPrice, basePrice, itemPrice, sender, obj_id, FormName ) {
	convfee = document.getElementById('conveniencefee');
	grandtotal = document.getElementById('grandtotal');
	var additionalFee = 0.00;
	var selectedcards = new Array();
	if (obj_id.length > 0) {
		var rawForm = document.getElementById(FormName);
		for (i = 0; i < rawForm.length; i++) {
			var tempobj = rawForm.elements[i];
			if  (tempobj.id.substr(0,obj_id.length) == obj_id) {
				if(tempobj.value == 0) {
					additionalFee = additionalFee + parseFloat(itemPrice);
				} else {
					if (selectedcards[tempobj.value] == true) {
						alert('you can only assign one ticket to a single reuseable card');
						sender.selectedIndex = 0;
						additionalFee = additionalFee + parseFloat(itemPrice);
					} else {
						selectedcards[tempobj.value] = true;
					}
				}
			}
		}
	} else {
		additionalFee = additionalFee + parseFloat(itemPrice);
	}
	var convfeevalue = parseFloat(baseConvPrice) + parseFloat(additionalFee);
	if(isNaN(convfeevalue)) convfeevalue = "0"; sign = (convfeevalue == (convfeevalue = Math.abs(convfeevalue)));
	convfeevalue = Math.floor(convfeevalue*100+.500000000001); cents = convfeevalue%100;
	convfeevalue = Math.floor(convfeevalue/100).toString();	if(cents<10) cents = "0" + cents;
	convfee.innerHTML = ((sign)?'':'-') + convfeevalue + '.' + cents;
	
	var granstotalvalue = parseFloat(basePrice) + parseFloat(additionalFee);
	if(isNaN(granstotalvalue)) granstotalvalue = "0"; sign = (granstotalvalue == (granstotalvalue = Math.abs(granstotalvalue)));
	granstotalvalue = Math.floor(granstotalvalue*100+.500000000001); cents = granstotalvalue%100;
	granstotalvalue = Math.floor(granstotalvalue/100).toString();	if(cents<10) cents = "0" + cents;
	grandtotal.innerHTML = ((sign)?'':'-') + granstotalvalue + '.' + cents;
}

function switch_deliverymethod_reusable( obj_id, display ) {
	triger = document.getElementById(obj_id);
	if (display == "show") {
		triger.style.display = "";
	} else {
		triger.style.display = "none";
	}
}

function ValidateCheckoutForm( FormName ) {
	//.disabled = true;
	var rawForm = document.getElementById(FormName);
	var eol = "\n";
	var formvalid = true;
	var formMessage = "";
	var submitButton = null;
	// usinge the form passed, check that all fields that start with a r_, contain a value
	for (i = 0; i < rawForm.length; i++) {
		var tempobj = rawForm.elements[i];
		if  (tempobj.id.substr(0,2) == "r_") {
			// this is a required field
			switch(tempobj.type) {
				case "checkbox":
					if (tempobj.checked == false) formMessage = formMessage + tempobj.title + " must be selected" + eol;
					break;
				case "text":
				case "hidden":
					if (tempobj.value == "") formMessage = formMessage + tempobj.title + " must be entered" + eol;
					break;
				case "textarea":
					if (tempobj.value == "") formMessage = formMessage + tempobj.title + " must be entered" + eol;
					break;
				case "select-one":
					if (tempobj.options.length > 0) {
						if (tempobj.options[tempobj.selectedIndex].value == "") formMessage = formMessage + tempobj.title + " must be selected" + eol;
					}
					break;
			}
		}
		
		if (tempobj.type == "submit") {
			submitButton = tempobj;
		}
	}
	
	if (formMessage.length > 0) {
		formvalid = false;
		alert("Please review the following errors." + eol + eol + formMessage);
	} else {
		formvalid = true;
		// on sucess, disable the submit button on the page so the user can not mess around while the post is going
		submitButton.disabled = true;
		rawForm.submit();
	}
	
	return formvalid;
}

// functions for moving items from one list box to another
function tb_hiLiteAll( obj ) {
	if ( obj.options.length>0 ) {
		for ( var x=0; x<obj.length; x++ ) {
			obj.options[x].selected=true;
		}
	}
}
function tb_delAttribute(Obj1, Obj2){
	var objcnt = Obj1.options.length;
	for (var i = 0; i < objcnt; i++) {
		if (Obj1.options[i].selected) {
			Obj2.appendChild(Obj1.options.item(i));
			i--;
			objcnt--;
		}
	}
}

function tb_addAttribute(Obj1, Obj2){
	var objcnt = Obj2.options.length;
	for (var i = 0; i < objcnt; i++) {
		if (Obj2.options[i].selected) {
			Obj1.appendChild(Obj2.options.item(i));
			i--;
			objcnt--;
		}
	}
}

function tb_selectNone(Obj1, Obj2){
    Obj1.selectedIndex = -1;
    Obj2.selectedIndex = -1;
}

function tb_selectAll(Obj){
	Obj.selectedIndex = -1;
	for (var i = 0; i < Obj.length; i++) {
		Obj.options[i].selected = false;
		Obj.options[i].selected = true;
	}
}

function StringToBool(stringval) {
	if (stringval != 'true') {
		return false;
	} else {
		return true;
	}
}

function SelectListBoxItems(control, doit) {
	if (doit != 'false') {
		for(var i = 0;i < control.length;i++) control.options[i].selected = true;
		return true;
	}
}

function ListBoxMove(formO,selectO,to) 
{
    var index = selectO.selectedIndex;
    
    var selectLength  = selectO.length - 1;
    
    //error handling
    //nothing selected
    if (index == -1) return false;
    
    if(to == +1 && index == selectLength)
    {
        //alert("Cannot move down anymore!");
        return false;
    }
    else if(to == -1 && index == 0)
    {
        //alert("Cannot move up anymore!");
        return false;
    }
    
    ListBoxSwap(index,index+to,formO,selectO);
    return true;
}

//basic swap
function ListBoxSwap(fIndex,sIndex,formO,selectO)
{
    //store first
    fText  = selectO.options[fIndex].text;
    fValue = selectO.options[fIndex].value;
    
    
    //make first = second
    selectO.options[fIndex].text  = selectO.options[sIndex].text;
    selectO.options[fIndex].value = selectO.options[sIndex].value;  
    
    //make second = first
    selectO.options[sIndex].text = fText;
    selectO.options[sIndex].value = fValue;
    
    //amke new one be selected
    selectO.options[fIndex].selected = false;    
    selectO.options[sIndex].selected = true;    
    
}

function UpdateTicketCounter() {
	ticketCounter = document.getElementById("ticketcounter");
	if (ticketCounter != undefined) {
		if (seedtime > 0) {
			left = new Date(seedtime*1000);
			//ticketCounter.innerHTML = (seedtime);
			seedtime = seedtime - 1;
			var strTime = "";
			strTime = left.getSeconds();
			if (strTime < 10) strTime = "0" + strTime;
			strTime = left.getMinutes() + ":" + strTime;
		} else {
			strTime = "0:00";
		}
		ticketCounter.innerHTML = strTime;
	}
   	ID=window.setTimeout("UpdateTicketCounter();",1000);
}

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0; 

function resizeIframebyobject(currentfr){
	if (currentfr && !window.opera){
		currentfr.style.display="block";
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight)
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		else if (currentfr.Document && currentfr.Document.body.scrollHeight)
			currentfr.height = currentfr.Document.body.scrollHeight;
		if (currentfr.addEventListener)
			currentfr.addEventListener("load", readjustIframe, false);
		else if (currentfr.attachEvent){
			currentfr.detachEvent("onload", readjustIframe);
			currentfr.attachEvent("onload", readjustIframe);
		}
	}
}

function resizeIframe(frameid){
	return;
	var currentfr=document.getElementById(frameid);
	resizeIframebyobject(currentfr);
}

function readjustIframe(loadevt) {
	var crossevt=(window.event)? event : loadevt;
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement;
	if (iframeroot)
		resizeIframe(iframeroot.id);
}


function GetASPObjectID( strName )
{
    var allElements = document.getElementsByTagName("*");
    var fullName = "_" + strName;
    for(var j=0; j<allElements.length; j++)
    {
        if (allElements[j].id.substr((allElements[j].id.length-fullName.length),fullName.length) == fullName)
        {
			return allElements[j].id;
		}
	}
	return null;
}

function GetASPObject( strName )
{
	var objID = GetASPObjectID( strName );
	if (objID != null)
	{
		return document.getElementById(objID);
	}
	return null;
}

function CheckEnterKeyForLogin(e, loginButtonControlName)
{
    // enter key pressed
    var loginButton = null;
    if (loginButtonControlName != '')
    {
        if(navigator.appName.indexOf("Microsoft")>(-1)){ 
            if (event.keyCode == 13)
            {
                event.returnValue = false;
                event.cancel = true;
                loginButton = GetASPObject(loginButtonControlName);
                if (loginButton != null)
                {
                    loginButton.click();
                }
                return false;
            }
        }
        else
        {
            if (e.keyCode == 13){ 
                loginButton = GetASPObject(loginButtonControlName);
                if (loginButton != null)
                {
                    loginButton.click(); 
                }
                return false; 
            } 
        }
    }
    else
    {
        if(navigator.appName.indexOf("Microsoft")>(-1)){ 
            if (event.keyCode == 13)
            {
                event.returnValue = false;
                event.cancel = true;
                return false;
            }
        }
        else
        {
            if (e.keyCode == 13){ 
                return false; 
            } 
        }
    }
    return true;
}



