

/******************************************************************/
/*                        customModalBox 1.0.0                    */
/* A modal box (inline popup), used to display content            */
/* loaded using AJAX, written for the mootools framework          */
/*         based on MOOdalBox written by                          */
/*         Razvan Brates, razvan [at] e-magine.ro                 */
/*                                                                */
/* mootools found at:                                             */
/* http://mootools.net/                                           */
/*                                                                */
/* Original code based on "Slimbox", by Christophe Beyls:         */
/* http://www.digitalia.be/software/slimbox                       */
/******************************************************************/

// Constants defined here can be changed for easy config / translation
// (defined as vars, because of MSIE's lack of support for const)

var _ERROR_MESSAGE = "Oops.. there was a problem with your request.<br /><br />" +
					"Please try again.<br /><br />" +
					"<em>Click anywhere to close.</em>"; // the error message displayed when the request has a problem

// The customModalBox object in its beauty
var customModalBox = {
	
	// init the customModalBox
	init: function (options) {
		

		// scan anchors for those opening a customModalBox
		this.anchors = [];
		$A($$('a')).each(function(el){
			// we use a regexp to check for links that 
			// have a rel attribute starting with "modalbox"
			if(el.rel && el.href && el.rel.test('^modalbox', 'i')) {
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		
		// add event listeners
		this.eventPosition = this.position.bind(this);
		
		// init the HTML elements
		// the overlay (clickable to close)
		this.overlay = new Element('div').setProperty('id','mb_overlay').injectInside(document.body);
		this.overlayFrame = new Element('iframe').setProperties({'id':'mb_frame', 'scrolling':'no', 'frameborder':'0'}).injectBefore(this.overlay);
		
		this.overlayFrame.setStyle('height','1px');
		
		// the center element
		this.center = new Element('div').setProperty('id', 'mb_center').setStyle('display','none').injectTop(document.forms[0]);
		this.header = new Element('div').setProperty('id', 'mb_header').injectInside(this.center);


		// the actual page contents
		this.contents = new Element('div').setProperty('id', 'mb_contents').injectInside(this.center);
		
		
		
		//this.caption = new Element('div').setProperty('id', 'mb_caption').injectInside(this.center);
		
		// This block may be unneccessary
		this.center.onclick = '';
		
				

	},


	position: function() {
		this.overlay.setStyles({top: '0px', height: Window.getScrollHeight()+'px'});
		this.overlayFrame.setStyles({top: '0px', height: Window.getScrollHeight()+'px'});
	},

	setup: function(open) {
		var elements = $A($$('object'));
		elements.extend($$(window.ActiveXObject ? 'select' : 'embed'));
		elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });
		var fn = open ? 'addEvent' : 'removeEvent';
		//window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
	},
	

	
	htmlBox: function(sContents, sHtml, sLinkTitle) {

		this.title = sLinkTitle;
		
		// create a unique classname based on passed title 
		// for outer container so we can style box with css
		// name format is "mb-{title}Modal"
		this.center.className = 'mb-'+this.title.replace(/ /g,'')+'Modal';		
		// set the box centered (optional if coded in CSS)
		if ((parseInt(this.center.getStyle('width'))/2) > 0) {
			var leftVal = '-'+(parseInt(this.center.getStyle('width'))/2)+'px';
		} else {
			var leftVal = (Math.abs(parseInt(this.center.getStyle('width'))/2))+'px';
		}
		this.center.setStyles({cursor: 'default', marginLeft: leftVal});
		
		
		// Set the modal top position (optional if hardcoded in CSS)
		
		this.top = Window.getScrollTop() + (Window.getHeight() / 15);
		this.center.setStyles({top: this.top+'px', display: ''});

		
		
		//Show overlay
		this.overlay.setStyle('opacity',0.7);
		this.overlayFrame.setStyle('opacity',0.1);
		
		if (sHtml) this.contents.setHTML(sHtml);
		if ($(sContents)) $(sContents).injectInside(this.contents);
		
		if ($('mb_close_link')) {
			$('mb_close_link').remove();
		}
		this.closelink = new Element('a').setProperties({id: 'mb_close_link', href: 'javascript: void(0);'}).injectInside(this.header);
		// attach the close event to the close button / the overlay
		this.closelink.onclick = this.close.bind(this);
		this.closelink.innerHTML = 'Close';
		
		this.position();
		
		//hide page contents for printing the modal only
		//must have .yt-NoPrint {display:none} in CSS
		//no print style is removed on modal close
		document.forms[0].getChildren().each(function(el) {
			if (el.id != "mb_center") {
				el.addClass('yt-NoPrint');
			}
		});
		this.closelink.addEvent('click', function() {
			document.forms[0].getChildren().each(function(el) {
				el.removeClass('yt-NoPrint');
			});
		});
		
	},

	
	close: function() {
		this.center.style.display = 'none';
		this.overlay.setStyle('opacity',0);
		this.overlayFrame.setStyle('opacity',0);
		this.overlayFrame.setStyle('height','1px');
		//this.setup(false);  //re-enable dropdowns, objects
		
		if ($$('.mb-TributeVideoModal #yt-flashcontent')) {
            $$('.mb-TributeVideoModal #yt-flashcontent').setHTML('');  //clear any videos that might be loaded
            }
		
		return false;
	}
		
};

// startup
Window.onDomReady(customModalBox.init.bind(customModalBox));




// Functions governing various modal boxes used throughout site



function modalClose() {		
		if($('mb_Title')) $('mb_Title').remove();
		if($('mb_Error')) $('mb_Error').remove();
		if($('mb_header')) $('mb_header').removeClass('yt-Panel-Primary');

		$('mb_center').style.display = 'none';
		
		$('mb_contents').getChildren()[0].remove();
		$('mb_overlay').setStyle('opacity',0);
		$('mb_frame').setStyle('opacity',0);		
}


function modalClose_() {		
		if($('mb_Title')) $('mb_Title').remove();
		if($('mb_Error')) $('mb_Error').remove();
		if($('mb_header')) $('mb_header').removeClass('yt-Panel-Primary');

		$('mb_center').style.display = 'none';
		
		$('mb_contents').getChildren()[0].remove();
		$('mb_overlay').setStyle('opacity',0);
		$('mb_frame').setStyle('opacity',0);
		window.location.reload(true); 		
}
function modalCloseLogin(){		
		if($('mb_Title')) $('mb_Title').remove();
		if($('mb_Error')) $('mb_Error').remove();
		if($('mb_header')) $('mb_header').removeClass('yt-Panel-Primary');

		$('mb_center').style.display = 'none';
		
		$('mb_contents').getChildren()[0].remove();
		$('mb_overlay').setStyle('opacity',0);
		$('mb_frame').setStyle('opacity',0);
		
		window.location.reload(true); 		
}

function setLocation(locatin)
{
        window.location=locatin;
        //window.reload();//COMDIFFRES: (this is commented to fix a defect in .com site by ankush)uncomment this
        //window.location.href="http://home.netscape.com/";
}


/*------------------------------------------------------------

Generates modal window with Tribute Video displayed

------------------------------------------------------------*/


function PopupVideo(swfsrc) {
	customModalBox.htmlBox('', '<div id="yt-flashcontent">Video flash here</div>', 'TributeVideo');
	var so = new SWFObject(swfsrc, 'yt-TributeVideo', '720', '480', '7', '#000000');	
	so.addParam("wmode", "transparent");
	so.write("yt-flashcontent");
}


/*------------------------------------------------------------

Generates modal window with photo slide show displayed

------------------------------------------------------------*/


function startSlideShow(sourceURL, startID) {

	customModalBox.htmlBox('', '<div id="yt-flashcontent">Photo show flash here</div>', 'SlideShow');

	var so = new SWFObject('http://www.yourtribute.com/assets/slideshows/photos/photosSlideShow.swf', 'yt-SlideShow', '512', '512', '7', '#000000');	//COMDIFFRES: (Remove absolute path of .net) absolute URL with yourtribute.net
	so.addVariable("xmlfile", EncodeUrl(sourceURL));	
	so.addVariable("startingPhotoID", startID);
	//so.addParam("wmode", "transparent");
	so.write("yt-flashcontent");
}


/*------------------------------------------------------------

Generates modal window with Gift Selection / Event image box injected

------------------------------------------------------------*/

function chooseThumb() {
	customModalBox.htmlBox('yt-ThumbSelection', '', 'Thumb'); 
	chooseThumbClose();
}

function chooseEventThumb() {
	customModalBox.htmlBox('yt-ThumbSelection', '', 'EventThumb'); 
	chooseThumbClose();
}


function chooseThumbClose() {
	$('mb_close_link').addEvent('click', function() {
		$('yt-ThumbSelection').injectInside('yt-ThumbContainer');
	});
}



/*------------------------------------------------------------

Generates modal window with Contact Info (to be passed in via AJAX)

------------------------------------------------------------*/

function UserProfileModal() {		
	customModalBox.htmlBox('yt-UserProfileContent', '', 'UserProfile'); 
	$('mb_close_link').addEvent('click', function() {
		$('yt-UserProfileContent').injectInside(document.forms[0]);		
		if($('txtarUserProfileMsg'))
		$('txtarUserProfileMsg').value="";
		
	//	window.location.reload(true); 
	});

	
}

/*------------------------------------------------------------

Generates modal window with Login Form injected

------------------------------------------------------------*/

function doModalLogin() {
	customModalBox.htmlBox('yt-LoginContent', '', 'Login'); 
	$('ctl00_txtLoginUsername1').focus();	
	loginClose();
}


function loginClose() {
	$('mb_close_link').addEvent('click', function() {
		$('yt-LoginContent').injectInside('yt-LoginContentContainer');
		$('ctl00_txtLoginUsername1').value = "";
		$('ctl00_txtLoginPassword1').value = "";
		$('ctl00_txtLoginEmail1').value = "";
		$('ctl00_UserContentPlaceHolder_txtEmail').focus();		
		if($('yt-LoginError'))
		{
				 // $('ctl00_PortalValidationSummary').style.visibility = 'hidden';
		}
		window.location.reload(true); 

	});
}



window.addEvent('load', function() {	
	// check to see if there is any error info posted from the login popup, if so, show modal box and error
	if($('yt-LoginError')) {
		//doModalLogin();
		$('yt-LoginError').injectBefore('mb_header');
	}
});


/*------------------------------------------------------------

Generates modal window with Contact Form injected

------------------------------------------------------------*/

function doModalContact() {
	customModalBox.htmlBox('yt-ContactContent', '', 'Contact'); 
	$('mb_close_link').addEvent('click', function() {
		$('yt-ContactContent').injectInside(document.forms[0]);
	});
}


/*------------------------------------------------------------

Generates "loading" modal window while importing contacts

------------------------------------------------------------*/

doContactImport = function(serviceName) { 
// This is a stub function to show "Importing Contacts" status modal
// Please modify as needed to post information to Hotmail, Gmail, etc.
	//var serviceName = "Hotmail";
	//When doing actual form submission you could use: var serviceName = document.forms[0].rdoContactType.value;
	var innerText = "<p>Importing contacts from " + serviceName + "</p>";
	innerText += '<img src="../assets/images/icon_loader.gif" class="yt-LoadingImage">';//COMDIFFRES: (remove absolute path and now working fine) absolute URL with yourtribute.net
	innerText = '<div class="yt-Panel-Primary">' + innerText + '</div>';
	customModalBox.htmlBox('', innerText, 'ContactLoading');
}

/*------------------------------------------------------------

Shows modal box confirming invited guests/shared tribute

------------------------------------------------------------*/

doContactSend = function() { 
	customModalBox.htmlBox('yt-ContactSendContent', '', 'ContactSend');
}


/*------------------------------------------------------------

Generates modal window with Share Tribute textarea injected

------------------------------------------------------------*/

function doModalShare() {
	customModalBox.htmlBox('yt-ShareContent', '', 'Share'); 
	$('mb_close_link').addEvent('click', function() {
		$('yt-ShareContent').injectInside($('yt-ShareContainer'));
		if($('yt-ShareError')) $('yt-ShareError').remove();
	});
}

window.addEvent('load', function() {	
	if($('yt-ShareError')) {
		//doModalShare();
		$('yt-ShareError').injectBefore('mb_header');
	}
});
/*------------------------------------------------------------

Generates modal window with Share Tribute textarea injected

------------------------------------------------------------*/

function doModalSponsor() {
	showWideRows();
	customModalBox.htmlBox('yt-SponsorContent', '', 'Sponsor');
	$('mb_close_link').addEvent('click', function() {
		$('yt-SponsorContent').injectInside($('yt-SponsorContainer'));
		//$('yt-UpgradeExtendContent').injectInside($('yt-UpgradeExtendContainer'));			
		//if($('yt-SponsorError')) $('yt-SponsorError').remove();
		window.location.reload(true); 
	});

	hideWideRows();
	
}

window.addEvent('load', function() {	
	if($('yt-SponsorError')) {
		//doModalUpgradeExtend();
		$('yt-SponsorError').injectBefore('mb_header');
	}
});


/*------------------------------------------------------------

Generates notice/error/message modal window

------------------------------------------------------------*/


function showNotice(nMessage, nBtnOkText, nBtnCancelText) {
	var innerText = '<div id="mb_Notice" class="yt-Panel-Primary">' + nMessage + '</div>';
	customModalBox.htmlBox('', innerText, 'Notice');

	btnContainer = new Element('div').addClass('yt-Form-Buttons').injectInside($('mb_Notice'));
	btnCancel = new Element('div').addClass('yt-Form-Delete').injectInside(btnContainer);
	btnOk = new Element('div').addClass('yt-Form-Submit').injectInside(btnContainer);
	okLink = new Element('a').setProperties({id: 'mb_ok', href: 'tributes.aspx'}).injectInside(btnOk);
	okLink.addClass("yt-Button yt-CheckButton");
	okLink.innerHTML = nBtnOkText;
	cancelLink = $('mb_close_link').setProperty('id','mb_cancel').injectInside(btnCancel);
	//cancelLink = new Element('a').setProperties({id: 'mb_cancel', href: 'javascript: void(0);'}).injectInside(btnCancel);	
	cancelLink.addClass("yt-Button yt-XButton");
	cancelLink.innerHTML = nBtnCancelText;
	buttonStyles();		
		
}

/*------------------------------------------------------------

Generates Google Map modal window

------------------------------------------------------------*/


function showMapModal(street, city, state, country) {
	
	var innerText = '<div class="yt-Panel-Primary"><div id="yt_MapArea">&nbsp;</div></div>';
	customModalBox.htmlBox('', innerText, 'Map');

	var directionsText = '<div class="yt-Form-Field"><label for="yt_FromAddress">Get directions to this address from:</label><input type="text" class="yt-Form-Input-Long" id="yt_FromAddress" value="" /> <a href="javascript:void(0);" onclick="showDirections()" class="yt-GoButton">Go!</a></div>';

	new Element('h2').setHTML('Location').setProperty('id','mb_MapTitle').injectTop($('mb_contents').getChildren()[0]);	
	new Element('div').setHTML(directionsText).setProperty('id','yt_MapDirections').injectAfter('yt_MapArea');	
	mapInit();
	showAddress(street, city, state, country);
	showMapModalClose();
	
}

function showMapModalClose() {
	$('mb_close_link').addEvent('click', function() {
		if($('yt_MapArea')) $('yt_MapArea').remove();
		if($('mb_MapTitle')) $('mb_MapTitle').remove();
		if($('yt_FromAddress')) $('yt_FromAddress').remove();
		if($('mb_contents')) $('mb_contents').removeClass('yt-Panel-Primary');
		if($('yt_MapDirections')) $('yt_MapDirections').remove();
		
		$('mb_contents').getChildren()[0].remove();
		$('mb_overlay').setStyle('opacity',0);
		$('mb_frame').setStyle('opacity',0);
	});
}

/*------------------------------------------------------------

Generates modal window with help system injected

------------------------------------------------------------*/





/*------------------------------------------------------------

Generates image cropper modal window

------------------------------------------------------------*/

function popupCropper(newSrc) {
	var srcFile = "image_cropper.htm";
	if (newSrc) srcFile = newSrc;
	var cFrame = new Element('iframe').setProperties({id:"yt-CropperFrame", height:'360px', width:'600px', frameborder:"0", scrolling:"no", src:srcFile}).injectInside(document.body);
	$('yt-CropperFrame').src = srcFile;													
	customModalBox.htmlBox('yt-CropperFrame', '', 'Cropper'); 
	$('mb_contents').addClass('yt-Panel-Primary');
	new Element('div').setHTML('&nbsp;').setProperty('id','mb_Error').injectTop($('mb_center'));
	new Element('h2').setHTML('Image Cropper').setProperty('id','mb_Title').injectTop($('mb_contents'));
	cropperClose();
}

// Quick function to remove cropper object when modal is closed
// Useful for if we decide to reset the contents of the cropper tool on close
function cropperClose() {
	$('mb_close_link').addEvent('click', function() {
		if($('yt-CropperFrame')) $('yt-CropperFrame').remove();
		if($('mb_Title')) $('mb_Title').remove();
		if($('mb_Error')) $('mb_Error').remove();
		if($('mb_header')) $('mb_header').removeClass('yt-Panel-Primary');
	});
}

function setpopdefault()
{     
    var bol=true;
    if(event.which || event.keyCode)
    {
     if ((event.which == 13) || (event.keyCode == 13))
     {
       $('ctl00_popuplbtnSignup').focus();
       //
       bol= false;
      }
   }  
    return bol;         
}

function setpopdefault2()
{    
    var bol=true;
    if(event.which || event.keyCode)
    {
     if ((event.which == 13) || (event.keyCode == 13))
     {
       $('ctl00_popuplbtnSignup').focus();
       bol= false;
      }
   }  
    return bol;         
}

function setpopemail()
{
    $('ctl00_PortalValidationSummary').validationGroup = "popupemail";
    var bol=true;
    if(event.which || event.keyCode)
    {
     if ((event.which == 13) || (event.keyCode == 13))
     {
       $('ctl00_popuplbtnSendemail').focus();
       bol= false;
      }
   }  
    return bol;         
}

/*------------------------------------------------------------

Generates modal window with Login Form injected for Tribute Creation.

------------------------------------------------------------*/

function doModalLogin_() {
	customModalBox.htmlBox('yt-LoginContent', '', 'Login'); 
	loginClose_();
}


function loginClose_() {
	$('mb_close_link').addEvent('click', function() {
		$('yt-LoginContent').injectInside('yt-LoginContentContainer');
		$('txtLoginUsername1').value = "";
		$('txtLoginPassword1').value = "";
		$('txtLoginEmail1').value = "";		
//		if($('yt-LoginError'))
//		{
//				 // $('ctl00_PortalValidationSummary').style.visibility = 'hidden';
//		}
		window.location.reload(true); 

	});
}


function UserProfileModal_1(guid)
    {		
	var srcFile = "../ModelPopup/UserProfile.aspx";	
	if (guid) srcFile += '?userid=' + guid; /* sample code to append a unique user ID to page called */	
	var cFrame = new Element('iframe').setProperties({id:"yt-UserProfileContent", name:"yt-UserProfileContent", height:'500px', width:'640px', frameborder:"0", scrolling:"no"}).injectInside(document.body);
	$('yt-UserProfileContent').src = srcFile;
	customModalBox.htmlBox('yt-UserProfileContent', '', 'UserProfile'); 
	$('mb_contents').addClass('yt-Panel-Primary');
	new Element('div').setHTML('&nbsp;').setProperty('id','mb_Error').injectTop($('mb_center'));
	new Element('h2').setHTML('Member Profile').setProperty('id','mb_Title').injectTop($('mb_contents'));
	
	UserProfileClose();
}

function UserProfileClose() {
	$('mb_close_link').addEvent('click', function() {
		//if($('yt-UserProfileContent')) $('yt-UserProfileContent').remove();
		if($('yt-UserProfileContent')) $('yt-UserProfileContent').remove();
		if($('mb_Title')) $('mb_Title').remove();
		if($('mb_contents')) $('mb_contents').removeClass('yt-Panel-Primary');
		if($('mb_Error')) $('mb_Error').remove();
	});
}

function UserLoginModalpopup(guid,title)
{
    var srcFile = "../ModelPopup/LoginPopup.aspx";	
	if (guid) srcFile += '?location=' + guid+'&title=' + title; /* sample code to append a unique user ID to page called */	
    var cFrame = new Element('iframe').setProperties({id:"iframe-login", name:"iframe-login", height:'320px', width:'332px', frameborder:"0", scrolling:"no"}).injectInside(document.body);
	$('iframe-login').src = srcFile;
	customModalBox.htmlBox('iframe-login', '', 'Login'); 
	$('mb_contents').addClass('yt-Panel-Primary');
	new Element('div').setHTML('&nbsp;').setProperty('id','mb_Error').injectTop($('mb_center'));
	new Element('h2').setHTML('Login').setProperty('id','mb_Title').injectTop($('mb_contents'));
	
	UserProfileClose1(); 
	
}
function UserLoginModalpopupFromLoginPage(guid,title)
{
    var srcFile = "ModelPopup/LoginPopup.aspx?source=Login";	
	if (guid) srcFile += '?location=' + guid+'&title=' + title; /* sample code to append a unique user ID to page called */	
    var cFrame = new Element('iframe').setProperties({id:"iframe-login", name:"iframe-login", height:'320px', width:'332px', frameborder:"0", scrolling:"no"}).injectInside(document.body);
	$('iframe-login').src = srcFile;
	customModalBox.htmlBox('iframe-login', '', 'Login'); 
	$('mb_contents').addClass('yt-Panel-Primary');
	new Element('div').setHTML('&nbsp;').setProperty('id','mb_Error').injectTop($('mb_center'));
	new Element('h2').setHTML('Login').setProperty('id','mb_Title').injectTop($('mb_contents'));
}

function UserProfileClose1() {
	$('mb_close_link').addEvent('click', function() {
		//if($('yt-UserProfileContent1')) $('yt-UserProfileContent1').remove();
		if($('iframe-login')) $('iframe-login').remove();
		if($('mb_Title')) $('mb_Title').remove();
		if($('mb_contents')) $('mb_contents').removeClass('yt-Panel-Primary');
		if($('mb_Error')) $('mb_Error').remove();
		
	});
}
/*------------------------------------------------------------

Generates modal window with Expired Tribute textarea injected

------------------------------------------------------------*/

function doModalExpired() {
	customModalBox.htmlBox('yt-ExpiredContent', '', 'Expired'); 
	$('mb_close_link').remove();
	$('mb_overlay').setStyle('opacity',0.5);
}

  window.addEvent('domready', function() {	
	if($('yt-ExpiredContent')) {
	    doModalExpired();
	}
});  



/*------------------------------------------------------------

Generates modal window for getting the acceptance for removal of existing video tribute.

------------------------------------------------------------*/

function doModalContact() {
	    customModalBox.htmlBox('yt-ContactContent', '', 'Contact'); 
	    $('mb_close_link').addEvent('click', function() {
		    $('yt-ContactContent').injectInside(document.forms[0]);
	    });
	
}


/*------------------------------------------------------------

Generates modal window for welcome message

------------------------------------------------------------*/

function showWelcome()
 {
// switched off on client request
//	var srcFile = "../ModelPopup/WelcomeModal.aspx";	//COMDIFF: prepend "../"
//	var cFrame = new Element('iframe').setProperties({id:"yt-HelpContent", height:'580px', width:'600px', frameborder:"0", scrolling:"no", src:srcFile}).injectInside(document.body);
//														
//	customModalBox.htmlBox('yt-HelpContent', '', 'Help'); 
//	$('mb_contents').addClass('yt-Panel-Primary');
//	new Element('h2').setHTML('Welcome to Your Tribute').setProperty('id','mb_Title').injectTop($('mb_contents'));
//	welcomeClose();
}

function welcomeClose() {
	$('mb_close_link').addEvent('click', function() {
		if($('yt-HelpContent')) $('yt-HelpContent').remove();
		if($('mb_Title')) $('mb_Title').remove();
		if($('mb_contents')) $('mb_contents').removeClass('yt-Panel-Primary');
	});
}

