/*-------------------------------------------------------------------------
	-- File: xgameops.js
	-- Purpose: Gameops.com JavaScript functions, primarily for AJAX calls
	-- Note:						
	--
	--  History:
			Date				By				Comments
		----------- 			----------	-------------------------------------
	-- 17 JUN 2008		S Martin	Created
	-- --------------------------------------------------------------------
*/

function update_vid_display(v_id,title,description,divname) 
{
    /******************************************************************************
    DESCRIPTION: Updates a div containing a video feed by using the supplied video ID
    
    PARAMETERS:
        v_id			 - string ID of the video to be called
		divname 	- string name of the div container to be updated
    
    RETURNS:
        N/A 
    ******************************************************************************/

	//alert("You are adding category: "+str+"; div = "+divname);

	//syntax: new Ajax.Updater(container, url[, options])
	var params = 'v_id=' + v_id + '&title=' + title + '&description=' +description + '&ajax_action=vid_playlist';
	var url = 'http://www.gameops.com/gameops-ajax.php';
	
	//Having conflicts with scriptaculous, attempting use of jQuery instead
	//SCRIPTACULOUS AJAX: var ajax = new Ajax.Updater(divname, url, {method: 'post', parameters: params});
	
	//jQuery AJAX
	$(document).ready(function(){
		$.ajax({
		   type: "POST",
		   url: url,
		   data: params,
		   success: function(response){
				$("#"+divname).html(response);
		  //   alert( "Data Saved: " + msg );
		   }
	   });
	 }); 


}


function makeSublist(parent,child,isSubselectOptional,childVal)
{
	$("body").append("<select style='display:none' id='"+parent+child+"'></select>");
	$('#'+parent+child).html($("#"+child+" option"));
	
	var parentValue = $('#'+parent).attr('value');
	$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
	childVal = (typeof childVal == "undefined")? "" : childVal ;
	$("#"+child+' option[@value="'+ childVal +'"]').attr('selected','selected');
	$('#'+parent).change( 
		function()
		{
		
			var parentValue = $('#'+parent).attr('value');

			$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());

			if(isSubselectOptional) 
				$('#'+child).prepend("<option value='none'> -- Select -- </option>");

			$('#'+child).trigger("change"); 
			$('#'+child).focus();

		}
	);
}

/*function createDependentList(parent,child,isSubselectOptional,childVal)
{
	$(document).ready(function()
	{
		makeSublist(parent,child,isSubselectOptional,childVal);	
	});
}*/


function update_promo_list(form) 
{
    /******************************************************************************
    DESCRIPTION: Updates a div containing a promo list using the supplied arguments
    
    PARAMETERS:
        search_word 	 - string with search word/s
        promo_sport 	 - string with sport word/s
        promo_month  - integer for search month
        random25 		 - checkbox value for random list of 25 results
        page				 - integer with current page number
		divname 	- string name of the div container to be updated
    
    RETURNS:
        N/A 
    ******************************************************************************/

	var search_word = form.search_word.value;
	var promo_sport = form.promo_sport.value;
	//var promo_refno = form.promo_refno.value;
	var page = form.page.value;
	var vsubmit = form.which_submit.value;
	var divname = form.divname.value;

	//if(typeof(promo_refno)=='undefined') promo_refno='';
	
	var params = 'search_word=' + search_word + '&promo_sport=' + promo_sport + '&page=' +page + '&submit=' + vsubmit + '&ajax_action=promo_search';
	var url = 'http://www.gameops.com/gameops-ajax.php';
	
	  $("#footer").hide();
	//alert("divname = " + divname);
//jQuery AJAX
	$(document).ready(function(){
		$.ajax({
		   type: "POST",
		   url: url,
		   data: params,
		   success: function(response){
				$("#"+divname).html(response);
				$("#footer").css("bottom","0px");
			  $("#footer").show();
		   }
	   });
	 }); 


}


function update_promo_list_alt(search_word,promo_sport,page,vsubmit,divname,promo_refno) 
{
    /******************************************************************************
    DESCRIPTION: Updates a div containing a promo list using the supplied arguments
    
    PARAMETERS:
        search_word 	 - string with search word/s
        promo_sport 	 - string with sport word/s
        promo_month  - integer for search month
        random25 		 - checkbox value for random list of 25 results
        page				 - integer with current page number
		divname 	- string name of the div container to be updated
    
    RETURNS:
        N/A 
    ******************************************************************************/
	var params = 'search_word=' + search_word + '&promo_refno=' + promo_refno + '&promo_sport=' + promo_sport + '&page=' +page + '&submit=' + vsubmit + '&ajax_action=promo_search';
	var url = 'http://www.gameops.com/gameops-ajax.php';
	
	  $("#footer").hide();
	//alert("divname = " + divname);
	//jQuery AJAX
	$(document).ready(function(){
		$.ajax({
		   type: "POST",
		   url: url,
		   data: params,
		   success: function(response){
				$("#promo_list").html(response);
				//alert("Response->"+response+"<-");
				//try moving the footer to the bottom of the page now
				$("#footer").css("bottom","0px");
			  $("#footer").show();
		   }
	   });
	 }); 
}


function promo_detail(pid,divname) 
{
    /******************************************************************************
    DESCRIPTION: Updates a div containing a promo list using the supplied arguments
    
    PARAMETERS:
        pid 	 - promotion ID
		divname 	- string name of the div container to be updated
    
    RETURNS:
        N/A 
    ******************************************************************************/

	var params = 'pid=' + pid + '&ajax_action=promo_detail';
	var url = 'http://www.gameops.com/gameops-ajax.php';
	
	//jQuery AJAX
	$(document).ready(function(){
		$.ajax({
		   type: "POST",
		   url: url,
		   data: params,
		   success: function(response){
				$("#"+divname).html(response);
				 //alert( "Data Saved: " + msg );
		   }
	   });
	 }); 
}


function reset_promo_form() {
	var form = document.getElementById('frmSearch');
	
	form.search_word.value = '';
	form.promo_sport.selectedIndex = 0;
	form.page = 1;
	
	return;
}//function reset_promo_form



function update_listing_list(form) 
{
    /******************************************************************************
    DESCRIPTION: Updates a div containing a promo list using the supplied arguments
    
    PARAMETERS:
        search_word 	 - string with search word/s
        lst_sport 	 - string with sport word/s
        page				 - integer with current page number
		vsubmit			- value of the submit button
		divname 	- string name of the div container to be updated
    
    RETURNS:
        N/A 
    ******************************************************************************/

	var search_word = form.search_word.value;
	var lst_sport = form.lst_sport.value;
	var lst_offering_cat = form.lst_offering_cat.value;
	var lst_premium_flag = form.lst_premium_flag.checked;
	var lst_type = form.lst_type.value;
	var page = form.page.value;
	var vsubmit = form.which_submit.value;
	var divname = form.divname.value;

	var params = 'search_word=' + search_word + '&lst_type=' + lst_type + '&lst_sport=' + lst_sport + '&lst_offering_cat=' + lst_offering_cat + '&lst_premium_flag=' + lst_premium_flag + '&page=' +page + '&submit=' + vsubmit + '&ajax_action=listing_search';
	var url = 'http://www.gameops.com/gameops-ajax.php';
	
	  $("#footer").hide();
	//alert("divname = " + divname);
//jQuery AJAX
	$(document).ready(function(){
		$.ajax({
		   type: "POST",
		   url: url,
		   data: params,
		   success: function(response){
				$("#"+divname).html(response);
				$("#footer").css("bottom","0px");
			  $("#footer").show();
		   }
	   });
	 }); 


}


function update_listing_list_alt(search_word,lst_type,lst_sport,lst_offering_cat,page,vsubmit,divname,lst_refno,lst_premium_flag) 
{
    /******************************************************************************
    DESCRIPTION: Updates a div containing a promo list using the supplied arguments
    
    PARAMETERS:
        search_word 	 - string with search word/s
        lst_sport 	 - string with sport word/s
        page				 - integer with current page number
		vsubmit			- value of the submit button
		divname 	- string name of the div container to be updated
    
    RETURNS:
        N/A 
    ******************************************************************************/

	var params = 'search_word=' + search_word + '&lst_refno=' + lst_refno+ '&lst_type=' + lst_type + '&lst_sport=' + lst_sport + '&lst_offering_cat=' + lst_offering_cat + '&lst_premium_flag=' + lst_premium_flag + '&page=' +page + '&submit=' + vsubmit + '&ajax_action=listing_search';
	var url = 'http://www.gameops.com/gameops-ajax.php';
	
	$("#footer").hide();
	//alert("params = " + params);
	//jQuery AJAX
	$(document).ready(function(){
		$.ajax({
		   type: "POST",
		   url: url,
		   data: params,
		   success: function(response){
				$("#"+divname).html(response);
				//alert( "Data sent: " + params );
				//try moving the footer to the bottom of the page now
				$("#footer").css("bottom","0px");
			 	$("#footer").show();
		   } //success
	   }); //ajax
		
		
	 }); //doc ready function
}//function update_listing_alt


function reset_listing_form() {
	var form = document.getElementById('frmSearch');
	
	form.search_word.value = '';
	form.lst_sport.selectedIndex = 0;
	form.lst_premium_flag.checked = 0;
	form.page = 1;
	
	return;
}//function reset_listing_form


function update_punchlist(form) 
{
    /******************************************************************************
    DESCRIPTION: Updates a div containing punchlist items using the supplied arguments
    
    PARAMETERS:
        search_word 	 - string with search word/s
        cn_cats		 	 - integer category id
        page			 - integer with current page number
		divname			 - string name of the div container to be updated
    
    RETURNS:
        N/A 
    ******************************************************************************/

	var search_word = form.search_word.value;
	var cn_cats = form.cn_cats.value;
	//var cn_refno = form.promo_refno.value;
	var page = form.page.value;
	var vsubmit = form.which_submit.value;
	var divname = form.divname.value;

	//if(typeof(cn_refno)=='undefined') cn_refno='';
	
	var params = 'search_word=' + search_word + '&cn_cats=' + cn_cats + '&page=' +page + '&submit=' + vsubmit + '&ajax_action=punchlist_search';
	var url = 'http://www.gameops.com/gameops-ajax.php';
	
	  $("#footer").hide();
	//alert("divname = " + divname);
//jQuery AJAX
	$(document).ready(function(){
		$.ajax({
		   type: "POST",
		   url: url,
		   data: params,
		   success: function(response){
				$("#"+divname).html(response);
				$("#footer").css("bottom","0px");
			  $("#footer").show();
		   }
	   });
	 }); 


}


function update_punchlist_alt(search_word,cn_cats,page,vsubmit,divname,cn_refno) 
{
    /******************************************************************************
    DESCRIPTION: Updates a div containing a promo list using the supplied arguments
    
    PARAMETERS:
        search_word 	 	- string with search word/s
        cn_cats		 	 	- integer category id
        page				- integer with current page number
		divname 			- string name of the div container to be updated
    
    RETURNS:
        N/A 
    ******************************************************************************/
	var params = 'search_word=' + search_word + '&cn_refno=' + cn_refno + '&cn_cats=' + cn_cats + '&page=' +page + '&submit=' + vsubmit + '&ajax_action=punchlist_search';
	var url = 'http://www.gameops.com/gameops-ajax.php';
	
	  $("#footer").hide();
	//alert("divname = " + divname);
	//jQuery AJAX
	$(document).ready(function(){
		$.ajax({
		   type: "POST",
		   url: url,
		   data: params,
		   success: function(response){
				$("#punch_list").html(response);
				//alert("Response->"+response+"<-");
				//try moving the footer to the bottom of the page now
				$("#footer").css("bottom","0px");
			  $("#footer").show();
		   }
	   });
	 }); 
}


function reset_punchlist_form() {
	var form = document.getElementById('frmSearch');
	
	form.search_word.value = '';
	form.cn_cats.selectedIndex = 0;
	form.page = 1;
	
	return;
}//function reset_punchlist_form
