
var xmlHttp;
var targetDIV;
var complete = false;

//=============================
// Returns correct ajax object
//=============================
function GetXmlHttpObject()
{
	var xmlHttp = null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e)
		{
			xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
	return xmlHttp;
}

//=========================
// Sets the target DIV ID
//=========================
function setTargetDIV(sTargetDIV)
{
	targetDIV = sTargetDIV;
}

//=========================
// Sets the complete
//=========================
function setComplete(sComplete)
{
	complete = sComplete;
}

//=========================
// Posts the returned data
//=========================
function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById(targetDIV).innerHTML = xmlHttp.responseText;
		setComplete(true);
	}
}

//========================
// Runs ajax
//========================
function runAjax(url)
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		return;
	}

	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open('GET', url, true);
	xmlHttp.send(null);
}

//================================================
// Checks if loading is complete
//================================================
function isComplete(panelID, loaderID, isIbox, AdditionalJS)
{
	if (complete == true)
	{
		document.getElementById(loaderID).style.display = 'none';
		document.getElementById(panelID).style.display	= 'block';
		if (isIbox == true)
		{
			init_ibox();
		}	
		eval(AdditionalJS);
	}
	else if (complete == false)
	{
		setTimeout('isComplete(\'' + panelID + '\', \'' + loaderID + '\', ' + isIbox + ', \'' + AdditionalJS + '\')', 500);
	}
}


//================================================================================================================

//================================================
// Adds 1 more view to the image
//================================================
function imageCounter(imgID)
{
	var url; 
	url = '/ajax/ajaxCounter.asp?ID=' + escape(imgID) ;
	setTargetDIV('View' + imgID);

	runAjax(url);
}

//================================================
// Refreshes gallery images and changes page
//================================================
function refreshGallery(categoryID, currentPage)
{	
	var url;
	var access;
	if ($('access')) {
		access = $('access').value;
	}
	url = '/ajax/ajaxGallery.asp?catID=' + escape(categoryID) + '&pgNo=' + escape(currentPage) + '&access=' + escape(access);

	new Ajax.Updater('AjaxGallery', url,{onCreate:function(){refreshGalleryCreate()},
										onComplete:function(){refreshGalleryComplete(categoryID)}, evalScripts:false,method:'post'});              

}

function refreshGalleryCreate()
{
	document.getElementById('AjaxGallery').style.display	= 'none';
	document.getElementById('AjaxLoading').style.display	= 'block';
}
function refreshGalleryComplete(categoryID)
{
	document.getElementById('AjaxLoading').style.display	= 'none';
	document.getElementById('AjaxGallery').style.display	= 'block';
	refreshGalleryBreadcrumbs(categoryID);
	init_ibox();
	
	var access;
	if ($('access')) {
		access = $('access').value;
	}
	
	if ($('uploadImageButton')){
		$('uploadImageButton').href = 'gallery-image-upload.asp?catID=' + categoryID + '&access=' + escape(access);
	}
	
	if ($('createCategoryButton')){
		$('createCategoryButton').href = '/admin/gallery-category-manage.asp?cCatID=' + categoryID;
	}
}

//================================================
// Refreshes Galleries Breadcrumb
//================================================
function refreshGalleryBreadcrumbs(categoryID)
{
	var url;
	url = '/ajax/ajaxGalleryBreadcrumbs.asp?catID=' + escape(categoryID);

	new Ajax.Updater('breadCrumbContainer', url,{onCreate:function(){},
										onComplete:function(){}, evalScripts:false,method:'post'}); 
}


//================================================
// Refreshes gallery images and changes page
//================================================
function refreshProduct(ProductCatID, ProductID, PreviousCatID)
{

	var url;
	url = '/ajax/ajaxProduct.asp?ProductCatID=' + escape(ProductCatID) + '&ProductID=' + escape(ProductID) + '&PreviousCatID=' + PreviousCatID

	new Ajax.Updater('AjaxProduct', url,{onCreate:function(){refreshProductCreate()},
										onComplete:function(){refreshProductComplete()}, evalScripts:false,method:'post'});              

}

function refreshProductCreate()
{
	var inHeight = document.getElementById('AjaxProduct').offsetHeight;
	document.getElementById('AjaxProduct').className	= 'setOpacityOn';
	document.getElementById('AjaxLoading').style.display	= 'block';
	//document.getElementById('AjaxLoading').style.height=inHeight+'px';
}
function refreshProductComplete()
{	
	document.getElementById('AjaxLoading').style.display	= 'none';
	document.getElementById('AjaxProduct').className	= 'setOpacityOff';
}

//================================================
// Just to show shopping cart and changes page
//================================================
function showShoppingCart()
{
	
	var url;
	url = '/ajax/ajaxShoppingCart.asp'

	new Ajax.Updater('AjaxProduct', url,{onCreate:function(){refreshShowCartCreate()},
										onComplete:function(){refreshShowCartComplete()}, evalScripts:false,method:'post'});              

}

function refreshShowCartCreate()
{
	var inHeight = document.getElementById('AjaxProduct').offsetHeight;
	document.getElementById('AjaxProduct').className	= 'setOpacityOn';
	document.getElementById('AjaxCartLoading').style.display	= 'block';
	document.getElementById('AjaxCartLoading').style.height=inHeight+'px';
}
function refreshShowCartComplete()
{
	document.getElementById('AjaxProduct').className	= 'setOpacityOff';
	document.getElementById('AjaxCartLoading').style.display	= 'none';
}

//================================================
// Refreshes shopping cart and changes page
//================================================
function refreshShoppingCart(action, ProductID)
{
	var url;
	url = '/ajax/ajaxShoppingCartRightPanel.asp?action=' + escape(action) + '&ProductID=' + escape(ProductID)

	new Ajax.Updater('AjaxShoppingCart', url,{onCreate:function(){refreshCartCreate()},
										onComplete:function(){refreshCartComplete()}, evalScripts:false,method:'post'});              

}

function refreshCartCreate()
{	
	var inHeight = document.getElementById('AjaxProduct').offsetHeight;
	document.getElementById('AjaxProduct').className	= 'setOpacityOn';
	document.getElementById('AjaxShoppingCart').className	= 'setOpacityOn';
	document.getElementById('AjaxCartLoading').style.display = 'block';
	document.getElementById('AjaxCartLoading').style.height=inHeight+'px';
	document.getElementById('AjaxShoppingCartRightLoading').style.display = 'block';
}
function refreshCartComplete()
{
	document.getElementById('AjaxCartLoading').style.display	= 'none';
	document.getElementById('AjaxShoppingCartRightLoading').style.display	= 'none';
	document.getElementById('AjaxShoppingCart').className	= 'setOpacityOff';
	document.getElementById('AjaxProduct').className	= 'setOpacityOff';
	//document.getElementById('AjaxShoppingCart').focus();
}

//search function for product
function ajaxFindProduct(inSearchArtist, inSearchAlbum, inPopularity)
{
	var url;
	url = '/ajax/ajaxSearchProduct.asp?ArtistName=' + escape(inSearchArtist) + '&AlbumName=' + escape(inSearchAlbum) + '&Popularity=' + escape(inPopularity)
	new Ajax.Updater('AjaxProduct', url,{onCreate:function(){searchProductCreate()},
										onComplete:function(){searchProductComplete()}, evalScripts:false,method:'post'});   	
}
function searchProductCreate()
{	
	document.getElementById('searchProductForm').className	= 'setOpacityOn';
	document.getElementById('AjaxSearching').style.display = 'block';
}
function searchProductComplete()
{
	document.getElementById('AjaxSearching').style.display	= 'none';
	document.getElementById('searchProductForm').className	= 'setOpacityOff';
}

//search function for product
function ajaxSubmitReviews(inReferralID, inReviews, inTableName)
{
	var url;
	url = '/ajax/ajaxReview.asp?referralID=' + escape(inReferralID) + '&reviews=' + inReviews + '&tableName=' + inTableName;
	new Ajax.Updater('ajaxReviewForm', url,{onCreate:function(){updateReviewCreate()},
										onComplete:function(){updateReviewComplete()}, evalScripts:false,method:'post'});   	
}
function updateReviewCreate()
{	
	document.getElementById('ajaxReviewForm').className	= 'setOpacityOn';
	document.getElementById('ajaxReviewFormLoading').style.display = 'block';
}
function updateReviewComplete()
{
	document.getElementById('ajaxReviewForm').className	= 'setOpacityOff';
	document.getElementById('ajaxReviewFormLoading').style.display = 'none';
}

//================================================
// Refreshes child pages for vibe.asp
//================================================
function refreshChildren(pageID, pageNo, searchText, orderField, orderDirection)
{	
	var url;
	var criteria = '';
	
	if (searchText != '')
	    criteria = '&searchTitle=' + searchText;
	if (orderField != '')
	    criteria = criteria + '&orderField=' + escape(orderField);
	if (orderDirection != '') 
	    criteria = criteria + '&orderDirection=' + escape(orderDirection);
	    
	url = '/ajax/ajaxVibe.asp?PageID=' + escape(pageID) + '&pg=' + escape(pageNo) + criteria

	new Ajax.Updater('AjaxChildren', url,{onCreate:function(){refreshChildrenCreate()},
										onComplete:function(){refreshChildrenComplete(pageID, pageNo, searchText, orderField, orderDirection)}, evalScripts:false,method:'post'});              
}

function refreshChildrenCreate()
{
	document.getElementById('AjaxChildren').className	= 'setOpacityOn';
	document.getElementById('ajaxLoadingMainPanel').style.display	= '';
}
function refreshChildrenComplete(pageID, pageNo, searchText, orderField, orderDirection)
{
	var criteria = '';
	
	if (searchText != '')
	    criteria = '&searchTitle=' + searchText;
	if (orderField != '')
	    criteria = criteria + '&orderField=' + escape(orderField);
	if (orderDirection != '') 
	    criteria = criteria + '&orderDirection=' + escape(orderDirection);

	document.getElementById('ajaxLoadingMainPanel').style.display	= 'none';
	document.getElementById('AjaxChildren').className	= 'setOpacityOff';
	if(typeof(urchinTracker) == 'function' && request && request.url)
		urchinTracker('vibe.asp?PageID='+pageID+'&pg='+pageNo+criteria);
}


//================================================
// Refreshes quick links in vibe.asp
//================================================

function refreshQuickLinks(params)
{
	var url;
	url = '/ajax/ajaxQuicklinks.asp' + (params)
	new Ajax.Updater('AjaxQuickLinks', url,{onCreate:function(){refreshQuickLinksCreate()},
										onComplete:function(){
											refreshQuickLinksComplete()}, 
												evalScripts:false,method:'post'});              
								
}

function refreshQuickLinksCreate()
{
	document.getElementById('AjaxQuickLinks').style.display	= 'none';
	document.getElementById('AjaxQuickLinksLoading').style.display	= 'block';
}

function refreshQuickLinksComplete()
{
	document.getElementById('AjaxQuickLinksLoading').style.display	= 'none';
	document.getElementById('AjaxQuickLinks').style.display	= '';

}


//================================================
// Refreshes comments
//================================================
function refreshReview(inReferralID, currentPage, inTableName)
{
	var url;
	url = '/ajax/ajaxRefreshReview.asp?referralID=' + escape(inReferralID) + '&pgNo=' + escape(currentPage) + '&tableName=' + escape(inTableName)
	new Ajax.Updater('ajaxViewReview', url,{onCreate:function(){refreshReviewCreate()},
										onComplete:function(){refreshReviewComplete()}, evalScripts:false,method:'post'});              
}

function refreshReviewCreate()
{
	document.getElementById('ajaxViewReview').className	= 'setOpacityOn';
	document.getElementById('ajaxViewReviewLoading').style.display = '';
}

function refreshReviewComplete()
{
	document.getElementById('ajaxViewReview').className	= 'setOpacityOff';
	document.getElementById('ajaxViewReviewLoading').style.display = 'none';
}

//================================================
// Refreshes jobs
//================================================
function refreshJob(inSearchCriteria, inSearchCriteria2, inSearchCriteria3, currentPage)
{
	var url;
	url = '/ajax/ajaxRefreshJob.asp?searchCriteria=' + escape(inSearchCriteria) + '&searchCriteria2=' + escape(inSearchCriteria2) + '&searchCriteria3=' + escape(inSearchCriteria3) + '&pgNo=' + escape(currentPage)
	new Ajax.Updater('ajaxViewJob', url,{onCreate:function(){refreshJobCreate()},
										onComplete:function(){refreshJobComplete()}, evalScripts:false,method:'post'});              
}

function refreshJobCreate()
{
	document.getElementById('ajaxViewJob').className	= 'setOpacityOn';
	document.getElementById('ajaxViewJobLoading').style.display = '';
}

function refreshJobComplete()
{
	document.getElementById('ajaxViewJob').className	= 'setOpacityOff';
	document.getElementById('ajaxViewJobLoading').style.display = 'none';
}

//================================================
// Get Stories List
//================================================
function findStories(inSearchField, inSearchCriteria, inSearchCriteria2, inSearchCriteria3, currentPage, recallCookie)
{
	var url;
	url = '/ajax/ajaxSearchStories.asp?searchField=' + escape(inSearchField) + '&searchCriteria=' + escape(inSearchCriteria)  + '&searchCriteria2=' + escape(inSearchCriteria2)  + '&searchCriteria3=' + escape(inSearchCriteria3) + '&pgNo=' + escape(currentPage) + '&recallCookie=' + escape(recallCookie) 
	new Ajax.Updater('ajaxViewStories', url,{onCreate:function(){refreshFindStoriesCreate()},
										onComplete:function(){refreshFindStoriesComplete()}, evalScripts:false,method:'post'});              
}

function refreshFindStoriesCreate()
{
	document.getElementById('ajaxViewStories').className	= 'setOpacityOn';
	document.getElementById('ajaxLoadingMainPanel').style.display = '';
}

function refreshFindStoriesComplete()
{
	document.getElementById('ajaxViewStories').className	= 'setOpacityOff';
	document.getElementById('ajaxLoadingMainPanel').style.display = 'none';
}

//================================================
// Get Stories Details
//================================================
function viewStoryDetails(inStoryID)
{
	var url;
	url = '/ajax/ajaxViewStoryDetails.asp?storyID=' + escape(inStoryID)
	new Ajax.Updater('ajaxViewStories', url,{onCreate:function(){viewStoryDetailsCreate()},
										onComplete:function(){viewStoryDetailsComplete()}, evalScripts:false,method:'post'});              
}

function viewStoryDetailsCreate()
{
	document.getElementById('ajaxViewStories').className	= 'setOpacityOn';
	document.getElementById('ajaxLoadingMainPanel').style.display = '';
}

function viewStoryDetailsComplete()
{
	document.getElementById('ajaxViewStories').className	= 'setOpacityOff';
	document.getElementById('ajaxLoadingMainPanel').style.display = 'none';
}

//================================================
// Get Directory Details
//================================================
function findDirectory(inSearchField, inSearchCriteria, inSearchCriteria2, inSearchCriteria3, currentPage, recallCookie)
{
	var url;
	url = '/ajax/ajaxSearchDirectories.asp?searchField=' + escape(inSearchField) + '&searchCriteria=' + escape(inSearchCriteria) + '&searchCriteria2=' + escape(inSearchCriteria2) + '&searchCriteria3=' + escape(inSearchCriteria3) + '&pgNo=' + escape(currentPage) + '&recallCookie=' + escape(recallCookie) 
	new Ajax.Updater('ajaxViewDirectories', url,{onCreate:function(){refreshFindDirectoriesCreate()},
										onComplete:function(){refreshFindDirectoriesComplete()}, evalScripts:false,method:'post'});                  
}

function refreshFindDirectoriesCreate()
{
	document.getElementById('ajaxViewDirectories').className	= 'setOpacityOn';
	document.getElementById('ajaxLoadingMainPanel').style.display = '';
}

function refreshFindDirectoriesComplete()
{
	document.getElementById('ajaxViewDirectories').className	= 'setOpacityOff';
	document.getElementById('ajaxLoadingMainPanel').style.display = 'none';
}
//================================================
// Get Directory Details
//================================================
function viewDirectoryDetails(inDirInfoID)
{
	var url;
	url = '/ajax/ajaxViewDirectoryDetails.asp?dirInfoID=' + escape(inDirInfoID)
	new Ajax.Updater('ajaxViewDirectories', url,{onCreate:function(){refreshFindDirectoriesCreate()},
										onComplete:function(){refreshFindDirectoriesComplete()}, evalScripts:false,method:'post'});              
}

//================================================
// Admin trying to update dircatinfo table
//================================================
function adminUpdatingDirCatInfo(inMode,inDirInfoID,inDirCatID,inDirCatInfoID)
{
	var url;
	url = '/admin/ajax/ajaxUpdateDirCatInfo.asp?mode=' + escape(inMode) + '&dirInfoID=' + escape(inDirInfoID) + '&dirCatID=' + escape(inDirCatID) + '&dirCatInfoID=' + escape(inDirCatInfoID)
	new Ajax.Updater('ajaxCatPanel', url,{onCreate:function(){refreshAdminUpdatingDirCatInfoCreate()},
										onComplete:function(){refreshAdminUpdatingDirCatInfoComplete()}, evalScripts:false,method:'post'});                  
}

function refreshAdminUpdatingDirCatInfoCreate()
{
	document.getElementById('ajaxCatPanel').className	= 'setOpacityOn';
	document.getElementById('ajaxLoadingMainPanel').style.display = '';
}

function refreshAdminUpdatingDirCatInfoComplete()
{
	document.getElementById('ajaxCatPanel').className	= 'setOpacityOff';
	document.getElementById('ajaxLoadingMainPanel').style.display = 'none';
}

//================================================
// Get Show List
//================================================
function findShow(inSearchField, inSearchCriteria, inSearchCriteria2, inSearchCriteria3, currentPage, recallCookie)
{
	var url;
	url = '/ajax/ajaxSearchShow.asp?searchField=' + escape(inSearchField) + '&searchCriteria=' + escape(inSearchCriteria)  + '&searchCriteria2=' + escape(inSearchCriteria2)  + '&searchCriteria3=' + escape(inSearchCriteria3) + '&pgNo=' + escape(currentPage) + '&recallCookie=' + escape(recallCookie) 
	new Ajax.Updater('ajaxViewShow', url,{onCreate:function(){refreshFindShowCreate()},
										onComplete:function(){refreshFindShowComplete()}, evalScripts:false,method:'post'});              
}

function refreshFindShowCreate()
{
	document.getElementById('ajaxViewShow').className	= 'setOpacityOn';
	document.getElementById('ajaxLoadingMainPanel').style.display = '';
}

function refreshFindShowComplete()
{
	document.getElementById('ajaxViewShow').className	= 'setOpacityOff';
	document.getElementById('ajaxLoadingMainPanel').style.display = 'none';
}

//================================================
// Export Show List
//================================================
function adminGeneratePlaylist(inType, inStrPath, inReferralID)
{
	var url;
	url = '/scripts/generate-xml.asp?referralID=' + escape(inReferralID) + '&type=' + escape(inType)  + '&strPath=' + escape(inStrPath) 
	new Ajax.Updater('ajaxXMLPanel', url,{onCreate:function(){refreshXMLCreate()},
										onComplete:function(){refreshXMLComplete()}, evalScripts:false,method:'post'});              
}

function refreshXMLCreate()
{
	document.getElementById('ajaxXMLPanel').className	= 'setOpacityOn';
	document.getElementById('ajaxLoadingMainPanel').style.display = '';
}

function refreshXMLComplete()
{
	document.getElementById('ajaxXMLPanel').className	= 'setOpacityOff';
	document.getElementById('ajaxLoadingMainPanel').style.display = 'none';
}