/* New Packages JS */

function toggleSubscriptionInfo(id) {
  textElement = id + 'Text';
  if ($(id).getStyle('display') == 'none') {
    $(textElement).hide();
    new Effect.SlideDown(id, {duration: 0.5, queue: { position: 'end', scope: 'SubArea'} });
    $(id + 'Toggle').innerHTML="-";
  } else {
    new Effect.SlideUp(id, {duration: 0.5, queue: { position: 'end', scope: 'SubArea'} });
    $(textElement).show();
    $(id + 'Toggle').innerHTML="+";
  }
}

function changePackage(newPkg) {
  if (newPkg.length == 0) {
    return false;
  }
  new Effect.SlideDown('loadingSub', { duration: 0.5, queue: { position: 'end', scope: 'Loading' } });
  new Effect.SlideUp('subscriptionArea', { duration: 0.5, queue: { position: 'end', scope: 'SubArea' } });
  new Ajax.Updater('subscriptionAreaContent', 'main.taf', { evalScripts: true, method: 'get', parameters: {live:'live',p:'9,2,1',packageid:newPkg} });
}

function buyPackage(pkgType) {
  new Effect.SlideDown('loadingSub', { duration: 0.5, queue: { position: 'end', scope: 'Loading' } });
  new Effect.SlideUp('subscriptionArea', { duration: 0.5, queue: { position: 'end', scope: 'SubArea' } });
  
  if (pkgType == 'seated') {
  new Ajax.Request("main.taf", 
    {
    evalScripts: false, 
    method: 'get',
    parameters: $('editpackage').serialize(true),
    onSuccess: function(response) {
        if (response.responseText.match('success')) {
          window.location="main.taf?p=10,8";
        } else if (response.responseText.search('tofood') > -1) {
					window.location="main.taf?p=10,20&tessitura.foodPerfNos=" + response.responseText.split("-")[1];
				} else {
          if (response.responseText.match('noseats')) {
            new Effect.SlideUp('loadingSub', { duration: 0.5, queue: { position: 'end', scope: 'Loading' } });
            new Effect.SlideDown('subscriptionArea', { duration: 0.5, queue: { position: 'end', scope: 'SubArea' } });
            new Effect.SlideDown('subscriptionAlert', { duration: 0.5, queue: { position: 'end', scope: 'SubArea' } });
          } else if (response.responseText.match('nosection')) {
            new Effect.SlideUp('loadingSub', { duration: 0.5, queue: { position: 'end', scope: 'Loading' } });
            new Effect.SlideDown('subscriptionArea', { duration: 0.5, queue: { position: 'end', scope: 'SubArea' } });
            new Effect.SlideDown('nosectionAlert', { duration: 0.5, queue: { position: 'end', scope: 'SubArea' } });            
          }
        }
      }
    }
  );
  } else {
  new Ajax.Request("main.taf", 
  {
  evalScripts: false, 
  method: 'get',
  parameters: $('editpackageunseated').serialize(true),
  onSuccess: function(response) {
      if (response.responseText.match('success')) {
        window.location="main.taf?p=10,8";
			} else if (response.responseText.search('tofood')  > -1) {
				window.location="main.taf?p=10,20&tessitura.foodPerfNos=" + response.responseText.split("-")[1];
			} else {
        if (response.responseText.match('noseats')) {
          new Effect.SlideUp('loadingSub', { duration: 0.5, queue: { position: 'end', scope: 'Loading' } });
          new Effect.SlideDown('subscriptionArea', { duration: 0.5, queue: { position: 'end', scope: 'SubArea' } });
          new Effect.SlideDown('subscriptionAlert', { duration: 0.5, queue: { position: 'end', scope: 'SubArea' } });
        } else if (response.responseText.match('nosection')) {
          new Effect.SlideUp('loadingSub', { duration: 0.5, queue: { position: 'end', scope: 'Loading' } });
          new Effect.SlideDown('subscriptionArea', { duration: 0.5, queue: { position: 'end', scope: 'SubArea' } });
          new Effect.SlideDown('nosectionAlert', { duration: 0.5, queue: { position: 'end', scope: 'SubArea' } });            
        }
      }
    }
  }
  );
  }
  return false;
}

/* Renewals JS */

var oldElement;

function togglePkgDiv(e) {
  if (oldElement != null) {
    new Effect.SlideUp(oldElement, {duration: 0.5, queue: { position: 'end', scope: 'newElem' }  });
  }
  new Effect.SlideDown(e, {duration: 0.5, queue: { position: 'end', scope: 'newElem2' }  });
  oldElement = e;
}


function doNewSeries() {
    new Effect.SlideDown('loadingSub', { duration: 0.5, queue: { position: 'end', scope: 'Loading' } });
    new Effect.SlideUp('subscriptionArea', { duration: 0.5, queue: { position: 'end', scope: 'subscriptionArea' } }); 
    new Ajax.Updater('subscriptionAreaContent', 'main.taf', { evalScripts: true, method: 'get', parameters: {live:'live',p:'10,21,2'} });
    return false; 
  }
  
  function doNewSeats(pkg_id) {
    new Effect.SlideDown('loadingSub', { duration: 0.5, queue: { position: 'end', scope: 'Loading' } });
    new Effect.SlideUp('subscriptionArea', { duration: 0.5, queue: { position: 'end', scope: 'subscriptionArea' } }); 
    new Ajax.Updater('subscriptionAreaContent', 'main.taf', { evalScripts: true, method: 'get', parameters: {live:'live',p:'10,21,3',pkg_id:pkg_id} });
    return false; 
  }
  
  function getCheckedValue(radioObj) {
  if(!radioObj)
    return "";
  var radioLength = radioObj.length;
  if(radioLength == undefined)
    if(radioObj.checked)
      return radioObj.value;
    else
      return "";
  for(var i = 0; i < radioLength; i++) {
    if(radioObj[i].checked) {
      return radioObj[i].value;
    }
  }
  return "";
}

function doSelectSeries() {
  var chosen_pkg = getCheckedValue(document.forms['choosePackage'].elements['tessitura.pkg_id']);
  if (chosen_pkg.length > 0) {
    var chosen_pkg_name = $('pkg_name' + chosen_pkg).innerHTML;
    $('currentPackageName').innerHTML = chosen_pkg_name;
    new Effect.SlideDown('loadingSub', { duration: 0.5, queue: { position: 'end', scope: 'Loading' } });
    new Effect.SlideUp('subscriptionArea', { duration: 0.5, queue: { position: 'end', scope: 'subscriptionArea' } }); 
    new Ajax.Updater('subscriptionAreaContent', 'main.taf', { evalScripts: true, method: 'get', parameters: {live:'live',p:'10,21,3',pkg_id:chosen_pkg} });
  } else {
    alert("Please choose a package from the list.");
  }
  return false;
}

var globalDialog = null;

function showSeatMapDialog(image) {
	globalDialog = new  Dialog({
		title:"Seat Map",
		opacity:.50,
		padding:5,
		margin:0,
		background:["#000000", "#ffffff"],
		close:{link:true,esc:true,overlay:false},
		content:"<div id=\"seatMapDialog\"><img src=\"/img/seatmaps/" + image + "\"/></div>"
	});
	globalDialog.open();  
}

document.observe("dom:loaded", function() {
  Dialogs.load();
});

function foodFieldsOK() {
	var zones = new Array();
	var itemSelected = false;
	
	zones = $('tessitura.zones').value.split(',');
	zones.each(function(item) {
		if ($F('tessitura.qty_' + item).value != 0) {
			itemSelected = true;
		}
	});
	if (!itemSelected) {
		alert("Please select at least one food item.");
		return false;
	} else {
		return true;
	}
}

function toggleFoodView(perfno) {
	var fd = $('foodDetail_' + perfno);
	var fdt = $('foodDetailLinkText_' + perfno);
	if (fd.getStyle('display') == 'none') {
		fd.show();
		fdt.innerHTML = 'Hide Items';
	} else {
		fd.hide();
		fdt.innerHTML = 'View Items';
	}
}
