var LoadingStatus="<img src='design/pic/ajax-loader.gif'/>";
var SiteAjaxFolder = SiteAjaxFolder;
var ModalStaticContent  ='';
var ModalStaticContentTitle='';
var CheckCallStage = '';

////////////////////////////////////////////////////////Modal Window Related Functions ////////////////////////////////////////////
	messageObj = new DHTML_modalMessage();	
	messageObj.setShadowOffset(5);	
	
	function ShowModalWindow(ModalType,width,height,PostValues,AjaxFilename,AjaxCheckFormData,strValue,AddAnother) {
		
		//alert(ModalType+","+width+","+height+","+PostValues+","+AjaxFilename+","+AjaxCheckFormData+","+strValue+","+AddAnother);
			if(AddAnother == 1)
			CheckCallStage = 'Stock';
			
			if(ModalStaticContent!='') {
			messageObj.setModalStaticContentTitle(ModalStaticContentTitle);
			messageObj.setModalStaticContent(ModalStaticContent);
			ModalStaticContent='';
			ModalStaticContentTitle='';
			messageObj.setAjaxFileNames(AjaxFilename,AjaxCheckFormData);
			messageObj.setSource(ModalType);
			messageObj.setPostValues(PostValues,strValue);
			messageObj.setCssClassMessageBox(false);
			messageObj.setSize(width,height);
			messageObj.setShadowDivVisible(false);	// Enable shadow for these boxes
			messageObj.display();
		}
		else {
					
			ModalStaticContent='';
			ModalStaticContentTitle='';
			messageObj.setModalStaticContentTitle(ModalStaticContentTitle);
			messageObj.setModalStaticContent(ModalStaticContent);
			messageObj.setAjaxFileNames(AjaxFilename,AjaxCheckFormData);
			messageObj.setSource(ModalType);
			messageObj.setPostValues(PostValues,strValue);
			messageObj.setCssClassMessageBox(false);
			messageObj.setSize(width,height);
			messageObj.setShadowDivVisible(false);	// Enable shadow for these boxes
			messageObj.display();
		}
	
	}
	function ShowModalWindowContent(ModalMasterID,ModalType,PostValues,AjaxFilename,AjaxCheckFormData)
	{
		var Filename=AjaxFilename;
	//	alert(AjaxFilename);
		ModalMasterID_public=ModalMasterID;
		if(CheckCallStage != "")
			document.getElementById(ModalMasterID).innerHTML = '<table align="center" height="100%"><tr><td colspan="2" valign="middle"  height=30 >'+StockLoadingStatus+'</td></tr></table>';
		else
			document.getElementById(ModalMasterID).innerHTML = '<table align="center" height="100%"><tr><td colspan="2" valign="middle"  height=30 >'+LoadingStatus+'</td></tr></table>';
		
		var success = function(t){ShowModalWindowContent_Complete(t,ModalMasterID,ModalType,PostValues,AjaxFilename,AjaxCheckFormData);}
		var failure = function(t){ShowOnFailure(t);}
		var url = Filename;
		//alert("URL="+url);
		var pars = '&ModalTypeCondition='+ModalType+'&PostValues='+PostValues;
		var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
	}
	function ShowModalWindowContent_Complete(t,ModalMasterID,ModalType,PostValues,AjaxFilename,AjaxCheckFormData)
	{
		//alert(t.responseText);
		var strValue = t.responseText;
		var strDisplay = strValue.split("|");
		document.getElementById(ModalMasterID).innerHTML =strDisplay[0];
	}
	
	function closeMessage(RedirectCondition,offerContent)
	{

		if(RedirectCondition=='AddReedem') {	
			window.top.location.href = sHome+"public/account/offerdetails/name_"+offerContent;
		}
		
		if(RedirectCondition=='PreviewClose') {
			if(offerContent > 0)
				DisplayOfferNotification();
		}
			
		messageObj.close();	
	}
	
	function DisplayOfferNotification(){
		setTimeout(function(){ShowModalWindow('OfferNotification','800','','','public/offers/notification/','')}, 5);
	}
	
	function ShowOnFailure(t) { alert(t); };
	
	function UpdateDontAsk(username,offerCnt) {
		var strvalue = document.getElementById("askgain").checked;
		if(strvalue==false) {
			alert("Please check the option");	
			return false;
		}
		if(strvalue==true) {
			var success = function(t){UpdateDontAsk_Success(t,username);}
			var failure = function(t){ShowOnFailure(t);}
			var url = "public/account/greetingmessage/";		
			var pars = '&ModalTypeCondition=UpdateUsername'+'&username='+username;
			var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
		}
		closeMessage('PreviewClose',offerCnt);
	}
	
	function UpdateDontAsk_Success(t, username){
		
	}
	
	function UpdateFirstClose(username,offerCnt) {
			var success = function(t){UpdateDontAsk_Success(t,username);}
			var failure = function(t){ShowOnFailure(t);}
			var url = "public/account/greetingmessage/";		
			var pars = '&ModalTypeCondition=FirstClose'+'&username='+username;
			var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
		closeMessage('PreviewClose',offerCnt);
	}
	
	function UpdateDontAsk_Success(t, username){
		
	}
	
	function AddReedemToOffer(Ident) {
		if(confirm("Are you sure you want to reedem this offer?"))	 {
			setTimeout(function(){ShowModalWindow('AddReedem','600','',Ident,'public/offers/addreedem/','')}, 1);
			return true;
		} else {
			return false;	
		}
	}
