
//search function for product
function ajaxAtWorkLogin(url,aweUser)
{
	var url;
	url = '/ajax/loginatwork.asp?aweUser=' + escape(aweUser) + '&url=' + escape(url)
	new Ajax.Updater('aweAtWorkSection', url,{onCreate:function(){ajaxAtWorkLoginCreate()},
										onComplete:function(){ajaxAtWorkLoginComplete()}, evalScripts:true,method:'post'});   	
}
function ajaxAtWorkLoginCreate()
{	
	//alert('start');
}
function ajaxAtWorkLoginComplete()
{
	//alert('complete');
}

//================================================
// Get Alert Details
//================================================
function findAlert(inPageDirection)
{
	var url;
	var currentPage;
	
	if(inPageDirection == "previous"){
		currentPage = document.getElementById("previousPage").value;
	}
	else{
		currentPage = document.getElementById("nextPage").value;
	}
	
	url = '/ajax/ajaxFindAlert.asp?currentPage=' + escape(currentPage)
	new Ajax.Updater('ajaxAlert', url,{onCreate:function(){refreshFindAlertCreate();},
										onComplete:function(){refreshFindAlertComplete()}, evalScripts:false,method:'post'});                  
}

function refreshFindAlertCreate()
{
	document.getElementById('ajaxLoadingMainPanel').style.display = '';
}

function refreshFindAlertComplete()
{
	document.getElementById('ajaxLoadingMainPanel').style.display = 'none';
}

//================================================
// Update Alert
//================================================
function updateAlertPrompt(inAlertId,inPrompt)
{	
	var isPrompt;
	var url;	
	var nextPage;
	var previousPage;
	var alertCount;
	var currentPage;
	
	currentPage = parseInt(document.getElementById("currentPage").value);
	nextPage = parseInt(document.getElementById("nextPage").value);
	previousPage = parseInt(document.getElementById("previousPage").value);
	alertCount = parseInt(document.getElementById("alertCount").value);
	
	if(inPrompt==true){
		isPrompt = "0";
		if(nextPage == 1){
			document.getElementById("nextPage").value = "1";  
		}
		else{
			document.getElementById("nextPage").value = nextPage-1;
		}
		if(currentPage == alertCount){
			document.getElementById("previousPage").value = previousPage;
		}
		else if(alertCount-1 < 1){
			document.getElementById("previousPage").value = "1";
		}
		else{
			if(previousPage == 1){
				document.getElementById("previousPage").value = "1";
			}
			else{
			document.getElementById("previousPage").value = previousPage-1;
			}
		}
	}
	else{
		isPrompt = "1";
		if(currentPage == alertCount){
			document.getElementById("nextPage").value = "1";  
		}
		else{
			if(nextPage+1 > alertCount){
				document.getElementById("nextPage").value = "1";
			}
			else{
				document.getElementById("nextPage").value = nextPage+1;  
			}
		}
		if(currentPage == alertCount){
			document.getElementById("previousPage").value = previousPage;  
		}
		else if(previousPage != 1){
			document.getElementById("previousPage").value = previousPage+1;
		}
	}
	url = '/ajax/ajaxUpdateAlertPrompt.asp?alertID=' + escape(inAlertId) + '&prompt=' + escape(isPrompt)
	new Ajax.Updater('ajaxWarningMessage', url,{onCreate:function(){refreshUpdateAlertPromptCreate();},
										onComplete:function(){refreshUpdateAlertPromptComplete()}, evalScripts:false,method:'post'});                  
}

function refreshUpdateAlertPromptCreate()
{
	//document.getElementById('alertDetails').className	= 'setOpacityOn';
	document.getElementById('ajaxUpdateMainPanel').style.display = '';
}

function refreshUpdateAlertPromptComplete()
{
	//document.getElementById('alertDetails').className	= 'setOpacityOff';
	document.getElementById('ajaxUpdateMainPanel').style.display = 'none';
	document.getElementById('ajaxWarningMessage').className = 'warning';
}

//============================  get event details function ==========================================================
function ajaxGetEventDetails(eventID, breadCrumbs)
{
	var url;
	url = '/ajax/ajaxFindEvent.asp?eventID=' + escape(eventID)
	new Ajax.Updater('eventResult', url,{onCreate:function(){searchEventCreate()},
										onComplete:function(){searchEventComplete(breadCrumbs)}, evalScripts:false,method:'post'});   	
}

//============================  search function for events ==========================================================
function ajaxFindEvents(searchCriteria, searchCategoryID, searchStateID, currentPage, breadCrumbs, categoryName)
{
	var url;
	url = '/ajax/ajaxFindEvent.asp?searchCriteria=' + escape(searchCriteria) + '&searchCategoryID=' + escape(searchCategoryID) + '&searchStateID=' + escape(searchStateID) + '&currentPage=' + escape(currentPage) + '&categoryName=' + escape(categoryName)
	new Ajax.Updater('eventResult', url,{onCreate:function(){searchEventCreate()},
										onComplete:function(){searchEventComplete(breadCrumbs)}, evalScripts:false,method:'post'});   	
}
function searchEventCreate()
{	
	document.getElementById('eventResult').className		= 'setOpacityOn';
	document.getElementById('AjaxLoading').style.display	= 'block';
}
function searchEventComplete(breadCrumbs)
{
	document.getElementById('AjaxLoading').style.display	= 'none';
	document.getElementById('eventResult').className		= 'setOpacityOff';
	document.getElementById('breadCrumbCol').innerHTML 		= breadCrumbs;
}

//============================  submit enquiry ==========================================================
function ajaxSubmitEnquiry(customerEmail, eventSeatingTypeID, eventPriceRangeID, eventID)
{
	var url;
	url = '/ajax/ajaxSubmitEnquiry.asp?customerEmail=' + escape(customerEmail) + '&eventSeatingTypeID=' + escape(eventSeatingTypeID) + '&eventPriceRangeID=' + escape(eventPriceRangeID) + '&eventID=' + escape(eventID)
	new Ajax.Updater('enquiry', url,{onCreate:function(){ajaxSubmitEnquiryCreate()},
										onComplete:function(){ajaxSubmitEnquiryComplete()}, evalScripts:false,method:'post'});   	
}
function ajaxSubmitEnquiryCreate()
{	
	document.getElementById('enquiry').className		= 'setOpacityOn';
	document.getElementById('AjaxEnquiryLoading').style.display	= 'block';
}
function ajaxSubmitEnquiryComplete(breadCrumbs)
{
	document.getElementById('AjaxEnquiryLoading').style.display	= 'none';
	document.getElementById('enquiry').className		= 'setOpacityOff';
}

//============================  child form ==========================================================
function ajaxHideChild(inFormID)
{
	$('childErrMsg').style.display = 'none';
	
	var myArray;
	var myInputArray;
	var form;
	var index;
	var lastHiddenRow = $F('lastHiddenRow');
	
	if(lastHiddenRow.length > 0){
		$('childRow'+inFormID).toggle();

		$('endOfRow').insert({before: $('childRow'+inFormID)});
		$('lastHiddenRow').value = $('endOfRow').previous().id;	
		myArray = $$('div.childRow')
		for (var index = 0, len = myArray.length; index < len; ++index) {
		  var item = myArray[index];
		  	if(item.style.display == 'none'){
	  			if(item.previous().id == "startOfRow"){
	  				$('lastDisplayedRow').value = '';
	  			}
	  			else{
	  				$('lastDisplayedRow').value = item.previous().id;
	  			}
		  		break;
		  	}
		}		
	}
	else{	
		$('childRow'+inFormID).toggle();
		
		$('endOfRow').insert({before: $('childRow'+inFormID)});
		$('lastHiddenRow').value = $('endOfRow').previous().id;
		myArray = $$('div.childRow')
		for (var index = 0, len = myArray.length; index < len; ++index) {
		  var item = myArray[index];
		  	if(item.style.display == 'none'){
	  			$('lastDisplayedRow').value = item.previous().id;
		  		break;
		  	}
		}		
	}
	
	//----------- Clear form's elements -----------
	$('child'+inFormID).className = 'editMode';
	$('childButtons'+inFormID).style.display 	= '';
	document.getElementById('delete'+inFormID).style.display 	= 'none';
	document.getElementById('childStatus'+inFormID).innerHTML = '';
	myInputArray = $('child'+inFormID).getElements();
	for (var index = 0, len = myInputArray.length; index < len; ++index) {
	  var item = myInputArray[index];
	  if(item.className != 'hidden'){
	  	item.className = 'onBlur2';
	  	item.value = '';
	  }
	}

	if($('childMsg'+inFormID)){
		$('childMsg'+inFormID).remove();
	}
	setFooter();
}

function ajaxChildForm(inFormID, inMode)
{
	var url;
	var qString	= '';
	var lastDisplayedRow;
	var rowToDisplay;
	var myArray;
	
	$('childErrMsg').style.display = 'none';
	
	if(inMode=="add"){
		if($('isNoChildren')){
			$('isNoChildren').style.display = 'none';
		}
		lastDisplayedRow = $F('lastDisplayedRow');
		if(lastDisplayedRow.length > 0){
			rowToDisplay = $(lastDisplayedRow).next().id;
			if(rowToDisplay != 'endOfRow'){
				$(rowToDisplay).toggle();
				$('lastDisplayedRow').value = rowToDisplay;
				if($(rowToDisplay).next().id == 'endOfRow'){
					$('lastHiddenRow').value = '';
				}
			}
			else{
				$('lastHiddenRow').value = '';
				$('childErrMsg').style.display = '';
			}
		}
		else{
			$('lastDisplayedRow').value = $('startOfRow').next().id;
			$($('lastDisplayedRow').value).toggle();
		}
	}
	else{
		qString = Form.serialize('child'+inFormID);
	
		url = '/ajax/ajaxChild.asp?formID=' + escape(inFormID) + '&mode=' + escape(inMode) + '&' + qString
		new Ajax.Updater('childRow'+inFormID, url,{onCreate:function(){ajaxChildFormCreate(inFormID)},
											onComplete:function(){ajaxChildFormComplete(inFormID,inMode)}, evalScripts:false,method:'post'});  
	} 	
	setFooter();
}

function ajaxChildFormCreate(inFormID)
{	
	document.getElementById('childRow'+inFormID).className	= 'setOpacityOn';
	document.getElementById('AjaxLoading'+inFormID).style.display	= 'block';
}

function ajaxChildFormComplete(inFormID,inMode)
{
	document.getElementById('AjaxLoading'+inFormID).style.display	= 'none';
	document.getElementById('childRow'+inFormID).className	= 'childRow';
	if(inMode=='delete'){
		$('child'+inFormID).className = 'editMode';
		$('savedChild'+inFormID).style.display = 'none';
		ajaxHideChild(inFormID);
	}
}

function deleteChild(inFormID,mode){
	if($('childMsg'+inFormID)){
		$('childMsg'+inFormID).remove();
	}
	if(mode == 'confirm'){
		$('child'+inFormID).className			= 'setOpacityOnRed';
		$('delete'+inFormID).style.display 	= 'block';
		$('childButtons'+inFormID).style.display 	= 'none';
	}
	else if(mode == 'cancel'){
		$('child'+inFormID).className		= 'setOpacityOff';
		$('delete'+inFormID).style.display 	= 'none';
		$('childButtons'+inFormID).style.display 	= '';
	}
}

//============================  load member section ==========================================================
function ajaxLoadSection(inLink)
{
	var url;
	var link;
	var qStr;
	var breadCrumbs;
	var selectedTab;
	
	switch(inLink.toLowerCase()){
		case "myorders" : {breadCrumbs = "My Order"; selectedTab = "myorders"; break;}
		case "mychildren" : {breadCrumbs = "My Children"; selectedTab = "mychildren"; break;}
		case "editaccount" : {breadCrumbs = "Edit Account"; selectedTab = "editaccount"; break;}
		case "editpassword" : {breadCrumbs = "Edit Account &gt; Edit Password"; selectedTab = "editaccount"; break;}
		case "editpreferences" : {breadCrumbs = "My Interest"; selectedTab = "editpreferences"; break;}
		case "eventrequestlist" : {breadCrumbs = "Wish List"; selectedTab = "eventrequestlist"; break;}
		case "myfamilyday" : {breadCrumbs = "Family Day"; selectedTab = "myfamilyday"; break;}
		default: {breadCrumbs = "View Order"; break;}
	}

	$('breadCrumbCol').innerHTML = 'You are here: <a href="/index.asp">awe Home</a> &gt; <span> Your Account &gt; ' + breadCrumbs + '</span>'
	$($('currentTab').value.toLowerCase()).className = 'inactive'; 
	$('tab'+selectedTab).className = 'active';
	$('currentTab').value = 'tab'+selectedTab;
	
	url = '/members.asp?ajax-section=' + inLink.toLowerCase() + '&' + qStr;
	new Ajax.Updater('ajaxMemberSection', url,{onCreate:function(){ajaxLoadSectionCreate()},
										onComplete:function(){ajaxLoadSectionComplete()}, evalScripts:false,method:'post'});   	
}

function ajaxLoadSectionCreate()
{	
	document.getElementById('ajaxMemberSection').className		= 'setOpacityOn';
	document.getElementById('AjaxLoading').style.display		= 'block';
}
function ajaxLoadSectionComplete()
{
	document.getElementById('AjaxLoading').style.display		= 'none';
	document.getElementById('ajaxMemberSection').className		= 'setOpacityOff';
	setFooter();
}

//============================  load member section ==========================================================
function ajaxSubmitForm(inLink)
{
	var url;
	var qStr;
	qStr = Form.serialize('form'+inLink.toLowerCase());
	url = '/members.asp?ajax-section='+ inLink.toLowerCase() + '&' + qStr;
	//url = '/ajax/'+ link +'.asp?' + qStr;
	new Ajax.Updater('ajaxMemberSection', url,{onCreate:function(){ajaxLoadSectionCreate()},
										onComplete:function(){ajaxLoadSectionComplete()}, evalScripts:false,method:'post'});   	
}

function AlertClick(alertMidCustomerID,url) {
	//We must find URL and document Name
	//if(document.images){
		(new Image()).src='/scripts/alertLog.asp?alertMidCustomerID='+alertMidCustomerID+'&url='+url;
	//}
	return true;
}

