
loci.home=new Object();var mainPageServiceUrl=ccm.config.serviceUrlRoot+"/creativeRecord";var pageCompleteEvents=["buyer","slot1","slot2"];function createPagehome(){ccm.commonUtils.preLoadImages(["/images/campaignbg2.png"]);ccmglobal.attachScripts("pr=http&s=s7.addthis.com&l=/js/250/addthis_widget.js");var lociKey="NONE";if(typeof jQuery.url.param("lociKey")!=="undefined"&&jQuery.url.param("lociKey")!=null&&jQuery.url.param("lociKey")!=""){lociKey=escape(jQuery.url.param("lociKey").replace(/\s|-/g,'').toUpperCase());}
var mainPageContent=ccm.commonUtils.getJson(mainPageServiceUrl+'/locikey/'+lociKey+'/locale/'+ccm.i18n.userLocale,"",false);var creativeObj;if(typeof mainPageContent.queriedLociCreative!="undefined"){creativeObj=mainPageContent.queriedLociCreative;}else{creativeObj=mainPageContent.fallbackLociCreative;if(lociKey!="ENTERKEY"&&lociKey!="ENTERYOURKEY"&&lociKey!="NONE"){paintErrorMessage(mainPageContent.queryStatus);}}
registerBuyerProxy(creativeObj);registerSlot1Proxy(creativeObj);registerSlot2Proxy(creativeObj);paintPollArea(creativeObj);ccm.i18n.applyLangPack();loci.home.dataString='pageName='+ccm.pageName+'&lociKeySearched='+jQuery.url.param("lociKey")+'&lociKeyDisplayed='+creativeObj.lociKey+'&status='+mainPageContent.queryStatus+'&tafMailLinkId='+jQuery.url.param("tafMailLinkId")+'&pollId='+creativeObj.pollId;}
function registerBuyerProxy(creativeObj){loci.home.returnLink=generateReturnLink(creativeObj.lociKey);var buyerContentUrl=creativeObj.buyerContentUrl;var cxdBuyerUrl=buyerContentUrl.replace(/^\/creatives/,"http://"+s3CreativesRoot);ccm.commonUtils.ccmAlert("cxdBuyerUrl="+cxdBuyerUrl);var file=buyerContentUrl.match(/([^\/\\]+)\.(\w+)$/);cxdBuyerProxy=new flensed.flXHR({autoUpdatePlayer:true,instanceId:"buyerProxy",xmlResponseText:false,onerror:debugDispXHRObj,onreadystatechange:function(XHRobj){if(XHRobj.readyState==4){debugDispXHRObj(XHRobj,"dump");if(file[2]=='html'){loadBuyersImage(XHRobj);}else if(file[2]=='json'){loadBuyersVideo(XHRobj);}}},noCacheHeader:false});cxdBuyerProxy.open("GET",cxdBuyerUrl);var p="";cxdBuyerProxy.send(p);}
function loadBuyersImage(XHRobj){var html=XHRobj.responseText;var buyerCreative=html.replace(/\/creatives/g,"http://"+s3CreativesRoot);var append='<script type="text/javascript">var addthis_config = {username: "rmesde", ui_click: true, ui_language: "'+ccm.i18n.userLocale.substr(0,ccm.i18n.userLocale.indexOf('_')).toLowerCase()+'", ui_hover_direction:-1};</script>';append+='<div class="homeTAFTextVideo"><a href="http://www.addthis.com/bookmark.php" class="addthis_button" addthis:url="'+loci.home.returnLink+'">'+ccm.i18n.languagePackages[ccm.i18n.userLocale]["ccmMainTAFMessage"]+'</a></div>';buyerCreative+=append;$('div.campaignpageContent').empty().append(buyerCreative);loci.home.dataString+='&buyerSlot='+$('#buyerCreativeId').val();eventComplete("buyer");}
function loadBuyersVideo(XHRobj){loci.home.videoInfoObj=$.evalJSON(XHRobj.responseText);var swfVersionStr="10.0.0";var xiSwfUrlStr="playerProductInstall.swf";var flashvars={};var params={};params.quality="high";params.allowscriptaccess="sameDomain";params.allowfullscreen="true";params.wmode="transparent";var attributes={};attributes.id="Main";attributes.name="Main";attributes.align="middle";swfobject.embedSWF("../tempFlash/Main.swf","CCMVideo","640","350",swfVersionStr,xiSwfUrlStr,flashvars,params,attributes,unCurtainPage);}
function unCurtainPage(){ccm.commonUtils.turnOffLoadingLayer($("body"));}
function updateVideoPlayer(){ccm.commonUtils.ccmAlert("updateVideoPlayer="+loci.home.videoInfoObj.url);var vUrl="http://"+s3CreativesRoot+loci.home.videoInfoObj.url;var jumpLink=null;if(typeof loci.home.videoInfoObj.jumpLink=="string"){jumpLink=loci.home.videoInfoObj.jumpLink;}
document["Main"].loadCSS("../tempFlash/skins/VidPlayerCSS.swf");document["Main"].setVideoUrl(vUrl,jumpLink);document["Main"].resizeVideoDisplay(loci.home.videoInfoObj.height,true);unCurtainPage();if(typeof loci.home.videoInfoObj.buyerCreativeId!="undefined"){loci.home.dataString+='&buyerSlot='+loci.home.videoInfoObj.buyerCreativeId;}
eventComplete("buyer");}
function registerSlot1Proxy(creativeObj){if(typeof creativeObj.supplierContentUrl!="undefined"&&creativeObj.supplierContentUrl!='NONE'){var slot1CreativeUrl=creativeObj.supplierContentUrl;var cxdSlot1Url=slot1CreativeUrl.replace(/^\/creatives/,"http://"+s3CreativesRoot);ccm.commonUtils.ccmAlert("cxdSlot1Url="+cxdSlot1Url);var cxdSlot1Proxy=new flensed.flXHR({autoUpdatePlayer:true,instanceId:"slot1Proxy",xmlResponseText:false,onerror:debugDispXHRObj,onreadystatechange:paintSlot1Content,noCacheHeader:false});cxdSlot1Proxy.open("GET",cxdSlot1Url);var p="";cxdSlot1Proxy.send(p);}}
function paintSlot1Content(XHRobj){if(XHRobj.readyState==4){debugDispXHRObj(XHRobj,"dump");var html=XHRobj.responseText;var embedHtml=html.replace(/\/creatives/g,"http://"+s3CreativesRoot);$("div.thinbox").empty().append(embedHtml);loci.home.dataString+='&slot1='+$('#slot1CreativeId').val();eventComplete("slot1");}}
function registerSlot2Proxy(creativeObj){if(typeof creativeObj.sneakPeakContentUrl!="undefined"&&creativeObj.sneakPeakContentUrl!='NONE'){var slot2CreativeUrl=creativeObj.sneakPeakContentUrl;var cxdSlot2Url=slot2CreativeUrl.replace(/^\/creatives/,"http://"+s3CreativesRoot);ccm.commonUtils.ccmAlert("cxdSlot2Url="+cxdSlot2Url);var cxdSlot2Proxy=new flensed.flXHR({autoUpdatePlayer:true,instanceId:"slot2Proxy",xmlResponseText:false,onerror:debugDispXHRObj,onreadystatechange:paintSlot2Content,noCacheHeader:false});cxdSlot2Proxy.open("GET",cxdSlot2Url);var p="";cxdSlot2Proxy.send(p);}}
function paintSlot2Content(XHRobj){if(XHRobj.readyState==4){debugDispXHRObj(XHRobj,"dump");var html=XHRobj.responseText;var embedHtml=html.replace(/\/creatives/g,"http://"+s3CreativesRoot);$("div.widebox").empty().append(embedHtml);loci.home.dataString+='&slot2='+$('#slot2CreativeId').val();eventComplete("slot2");}}
function eventComplete(eventType){for(var i=0,j=pageCompleteEvents.length;i<j;i++){if(pageCompleteEvents[i]===eventType)
pageCompleteEvents.splice(i,1);}
if(pageCompleteEvents.length==0){ccm.commonUtils.ccmPersistData(loci.home.dataString,true);}}
function paintPollArea(creativeObj){if(typeof creativeObj.pollId!=="undefined"){$('iframe#poll_iframe').attr('src','/pollDisplay?pollId='+creativeObj.pollId);}}
function paintErrorMessage(queryStatus){ccm.commonUtils.ccmAlert('queryStatus='+queryStatus);switch(queryStatus){case'defaultLociKey':$('input#lociKey_value').removeClass("inputbox").addClass("inputbox invalid");$('p.error').append("<span ccmres=\"ccmKeyNotFoundError\"></span>");break;case'expired':$('input#lociKey_value').removeClass("inputbox").addClass("inputbox invalid");$('p.error').append("<span ccmres=\"ccmKeyExpiredError\"></span>");break;}}
function generateReturnLink(key){return"http://"+$.url.attr('host')+"/home.html?lociKey="+key+'&tafMailLinkId='+ccm.entry.sessionId;}