/**
 * Functions to support QGL Content Server
 *
 * @dependency YAHOO UI Library 
 * 
 * @author Don Ramos
 *
 */
var contentServerUrl='https://www.supapromos.com/qffcontent';
var contentServerCallback=null;

var imgObj=null, rTimer=null, attempts=1, timeout=2000

/** verify that StoreOffers server is active **/
function pingContentServer(callback) {
    var flag=new Date();
    if(rTimer==null) { // disable submit if in process
        imgObj=new Image()
        imgObj.onload=function(evt){callback.invoke()}
        imgObj.src= contentServerUrl+"/ping.php?flag="+flag.valueOf();
        rTimer=setTimeout("noResponse()",5000);
    }
    return false;
}

/* handle no response */
function noResponse() {
    imgObj=rTimer=null;
    if(--attempts) pingContentServer(contentServerCallback);
       // else give up and do nothing;
}

/* Dynamic promos */
var __dynPromoUrl = "https://www.supapromos.com/qffcontent/dynpromoJSON.php";

function DynPromoService() {
    var loading = false;

	var onDynPromoSuccess = function(o) {
	     // stop blocking requests
	     loading = false;
	};

	var onDynPromoFailure = function(o) {
		loading = false;
	};
};

DynPromoService.prototype.getContent = function(panel_id, ffnumber,callback) {
     // block multiple requests
     if (this.loading) {
         return;
     }
     this.loading = true;
     
     var sURL = __dynPromoUrl
                + "?panel_id="+panel_id
                + "&ff_number="+ffnumber
                + "&callback="+callback;
    // alert(sURL);
                
     var transactionObj = YAHOO.util.Get.script(sURL, {
         onSuccess: this.onDynPromoSuccess,
         onFailure: this.onDynPromoFailure,
         scope    : this
     });
     
}   
 
/**
 * "Singleton" for using service
 *
 */
var _dynPromoService=new DynPromoService;


// Below is a special version of "writeSimpleFlash" in "flash_detect.js".  It includes a 
// fix for alternate content with targetId specified.
//
// This fix must eventually be added into the "writeSimpleFlash"
//
//
function writeSimpleFlash2(flashURL, flashWidth, flashHeight, altContext, addParams, targetId, wmode) {
	detectFlash();

	if (hasRightVersion) {
		if(targetId){
			var myTarget = document.getElementById(targetId);
			if (myTarget) {
			   myTarget.innerHTML = assembleFlash(flashURL, flashWidth, flashHeight, "", "", "", addParams,wmode);
			}
		}
		else{
			document.write(assembleFlash(flashURL, flashWidth, flashHeight, "", "", "", addParams,wmode));
		}
	} else {
		if(targetId){
			var myTarget = document.getElementById(targetId);
			if (myTarget) {
			   myTarget.innerHTML = altContext;
			}
		}
		else{
			document.write(altContext);
		}
	}

}
