/******************************************
  errors
******************************************/
var Errors = {
	NOT_REGISTERED 		: 'The information entered is currently not registered with this site.  Please start creating an account by submitting your age to the left.',
	ALREADY_REGISTERED 	: 'This Email Address has been used by another account.  Please enter a new email address or login to the existing account.',
	INVALID_EMAIL 			: 'The Email Address entered is invalid.',
	ACCOUNT_DOESNT_EXIST : 'An account with the information you entered does not exist. Please note that registration on DisneyPhotoPass.com is separate from the Disney family of websites. Please <a href="registration_gate.aspx">create a new account</a> on our site to continue.',
	INVALID_PHOTOPASSID	: 'You have entered an invalid Disney\'s PhotoPass ID number.  Please try again.<br/><br/><span class="extratext">Learn how to <a href="javascript:LaunchWhatClaimingPP();">find your PhotoPass ID number</a>.</span>',
	REGISTERED_BADPHOTOPASS : 'Your account has been created, but the Disney\'s PhotoPass was invalid. Please log in from the homepage and try adding your PhotoPass again.',
	INVALID_LOGIN : 'The email address or password entered is invalid. Please check your information and try again.',
	SYSTEM_ERROR: 'We are currently experiencing technical difficulties. Please try again in a few minutes.',
	PHOTO_PASS_PASSWORD: 'It looks like you entered a photopass id for the password.  Would you like to create an account?'
} 
var _brandID = '100147';



/*********************
	generic stuff
*********************/
function deleteToken() {
	var date = new Date();  // current date & time
	date.setTime ( date.getTime() - 1 );
	document.cookie = "ezpUserToken=;expires=" + date.toGMTString();
	document.cookie = "site=;";
}

function getToken() {
	return getCookie('ezpUserToken');
}

function showCountryFields() {
	if ( $F('ShippingCountry') == 'USA' || $('ShippingCountry').value == '') {
		Element.show('domestic');
		Element.hide('international');
		Element.hide('canada');
		$('CityLabel').innerHTML = 'City:'
	}
	else if ( $F('ShippingCountry') == 'CAN' ) {
		Element.hide('domestic');
		Element.hide('international');
		Element.show('canada');
		$('CityLabel').innerHTML = 'City:'
	}
	else {
		Element.hide('domestic');
		Element.show('international');
		Element.hide('canada');
		$('CityLabel').innerHTML = 'City / Post Town:'
	}
}

function setEmail()
          {
          var eml = getCookie('eml');
          var bUndefined = false;
          if (eml == 'undefined')
            bUndefined = true

          if (bUndefined == true)
          {
          $('login_username').value = '';
          }
          else
          $('login_username').value = eml;
          }

/*********************
	header stuff
*********************/

function doSignOut() {
	var yesBtn = '<a href="" onclick="return doSignOutNow();" style="border:0px"><img width="82px" height="22px" class="yesBtn" src="/skins/100147/resources/images/editor/blank.gif" border="0" onmouseover="this.style.backgroundPosition=\'0px -645px\'" onmouseout="this.style.backgroundPosition=\'0px -620px\'"></a>';
	var noBtn = '<a href="" onclick="return doModalEnd(\'alertsignout\');" style="border:0px"><img width="82px" height="22px" class="noBtn" src="/skins/100147/resources/images/editor/blank.gif" border="0" onmouseover="this.style.backgroundPosition=\'0px -694px\'" onmouseout="this.style.backgroundPosition=\'0px -669px\'"></a>';

	var html = 'Are you sure you want to Sign Out?<br/><br/> ' + yesBtn + noBtn;

	doPopover('alertsignout', 'Sign Out', html);

	return false;
}

function doSignOutNow() {
    // sdk call
    setTimeout('completeLogoff();', 100);
	ezpJcmSdk.logOffDisney( getToken(), EZP.util.Callback(null,completeLogoff) );
	return false;
}

function completeLogoff() {
	deleteToken();

	location.href="http://" + _domain + "/default.aspx";
	return false;
}


//  handle enter key on form, used by default.aspx and registration_gate
function handleEnter(e) {

	if ( $('login_username').value != "" || $('login_password').value != "") {
		var bEnterPressed = false;
		if ( window.event ) {
			if (window.event.keyCode == 13) { bEnterPressed = true; }
		}else if (e.which) {
			if (e.which == 13) { bEnterPressed = true; }
		}
		if (bEnterPressed) {
    		loadLoadingMask("Loading.  Please Wait...");
		    doSignIn(); }
	    }
	return false;
}

function doSignIn() {

	//$("btnSignIn").innerHTML = "Please Wait...";

	var user=$("login_username").value;
	var password=$("login_password").value;

	// sdk call
    ezpJcmSdk.loginDisney( BrandId, user, password, EZP.util.Callback(null, completeLoginSuccess, completeLoginFailed) );

	return false;
}

function completeLoginSuccess(obj) {
	setToken(obj);

	ezpRegistrationSdk.getContact( obj, EZP.util.Callback(null,doLoginSuccess) );

	return false;
}

function doLoginSuccess(obj)
{

    document.cookie = 'eml=' + obj.Email + '; expires=Fri, 31 Dec 2012 23:59:59 GMT;';

    document.cookie = 'as=' + obj.CustomData1;
    document.cookie = 'sb=0';
    document.cookie = 'page=1';
    //alert(getCookie('siteReferrer'));
    var toURL = getCookie('toURL');
      document.cookie = 'toURL=' ;

    if (toURL == '')
        toURL = 'photoalbum.aspx';


//    if (_domain.length > 0 )
//	    location.href= 'http://' + _domain + toURL;
//	else
	    location.href= toURL;
	return false;
}

function completeLoginFailed(obj) {

	switch (obj.status) {
		case '999' :
		default :
		    if (obj._message == 'Invalid Password')
			    location.href='registration_gate.aspx?error=IP';
			else if (obj._message == 'System Error')
			      location.href='registration_gate.aspx?error=SE';
			else if (obj._message == 'Photopass Password')
			      location.href='registration_gate.aspx?error=PP';
			else if (obj._message == 'User Not Found')
			    location.href='registration_gate.aspx?error=NF';
            else
                location.href='registration_gate.aspx?error=SE';
	}
	return false;
}

function setToken(obj) {
	document.cookie = 'ezpUserToken=' + obj + '; path=/;';
	//alert(document.cookie);
}

function getSite()
{
    var as = getCookie('as');
   
    return as;
}

function getBrand()
{
var site = getCookie('site');
if (site == 'Default')
{
    site = getCookie('as');
    document.cookie = 'site=' + site;
}

if (site == '')
    site = 'Default';

  
    return site;
}

function getAffinity(theToken)
{
     ezpJcmSdk.getAccountAffinity( theToken, EZP.util.Callback(null, setAffinity, FailResultAd) );
}
function setAffinity(obj)
{
     
     document.cookie = 'as=' + obj;
}

/*********************
	from footer
*********************/
var windowReference;
function LaunchHelp() {
	window.open ('http://' + _domain + '/skins/100147/help/helpmain.htm', 'help');
}
function LaunchWhatPhotoPass() {
	window.open ('http://' + _domain + '/skins/100147/help/producthelp_photopass.htm', 'help');
}
function LaunchWhatPromoCode() {
	window.open ('http://' + _domain + '/skins/100147/help/placingorder_help.htm', 'help');
}
function LaunchWhatStoragePolicy() {
	window.open ('http://' + _domain + '/skins/100147/help/Policies_Help.htm#storage', 'help');
}
function LaunchPhotoMovieHelp() {
	window.open ('http://' + _domain + '/skins/100147/help/producthelp_movie.htm', 'help');
}

function LaunchDisneyCredit()
{
	LaunchHelper('PlacingOrder_Help.htm');
}

function LaunchWhatShipping() {
	window.open ('http://' + _domain + '/skins/100147/help/OrderInfo_Shipping.htm', 'help');
}
function LaunchWhatUpload() {
	window.open ('http://' + _domain + '/skins/100147/help/uploadhelp.htm', 'help');
}
function LaunchWhatClaimingPP() {
	window.open ('http://' + _domain + '/skins/100147/help/accounthelp_gettingstarted.htm#claiming', 'help');
}

function LaunchWhatJavascript() {
	window.open ('http://' + _domain + '/skins/100147/help/JavaScript_Help.htm', 'help');
}
function LaunchContactUs() {
	window.open ('http://' + _domain + '/skins/100147/forms/contact_us_form.aspx', 'contactus');
}
function LaunchLostPhotoPass() {
	window.open ('/skins/100147/forms/lost_photopass.aspx', 'lostphotopass');
}

function LaunchWhatPhotoTips() {
          window.open ('/skins/100147/help/phototips.htm', 'help');
          }

function LaunchTerms() {
	window.open ('http://' + _domain + '/skins/100147/forms/terms_frm.htm', 'terms');
}

function LaunchPrivacyPolicy() {
	window.open ('http://' + _domain + '/skins/100147/forms/privacypolicy_frm.htm', 'privacypolicy');
}

function LaunchAboutUs()
{
    window.open ('http://' + _domain + '/aboutdpp.aspx', '_blank');
    

}
function LaunchHelp2() {
	window.open ('/skins/100147/help/helpmain.htm', 'help');
}
function uploadPhotoHtml(){
   
	window.open("/upload/upload.aspx?AccountId=" + accountID, "htmlPopupUploader",
	"width=780,height=670,location=0,status=0,menubar=0,toolbar=0,resizable=0");
}

function LaunchFlashBuilderHelp(obj)
{


    switch (obj.toLowerCase())
        {
            case 'foldedcards':
                LaunchHelper('producthelp_card.htm#building_folded');
                break;
            case 'photomovie':
                LaunchPhotoMovieHelp();
                break;
            case 'photobook':
                LaunchHelper('producthelp_book.htm');
                break;
            case 'flatcard':
                LaunchHelper('producthelp_card.htm');
                break;
            case 'editor':
                LaunchHelper('ViewingPhotos_Help.htm#editing');
                break;
            case 'photoshare':
                LaunchHelper('ViewingPhotos_Help.htm#sharing');
                break;
            case 'photomug':
                LaunchHelper('producthelp_mug.htm');
                break;
            case 'photoshirt':
                LaunchHelper('producthelp_shirt.htm');
                break;
           case 'mousepad':
                LaunchHelper('producthelp_mouse_pad.htm');
                break;
            case 'chromaluxe':
                LaunchHelper('producthelp_DisPlay.htm');
                break;
            case 'canvasprints':
                LaunchHelper('producthelp_Canvas.htm');
                break;
            case 'calendar':
                LaunchHelper('ProductHelp_Calendar.htm');
                break;
            case 'ornament':
                LaunchHelper('ProductHelp_Ornament.htm');
                break;
           default:
                LaunchHelper('helpmain.htm');
                break;
           
           
        }
        
}

function LaunchFoldedCardsHelp() {
	window.open ('/skins/100147/help/help.htm?helpfile=producthelp_card.htm#building_folded', 'help');
}

function LaunchHelper(obj)
{
	window.open ('/skins/100147/help/help.htm?helpfile=' + obj, 'help');
}

/*********************
  pop-over divs
*********************/
function doPopover(sId, sTitle, sContent){
    doPopoverNew(sId, sTitle, sContent,true);
}
function doPopoverNew(sId, sTitle, sContent, bLoadClose){
    doPopoverStyled(sId, sTitle, sContent, bLoadClose, '')
}

function doPopoverStyled(sId, sTitle, sContent, bLoadClose, styleId){
var sClose = '<img src="' + closebtn.src + '" border="0" alt="Close" onclick="return doModalEnd(\'' + sId + '\');" onmouseover="this.src=closebtn_on.src;" onmouseout="this.src=closebtn.src;" />';

if (!bLoadClose)
    sClose = '';
        if (styleId != '')
            styleId = ' ' + styleId;
	if ( typeof($(sId)) == 'undefined' ) {	// create it
		var s = '';
		s+='<div id="' + sId + '" class="popover' + styleId + '">\n';
		s+='<div class="dialog">\n';
		s+='<div class="hd"><div class="close">' + sClose + '</div></div>\n';
		s+='<div class="bd" style="background:none;background-color:#ffffff">\n';
		s+='<div class="c">\n';
		s+='<div class="s">\n';
		s+='<div class="title">' + sTitle + '</div>\n';
		s+= sContent;
		s+='</div>\n';
		s+='</div>\n';
		s+='<div class="ft"><div class="c"></div></div>\n';
		s+='</div>\n';
		s+='</div>\n';
		s+='</div>\n';

		var popopver = document.createElement('div');
		//popopver.setAttribute('id',sId );


		//$('content').appendChild(popopver);
		var objBody = document.getElementsByTagName("body").item(0); // needs to be on the body so it doesn't get hidden
		//alert(sContent);
		objBody.appendChild(popopver);
        popopver.innerHTML = s;
		// for Y drag n drop, not using
		//var dd1 = new YAHOO.util.DD(sId);
	}

	doModal(sId);

	return false;
}

function doPopoverQuiltStyled(sId, sTitle, sContent, bLoadClose, styleId){
var sClose = '<img src="' + closebtn.src + '" border="0" alt="Close" onclick="return doModalEnd(\'' + sId + '\');" onmouseover="this.src=closebtn_on.src;" onmouseout="this.src=closebtn.src;" />';

if (!bLoadClose)
    sClose = '';
        if (styleId != '')
            styleId = ' ' + styleId;
	if ( typeof($(sId)) == 'undefined' ) {	// create it
		var s = '';
		s+='<div id="' + sId + '" class="popover' + styleId + '">\n';
		s+='<div class="dialog">\n';
		s+='<div class="hd"><div class="close">' + sClose + '</div></div>\n';
		s+='<div class="bd" style="background:none;background-color:#ffffff">\n';
		s+='<div class="c">\n';
		s+='<div class="s">\n';
		s+='<div class="title">' + sTitle + '</div>\n';
		s+= sContent;
		s+='</div>\n';
		s+='</div>\n';
		s+='<div class="ft"><div class="c"></div></div>\n';
		s+='</div>\n';
		s+='</div>\n';
		s+='</div>\n';

		var popopver = document.createElement('div');
		//popopver.setAttribute('id',sId );


		//$('content').appendChild(popopver);
		var objBody = document.getElementsByTagName("body").item(0); // needs to be on the body so it doesn't get hidden
		//alert(sContent);
		objBody.appendChild(popopver);
        popopver.innerHTML = s;
		// for Y drag n drop, not using
		//var dd1 = new YAHOO.util.DD(sId);
	}

	doModal(sId);

	return false;
}

function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
}

//=============================================================================
// Image Preloader
function ImagePreloader(images,callback)
{
	// store the callback
	this.callback = callback;

	// initialize internal state.
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.aImages = new Array;

	// record the number of images.
	this.nImages = images.length;

	// for each image, call preload()
	for ( var i = 0; i < images.length; i++ )
		this.preload(images[i]);
}
ImagePreloader.prototype.preload = function(image)
{
	// create new Image object and add to array
	var oImage = new Image;
	this.aImages.push(oImage);

	// set up event handlers for the Image object
	oImage.onload = ImagePreloader.prototype.onload;
	oImage.onerror = ImagePreloader.prototype.onerror;
	oImage.onabort = ImagePreloader.prototype.onabort;

	// assign pointer back to this.
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;
	oImage.source = image;

	// assign the .src property of the Image object
	oImage.src = image;
}
ImagePreloader.prototype.onComplete = function()
{
	this.nProcessed++;
	if ( this.nProcessed == this.nImages )
		this.callback(this.aImages);
}
ImagePreloader.prototype.onload = function()
{
	this.bLoaded = true;
	this.oImagePreloader.nLoaded++;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onerror = function()
{
	this.bError = true;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onabort = function()
{
	this.bAbort = true;
	this.oImagePreloader.onComplete();
}
var sId = '';
var sTitle = '';

function doPromoPopoverButtons(sId1, sTitle1, sContent,sButtons){
    
    if (sTitle1 != 'Learn More')
        sId = sId1 + String(Math.floor(Math.random()*1000001));
    else
        sId = sId1;
    sTitle = sTitle1;
    doHBPV('HtmlPhotoPrintsPromoPage');
   
       //     var oImage = new Image;
       //     oImage.src = sContent;
     //  sButtons="<a href='?coupon=test'  class='butn'>Apply $30 Coupon</a>&nbsp;<a href='#' class='butn'>Apply 20% off Coupon</a>&nbsp;<a href='#' class='butn'>Continue</a>";
    
    setTimeout('onPreloadPromo("' + sContent + '","' + sButtons + '")',100);
         //   onPreloadPromo(sContent);
   

  }
function doPromoPopover(sId1, sTitle1, sContent){
    
    doPromoPopoverButtons(sId1, sTitle1, sContent,'');
}
function onPreloadPromo(aImages,buttons)
{
    
    if (sTitle == '')
        sTitle = '&nbsp;';
	if (buttons !='')
	    {
	        buttons = '<div style="margin-top:-135px;padding-bottom:110px;" class="promopopoverbuttons"><table width="480px"><tr><td align="center">' + buttons + '</td></tr></table></div>';
	    }
	if ( typeof($(sId)) == 'undefined' ) {	// create it
		var s = '';
		s+='<div id="' + sId + '" class="promopopover">\n';
		s+='<div class="dialog">\n';
		s+='	<div class="hd"><div class="close"><img src="' + closebtn.src + '" border="0" alt="Close" onclick="return doModalEnd(\'' + sId + '\');" onmouseover="this.src=closebtn_on.src;" onmouseout="this.src=closebtn.src;" /></div></div>\n';
		s+='	<div class="bd">\n';
		s+='		<div class="c">\n';
		s+='			<div class="s" style="padding-bottom:0px;">\n';
		s+='				<div class="title">' + sTitle + '</div>\n';
		s+='<div style="padding-top:20px;"><img class="promodetails" id="promoimage1" src="' + aImages + '" /><div class="clearboth"></div></div>';
        s+=buttons;		
		s+='			</div>\n';
		s+='		</div>\n';
		s+='		<div class="ft"><div class="c"></div></div>\n';
		s+='	</div>\n';
		s+='</div>\n';
		s+='</div>\n';

		var popopver = document.createElement('div');
		var objBody = document.getElementsByTagName("body").item(0); // needs to be on the body so it doesn't get hidden
		objBody.appendChild(popopver);
		popopver.innerHTML = s;


		// for Y drag n drop, not using
		//var dd1 = new YAHOO.util.DD(sId);
	}

	doModal(sId);

	return false;
}
function closeme()
{
    doModalEnd('promodisplay');
}
function doModalEnd(popupId) {

	if (typeof($(popupId))!='undefined') {
		Element.hide(popupId);
		
	}

	new Effect.Fade('modal', { duration: 0.2});
	showSelectBoxes();

	return false;
}
function doModalEndRemove(popupId) {

	if (typeof($(popupId))!='undefined') {
		Element.hide(popupId);
		$(popupId).innerHTML = '';
	}

	new Effect.Fade('modal', { duration: 0.2});
	showSelectBoxes();

	return false;
}



function doModal(popupId) {

	hideSelectBoxes();

	// create it
	if ( typeof($('modal')) == 'undefined' ) {
		var objBody = document.getElementsByTagName("body").item(0);
		var modalOverlay = document.createElement("div");
		modalOverlay.setAttribute('id','modal');
		modalOverlay.style.display = 'none';
		modalOverlay.onclick = function() { return false; }	// disable clicks
		objBody.appendChild(modalOverlay);
	}
	else
        {
	    new Effect.Fade('modal',{ duration: 0.1, from: 0.0, to: 0.8 });
        var date = new Date();
        varcurDate = null;
        
        do {curDate = new Date();}
        while (curDate-date < 400);
        }

	// get page size and scroll
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();


	// stretch overlay to fill page and fade in
	Element.setHeight('modal', arrayPageSize[1]);

	// do modal effect
	new Effect.Appear('modal', { duration: 0.4, from: 0.0, to: 0.8 });

	// calculate top offset for the dialog
	var boxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);
	Element.setTop(popupId, boxTop);

	// calculate left offset for the dialog
	var boxLeft = (arrayPageSize[2] - 500) / 2;
	Element.setLeft(popupId, boxLeft);

	// show it
	Element.show(popupId);

	return false;
}


function doMiniEditor(imageId,imageType){
	window.open('photoeditor_popup.aspx?imageId=' + imageId + '&imageType=' + imageType, 'photoeditor_popup', 'resizable,scrollbars,width=500,height=600');
	return false;
}

function doZoom(imageId,imageType){
	window.open('photostore_zoom.aspx?imageId=' + imageId + '&imageType=' + imageType, 'photostore_zoom', 'resizable,scrollbars,width=500,height=600');
	return false;
}

function doCartZoom(imageId,imageType, sku){
	switch( imageType.toUpperCase() ) {
		case 'PROFESSIONAL' :
			//window.open('photoeditor_popup.aspx?from=cart&imageId=' + imageId + '&imageType=' + imageType, 'photoeditor_popup', 'resizable,scrollbars,width=500,height=600');
			window.open('cart_zoom.aspx?imageId=' + imageId + '&imageType=' + imageType + '&sku=' + sku, 'cart_zoom', 'resizable,width=400,height=480');
			break;
		case 'STOCK' :
			window.open('cart_zoom.aspx?imageId=' + imageId + '&imageType=' + imageType + '&sku=' + sku, 'cart_zoom', 'resizable,width=400,height=480');
			break;
	}
	return false;
}

function doPopupLink(thelink) {
	if (window.opener) {
		window.opener.location.href = thelink.href;
		window.close();
	}
	else {
		return true;
	}
	return false;
}

/*********************
	Date stuff
*********************/
function frmtDate(sDate, sRetIfNotDate){

  var sRet = new String();
  var date = new Date(String(sDate));

  if (date.toString() == 'NaN' || sDate == '') {
    if (arguments.length > 1) {

      sRet = sRetIfNotDate;
    }
    else {

      sRet = '';
    }
  }
  else {
    sRet += getDisplayNumber(date.getMonth()+1) + "/";
    sRet += getDisplayNumber(date.getDate()) + "/";
    sRet += getDisplayNumber(date.getFullYear());
  }
  return sRet;
}

function formatDate(sDate, sRetIfNotDate){

  var sRet = new String();
  var temp = new Array();
  temp = sDate.split('T');

  var sTemp = new String();
  sTemp = temp[0];

  sTemp = sTemp.replace(/-/g,"/");

  var date = new Date(String(sTemp));
  if (date.toString() == 'NaN' || sDate == '') {
    if (arguments.length > 1) {

      sRet = sRetIfNotDate;
    }
    else {

      sRet = '';
    }
  }
  else {
    sRet += getDisplayNumber(date.getMonth()+1) + "/";
    sRet += getDisplayNumber(date.getDate()) + "/";
    sRet += getDisplayNumber(date.getFullYear());
  }
  return sRet;
}

function getDisplayNumber(iNumber) {
   var sNumber = (iNumber <= 9) ? "0" + iNumber : "" + iNumber;
   return sNumber;
}


/************************************************
	create a class to cache the image list
	NOTE: be sure to check isLoaded before using
*************************************************/
function PhotoList(imgType) {
	// PRIVATE Variables And Functions
	// only Priveleged Methods may view/edit/invoke
	var _images = null;
	var _index = -1;
	var _loaded = false;
	var _imgType = imgType;

	function cb(obj) {
		_images = obj;
		_loaded = true;
	}

	function cbFail(obj) {
		alert(obj.statusText);
	}

	// PRIVILEGED Methods
	// may be invoked publicly and may access private items
	// may not be changed; may be replaced with public flavors
	this.initialize = function() {
		ezpJcmSdk.imagesGet(getToken(), imgType.toUpperCase(), EZP.util.Callback(this, cb, cbFail));
	}

	this.getPhotoById = function(imgId) {
		for (var i=0; i<_images.length; i++) {
			if (_images[i].ImageId == imgId) {
				return _images[i];
				break;
			}
		}
		return null;
	}

	this.getPhotoByIndex = function(pos) {
		if (pos > -1 && pos < _images.length) {
			return _images[pos];
		}
		else {
			return null;
		}
	}

	this.getIndex = function(imgId) {
		var retVal = -1;
		for (var i=0; i<_images.length; i++) {
			if (_images[i].ImageId == imgId) {
				retVal = i;
				break;
			}
		}
		return retVal;
	}

	this.getListLength = function() {
		return _images.length;
	}

	this.isLoaded = function() {
		return _loaded;
	}

	this.initialize();
}



/*********************
	?
*********************/
function doLeavingSite(sURL) {
    var sId = 'leaving';
    var sTitle = 'DisneyPhotoPass.com';
    var sContent = 'The website you are about to link to is not controlled by <i>Disney\'s PhotoPass</i> Service and different Terms & Conditions and Privacy Policy may apply. By proceeding you agree and understand that DisneyPhotoPass.com is not responsible for the site you are about to access.<br/><br/><a href="' + sURL + '" class="butn">Continue To Site</a>';
    doPopover (sId, sTitle, sContent);
}


function isValidDisneyEmail(str) {
	// check that regular expressions are supported
	var bSupported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) {
			bSupported = 1;
		}
	}
	if (!bSupported) {
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	}

	// special check for disney
	if ( str.match('@photopass.com') ) {
		return false;
	}

	var re = /^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/;



	return re.test(str);
}


function oldAccount()
{
    var s;
    s =  '<div style="height:400px;overflow: auto;padding-right:10px;"><b>Welcome Back!</b><br/><br/>';
    s += 'Exciting News: We have recently added more magic and launched an all new DisneyPhotoPass.com!<br/><br/>';
    s += '<span class="goldtext">Note: You do not need to re-register.  The account information you created on the previous version of our site is still valid at the new DisneyPhotoPass.com. To log in to your account, please Sign In using your existing email address and password on the upper right-hand corner of the main page under the header "Returning Guests."</span><br/><br/>';
    s += 'Once you\'re logged in, you can see, share and purchase prints of your <i>Disney\'s PhotoPass</i> photos as well as order Disney\'s Photo CD. Plus now you can upload your own photos and create Disney-themed keepsake products including Disney\'s PhotoCards and PhotoBook!<br/><br/>';
    s += 'Having problems accessing your account?  Here are some troubleshooting tips:<br/><br/>';
    s += '<ol><li><b>In general, you should not need to re-register or "re-claim" your photos.</b> Use your existing user name (email address) and password to sign in to the site as a returning guest.</li>';
    s += '<li><b>If you forgot the password associated with your account, please use the "Forgot Password" link.</b>  An email containing a temporary password will be sent to the email address that you registered with.  You should then be able to access your account by using your email address and the temporary password.</li>';
    s += '<li><b>If your old account was set up with an invalid or "fake" email address, note that we will not be able to send a password reset email to you.</b> If you are experiencing this problem, please use the "Contact Us" form and choose subject line "Account Questions" using a valid email address and let us know what address was used to set up your account.  We can then attempt to change your user name to the new, correct email address.</li></ol>';
    s += 'Note that any edits made to photos on the old version of the site will not carry over to the new site. Also note that items added to your shopping cart in the old site have been cleared; however, items that have already been purchased will not be impacted. If you have questions about orders placed on the old version of the site, please contact DisneyPhotoPass.com Guest Services.<br/><br/>'
    s += 'We hope you enjoy the new DisneyPhotoPass.com!</div>';

    doPopover('oldAccount', 'Returning To DisneyPhotoPass.com?',s) ;
}

function doHBLink(hblink)
{

    try{
    
        //setTimeout('_hbLink("' + hblink + '")',100);
    }
    catch(err)
    {
//alert('err' + hblink);
    }
}

function doHBPV(hbpageview)
{
    try
    {
        if (hbpageview.indexOf(':dpp',0) > 0)
        { 
s_omni.pageName=hbpageview;

s_omni.prop1= _prop1;

s_omni.hier1=hbpageview.replace('dpi:dpp:','');

//s_omni.channel="first_position_from_hierarchy";

s_omni.prop4=_prop4;

//s_omni.prop5="second_position_from_hierarchy";

//s_omni.prop6="third_position_from_hierarchy";
s_omni.prop14 = "dpi";
//alert(hbpageview);
        var s_code=s_omni.t();if(s_code)document.write(s_code)
}
    }
    catch(err)
    {

    }
}

function pardon()
{
	if (getCookie('ezpPardon')!='true')
	{
		doPopover('alertdpg', 'DisneyPhotoPass.com', '<center><img src="' + g_resourceFolder + 'images/pardon.jpg" /></center>') ;
		document.cookie = "ezpPardon=true";
	}
}


/******************************************
	disable right-click
******************************************/
function clickIE4(){
	if (event.button==2){
		return false;
	}
}
function clickNS4(e){
	if (document.layers||document.getElementById&&!document.all){
		if (e.which==2||e.which==3){
			return false;
		}
	}
}
var g_debug = ( String(QueryString("debug")) == "1" )  ? true : false;
if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
	document.onmousedown=clickIE4;
}
if ( !g_debug ) {
	document.oncontextmenu=new Function("return false")
}

function displayFender(rightfender, bottomfender)
{
   try
   {
    if (bottomfender != '')
        ezpDPPSdk.getAdAff('100147',bottomfender,'Fender3','', getBrand(), EZP.util.Callback(this,displaytheBottomFender,FailResultAd));
        }
        catch(err)
        {

        }

}

function displaytheRightFender(obj)
{

if (obj.length > 25)
    $('adFenderRight').style.display = 'block';

  $('adFenderRightInner').innerHTML = obj;
  //setTimeout('displayAd()',10000);
}


function displaytheBottomFender(obj)
{
try{
if (obj.length > 25)
    $('adFenderBottom').style.display = 'block';

  $('adFenderBottomInner').innerHTML = obj;
  //setTimeout('displayAd()',10000);
  }
  catch(err)
  {

  }
}



function FailResultAd(obj)
{

}


function loadAd(adID)
{
  //var cmld="ezpDPPSdk.getUCAffRulesFlash('100147','" + adID + "','','', getSite(),'','', EZP.util.Callback(this,displaytheAdFlash,FailResultAd))";
//  var cmd="ezpDPPSdk.getAdAff('100147','" + adID + "','','',getSite(),EZP.util.Callback(this,displaytheAd,FailResultAd));";
//  setTimeout(cmd,100);
EZP.Api.Presentation.Web.Ajax.DPP.getAdAffAcct('100147', adID,'','',getSite(),accountID,displaytheAd,FailResultAd);
}

function loadAdStyle(adID,styleclass)
{

  var cmd="ezpDPPSdk.getAdAff('100147','" + adID + "', '" + styleclass + "','',getSite(),EZP.util.Callback(this,displaytheAd,FailResultAd));";
  setTimeout(cmd,100);

}

function loadHeaderMenu(adID)
{
 var cmd="ezpDPPSdk.getAdTextAff('100147','" + adID + "','','',getSite(),EZP.util.Callback(this,displayHeaderMenu,FailResultAd));";
  setTimeout(cmd,100);

}

function displayHeaderMenu(obj)
  {
     $('prodmenu').innerHTML = obj;
  }
function loadAdText(adID)
{

  var cmd="ezpDPPSdk.getAdTextAff('100147','" + adID + "','','',getSite(),EZP.util.Callback(this,displaytheAdText,FailResultAd));";
  setTimeout(cmd,100);

}

function loadContentTileTop(adID)
{
  var cmd="ezpDPPSdk.getAdAff('100147','" + adID + "','','',getSite(),EZP.util.Callback(this,displaytheContentTileTop,FailResultAd));";
  setTimeout(cmd,100);
}


   function displaytheTLFender(obj)
          {

         
          if ($('adFenderTL') != null)
          {
             $('adFenderTL').style.display = 'block';

            $('adFenderTLInner').innerHTML = obj.HTMLAd;
            
               
          }
           checkFlashTile(obj);
        //  incrementCount();
          }
   function adisplaytheTLFender(obj)
          {

          if (obj.length > 25)
          if ($('adFenderTL') != null)
          {
             $('adFenderTL').style.display = 'block';

            $('adFenderTLInner').innerHTML = obj;
            
               
          }
        //  incrementCount();
          }
          function displaytheTRFender(obj)
          {

          if (obj.length > 25)
          $('adFenderTR').style.display = 'block';

          $('adFenderTRInner').innerHTML = obj;
         // incrementCount();
          }
          function displaytheMFender(obj)
          {

          if (obj.length > 25)
          $('adFenderM').style.display = 'block';

          $('adFenderMInner').innerHTML = obj;
       //   incrementCount();
          }

function incrementCount()
{
    loadedcount ++;
    if (loadedcount >2)
       // fo.write("flashcontent");
       setTimeout('fo.write("flashcontent")',1000);
}


function selectPhotoShirtSizes(projectId,action)
{
var myRand = String(Math.floor(Math.random()*1000001));
var sId = 'ShirtSizeSelector' + projectId + myRand ;
var msgBox = "Enter the desired quantity of each size.<br/><br/>";
msgBox += "<span class='goldtext' >Note: Changing all quantities to \"0\" will delete this Disney's PhotoShirt project from your cart.</span><br/><br/>";
msgBox += "<table align='center' ><tr class='headerrow'><td style='width:70px;'>Adult Sizes</td><td style='width:40px;'>Qty</td><td style='width:70px;'>Youth Sizes</td><td style='width:20px;'>Qty</td></tr>";
msgBox += "<tr><td>Adult S</td><td><input type='textbox' id='DpiShirtAdultS001' size='2'/></td><td>Youth S</td><td><input type='textbox' id='DpiShirtYouthS001' size='2'/></td></tr>";
msgBox += "<tr><td>Adult M</td><td><input type='textbox' id='DpiShirtAdultM001' size='2'/></td><td>Youth M</td><td><input type='textbox' id='DpiShirtYouthM001' size='2'/></td></tr>";
msgBox += "<tr><td>Adult L</td><td><input type='textbox' id='DpiShirtAdultL001' size='2'/></td><td>Youth L</td><td><input type='textbox' id='DpiShirtYouthL001' size='2'/></td></tr>";
msgBox += "<tr><td>Adult XL</td><td><input type='textbox' id='DpiShirtAdultXL001' size='2'/></td><td>Youth XL</td><td><input type='textbox' id='DpiShirtYouthXL001' size='2'/></td></tr>";
msgBox += "<tr><td>Adult XXL</td><td><input type='textbox' id='DpiShirtAdultXXL001' size='2'/></td><td>&nbsp;</td><td>&nbsp;</td></tr>";
msgBox += "<tr><td colspan='4' style='padding-top:15px;text-align:center'><a href='javascript:UpdateShirtSizes(\"" + projectId + "\", \"" + action + "\", \"\", " + myRand + ")' class='butn'>Continue</a> <a href='javascript: void();' onClick='return doModalEndRemove(\"" + sId + "\");' class='butn'>Cancel</a></td></tr>";
msgBox += "</table>";
msgBox += "<input type='hidden' id='oDpiShirtAdultS001' /><input type='hidden' id='oDpiShirtYouthS001'/>";
msgBox += "<input type='hidden' id='oDpiShirtAdultM001' /><input type='hidden' id='oDpiShirtYouthM001'/>";
msgBox += "<input type='hidden' id='oDpiShirtAdultL001' /><input type='hidden' id='oDpiShirtYouthL001'/>";
msgBox += "<input type='hidden' id='oDpiShirtAdultXL001' /><input type='hidden' id='oDpiShirtYouthXL001'/>";
msgBox += "<input type='hidden' id='oDpiShirtAdultXXL001' />";


doPopoverStyled(sId, 'Select PhotoShirt Sizes', msgBox, true, 'selectPhotoShirtSizes') ;

$('DpiShirtAdultS001').value = getCartValue ('DpiShirtAdultS001', projectId);
$('DpiShirtAdultM001').value = getCartValue ('DpiShirtAdultM001', projectId);
$('DpiShirtAdultL001').value = getCartValue ('DpiShirtAdultL001', projectId);
$('DpiShirtAdultXL001').value = getCartValue ('DpiShirtAdultXL001', projectId);
$('DpiShirtAdultXXL001').value = getCartValue ('DpiShirtAdultXXL001', projectId);
$('DpiShirtYouthS001').value = getCartValue ('DpiShirtYouthS001', projectId);
$('DpiShirtYouthM001').value = getCartValue ('DpiShirtYouthM001', projectId);
$('DpiShirtYouthL001').value = getCartValue ('DpiShirtYouthL001', projectId);
$('DpiShirtYouthXL001').value = getCartValue ('DpiShirtYouthXL001', projectId);



$('oDpiShirtAdultS001').value = $('DpiShirtAdultS001').value;
$('oDpiShirtAdultM001').value = $('DpiShirtAdultM001').value ;
$('oDpiShirtAdultL001').value = $('DpiShirtAdultL001').value ;
$('oDpiShirtAdultXL001').value = $('DpiShirtAdultXL001').value ;
$('oDpiShirtAdultXXL001').value = $('DpiShirtAdultXXL001').value ;
$('oDpiShirtYouthS001').value = $('DpiShirtYouthS001').value ;
$('oDpiShirtYouthM001').value = $('DpiShirtYouthM001').value ;
$('oDpiShirtYouthL001').value = $('DpiShirtYouthL001').value ;
$('oDpiShirtYouthXL001').value = $('DpiShirtYouthXL001').value ;


}


function getCartValue (sku, projectId)
{
  try{
  if ($(projectId + sku).value != null)
  {
    return $(projectId + sku).value * 1;
  }
  else
    return;
    }
  catch(err)
  {
    return '';
  }
}

function getCartUpdateValue (sku)
{

 if ($(sku).value != null)
  {
    return $(sku).value * 1;
  }
  else
    return;
}

function CartItemUpdate(projectId,qty,sku){
                this.ProjectId=projectId;
                this.Qty=Number(qty);
                this.Sku=sku;
}
 
function UpdateShirtSizes(projectId,action,zeroIt, myRand)
{

var CartUpdate=new EZP.Api.Presentation.Web.Ajax.CartQuantityUpdate();
  CartUpdate.Updates=new Array();
  CartUpdate.Token=_token;
var totalqty = 0;
var qty = 0;
var oqty = 0;
if (!zeroIt)
{
  qty = getCartUpdateValue('DpiShirtAdultS001'); 

oqty = getCartUpdateValue('oDpiShirtAdultS001'); 
}
totalqty += qty;

if (oqty != qty || (oqty == 0 && qty ==0))
    CartUpdate.Updates.push(new CartItemUpdate( projectId,qty,'DpiShirtAdultS001' ) );
    
if (!zeroIt)
{
  qty = getCartUpdateValue('DpiShirtAdultM001');
 oqty = getCartUpdateValue('oDpiShirtAdultM001');
 }
 totalqty += qty;
 
if (oqty != qty || (oqty == 0 && qty ==0))
CartUpdate.Updates.push(new CartItemUpdate( projectId,qty,'DpiShirtAdultM001' ) );
if (!zeroIt)
{
  qty =getCartUpdateValue('DpiShirtAdultL001');
oqty =getCartUpdateValue('oDpiShirtAdultL001');
}
totalqty += qty;
if (oqty != qty || (oqty == 0 && qty ==0))
CartUpdate.Updates.push(new CartItemUpdate( projectId,qty,'DpiShirtAdultL001') );
if (!zeroIt)
 {
  qty =getCartUpdateValue('DpiShirtAdultXL001');
oqty =getCartUpdateValue('oDpiShirtAdultXL001');
}
totalqty += qty;
if (oqty != qty || (oqty == 0 && qty ==0))
CartUpdate.Updates.push(new CartItemUpdate( projectId,qty,'DpiShirtAdultXL001') ); 
if (!zeroIt)
  {
  qty =getCartUpdateValue('DpiShirtAdultXXL001');
oqty =getCartUpdateValue('oDpiShirtAdultXXL001');
}
totalqty += qty;
if (oqty != qty || (oqty == 0 && qty ==0))
CartUpdate.Updates.push(new CartItemUpdate( projectId,qty,'DpiShirtAdultXXL001') ); 
if (!zeroIt)
 {   qty =getCartUpdateValue('DpiShirtYouthS001'); 
oqty =getCartUpdateValue('oDpiShirtYouthS001'); 
}
totalqty += qty;
if (oqty != qty || (oqty == 0 && qty ==0))
CartUpdate.Updates.push(new CartItemUpdate( projectId,qty,'DpiShirtYouthS001' ) );
if (!zeroIt)
 {   qty = getCartUpdateValue('DpiShirtYouthM001');
oqty = getCartUpdateValue('oDpiShirtYouthM001');
}
totalqty += qty;
if (oqty != qty || (oqty == 0 && qty ==0))
CartUpdate.Updates.push(new CartItemUpdate( projectId,qty,'DpiShirtYouthM001' ) );
if (!zeroIt)
 {
    qty =getCartUpdateValue('DpiShirtYouthL001');
oqty =getCartUpdateValue('oDpiShirtYouthL001');
}
totalqty += qty;
if (oqty != qty || (oqty == 0 && qty ==0))
CartUpdate.Updates.push(new CartItemUpdate( projectId,qty,'DpiShirtYouthL001') );
if (!zeroIt)
 {   qty =getCartUpdateValue('DpiShirtYouthXL001');
oqty =getCartUpdateValue('oDpiShirtYouthXL001');
}
totalqty += qty;
if (oqty != qty || (oqty == 0 && qty ==0))
CartUpdate.Updates.push(new CartItemUpdate( projectId,qty,'DpiShirtYouthXL001') ); 

if (totalqty == 0 && action == 'update' && zeroIt != true)
{
    var alertwindow = 'remove' + projectId;
    var yesBtn = '<a href="" onclick="UpdateShirtSizes( \'' + projectId + '\',\'update\',true, ' + myRand + ' ); return doModalEnd(\'' + alertwindow + '\');" style="border:0px"><img width="82px" height="22px" class="yesBtn" src="/skins/100147/resources/images/editor/blank.gif" border="0" onmouseover="this.style.backgroundPosition=\'0px -645px\'" onmouseout="this.style.backgroundPosition=\'0px -620px\'"></a>';  
    var noBtn = '<a href="" onclick="return doModalEnd(\'' + alertwindow + '\');" style="border:0px"><img width="82px" height="22px" class="noBtn" src="/skins/100147/resources/images/editor/blank.gif" border="0" onmouseover="this.style.backgroundPosition=\'0px -694px\'" onmouseout="this.style.backgroundPosition=\'0px -669px\'"></a>';
   doPopover(alertwindow, 'Remove from Cart', '<center>Are you sure you wish to remove the Disney\'s PhotoShirt from your cart?<br/><br/>' + yesBtn + noBtn + '</center>');
}
else
{
if (action == 'update')
  EZP.Api.Presentation.Web.Ajax.eCommerce.updateCartBulk(CartUpdate,removesuccess,FailResult,null);
else
  EZP.Api.Presentation.Web.Ajax.eCommerce.addToCartBulk(CartUpdate,removesuccess,FailResult,null);
if (myRand != null)
{
$('ShirtSizeSelector' + projectId + myRand).innerHTML = '';
doModalEnd('ShirtSizeSelector' + projectId + myRand);
}

 } 
  
}
function previewProducts(preview,imgPreview,popoverId,title,orientation)
 {
 var msg = '';
 var closeBtn = '<table style="width:400px;margin-top:20px;"><tr><td style="text-align:center;"><a href=\'javascript: void();\' onClick=\'return doModalEnd("' + popoverId + '");\' class=\'butn\'>Continue Shopping</a></td></tr></table>'; 
  switch(preview)
        {
            case 'dpigupmagnet001':
            case 'dpimagnet001':
            case 'dpipkg5x7magnet001':
                //msg = '<table ><tr><td><img src="' + imgPreview + '" /></td><td ><div style="float:left;margin-left:10px;margin-right:5px;"><b>Photo Magnet</b><br/>Product Information:<ul><li class="list">2.375" x 3.375"</li><li class="list">Photo print with magnetic backing</li><li class="list">Matte finish with rounded corners</li></ul></div></td></tr></table>';
                 backgroundposition = 'center center';
                iHeight = 235;
                iWidth = 167;
                if (orientation == 'Landscape')
                    {
                    iHeight = 167;
                    iWidth = 235;
                     backgroundposition = 'center center';
                     }
             
                  msg = '<table cellspacing="0" cellpadding="0" ><tr><td style="height:238px;"><div style="height: ' + iHeight + 'px; width: ' + iWidth + 'px; margin-bottom:-5px;background-image:url(\'' + imgPreview +'\');background-repeat:no-repeat;background-position:' + backgroundposition + ';"><img src="/skins/100147/resources/images/magnet-overlay-' + orientation + '.gif" /></td><td valign="top"><div style="float:left;margin-left:10px;padding-right:12px;padding-top:30px;"><b>Photo Magnet</b><br/>Product Information:<ul><li class="list">2.375" x 3.375"</li><li class="list">Photo print with magnetic backing</li><li class="list">Matte finish with rounded corners</li></ul><div style="padding-top:5px;margin-right:15px;" class="goldtext">Note: Final product will appear cropped as shown.</div></div></td></tr></table>';
            break;
            case 'dpiluggage001':
            case 'dpigupluggage001':
            case 'dpipkg5x7luggage001':
                iHeight = 251;
                iWidth = 167;
                backgroundposition = 'bottom center';
               if (orientation.toLowerCase() == 'landscape')
                {
                iHeight = 167;
                iWidth = 251;
                 backgroundposition = 'center right';
                 }
                  msg = '<table cellspacing="0 cellpadding="0" ><tr><td style="height:238px;"><div style="height: ' + iHeight + 'px; width: ' + iWidth + 'px; margin-bottom:-5px;background-image:url(\'' + imgPreview +'\');background-repeat:no-repeat;background-position:' + backgroundposition + ';"><img src="/skins/100147/resources/images/luggagetag-overlay-' + orientation + '.gif" /></td><td valign="top"><div style="float:left;margin-left:10px;padding-right:10px;padding-top:30px;"><b>Photo Luggage Tag</b><br/>Product Information:<ul><li class="list">2.3" x 3.5"</li><li class="list" >Back is blank to add personal info</li><li class="list">Durable plastic construction</li><li class="list">Rounded corners</li><li class="list">Flexible rubber strap</li></ul><div style="padding-top:5px;" class="goldtext">Note: Final product will appear cropped as shown.</div></div></td></tr></table>';
                //msg = '<table cellspacing="0" cellpadding="0" ><tr><td><table cellpadding="0" cellspacing="0" border="0"><tr><td style="margin-bottom:-5px;background-image:url(\'' + imgPreview +'\');background-repeat:no-repeat;background-position:' + backgroundposition + ';"><img src="/skins/100147/resources/images/luggagetag-overlay-' + orientation + '.gif"/></td></tr></table></td><td ><div style="float:left;margin-left:10px;"><b>Photo Magnet</b><br/>Product Information:<ul><li class="list">2.375" x 3.375"</li><li class="list">Photo print with magnetic backing</li><li class="list">Matte finish with rounded corners</li></ul></div></td></tr></table>';
            break;
             case 'dpigupsticker001':
             case 'dpipkg5x7sticker001':
             case 'dpisticker001':
                 backgroundposition = 'center center';
                iHeight = 235;
                iWidth = 167;
                if (orientation == 'Landscape')
                    {
                    iHeight = 167;
                    iWidth = 235;
                     backgroundposition = 'center center';
                     }
             
                  msg = '<table cellspacing="0" cellpadding="0" ><tr><td style="height:238px;"><div style="height: ' + iHeight + 'px; width: ' + iWidth + 'px; margin-bottom:-5px;background-image:url(\'' + imgPreview +'\');background-repeat:no-repeat;background-position:' + backgroundposition + ';"><img src="/skins/100147/resources/images/magnet-overlay-' + orientation + '.gif" /></td><td valign="top"><div style="float:left;margin-left:10px;padding-right:12px;padding-top:30px;"><b>Photo Sticker</b><br/>Product Information:<ul><li class="list">1.6" x 2.25" each</li><li class="list">1 sheet of 20 stickers</li><li class="list">Strong adhesive backing</li><li class="list">Matte finish</li><li class="list">Rounded corners</li></ul><div style="padding-top:5px;margin-right:15px;" class="goldtext">Note: Final product will appear cropped as shown.</div></div></td></tr></table>';
            break;
            
            case 'dpijpeg4x6001':
            case 'dpijpeg5x7001':
            case 'dpijpeg8x10001' :
                    title = 'Disney\'s PhotoDownload';
                  msg = '<table cellspacing="0" cellpadding="0" style="align:center;"><tr><td><img src="/skins/100147/resources/images/digitalpopover.gif" style="padding-left:30px;"/></td></tr></table>';
                break;                  
        }

    if (msg != '')
    {
    window.focus();
	var html = msg + closeBtn;
	doPopoverStyled(popoverId, title, html, true, 'ImagePreview' );
	}
	}
	
function adjustSKU(sku,style)
{
    var skuType = whatType(sku);
    if (skuType == 'glossy' && style == 'glossy')
        return sku;
    else if (skuType == 'matte' && style == 'glossy')
        return convertToGlossySku(sku);
    else if (skuType == 'matte' && style == 'matte')
        return sku;
    else
    {
        switch (sku)
        {
            case 'Dpi5x7001' :
	            return 'Dpi5x7Matte001';
	            break;
            case 'Dpi8x10001' :
	            return 'Dpi8x10Matte001';
	            break;
	        case 'Dpi4x6001' :
        	    return 'Dpi4x6Matte001';
	            break;
	        case 'DpiProTwo4x6001' :
        	    return 'DpiProTwo4x6Matte001';
	            break;
            case 'Dpi16x20001' :
        	    return 'Dpi16x20Matte001';
	            break;
	        case 'DpiPkg5x7Magnet001' :
                return 'DpiPkg5x7MatteMagnet001';
	            break;
	        case 'DpiPkg5x7Luggage001' :
                return 'DpiPkg5x7MatteLuggage001';
                break;
            case 'DpiPkg5x7Sticker001' :
                return 'DpiPkg5x7MatteSticker001';
                break;
            case 'DpiPkg001':
                return 'DpiPkgMatte001';
                break;
            case 'DpiJpegPkg4x6001':
                return 'DpiJpegPkg4x6Matte001';
                break;
            case 'DpiJpegPkg5x7001':
                return 'DpiJpegPkg5x7Matte001';
                break;
            case 'DpiJpegPkg8x10001':
                return 'DpiJpegPkg8x10Matte001';
                break;                
            default:
                return sku;
                break;
        }
    }
}

function whatType(sku)
{
    var mysku = sku.toLowerCase();
    if (mysku.indexOf('matte') > 0)
        return 'matte';
    else
        return 'glossy';
}

function convertToGlossySku(sku)
{
    return sku.replace('Matte','');
}

function translateCategoryName (catName, bHTML)
{
    switch (catName.toUpperCase())
    {
        case "PROFESSIONAL":
             if (bHTML)
                return "<i>Disney's PhotoPass</i> Photos";
             else
                return "Disney's PhotoPass Photos";
        break;
        
        case "GUEST":
             return "My Uploaded Photos";
             
        break;
        
        case "STOCK":
            return "Disney's Photo Gallery";        
        break;
        
        case "ABD":
            return "Adventures By Disney";
        
        default:
            return catName;
    }
    
}
function DisplayProduct(Description, Pic1, Pic2, Pic3, Feature1, Feature2, Feature3, Price, SKU)
{
    var myProduct = '<div id="productinfo"><div style="float:left;width:200px;"><img id="largepic' + SKU + '" src="' + Pic1 + '"></div>';
    myProduct = myProduct + '<div style="float:right;width:180px;"><div class="productdescription">' + Description + '</div>';
    myProduct = myProduct + '<div class="productfeatures">Product Features:</div>';
    myProduct = myProduct + '<ul class="twinkle2">';
    if (Feature1 != '')
        myProduct = myProduct + '<li class="smallfont">' + Feature1 + '</li>';
    if (Feature2 != '')
        myProduct = myProduct + '<li class="smallfont">' + unescape(Feature2) + '</li>';
    if (Feature3 != '')
        myProduct = myProduct + '<li class="smallfont">' + unescape(Feature3) + '</li>';    
    myProduct = myProduct + '</ul>';      
        
    myProduct = myProduct + '<div style="height:85px;"><div style="float:left;padding-top:13px;font-weight:bold;">Cost: $' + Price + '</div><div style="float:left;padding-left:5px;"><a href="" onclick="javascript:AddToCart(\'' + SKU + '\');doModalEnd(\'' + SKU + '\');return false;"><img border="0"  src="/skins/100147/resources/images/addtocartsmall.gif"/></a></div></div>';
    myProduct = myProduct + '<div style="margin-bottom:5px;clear:both;">CLICK TO VIEW LARGER:</div>';
    if (Pic1 != '')
        myProduct = myProduct + '<a href=\'javascript:changeImage("' + Pic1 + '", "largepic' + SKU + '")\'><img class="productsmallimage" src="' + Pic1 + '"/>';
    if (Pic2 != '')
        myProduct = myProduct + '<a href=\'javascript:changeImage("' + Pic2 + '", "largepic' + SKU + '")\'><img class="productsmallimage" src="' + Pic2 + '"/>';

    if (Pic3 != '')
        myProduct = myProduct + '<a href=\'javascript:changeImage("' + Pic3 + '", "largepic' + SKU + '")\'><img class="productsmallimage" src="' + Pic3 + '"/>';


    myProduct = myProduct + '</div><div style="clear:both">&nbsp;</div></div>';
    
    
   
    doPopoverStyled(SKU, 'Frames & More', myProduct,true,'productpopover') ;
    


}


function DisplayQuiltProduct(Description, Pic1, Pic2, Pic3, Feature1, Feature2, Feature3, Price, SKU, HtmlSnippet, Button1Text, Button1Target, Button2Text, Button2Target,
                                Sample1URI, Sample1Text, Sample2URI, Sample2Text, Sample3URI, Sample3Text, Sample4URI, Sample4Text, Sample5URI, Sample5Text, Sample6URI, Sample6Text, Sample7URI, Sample7Text, Sample8URI, Sample8Text)
{
    var safeDescription = Description.replace(/'/, "~");
    var unsafeDescription = Description.replace(/\^/gi, "\'");

    var myProduct = '<div id="productinfoquilt"><div style="float:left;width:50%;"><img class="productquiltlargeimage" id="largepic' + SKU + 'info' + '" src="' + Pic1 + '"></div>';
    myProduct = myProduct + '<div style="float:right;width:50%;"><div class="productdescription">' + unsafeDescription + '</div>';
    myProduct = myProduct + '<ul class="twinkle2">';

    if (Feature1 != '')
        myProduct = myProduct + '<li class="smallfont">' + unescape(Feature1) + '</li>';
    if (Feature2 != '')
        myProduct = myProduct + '<li class="smallfont">' + unescape(Feature2) + '</li>';
    if (Feature3 != '')
        myProduct = myProduct + '<li class="smallfont">' + unescape(Feature3) + '</li>';    
    myProduct = myProduct + '</ul>';      
        
    myProduct = myProduct   + '<div ><div>' + HtmlSnippet 
                            + '</div><br>';

    myProduct = myProduct + '<div style="text-align:left;padding-left:5px;">';    

    if(Feature1 != '')
        Feature1 = Feature1.replace(/\"/,'~');

                                                          
    if(Button1Target != '')
    {            
        // wire up a call to DisplayQuiltSamples      
        var sLaunchDesignView = "onclick=\"doModalEnd(\'" + SKU + "info\');DisplayQuiltSamples('" 
                                                                        + safeDescription + "','" 
                                                                        + Pic1 + "','"
                                                                        + Pic2 + "','"
                                                                        + Pic3 + "','"
                                                                        + escape(Feature1) + "','"
                                                                        + escape(Feature2) + "','"
                                                                        + escape(Feature3) + "','"
                                                                        + Price + "','"
                                                                        + SKU + "','"
                                                                        + escape(HtmlSnippet) + "','"
                                                                        + Button1Text + "','"
                                                                        + Button1Target + "','"
                                                                        + Button2Text + "','"
                                                                        //+ escape(Button2Target) + "','"
                                                                        + Button2Target + "','"
                                                                        + escape(Sample1URI) + "','"
                                                                        + Sample1Text + "','"
                                                                        + escape(Sample2URI) + "','"
                                                                        + Sample2Text + "','"
                                                                        + escape(Sample3URI) + "','"
                                                                        + Sample3Text + "','"
                                                                        + escape(Sample4URI) + "','"
                                                                        + Sample4Text + "','"
                                                                        + escape(Sample5URI) + "','"
                                                                        + Sample5Text + "','"
                                                                        + escape(Sample6URI) + "','"
                                                                        + Sample6Text  + "','"
                                                                        + escape(Sample7URI) + "','"
                                                                        + Sample7Text  + "','"
                                                                        + escape(Sample8URI) + "','"
                                                                        + Sample8Text + "');return false;\"";
                
        myProduct = myProduct + '<a href= "#" ' + sLaunchDesignView + ' class=\'butnthin2\'>' + Button1Text + '</a>';

    }                             

    if(Button2Target != '')        
        myProduct = myProduct + ' <a href="' + Button2Target + '" onclick=\"doModalEnd(\'' + SKU + 'info\');\" class=\'butnthin2\'>' + Button2Text + '</a>';


    myProduct = myProduct + '</div>';
    myProduct = myProduct + '<div style="height:60px;"></div>';
    myProduct = myProduct + '<div style="margin-bottom:5px;clear:both;">ALTERNATE VIEWS:</div>';
    if (Pic1 != '')
        myProduct = myProduct + '<a style="border:none;" href=\'javascript:changeImage("' + Pic1 + '", "largepic' + SKU + 'info' + '")\'><img class="productsmallimage" src="' + Pic1 + '"/>';
    if (Pic2 != '')
        myProduct = myProduct + '<a style="border:none;" href=\'javascript:changeImage("' + Pic2 + '", "largepic' + SKU + 'info' + '")\'><img class="productsmallimage" src="' + Pic2 + '"/>';

    if (Pic3 != '')
        myProduct = myProduct + '<a style="border:none;" href=\'javascript:changeImage("' + Pic3 + '", "largepic' + SKU + 'info' + '")\'><img class="productsmallimage" src="' + Pic3 + '"/>';


    myProduct = myProduct + '</div><div style="clear:both">&nbsp;</div></div>';
      
    doPopoverQuiltStyled(SKU + 'info', 'Photo Products', myProduct,true,'productpopoverquilt') ;
}

function DisplayQuiltSamples(Description, Pic1, Pic2, Pic3, Feature1, Feature2, Feature3, Price, SKU, HtmlSnippet, Button1Text, Button1Target, Button2Text, Button2Target,
                                Sample1URI, Sample1Text, Sample2URI, Sample2Text, Sample3URI, Sample3Text, Sample4URI, Sample4Text, Sample5URI, Sample5Text, Sample6URI, Sample6Text, Sample7URI, Sample7Text, Sample8URI, Sample8Text)
{

//    var safeDescription = Description.replace(/\'/gi,"^");
    var safeDescription = Description.replace(/'/, "^");
    var unsafeDescription = "Product Details"; // Description.replace(/\^/gi, "\'");

    // large image centered at the top 
    var myProduct               = '<div id="productinfoquiltsample" ><img class="productquiltlargeimage" id="largepic' + SKU + 'sample' + '" src="' + Sample1URI + '"><br>';

    // small alternates centered next
    myProduct = myProduct       + '<div style="height:60px;text-align:center;clear:both;" >';  
    if (Sample1URI != '')
        myProduct = myProduct   + '<a style="border:none;" href=\'javascript:changeImage("' + Sample1URI + '", "largepic' + SKU + 'sample' + '")\'><img class="productsmallimagewide" src="' + Sample1URI + '"/>';
    if (Sample2URI != '')
        myProduct = myProduct   + '<a style="border:none;" href=\'javascript:changeImage("' + Sample2URI + '", "largepic' + SKU + 'sample' + '")\'><img class="productsmallimagewide" src="' + Sample2URI + '"/>';
    if (Sample3URI != '')
        myProduct = myProduct   + '<a style="border:none;" href=\'javascript:changeImage("' + Sample3URI + '", "largepic' + SKU + 'sample' + '")\'><img class="productsmallimagewide" src="' + Sample3URI + '"/>';
    if (Sample4URI != '')
        myProduct = myProduct   + '<a style="border:none;" href=\'javascript:changeImage("' + Sample4URI + '", "largepic' + SKU + 'sample' + '")\'><img class="productsmallimagewide" src="' + Sample4URI + '"/>';
    if (Sample5URI != '')
        myProduct = myProduct   + '<a style="border:none;" href=\'javascript:changeImage("' + Sample5URI + '", "largepic' + SKU + 'sample' + '")\'><img class="productsmallimagewide" src="' + Sample5URI + '"/>';
    if (Sample6URI != '')
        myProduct = myProduct   + '<a style="border:none;" href=\'javascript:changeImage("' + Sample6URI + '", "largepic' + SKU + 'sample' + '")\'><img class="productsmallimagewide" src="' + Sample6URI + '"/>';

    if (Sample7URI != '')
        myProduct = myProduct   + '<a style="border:none;" href=\'javascript:changeImage("' + Sample7URI + '", "largepic' + SKU + 'sample' + '")\'><img class="productsmallimagewide" src="' + Sample7URI + '"/>';

    if (Sample8URI != '')
        myProduct = myProduct   + '<a style="border:none;" href=\'javascript:changeImage("' + Sample8URI + '", "largepic' + SKU + 'sample' + '")\'><img class="productsmallimagewide" src="' + Sample8URI + '"/>';


    myProduct = myProduct       + '</div>';
    

    // buttons centered at the bottom
    myProduct = myProduct       + '<div style="text-align:center;padding-left:5px;padding-right:5px;">';

    // wire up a call to DisplayQuiltProduct  
    HtmlSnippet = HtmlSnippet.replace(/\'/gi,"&#34;");

        
    var sLaunchProdInfo = "onclick=\"doModalEnd(\'" + SKU + "sample\');DisplayQuiltProduct('" 
                                                                    + safeDescription + "','" 
                                                                    + Pic1 + "','"
                                                                    + Pic2 + "','"
                                                                    + Pic3 + "','"
                                                                    + escape(Feature1) + "','"
                                                                    + escape(Feature2) + "','"
                                                                    + escape(Feature3) + "','"
                                                                    + Price + "','"
                                                                    + SKU + "','"
                                                                    + HtmlSnippet + "','"
                                                                    + Button1Text + "','"
                                                                    + Button1Target + "','"
                                                                    + Button2Text + "','"
                                                                    //+ escape(Button2Target) + "');return false;\"";
                                                                    + Button2Target + "');return false;\"";
    
    myProduct = myProduct + '<a href= "#" ' + sLaunchProdInfo + ' class=\'butnthin2\'>' + unsafeDescription + '</a> | ';



//    myProduct = myProduct       + '<a href="' + unescape(Button2Target) + '" onclick="doModalEnd(\'' + SKU + 'sample' + '\');" class=\'butnthin2\'>' + Button2Text + '</a>';
    myProduct = myProduct       + '<a href="' + Button2Target + '" onclick="doModalEnd(\'' + SKU + 'sample' + '\');" class=\'butnthin2\'>' + Button2Text + '</a>';
                                + '</div>';

    myProduct = myProduct       + '<div style="clear:both"><br/>Additional designs may be available. Create a product to see the full selection.</div></div>';
       
    doPopoverQuiltStyled(SKU + 'sample', 'Photo Products', myProduct,true,'productpopoverquiltsample') ;
}



function changeImage(img,imgholder)
{
   $(imgholder).src = img; 
}

function checkFlashTile(obj)
{
if (obj.FlashFile != null)
{
   if (obj.FlashFile.length > 3 )
         {
          var fo = new FlashObject(obj.FlashFile, "flashBuilder", obj.FlashWidth, obj.FlashHeight, "9.0.00", "#ffffff", true);
          fo.addParam("wmode", "transparent");
          fo.addParam("menu", "false");
          fo.addParam("quality", "high");
          fo.addParam("loop",obj.FlashRepeat);
          fo.addParam("allowScriptAccess", "always");
          if(accountID != '')
            fo.addVariable("accountID",accountID);
          fo.write("flashcontent");
          }
  }
}          

function escapeHTML (str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}; 

/**
Opens the Jostens Virtual Photo Book
*/
function showVirtualBook(){
window.open("/flash/images/photobook/virtualbook/index.html", "virtualbook", "width=1000,height=600,location=0,status=0,menubar=0,toolbar=0,resizable=0");
}