//ool-click
var oolClickCurrentTab = 1;
var oolClickLoaded = false;
var oolClickTabDisabled = false;
var oolClickWhatBoxExpanded = false;
var oolClickCurrentTabName = 'info';
var oolClickCurrentCtx = 'P';
var oolClickButtonsTabVisible = false;



function signInAsWalletOwner(referer){
	var targetLocation = "/SignInNew?area=oe&id=";
	targetLocation += document.getElementById("walletOwnerId").innerHTML;
	targetLocation += "&referer=" + referer;
	top.window.location=targetLocation;
}



function clickShowWhatBox(){
	if(oolClickWhatBoxExpanded){
		oolClickWhatBoxExpanded = false;
		displayWhatBox("none");
	} else {
		oolClickWhatBoxExpanded = true;
		displayWhatBox("block");
	}
}

function displayWhatBox(display){
	document.getElementById("whatbox").style.display=display;
	document.getElementById("whatboxTriangle").style.display=display;
}

function disableTabs(){
	oolClickTabDisabled = true;
	for(i=0;i<5;i++){
		if(document.getElementById("tabLink"+i)){
			document.getElementById("tabLink"+i).disabled = 1;
		}
	}
}

function enableTabs(){
	oolClickTabDisabled = false;
	for(i=0;i<5;i++){
		if(document.getElementById("tabLink"+i)){
			document.getElementById("tabLink"+i).disabled = 0;
		}
	}
}

function disableButtons(){
	for(i=1;i<4;i++){
		if(document.getElementById("button"+i)){
			document.getElementById("button"+i).disabled = 1;
		}
	}
	if(document.getElementById("saveButtonLink")){
		document.getElementById("saveButtonLink").disabled = 1;
	}
}

function enableButtons(){
	for(i=1;i<4;i++){
		if(document.getElementById("button"+i)){
			document.getElementById("button"+i).disabled = 0;
		}
	}
	if(document.getElementById("saveButtonLink")){
		document.getElementById("saveButtonLink").disabled = 0;
	}
}

function showTabs(){
	document.getElementById("tabsContainer").style.display="block";
}
function hideTabs(){
	document.getElementById("tabsContainer").style.display="none";
}

function oolClickShowTab(nr,ctx,tabName) {
	if(!oolClickTabDisabled){
		
		oolClickCurrentTabName = tabName;
		oolClickCurrentCtx = ctx;
		
		if(ctx=="CB") {
			location.href="/OptimumSelect/PartnerPageInfo?productId="+oolClickProductId+"&tab="+tabName + "&tabNr="+nr;
		} else {
			if(document.getElementById("signInBox")){
				document.getElementById("signInBox").style.display="none";
			}
			if(document.getElementById("idNotWalletOwnerInfoBox")){
				document.getElementById("idNotWalletOwnerInfoBox").style.display="none";
			}
			
			oolClickOutTab(oolClickCurrentTab);
			oolClickCurrentTab = nr;
			oolClickSetTab(nr);
	
			var obj = document.getElementById('oolClickProductDetailsContent');
			try { if(obj.childNodes[0].className=='gwt-HTML') obj = obj.childNodes[0]; } catch(err) {}
			obj.innerHTML = '<div id="loadingDiv"><img src="/images/click/process_circle.gif" /></div>';
			ajaxSetContent('oolClickProductDetailsContent','/Click/ProductInner?ctx='+ctx+'&tab='+tabName+'&productId='+oolClickProductId,'','top.sendTabStats(\''+ctx+'\')');
		}
	}
}

function sendTabStats(ctx){
	internalCallClickOmniture(ctx,oolClickCurrentTabName,'');
	if(oolClickCurrentTabName=="video"){		
		top.oolClickLaunchPlayer();
	}
	enableButtons();
	showButtonsTab();
}

function oolClickSetTab(nr){
	var obj = document.getElementById('clickTab'+nr);
	obj.className = 'tabActive';
}

function oolClickOutTab(nr){
	var obj = document.getElementById('clickTab'+nr);
	obj.className = 'tabNotActive';
}


function oolClickShowProduct(productId) {
	oolClickProductId = productId;
	oolClickButtonsTabVisible = true;
	if(!oolClickLoaded) {
		ajaxSetContent('tabsContainer', '/Click/ProductTabs?ctx=B&productId='+productId, '', 'top.loadProductDetails('+productId+')');
	} else {
		oolClickShow();
	}
}
function loadProductDetails(productId){
	oolClickProductId = productId;
	if(!oolClickLoaded) {
		//wallet - lazy loading 
		ajaxSetContent('oolClickStatus', '/Click/Controller?action=LLW&ctx=B&productId='+productId, '', '');		
		ajaxSetContent('oolClickProductDetailsContent', '/Click/ProductInner?ctx=B&productId='+productId, '', 'top.oolClickShow()');
	} else {
		oolClickShow();
	}
}

function oolClickShow() {
	document.getElementById('oolClickBackgroundDiv').style.display = 'block';
	var obj = document.getElementById('oolClickPlaceholder');
	var pos = tpFindPos2(document.getElementById('oolClickPositionHolder'));
	if(navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
		obj.style.left = pos[0]+16+'px';
		obj.style.top = pos[1]-64+'px';
	} else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { 	
		obj.style.top = pos[1]+157+'px';	
	} else {
		//obj.style.top = pos[1]+210+'px';	
		obj.style.top = pos[1]+117+'px';	
	}
	obj.style.display = 'block';
	oolClickLoaded = true;
	oolClickCurrentTabName="info";
	oolClickCurrentTab = 1;
	internalCallClickOmniture('B','info','');
	enableTabs();
	enableButtons();
	showButtonsTab();
}

function oolClickHide() {
	oolClickLoaded = false;
	if(oolClickCurrentTabName=="video"){
		if (tpController && tpController.thisMovie('communicationwidget')) {
			tpController.pause(true);
		}
	}
	document.getElementById('oolClickPlaceholder').style.display = 'none';
	document.getElementById('oolClickBackgroundDiv').style.display = 'none';
	enableTabs();
	showTabs();
	internalCallClickOmniture('B',oolClickCurrentTabName,'Close');		
}

function oolClickInit() {
	if(navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
		var obj = document.getElementById('oolClickBackgroundDiv');
		obj.parentNode.removeChild(obj);
		obj = document.createElement('<div id="oolClickBackgroundDiv" class="oolClickBackgroundDivIE">');
		obj.setAttribute('id', 'oolClickBackgroundDiv');
		obj.id = 'oolClickBackgroundDiv';
		obj.onclick = function() { oolClickHide(); };
		document.body.insertBefore(obj, document.body.childNodes[0]);
		obj.style.setExpression("width", "document.body.clientWidth");
		obj.style.setExpression("height", "document.body.clientHeight");
		obj.style.setExpression("top", "(document.body.scrollTop) + 'px'");
		obj.style.setExpression("left", "(document.body.scrollLeft) + 'px'");
		document.body.onscroll = function() {
			document.getElementById('oolClickBackgroundDiv').style.top = (document.body.scrollTop) + 'px';
			document.getElementById('oolClickBackgroundDiv').style.left = (document.body.scrollLeft) + 'px';
		};
		obj = document.getElementById('oolClickPlaceholder');
		var inner = obj.innerHTML;
		var pos = tpFindPos2(obj)
		obj.parentNode.removeChild(obj);
		obj = document.createElement('<div id="oolClickPlaceholder">');
		obj.setAttribute('id', 'oolClickPlaceholder');
		obj.id = 'oolClickPlaceholder';
		obj.innerHTML = inner;
		document.body.insertBefore(obj, document.body.childNodes[0]);
		obj.style.left = pos[0] + 'px';
		obj.style.top = pos[1] + 'px';
	}
}

try{
oolClickInit();
} catch(error){}

function playProductVideo(){
	if(document.getElementById("clickReleasePID")){
		var pid = document.getElementById("clickReleasePID").innerHTML;
		//alert("play " + pid);
		tpController.setReleaseURL("http://release.theplatform.com/content.select?pid=" + pid);
	} else {
		//alert("no release PID");
	}
}


function oolClickLaunchPlayer()
{
	//alert("create player");
	
	tpSetCommManagerID("communicationwidget");
	tpRegisterID("playerwidget");
	
	var so = new SWFObject("/thePlatform412/swf/flvPlayer.swf", "playerwidget", "300", "220", "9.0.115.0", "#000000");
	so.addParam("quality", "high");
	so.addParam("scale", "noscale");
	so.addParam("salign", "tl");
	so.addParam("menu", "true");
	so.addParam("bgcolor", "#131313");
	so.addParam("wmode", "transparent");
	//so.addVariable("adPattern", "count:2");
	
	if(DetectFlashVer(requiredMajorVersion,requiredMinorVersion,requiredRevision)){
		so.addParam("allowFullScreen", "true");
	} else {
		so.addParam("allowFullScreen", "false");
	}
	so.addParam("allowScriptAccess", "always");

	if(DetectFlashVer(requiredMajorVersion,requiredMinorVersion,requiredRevision)){
		so.addVariable("allowFullScreen", "true");
	} else {
		so.addVariable("allowFullScreen", "false");
	}
	so.addVariable("ID", "playerwidget");
	so.addVariable("plugin0", "type=adcomponent|URL=/thePlatform412/swf/SMIL.swf|priority=3");
	so.addVariable("height", 220);
	so.addVariable("width", 300);
	so.addVariable("skinUrl", "/thePlatform412/swf/skinCinematic.swf");
	so.addVariable("autoPlay","true");
	so.addVariable("showFullTime", "true");
	so.addVariable("pageBackgroundColor", "0x131313");
	so.addVariable("loadProgressColor", "0xcc6600");
	so.addVariable("backgroundColor", "0x131313");
	so.addVariable("controlBackgroundColor", "0x131313");
	so.addVariable("controlColor", "0xBEBEBE");
	so.addVariable("controlFrameColor", "0x545759");
	so.addVariable("controlHoverColor", "0x00CCFF");
	so.addVariable("controlSelectedColor", "0xBEBEBE");
	so.addVariable("frameColor", "0x545759");
	so.addVariable("playProgressColor", "0x00CCFF");
	so.addVariable("scrubberColor", "0xBEBEBE");
	so.addVariable("scrubberFrameColor", "0x00CCFF");
	so.addVariable("scrubTrackColor", "0xBEBEBE");
	so.addVariable("textBackgroundColor", "0x383838");
	so.addVariable("textColor", "0xBEBEBE");
	so.addVariable("style", "z-index:1500");
	so.write("oolClickPlayerDiv");
	
	//alert(document.getElementById('oolClickPlayerDiv').innerHTML);
	
	var so = new SWFObject("/thePlatform412/swf/commManager.swf", tpGetCommManagerID(), "1", "1", "9.0.115.0");
	so.addParam("allowScriptAccess", "always");
	so.addParam("wmode", "transparent");
	so.addVariable("ID", tpGetCommManagerID());
	so.addVariable("instanceID", tpGetInstanceID());
	so.addVariable("registeredIDs", tpGetRegisteredIDs());
	so.write("oolClickCommManagerDiv");
	
	tpController.addEventListener("OnShowFullScreen","onShowFullScreen");	
	tpController.addEventListener("OnPlayerLoaded","playProductVideo");	
	tpController.addEventListener("OnMediaStart","productVideoMediaStart");	
	tpController.addEventListener("OnMediaPause","productVideoMediaPause");	
	tpController.addEventListener("OnMediaUnpause","productVideoMediaUnpause");	
	tpController.addEventListener("OnMediaEnd","productVideoMediaEnd");	
}

function onShowFullScreen(){
	if(!fullScreenAllowed){
		alert("To view this video in fullscreen mode, you need to have Flash Version " + requiredMajorVersion+","+requiredMinorVersion+","+requiredRevision + " or later.");
	}
}

function productVideoMediaStart(evt){
	internalCallClickOmniture(oolClickCurrentCtx,'video','Play');		
}

function productVideoMediaPause(evt){
	internalCallClickOmniture(oolClickCurrentCtx,'video','Pause');		
}

function productVideoMediaUnpause(evt){
	internalCallClickOmniture(oolClickCurrentCtx,'video','Unpause');		
}

function productVideoMediaEnd(evt){
	internalCallClickOmniture(oolClickCurrentCtx,'video','End');		
}

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }
}



var buttonsIdTab = "buttonArea";

function initButtonsTab() {
	oolClickButtonsTabVisible = true;
	showButtonsTab();
}

function showButtonsTab() {
	enableButtons();
	if (document.getElementById(buttonsIdTab)) {
		document.getElementById(buttonsIdTab).style.display="block";
	}
	//if ((typeof oolClickButtonsTabVisible == "undefined") || oolClickButtonsTabVisible) {
	//	if (document.getElementById(buttonsIdTab)) {
	//		document.getElementById(buttonsIdTab).style.display="block";
	//	}
	//}
}

function handleInitResponse(ctx){
	if(document.getElementById("oolClickPerformedAction")){
		var pa = document.getElementById("oolClickPerformedAction").innerHTML;
		if(pa=="S"){
			var status = document.getElementById("oolClickActionStatus").innerHTML;
			if(status=="SUCCESS"){
				internalCallClickOmnitureWithPageCtx(ctx,'Save Thank you Page');			
			} else {
				internalCallClickOmnitureWithPageCtx(ctx,'Save Error');			
			}
		}
	}
}

function clearActionStatus(){
	if(document.getElementById("oolClickActionStatus")){
		document.getElementById("oolClickActionStatus").innerHTML = "";
	}
	if(document.getElementById("oolClickForwardUrl")){
		document.getElementById("oolClickForwardUrl").innerHTML = "";
	}
	if(document.getElementById("oolClickForwardUrlReferer")){
		document.getElementById("oolClickForwardUrlReferer").innerHTML = "";
	}
	if(document.getElementById("oolClickAjaxUrl")){
		document.getElementById("oolClickAjaxUrl").innerHTML = "";
	}
	if(document.getElementById("oolClickMessage")){
		document.getElementById("oolClickMessage").innerHTML = "";
	}
	if(document.getElementById("statusMessage")){
		document.getElementById("statusMessage").innerHTML = "";
	}
	if(document.getElementById("oolClickShowTabs")){
		document.getElementById("oolClickShowTabs").innerHTML = "";
	}
	if(document.getElementById("walletOwnerId")){
		document.getElementById("walletOwnerId").innerHTML = "";
	}
}

function doAction(action,ctx,productId,ajaxMode){	
	//clear status fields
	clearActionStatus();
	
	if(!ajaxMode){
		ajaxMode = false;
	}	
	var doAction = "/Click/Controller?action="+action+"&ctx="+ctx+"&productId="+productId+"&ajaxMode="+ajaxMode;

	disableTabs();
	
	if( (action=="SB") || (action=="S") ){
		if(document.getElementById("signInBox")){
			document.getElementById("signInBox").style.display="none";
			document.getElementById("signInBox").style.height="169px";
		}
		if(document.getElementById("signInMessage")) {
			document.getElementById("signInMessage").innerHTML="Please re-enter your password to continue:";
		}
		if(document.getElementById("idNotWalletOwnerInfoBox")){
			document.getElementById("idNotWalletOwnerInfoBox").style.display="none";
		}
		if(document.getElementById(buttonsIdTab)){
			document.getElementById(buttonsIdTab).style.display="none";
		}
		document.getElementById("loadingDivButtonsAction").style.display="block";
	}
	if( (action=="B") || (action=="DCB") ){
		if(document.getElementById("yes")){
			document.getElementById("yes").style.display="none";
		}
		if(document.getElementById("no")){
			document.getElementById("no").style.display="none";
		}
		if(document.getElementById(buttonsIdTab)){
			document.getElementById(buttonsIdTab).style.display="none";
		}
		document.getElementById("loadingDivButtonsAction").style.display="block";
	}	
	
	document.getElementById("statusMessage").innerHTML = "";
	
	if(action=="SB"){
		//internalCallClickOmniture(ctx,oolClickCurrentTabName,'Buy');
		ajaxSetContent('oolClickStatus',doAction,'','this.handleStartBuyingResponse("'+ctx+'")');	
	}	
	if(action=="S"){
		internalCallClickOmniture(ctx,oolClickCurrentTabName,'Save');
		ajaxSetContent('oolClickStatus',doAction,'','this.handleSaveResponse("'+ctx+'")');	
	}	
	if(action=="B"){		
		document.getElementById("statusMessage").innerHTML = "";
		ajaxSetContent('oolClickProductDetailsContent', '/Click/BuyInProgress?productId='+productId+'&ctx='+ctx, '', 'top.confirmBuy("'+action+'","'+ctx+'","'+productId+'","'+ajaxMode+'")');
	}	
	if(action=="RE"){
	 	var password = document.getElementById("reauthPassword").value;
	 	if(password==""){
	 		alert("Please provide your password.");
	 	} else {
			if(document.getElementById(buttonsIdTab)){
				document.getElementById(buttonsIdTab).style.display="none";
			}			
			document.getElementById("reauthActions").style.display="none";
			document.getElementById("loadingReauthAction").style.display="block";
	 		ajaxSetContent('oolClickStatus','/signIn/processLogin?ajaxMode=reauth&password='+password,'','this.handleReauthResponse("'+action+'","'+ctx+'","'+productId+'")');	
	 	}	
 	}	
	if(action=="DCB"){
		oolClickOutTab(oolClickCurrentTab);
		oolClickCurrentTab = 1;
		oolClickSetTab(1);
		oolClickCurrentTabName = 'info';
		if(ctx=="B"){
			showTabs();
			ajaxSetContent('oolClickProductDetailsContent', '/Click/ProductInner?productId='+productId+'&ctx='+ctx, '', 'top.handleActionResponse("'+ctx+'")');
		} else {
			if(ajaxMode){
				showTabs();
				ajaxSetContent('oolClickProductDetailsContent','/Click/ProductInner?productId='+productId+'&ctx='+ctx, '', 'top.handleActionResponse("'+ctx+'")');
			} else {
				location.href='/OptimumSelect/PartnerPageInfo?productId='+productId;
			}
		}
	}
}

function confirmBuy(action,ctx,productId,ajaxMode){
	hideTabs();
	ajaxSetContent('oolClickStatus','/Click/Controller?productId='+productId+'&action=B&ctx='+ctx+'&ajaxMode='+ajaxMode,'','this.handleConfirmBuyResponse("'+productId+'","'+ctx+'")');	
}

//default handler, if return true processing is finished otherwise it is delegated to
//child handlers
function handleActionResponse(ctx){
	var status = "";
	var forwardUrl = "";
	var forwardUrlReferer = "";
	var ajaxUrl = "";
	var showTabsAction = "true";
	
	enableTabs();
	enableButtons();
	
	if(document.getElementById("loadingDivButtonsAction")){
		document.getElementById("loadingDivButtonsAction").style.display="none";
	}
	if(document.getElementById("oolClickActionStatus")){
		status = document.getElementById("oolClickActionStatus").innerHTML;
	}
	if(document.getElementById("oolClickForwardUrl")){
		forwardUrl = document.getElementById("oolClickForwardUrl").innerHTML;
	}
	if(document.getElementById("oolClickForwardUrlReferer")){
		forwardUrlReferer = document.getElementById("oolClickForwardUrlReferer").innerHTML;
	}
	if(document.getElementById("oolClickAjaxUrl")){
		ajaxUrl = document.getElementById("oolClickAjaxUrl").innerHTML;
	}
	if(document.getElementById("oolClickShowTabs")){
		showTabsAction = document.getElementById("oolClickShowTabs").innerHTML;
	}
	var redirectUrl = forwardUrl.replace(/\&amp;/g,'&');
	if(forwardUrlReferer!=""){
		if(redirectUrl.indexOf("?")==-1){
			redirectUrl += "?";
		}
		if(redirectUrl.indexOf("=")==-1){
			redirectUrl += "referer="+forwardUrlReferer;
		} else {
			redirectUrl += "&referer="+forwardUrlReferer;
		}
	}

		
	if(status=="NOT_LOGGED"){
		window.location = redirectUrl;
		return true;
	} else if (status=="NEEDS_REAUTH"){ 
		if(document.getElementById("signInBox")){
			document.getElementById("optimumID").innerHTML=getRealCookie('oolsub');
			document.getElementById("signInBox").style.display="block";
			ensureVisibleInWindow(document.getElementById("oolClickPlaceholder"));
			setFocus('reauthPassword');
			internalCallClickOmnitureWithPageCtx(ctx,'Buy Reauthentication');
		}
	} else if (status=="ID_NOT_WALLET_OWNER"){ 
		if(document.getElementById("oolClickWalletOwnerId")){
			document.getElementById("walletOwnerId").innerHTML=document.getElementById("oolClickWalletOwnerId").innerHTML;
			document.getElementById("walletOwnerIdContent").innerHTML=document.getElementById("oolClickWalletOwnerId").innerHTML;
		}
		if(document.getElementById("idNotWalletOwnerInfoBox")){
			document.getElementById("idNotWalletOwnerInfoBox").style.display="block";
		}
		internalCallClickOmnitureWithPageCtx(ctx,'Existing Wallet');
	} else if(forwardUrl!=""){
		window.location = redirectUrl;
		return true;
	} else if(ajaxUrl!=""){
		ajaxUrl = ajaxUrl.replace(/\&amp;/g,'&');
		ajaxSetContent('oolClickProductDetailsContent',ajaxUrl, '', 'this.handleProductDetailsResponse("'+ctx+'","'+ajaxUrl+'")');
		return true;
	} else {
		var statusMessage = "";
		if(document.getElementById("oolClickMessage")){
			statusMessage = document.getElementById("oolClickMessage").innerHTML;
			if(statusMessage && statusMessage!="" && document.getElementById("copyArea")){
				document.getElementById("copyArea").innerHTML=statusMessage;		
			}
		}
	}
	showButtonsTab();
	return false;
}

function handleProductDetailsResponse(ctx,ajaxUrl){
	top.resolveLoadedUrl(ctx,ajaxUrl);
	showButtonsTab();
}

function resolveLoadedUrl(ctx,ajaxUrl){
	if(ajaxUrl.indexOf("/Click/ConfirmBuyInner")!=-1){
		internalCallClickOmnitureWithPageCtx(ctx,'Product Buy Confirmation');
	}
	if(ajaxUrl.indexOf("/Click/ThankYou")!=-1){
		showButtonsTab();
		internalCallClickOmnitureWithPageCtx(ctx,'Product Buy Thank you');
	}
	if(ajaxUrl.indexOf("/Click/TransactionFailed")!=-1){
		internalCallClickOmnitureWithPageCtx(ctx,'Product Buy Error');
	}
	resolveTabs();
}

function resolveTabs(){
	var showTabsAction = "true";
	if(document.getElementById("oolClickShowTabs")){
		showTabsAction = document.getElementById("oolClickShowTabs").innerHTML;
	}
	if(showTabsAction=="false"){
		hideTabs();
	} else {
		showTabs();
	}

}

function handleStartBuyingResponse(ctx){
	if(!handleActionResponse(ctx)){
		document.getElementById(buttonsIdTab).style.display="block";		
		var status = "SUCCESS";
		if(document.getElementById("oolClickActionStatus")){
			status = document.getElementById("oolClickActionStatus").innerHTML;
		}
		if(status=="ERROR"){
			if(document.getElementById("signInBox")){
				document.getElementById("loadingReauthAction").style.display="none";
				document.getElementById("signInBox").style.display="none";
			}
		}
	}
}

function handleSaveResponse(ctx){
	if(!handleActionResponse(ctx)){
		var status = document.getElementById("oolClickActionStatus").innerHTML;
		if(status=="SUCCESS"){
			document.getElementById("saveButton").style.display="none";
			document.getElementById("saveButtonImage").style.display="none";
			document.getElementById("saveButtonLink").style.display="none";
			document.getElementById("saveButtonImageArrow").style.visibility="hidden";
		
			//change css class
			if(document.getElementById("buttonAreaContainer")){
				document.getElementById("buttonAreaContainer").className="view1";
			}


			internalCallClickOmnitureWithPageCtx(ctx,'Save Thank you Page');			
		} else {
			document.getElementById("saveButton").style.display="block";
			document.getElementById("saveButtonImage").style.display="block";
			document.getElementById("saveButtonLink").style.display="block";
			document.getElementById("saveButtonImageArrow").style.visibility="visible";
			internalCallClickOmnitureWithPageCtx(ctx,'Save Error');			
		}
		document.getElementById(buttonsIdTab).style.display="block";		
	}
}

function handleReauthResponse(action,ctx,productId){
	var status = document.getElementById("reauthStatus").innerHTML;
	if(status==2){
		document.getElementById("signInMessage").innerHTML="Password is not valid.<BR />Please note that passwords are case sensitive.<BR /><BR />Please try again:";
		document.getElementById("signInBox").style.height="200px";
		document.getElementById("reauthActions").style.display="block";
		document.getElementById("loadingReauthAction").style.display="none";
		if(document.getElementById(buttonsIdTab)){
			document.getElementById(buttonsIdTab).style.display="block";
		}		
		enableTabs();	
		internalCallClickOmnitureWithPageCtx(ctx,'Buy Reauthentication Error');
	} else if(status==0){
		//do action
 		ajaxSetContent('oolClickStatus','/Click/Controller?action=SB&ctx='+ctx+'&productId='+productId+'&from=Reauth&ajaxMode=true','','this.handleConfirmBuyAfterReauth("'+ctx+'")');
		//if(document.getElementById("signInBox")){
		//	document.getElementById("signInBox").style.display="none";
		//}
		//if(document.getElementById("idNotWalletOwnerInfoBox")){
		//	document.getElementById("idNotWalletOwnerInfoBox").style.display="none";
		//}
		//if(document.getElementById(buttonsIdTab)){
		//	document.getElementById(buttonsIdTab).style.display="none";
		//}
		//if(document.getElementById("loadingDivButtonsAction")){
		//	document.getElementById("loadingDivButtonsAction").style.display="block";
		//}
	}
}

function handleConfirmBuyAfterReauth(ctx){
	if(!handleActionResponse(ctx)){
		var status = "SUCCESS";
		if(document.getElementById("oolClickActionStatus")){
			status = document.getElementById("oolClickActionStatus").innerHTML;
		}
		if(status=="ERROR"){
			if(document.getElementById("signInBox")){
				document.getElementById("loadingReauthAction").style.display="none";
				document.getElementById("signInBox").style.display="none";
			}
		}
		if(document.getElementById("loadingDivButtonsAction")){
			document.getElementById("loadingDivButtonsAction").style.display="none";
		}
	}
}

function handleConfirmBuyResponse(productId,ctx){
	if(!handleActionResponse(ctx)){
		
		showButtonsTab();
		
		if(document.getElementById("yes")){
			document.getElementById("yes").style.display="block";
		}
		if(document.getElementById("no")){
			document.getElementById("no").style.display="block";
		}	
		document.getElementById("loadingDivButtonsAction").style.display="none";
	}
}


function editBillingInfo(host, productId) {
	location.href = host + '/OptimumSelect/Profile?mode=update&follow=cardInfo&referer=' + Url.encode(host + '/Click/Controller?action=SB&ctx=P&productId='+productId+'&from=EditWallet');
}

function editCreditCardInfo(host, productId) {
	editBillingInfo(host, productId);
}

function editShippingInfo(host, productId) {
	location.href = host + '/OptimumSelect/Profile/SecurityQA?referer=' + Url.encode(host + '/Click/Controller?action=SB&ctx=P&productId='+productId+'&from=EditWallet');
}

function setFocus(id) {
	var elem = document.getElementById(id);
	if (elem) {
		elem.focus();
	}
}

function postClickOnSubmit(id) {
	var obj = document.getElementById(id);
	if (obj && obj.onclick) {
		obj.onclick();
	}					
	return false;
}

function clickGetWindowScrollTop() {
	return ((document.all) ? document.body.scrollTop : window.scrollY);
}

function clickGetWindowScrollLeft() {
	return ((document.all) ? document.body.scrollLeft : window.scrollX);
}

function clickGetTop(obj) {
	var result = 0;
	while (obj) {
		result += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return result;
}

function clickGetLeft(obj) {
	var result = 0;
	while (obj) {
		result += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return result;
}

function ensureVisibleInWindow(obj) {
	if (obj) {
		var dy = clickGetTop(obj) - clickGetWindowScrollTop();
		if (dy < 0) {
			window.scrollBy(0, dy);
		}
		var dx = clickGetLeft(obj) - clickGetWindowScrollLeft();
		if (dx < 0) {
			window.scrollBy(dx, 0);
		}
	}
}

