var $icount = 0;
var $i = 0;
var i_img = new Array();

// Preload script
$.fn.image = function(src, f) {
 return this.each(function(){
  i_img[$i] = new Image();
  i_img[$i].onload = f;
		i_img[$i].onerror = f;
  i_img[$i].src = src;
  $i++;
 });
};

// Keywords
$(document).ready(function(){
 $("#wrapper").focus();
 $("#kwds").val("Search by Artist, Team or Event");
 
 $(".viewbtn").hover(
  function () {
   $(this).attr("src", "px/results_viewbtn2.gif");
  },
  function () {
   $(this).attr("src", "px/results_viewbtn.gif");
  }
 );
  $(".sendbtn").hover(
  function () {
   $(this).attr("src", "px/contact_send2.gif");
  },
  function () {
   $(this).attr("src", "px/contact_send.gif");
  }
 );
});

function preloader() {
	
	$imgs = document.images.length;
	$img = document.images;
	$icount = 0;
	
	$($img).each(function(){
		$("#wrapper").image($(this).attr("src"), function() {
			$icount++;
			if($icount == $imgs) {
				if ($("#tixPage").val() == undefined) {
					setTimeout('$("#container").show()', 5);
					setTimeout('$("#preloader").hide()', 10);
				}
			}
		});
	});
}

// Mcafee Popup
function popUp(URL){
 day = new Date();
 id = day.getTime();
 eval("page" + id + "=window.open(URL,'" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=525,height=500');");
}

// Verisign Popup
function popUp2(URL){
 day = new Date();
 id = day.getTime();
 eval("page" + id + "=window.open(URL,'" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=700');");
}

// Popup script
var popupStatus = 0;
function loadPopup(popup, background){
 if (popupStatus == 0) {
  $("#backgroundPopup_"+background).css({"opacity": "0.7"});
  
  $("#backgroundPopup_"+background).show();
  $("#backgroundPopup2_"+background).show();
  $("#"+popup).show();
  $("#backgroundPopup_"+background).bgiframe();
  popupStatus = 1;
 }
}

function disablePopup(popup, content, background){
 if (popupStatus == 1) {
  $("#backgroundPopup_"+background).hide();
  $("#backgroundPopup2_"+background).hide();
  $("#"+popup).hide();
  $("#"+content).html("");
  popupStatus = 0;
 }
}

function centerPopup(popup, background){
 
 var windowWidth = $(window).width();
 var windowHeight = $(document).height();
 var popupHeight = $("#"+popup).height();
 var popupWidth = $("#"+popup).width();
 $("#"+popup).css({
  "position": "absolute",
  "top": ($(window).scrollTop() + 40) + "px",
  "left": ((windowWidth / 2 - popupWidth / 2) - 4) + "px"
 });
 
 $("#backgroundPopup_"+background).css({
  "height": windowHeight+"px",
  "width": (windowWidth-2)+"px"
 });
 
 $("#backgroundPopup2_"+background).css({
  "height": windowHeight+"px",
  "width": (windowWidth-2)+"px"
 });
}

// Method used to show select box below pop-up
(function($) {
 
 $.fn.bgIframe = $.fn.bgiframe = function(s){
  if ($.browser.msie && parseInt($.browser.version) === 6) {
   s = $.extend({
    top: 'auto',
    left: 'auto',
    width: 'auto',
    height: 'auto',
    opacity: true,
    src: 'javascript:false;'
   }, s || {});
   
   var prop = function(n){
    return n && n.constructor == Number ? n + 'px' : n;
   }, html = '<iframe class="bgiframe" frameborder="0" tabindex="-1" src="' + s.src + '"' + ' style="display:block; position:absolute; z-index:-1;' + (s.opacity !== false ? 'filter:Alpha(Opacity=\'0\');' : '') + 'top:' + (s.top == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')' : prop(s.top)) + ';' + 'left:' + (s.left == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')' : prop(s.left)) + ';' + 'width:' + (s.width == 'auto' ? 'expression(this.parentNode.offsetWidth+\'px\')' : prop(s.width)) + ';' + 'height:' + (s.height == 'auto' ? 'expression(this.parentNode.offsetHeight+\'px\')' : prop(s.height)) + ';' + '"/>';
            return this.each(function(){
    if ($('> iframe.bgiframe', this).length == 0) 
     this.insertBefore(document.createElement(html), this.firstChild);
   });
  }
  return this;
 };
})(jQuery);

// Show Contact Pop-up
function getContactUs(){
 $("#ajaxContent_contact").html(getLoadingMessage("contact"));
 centerPopup("ajaxPopup_contact", "contact");
 loadPopup("ajaxPopup_contact", "contact");
 
 $("#backgroundPopup2_contact").click(function() { disablePopup("ajaxPopup_contact", "ajaxContent_contact", "contact"); });

 $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_contact", "ajaxContent_contact", "contact");
  }
 });
 
 $.get("ajax/popup_contact_us.php", function(data){

  $("#ajaxContent_contact").html(data);
  $(".sendbtn").hover(function () {
	$(this).attr("src", "px/contact_send2.gif");
  },function () { $(this).attr("src", "px/contact_send.gif"); }
 );  
  $("#ajaxClose_contact").click(function(){
   disablePopup("ajaxPopup_contact", "ajaxContent_contact", "contact");
  });
  
  $('#ajaxPopup_contact').animate({
   top: ($(window).scrollTop() + 40) + "px"
  }, {
   queue: false,
   duration: 350
  });
 });
}

// Show Settings Pop-up
function getSettings(){
 $("#ajaxContent_settings").html(getLoadingMessage("settings"));
 centerPopup("ajaxPopup_settings", "settings");
 loadPopup("ajaxPopup_settings", "settings");
 
 $("#backgroundPopup2_settings").click(function() { disablePopup("ajaxPopup_settings", "ajaxContent_settings", "settings"); });

 $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_settings", "ajaxContent_settings", "settings");
  }
 });
 
 $.get("ajax/popup_settings.php", function(data){

  $("#ajaxContent_settings").html(data);
  
  $("#ajaxClose_settings").click(function(){ disablePopup("ajaxPopup_settings", "ajaxContent_settings", "settings"); });
  $("#btnCancel").click(function(){  disablePopup("ajaxPopup_settings", "ajaxContent_settings", "settings");});
  
  $('#ajaxPopup_settings').animate({
	top: ($(window).scrollTop() + 40) + "px"
  }, {
   queue: false,
   duration: 350
  });
 });
}

/**
 * ----------------------------------------------------------------
 * Save Settings for Users
 * ----------------------------------------------------------------
 */
function saveSettings() {

  var includeFees = $("input[name='rbtIncFees']:checked").val();
  var priceChange = $("input[name='rbtPriceChange']:checked").val();
  var sortOption = $("input[name='rbtSort']:checked").val();
  var listOption = $("input[name='rbtList']:checked").val();  
  
  document.getElementById("btnSave").disabled = true;
  
  var settings = "includeFees="+includeFees;
  settings += "|priceChange="+priceChange;
  settings += "|sortOption="+sortOption;
  settings += "|listOption="+listOption;  
  
  $.post("ajax/save_settings.php", {includeFees: includeFees, priceChange: priceChange, sortOption: sortOption, listOption: listOption },  function(data) {

	var evtid = $("#evtid").val();
	gotoPage("Tix.php?evtid="+evtid);
	
  });
  
}

// Show Help Pop-up
function getHelpTickets(){
 $("#ajaxContent_tickethelp").html(getLoadingMessage("tickethelp"));
 centerPopup("ajaxPopup_tickethelp", "tickethelp");
 loadPopup("ajaxPopup_tickethelp", "tickethelp");
 
 $("#backgroundPopup2_tickethelp").click(function() { disablePopup("ajaxPopup_tickethelp", "ajaxContent_tickethelp", "tickethelp"); });

 $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_tickethelp", "ajaxContent_tickethelp", "tickethelp");
  }
 });
 
 $.get("ajax/popup_tickethelp.php", function(data){

  $("#ajaxContent_tickethelp").html(data);
  $("#ajaxClose_tickethelp").click(function(){
   disablePopup("ajaxPopup_tickethelp", "ajaxContent_tickethelp", "tickethelp");
  });
  
  $('#ajaxPopup_tickethelp').animate({
   top: ($(window).scrollTop() + 40) + "px"
  }, {
   queue: false,
   duration: 350
  });
 });
}

// Show City pop-up
function showCity(id){
 $("#div" + id + "City").slideToggle();
}

// Show States Pop-up
function getStates(){
 
 $("#ajaxContent_locations").html(getLoadingMessage("locations"));
 centerPopup("ajaxPopup_locations", "locations");
 loadPopup("ajaxPopup_locations", "locations");
 $("#backgroundPopup2_locations").click(function(){
  disablePopup("ajaxPopup_locations", "ajaxContent_locations", "locations");
 });
 $("#ajaxClose_locations").click(function(){
  disablePopup("ajaxPopup_locations", "ajaxContent_locations", "locations");
 });
 
 $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_locations", "ajaxContent_locations", "locations");
  }
 });
 getStateList("");
}

// Show Category Pop-up
function getCategories(){
 $("#ajaxContent_cats").html(getLoadingMessage("cats"));
 centerPopup("ajaxPopup_cats", "cats");
 loadPopup("ajaxPopup_cats", "cats");
 
 $("#backgroundPopup2_cats").click(function() { disablePopup("ajaxPopup_cats", "ajaxContent_cats", "cats"); });

    $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_cats", "ajaxContent_cats", "cats");
  }
 });
 
 $.get("ajax/popup_categories.php", function(data){
  $("#ajaxContent_cats").html(data);
  $("#ajaxClose_cats").click(function(){
   disablePopup("ajaxPopup_cats", "ajaxContent_cats", "cats");
  });
  
  $('#ajaxPopup_cats').animate({
   top: ($(window).scrollTop() + 40) + "px"
  }, {
   queue: false,
   duration: 350
  });
 });
}

// Used for showing Sports Pop-up
function getSports(){
 
 $("#ajaxContent_sports").html(getLoadingMessage("sports"));
 centerPopup("ajaxPopup_sports", "sports");
 loadPopup("ajaxPopup_sports", "sports");
 $("#backgroundPopup2_sports").click(function() { disablePopup("ajaxPopup_sports", "ajaxContent_sports", "sports"); });
 
 $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_sports", "ajaxContent_sports", "sports");
  }
 });
 
 $.get("ajax/popup_sports.php", function(data){
  $("#ajaxContent_sports").html(data);
  $("#ajaxClose_sports").click(function(){
   disablePopup("ajaxPopup_sports", "ajaxContent_sports", "sports");
  });
  $('#ajaxPopup_sports').animate({
   top: ($(window).scrollTop() + 40) + "px"
  }, {
   queue: false,
   duration: 350
  });
 });
}

// Used for showing Concerts Pop-up
function getConcerts(){
 
 $("#ajaxContent_concerts").html(getLoadingMessage("concerts"));
 centerPopup("ajaxPopup_concerts", "concerts");
 loadPopup("ajaxPopup_concerts", "concerts");
 $("#backgroundPopup2_concerts").click(function(){
  disablePopup("ajaxPopup_concerts", "ajaxContent_concerts", "concerts");
 });
 
 $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_concerts", "ajaxContent_concerts", "concerts");
  }
 });
 
 $.get("ajax/popup_concerts.php", function(data){
  $("#ajaxContent_concerts").html(data);
  $("#ajaxClose_concerts").click(function(){
   disablePopup("ajaxPopup_concerts", "ajaxContent_concerts", "concerts");
  });
  $('#ajaxPopup_concerts').animate({
   top: ($(window).scrollTop() + 40) + "px"
  }, {
   queue: false,
   duration: 350
  });
 });
}

// Used for showing Theater Pop-up
function getTheatre(){
 
 $("#ajaxContent_theatre").html(getLoadingMessage("theatre"));
 centerPopup("ajaxPopup_theatre", "theatre");
 loadPopup("ajaxPopup_theatre", "theatre");
 
 $("#backgroundPopup2_theatre").click(function(){
  disablePopup("ajaxPopup_theatre", "ajaxContent_theatre", "theatre");
 });
 
 $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_theatre", "ajaxContent_theatre", "theatre");
  }
 });
 
 $.get("ajax/popup_theatre.php", function(data){
  
  $("#ajaxContent_theatre").html(data);
  $("#ajaxClose_theatre").click(function(){
   disablePopup("ajaxPopup_theatre", "ajaxContent_theatre", "theatre");
  });
  $('#ajaxPopup_theatre').animate({
   top: ($(window).scrollTop() + 40) + "px"
  }, {
   queue: false,
   duration: 350
  });
 });
}

// Used for fetching State list based on Country on locations Pop-up
function getStateList(country){
 
 $.get("ajax/popup_locations_state.php", {
  country: country
 }, function(data){
   
  $("#ajaxContent_locations").html(data);
  $("#ajaxClose_locations").click(function(){
   disablePopup("ajaxPopup_locations", "ajaxContent_locations", "locations");
  });
   
  $('#ajaxPopup_locations').animate({
   top: ($(window).scrollTop() + 40) + "px"
  }, {
   queue: false,
   duration: 350
  });
 });
}

function showLocation(data) {
 
 $("#ajaxContent_locations").html(getLoadingMessage("locations"));
 centerPopup("ajaxPopup_locations", "locations");
 loadPopup("ajaxPopup_locations", "locations");
 
 $("#backgroundPopup2_locations").click(function(){
  disablePopup("ajaxPopup_locations", "ajaxContent_locations", "locations");
 });
 
 $("#ajaxContent_locations").html(data);
 
 $("#ajaxClose_locations").click(function(){
  disablePopup("ajaxPopup_locations", "ajaxContent_locations", "locations");
 });
 
 $('#ajaxPopup_locations').animate({
  top: ($(window).scrollTop() + 40) + "px"
 }, {
  queue: false,
  duration: 350
 });
}


// Used for fetching locations based on stateId list on locations Pop-up
function getCities(lid, state){
 
 $.get("ajax/popup_locations_region.php", {
  lid: lid,
  state: state
 }, function(data){
  
  $("#ajaxContent_locations").html(data);
  $("#ajaxClose_locations").click(function(){
   disablePopup("ajaxPopup_locations", "ajaxContent_locations", "locations");
  });
   
  $('#ajaxPopup_locations').animate({
   top: ($(window).scrollTop() + 40) + "px"
  }, {
   queue: false,
   duration: 350
  });
 });
}

function getAnalytics() {
 
 $("#ajaxContent_analytics").html(getLoadingMessage("analytics"));
 centerPopup("ajaxPopup_analytics", "analytics");
 loadPopup("ajaxPopup_analytics", "analytics");
 
 $("#backgroundPopup2_analytics").click(function(){
  disablePopup("ajaxPopup_analytics", "ajaxContent_analytics", "analytics");
 });
 
 $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_analytics", "ajaxContent_analytics", "analytics");
  }
 });
 
 var evtid = $("#evtid").val();

 $.post("ajax/popup_analytics.php", {
  evtid: evtid
 }, function(data){
    
   $("#ajaxContent_analytics").html(data);
   $("#ajaxClose_analytics").click(function(){  disablePopup("ajaxPopup_analytics", "ajaxContent_analytics", "analytics"); });
  
 });
 
 $('#ajaxPopup_analytics').animate({ top: ($(window).scrollTop() + 40) + "px" }, {
  queue: false,
  duration: 350
 });
}

function showNoWatchlistPopup() {
 
 $("#ajaxContent_watchlist").html(getLoadingMessage("watchlist"));
 centerPopup("ajaxPopup_watchlist", "watchlist");
 loadPopup("ajaxPopup_watchlist", "watchlist");
 
 $("#backgroundPopup2_watchlist").click(function(){
  disablePopup("ajaxPopup_watchlist", "ajaxContent_watchlist", "watchlist");
 });
 
 $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_watchlist", "ajaxContent_watchlist", "watchlist");
  }
 });
 
 var evtid = $("#evtid").val();

 $.post("ajax/popup_tix_watchlist.php", {
  evtid: evtid
 }, function(data){
    
   $("#ajaxContent_watchlist").html(data);
   $("#ajaxClose_watchlist").click(function(){  disablePopup("ajaxPopup_watchlist", "ajaxContent_watchlist", "watchlist"); });
   $("#btnCancel").click(function(){  disablePopup("ajaxPopup_watchlist", "ajaxContent_watchlist", "watchlist"); });
   
   $('#add').click(add);
   $('#remove').click(remove);
   $("#removeAll").click(removeAll);
   $("#addAll").click(addAll);
   $("#selSection").dblclick(add);
   $("#selSectionSelected").dblclick(remove);
 });
 
 $('#ajaxPopup_watchlist').animate({ top: ($(window).scrollTop() + 40) + "px" }, {
  queue: false,
  duration: 350
 });
}

function showWatchlistPopup() {
 
 $("#ajaxContent_watchlist").html(getLoadingMessage("watchlist"));
 centerPopup("ajaxPopup_watchlist", "watchlist");
 loadPopup("ajaxPopup_watchlist", "watchlist");
 
 $("#backgroundPopup2_watchlist").click(function(){
  disablePopup("ajaxPopup_watchlist", "ajaxContent_watchlist", "watchlist");
 });
 
 $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_watchlist", "ajaxContent_watchlist", "watchlist");
  }
 });
 
 var evtid = $("#evtid").val();
 
 $.post("ajax/popup_tix_watchlist.php", {
  evtid: evtid
 }, function(data){
   
   $("#ajaxContent_watchlist").html(data);
   $("#ajaxClose_watchlist").click(function(){  disablePopup("ajaxPopup_watchlist", "ajaxContent_watchlist", "watchlist"); });
   $("#btnCancel").click(function(){  disablePopup("ajaxPopup_watchlist", "ajaxContent_watchlist", "watchlist"); });
   
   $('#add').click(add);
   $('#remove').click(remove);
   $("#removeAll").click(removeAll);
   $("#addAll").click(addAll);
   $("#selSection").dblclick(add);
   $("#selSectionSelected").dblclick(remove);
 });
 
 $('#ajaxPopup_watchlist').animate({ top: ($(window).scrollTop() + 40) + "px" }, {
  queue: false,
  duration: 350
 });
}

function saveWatchlist() {
 
 var evtid = $("#evtid").val();
 var sectionList = getSectionList();
 
 $("#btnSave").attr("disabled", "true");
 
 $.post("ajax/save_tix_watchlist.php", {
  evtid: evtid,
  sectionList: sectionList
 }, function(data){
  
 if(data == "login") {
 
 $("#watchlistLogin").show();
 
 } else {
  
 disablePopup("ajaxPopup_watchlist", "ajaxContent_watchlist", "watchlist");
 disablePopup("ajaxPopup_watchlist", "ajaxContent_watchlist", "watchlist");
 
 gotoPage("Tix.php?evtid="+evtid);
  
 }
 });
}

function tix_contact_us() {
	
	var evtid = $("#evtid").val();
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	var numExp = /^[0-9]+$/;
	var comment = $("#txtComment").val();
	var email = $("#txtEmail").val();
	
	if (comment == "") {
		alert("Please Enter A Comment");
		document.emailform.comment.focus();
		return false;
	}
	
	if (email == "") {
		alert("Please Enter Your Email Address");
		document.emailform.email.focus();
		return false;
	}
	
	if (!email.match(emailExp)) {
		alert("Please Enter Valid Email Address");
		document.emailform.email.focus();
		return false;
	}
	
	$("#msgSend").show();
	$("#msgSend").html("Sending...");
	
	$.get("ajax/save_contact_us.php", {
		action: 'email',
		evtid: evtid,
		comment: comment,
		email: email
	}, function(data){
		/*
		if (data == "success") {
			
		} else {
			$("#msgSend").html("Sending Failed");
		}
		*/
	});
	
	$("#msgSend").html("Message Sent");
	$("#txtComment").val("");
	$("#txtEmail").val("");
	setTimeout("document.getElementById('msgSend').style.display = 'none';", 5000);	
	
	return false;

}

// Showing Loading Message in all pop-up
function getLoadingMessage(loader){
 var msg = $("#loaderDiv_"+loader).html();
 return msg;
}

/*
* ------------------------------------------------------------
* This code is used for redirecting page to another page
* ------------------------------------------------------------
*/
function gotoPage(url){
    try {
        window.location.href = url;
        window.event.returnValue = false;
    } 
    catch (e) {
    }
}

/*
* ------------------------------------------------------------
* FilterPage is used for filtering the page with only 
* those parameter which are applied which helps to keep the
* URL clean
* ------------------------------------------------------------
*/
function filterPage(page) {
 
 var link = getPageLink(page);
 gotoPage(page+"?"+link);
 
}

/*
* ------------------------------------------------------------
* SortPage is used for sorting the page with only 
* those parameter which are applied which helps to keep the
* URL clean
* ------------------------------------------------------------
*/
var isSort = false;
function sortPage(page, sortord) {
 isSort = true;	
 var link = getPageLink(page);
 gotoPage(page+"?"+link+"&sort="+sortord);
}

/*
* ------------------------------------------------------------
* This code will return a clean URL
* This method check for what element are present in the 
* page and based on that create a link
* ------------------------------------------------------------
*/
function getPageLink(page) {

 var link = "";
 if(page == "Results.php") {
  link = createLink(link, "kwds", getValue("kwdsFilter"));
 }
 if(page == "Events.php") {
  link = createLink(link, "kwds", getValue("kwdsFilter"));
 } 
 
 link = createLink(link, "rid", getInt(getValue("rid")));
 link = createLink(link, "loc", getValue("loc")); 
 link = createLink(link, "rslt", getValue("rslt"));  
 link = createLink(link, "lp", getInt(getValue("lp"))); 
 link = createLink(link, "list", getInt(getValue("list")));   
 link = createLink(link, "block", getValue("block"));
 link = createLink(link, "event", getValue("event"));
 link = createLink(link, "pid", getValue("pid"));
 link = createLink(link, "lid", getInt(getValue("lid")));
 link = createLink(link, "state", getValue("state"));
 link = createLink(link, "city", getValue("city"));
 link = createLink(link, "area", getValue("area"));
 link = createLink(link, "region", getValue("region")); 
 link = createLink(link, "venid", getInt(getValue("venid")));
 link = createLink(link, "pcid", getInt(getValue("pcid")));
 link = createLink(link, "category", getInt(getValue("category")));
 link = createLink(link, "cid", getInt(getValue("cid")));
 link = createLink(link, "ccid", getInt(getValue("ccid")));
 link = createLink(link, "gcid", getInt(getValue("gcid")));
 link = createLink(link, "month", getValue("month"));
 link = createLink(link, "date", getValue("date"));
 link = createLink(link, "option", getValue("option")); 
 if(isSort == false) { link = createLink(link, "sort", getValue("sort")); }
 return link;
}

/*
* ------------------------------------------------------------
* This method is used for creating link
* If the value passed is "blank" or "0"
* that value wont be passed in the url
* ------------------------------------------------------------
*/
function createLink(link, param, val) {
 
 if(param == "lp") {
	 
  if(val != "" || val != 0) {
   if(link == "") {
	link = param;
   } else {
	link = link + "&" + param;
   }
  } 	 
	 
 } else {
  
  if(val != "" || val != 0) {
   if(link == "") {
	link = param + "=" + val;
   } else {
	link = link + "&" + param + "=" + val;
   }
  } 
  
 }
 return link;
}

/*
* ------------------------------------------------------------
* Get value for the given parameter
* ------------------------------------------------------------
*/
function getValue(param) {
 
 var value = $("#"+param).val();
 if(value == undefined) {
  value = "";
 }
 return value;
}

/*
* ------------------------------------------------------------
* Convert the value to integer, if blank than "0" is returned
* ------------------------------------------------------------
*/
function getInt(value) {
 if(value != "") {
   return parseInt(value);
 } else {
  return 0;
 }
}

function searchKwds() {
	var kwds = $("#kwds").val();
	gotoPage("Results.php?kwds="+urlencode(kwds));
	return false;
}

function urlencode (str) {
    str = (str+'').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

// hide and show answers in support page
function toggleMe(a){
 var e = document.getElementById(a);
 if (!e)
  return true;
 if (e.style.display == "none") {
  e.style.display = "block";
 }
 else {
  e.style.display = "none";
 }
    return true;
}

// Sending Email to Ticketturbo from users
function chkemail(){
 var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
 var numExp = /^[0-9]+$/;
 var type = $("input[name='type']:checked").val();
 var orderNo = $("#txtOrderNo").val();
 var comment = $("#txtComment").val();
 var email = $("#txtEmail").val();
 
 if (type == "support") {
  if (!orderNo.match(numExp)) {
   alert("Please Enter Valid Order Number");
   $("#txtOrderNo").val("");
   document.emailform.email.focus();
   return false;
  } else {
   if (orderNo.length != 7) {
    alert("Please Enter A Valid Order Number");
    document.emailform.order.focus();
    return false;
   }
  }
 }
 
 if (comment == "") {
  alert("Please Enter A Comment");
  document.emailform.comment.focus();
  return false;
 }
 if (email == "") {
  alert("Please Enter Your Email Address");
  document.emailform.email.focus();
  return false;
 }
    if (!email.match(emailExp)) {
  alert("Please Enter Valid Email Address");
  document.emailform.email.focus();
  return false;
 }
 
 $("#msgSend").show();
 $("#msgSend").html("Sending...");
 $.get("ajax/save_contact_us.php", {
  action: 'email',
  type: type,
  orderNo: orderNo,
  comment: comment,
  email: email
 }, function(data){
  
  /*
  if (data == "success") {
   
  } else {
   $("#msgSend").html("Sending Failed");
  }
*/
 });
 
 $("#msgSend").html("Message Sent");
   $("#txtComment").val("");
   $("#txtEmail").val("");
   setTimeout("document.getElementById('msgSend').style.display = 'none';", 5000);
    return false;
}

function showFavoritesPopup() {
 
 $("#ajaxContent_favorite").html(getLoadingMessage("favorite"));
 centerPopup("ajaxPopup_favorite", "favorite");
 loadPopup("ajaxPopup_favorite", "favorite");
 
 $("#backgroundPopup2_favorite").click(function(){
  disablePopup("ajaxPopup_favorite", "ajaxContent_favorite", "favorite");
 });
 
 $(document).keypress(function(e){
  if (e.keyCode == 27 && popupStatus == 1) {
   disablePopup("ajaxPopup_favorite", "ajaxContent_favorite", "favorite");
  }
 });
 
 var evtid = $("#evtid").val();
 
 $.post("ajax/popup_favorites.php", {
  evtid: evtid
 }, function(data){
   
   $("#ajaxContent_favorite").html(data);
   $("#ajaxClose_favorite").click(function(){  disablePopup("ajaxPopup_favorite", "ajaxContent_favorite", "favorite"); });
   $("#btnCancel").click(function(){  disablePopup("ajaxPopup_favorite", "ajaxContent_favorite", "favorite"); });
   
	  $('#add').click(add);
	  $('#remove').click(remove);
	  $("#removeAll").click(removeAll);
	  $("#addAll").click(addAll);
	  $("#selCity").dblclick(add);
	  
	  $('#add_cat').click(add_cat);
	  $('#remove_cat').click(remove_cat);
	  $("#removeAll_cat").click(removeAll_cat);
	  $("#addAll_cat").click(addAll_cat);
	  $("#selCategory").dblclick(add_cat);
 });
 
 $('#ajaxPopup_favorite').animate({ top: ($(window).scrollTop() + 40) + "px" }, {
  queue: false,
  duration: 350
 });
}

/* CREATING COOKIES FUNCTIONS */
function createCookie(name,value,days) {
 if (days) {
  var date = new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();
 }
 else var expires = "";
 document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
 var nameEQ = name + "=";
 var ca = document.cookie.split(';');
 for(var i=0;i < ca.length;i++) {
  var c = ca[i];
  while (c.charAt(0)==' ') c = c.substring(1,c.length);
  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
 }
 return null;
}

function removeCookie(name) {
 createCookie(name,"",-1);
}

/**
@author Raju Vishwas
This function will create array of given value
*/
function getCookieArray(value, seperator) {
 return value.split(seperator);
}

/**
@author Raju Vishwas @date 31th March 09
Used for appending values in cookies
*/
function appendCookie(name, value, seperator) {
 var schemeList = readCookie(name);
 schemeList  = value+seperator+schemeList;
 createCookie(name, schemeList, 365);
}
