// V1.01 JC changed to load .hml from a different directory
// V1.02 JC Changed to resize if a setDialogSize div is available
//v10.3 JC Changed to add tellafriend

	YAHOO.namespace("example.container");

        var fngetDialogSize = function(el) {
            if(el.id == "setDialogSize" ) return true;
            else return false;
        };

	// BEGIN MODALDIALOG SUBCLASS //
	YAHOO.widget.ModalDialog = function(el, userConfig) {
		if (arguments.length > 0) {
			YAHOO.widget.ModalDialog.superclass.constructor.call(this, el, userConfig);
		}
	}
	
	// Inherit from YAHOO.widget.Panel
	YAHOO.extend(YAHOO.widget.ModalDialog, YAHOO.widget.Panel);

	// Define the CSS class for the ModalDialog
	YAHOO.widget.ModalDialog.CSS_MODALDIALOG = "modalDialog";
/*
	// Define the HTML for the footer navigation
	YAHOO.widget.ModalDialog.NAV_FOOTER_HTML = "<a id=\"$back.id\" href=\"javascript:void(null)\" class=\"back\"><img src=\".js/yui_2.2.2/yui/examples/container/assets/img/ybox-back.gif\" /></a><a id=\"$next.id\" href=\"javascript:void(null)\" class=\"next\"><img src=\".js/yui_2.2.2/yui/examples/container/assets/img/ybox-next.gif\" /></a>";
*/

	// Initialize the ModalDialog by setting up the footer navigation
	YAHOO.widget.ModalDialog.prototype.init = function(el, userConfig) {
		YAHOO.widget.ModalDialog.superclass.init.call(this, el); 
		
		this.beforeInitEvent.fire(YAHOO.widget.ModalDialog);

		YAHOO.util.Dom.addClass(this.innerElement, YAHOO.widget.ModalDialog.CSS_MODALDIALOG);

		if (userConfig) {
			this.cfg.applyConfig(userConfig, true);
		}

		this.initEvent.fire(YAHOO.widget.ModalDialog);
	}
/*
	// Initialize the ModalDialog by setting up the footer navigation
	YAHOO.widget.PhotoBox.prototype.init = function(el, userConfig) {
		YAHOO.widget.PhotoBox.superclass.init.call(this, el); 
		
		this.beforeInitEvent.fire(YAHOO.widget.PhotoBox);

		YAHOO.util.Dom.addClass(this.innerElement, YAHOO.widget.PhotoBox.CSS_MODALDIALOG);
		
		if (userConfig) {
			this.cfg.applyConfig(userConfig, true);
		}
		
		this.setFooter(YAHOO.widget.PhotoBox.NAV_FOOTER_HTML.replace("$back.id",this.id+"_back").replace("$next.id",this.id+"_next"));
		
		this.renderEvent.subscribe(function() {
			var back = document.getElementById(this.id + "_back");
			var next = document.getElementById(this.id + "_next");

			YAHOO.util.Event.addListener(back, "mousedown", this.back, this, true);
			YAHOO.util.Event.addListener(next, "mousedown", this.next, this, true);

		}, this, true);

		this.initEvent.fire(YAHOO.widget.PhotoBox);

	};
*/

	// Set up the PhotoBox's "photos" property for setting up the list of photos
	YAHOO.widget.ModalDialog.prototype.initDefaultConfig = function() {
		YAHOO.widget.ModalDialog.superclass.initDefaultConfig.call(this);
		
		this.cfg.addProperty("contentSource", { handler:this.configContentSource, suppressEvent:true });
	};

	// Handler executed when the "photos" property is modified
	YAHOO.widget.ModalDialog.prototype.configContentSource = function(type, args, obj) {
		this.contentSource = args[0];
/*
		if (contentSource) {

			this.setContent();
		}
		*/
	};

	// Sets the current image displayed in the PhotoBox to the corresponding image in the photo dataset, 
	// and determines whether back and forward arrows should be diplsayed, based on the position in the dataset
	YAHOO.widget.ModalDialog.prototype.setContent = function() {
		var contentSource = this.cfg.getProperty("contentSource");
                var dialogCfg = this.cfg;
		if (contentSource) {
			this.htmlContent = "";

			var contentContainer = document.getElementById(this.id + "_content");
			contentContainer.innerHTML = '<img src="../images/ajaxLoading.gif" alt="Loading Content" />'

			var responseSuccess = function(o)
			{
                        	contentContainer.innerHTML = o.responseText;
                                var setupDiv = YAHOO.util.Dom.getElementsBy(fngetDialogSize,"div",contentContainer);
                                if (setupDiv[0] != null) {
                                    dialogCfg.setProperty("width",setupDiv[0].style.width);
                                    dialogCfg.setProperty("fixedcenter",true);
                                    //this.render();
                                }
			}
			var responseFailure = function(o)
			{
				contentContainer.innerHTML = o.statusText; // + '<br /><a id="tryagain" href="javascript:void(null)">Try Again</a>';
				//YAHOO.util.Event.addListener("tryagain", "click", this.setContent(), this, true)
			}
			var callback =
			{
			   success : responseSuccess,
			   failure : responseFailure
			};
			YAHOO.util.Connect.asyncRequest("GET",contentSource,callback);

		}
	};

/*	
	// Navigates to the next image
	YAHOO.widget.PhotoBox.prototype.next = function() {	
		if (typeof this.currentImage == 'undefined') {
			this.currentImage = 0;
		}

		this.setImage(this.currentImage+1);
	};

	// Navigates to the previous image
	YAHOO.widget.PhotoBox.prototype.back = function() {
		if (typeof this.currentImage == 'undefined') {
			this.currentImage = 0;
		}

		this.setImage(this.currentImage-1);
	};
*/
	// Overrides the handler for the "modal" property with special animation-related functionality
	YAHOO.widget.ModalDialog.prototype.configModal = function(type, args, obj) {
		var modal = args[0];

		if (modal) {
			this.buildMask();

			if (typeof this.maskOpacity == 'undefined') {
				this.mask.style.visibility = "hidden";
				this.mask.style.display = "block";
				this.maskOpacity = YAHOO.util.Dom.getStyle(this.mask,"opacity");
				this.mask.style.display = "none";
				this.mask.style.visibility = "visible";
			}

			if (! YAHOO.util.Config.alreadySubscribed( this.beforeShowEvent, this.showMask, this ) ) {
				this.beforeShowEvent.subscribe(this.showMask, this, true);
			}
			if (! YAHOO.util.Config.alreadySubscribed( this.hideEvent, this.hideMask, this) ) {
				this.hideEvent.subscribe(this.hideMask, this, true);
			}
			if (! YAHOO.util.Config.alreadySubscribed( YAHOO.widget.Overlay.windowResizeEvent, this.sizeMask, this ) ) {
				YAHOO.widget.Overlay.windowResizeEvent.subscribe(this.sizeMask, this, true);
			}
			if (! YAHOO.util.Config.alreadySubscribed( this.destroyEvent, this.removeMask, this) ) {
				this.destroyEvent.subscribe(this.removeMask, this, true);
			}
			this.cfg.refireEvent("zIndex");
		} else {
			this.beforeShowEvent.unsubscribe(this.showMask, this);
			this.beforeHideEvent.unsubscribe(this.hideMask, this);
			YAHOO.widget.Overlay.windowResizeEvent.unsubscribe(this.sizeMask);
		}
	};
	
	// Overrides the showMask function to allow for fade-in animation
	YAHOO.widget.ModalDialog.prototype.showMask = function() {
		//alert(this.cfg.getProperty("contentSource"));
		this.setContent();
		if (this.cfg.getProperty("modal") && this.mask) {
			YAHOO.util.Dom.addClass(document.body, "masked");
			this.sizeMask();

			var o = this.maskOpacity;

			if (! this.maskAnimIn) {
				this.maskAnimIn = new YAHOO.util.Anim(this.mask, {opacity: {to:o}}, 0.25)
				YAHOO.util.Dom.setStyle(this.mask, "opacity", 0);
			}

			if (! this.maskAnimOut) {
				this.maskAnimOut = new YAHOO.util.Anim(this.mask, {opacity: {to:0}}, 0.25)
				this.maskAnimOut.onComplete.subscribe(function() {
														this.mask.tabIndex = -1;
														this.mask.style.display = "none";
														this.hideMaskEvent.fire();
														YAHOO.util.Dom.removeClass(document.body, "masked");
													  }, this, true);
				
			}
			this.mask.style.display = "block";
			this.maskAnimIn.animate();
			this.mask.tabIndex = 0;
			this.showMaskEvent.fire();
		}
	};
/*
	// Overrides the showMask function to allow for fade-out animation
	YAHOO.widget.PhotoBox.prototype.hideMask = function() {
		if (this.cfg.getProperty("modal") && this.mask) {
			this.maskAnimOut.animate();
		}
	};
	// END PHOTOBOX SUBCLASS //
*/
	function init() {
              YAHOO.example.container.cataloguesDialog = new YAHOO.widget.ModalDialog("cataloguesDialog",
		{
			effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.45},
                         fixedcenter:true,
                         top:"20px",
			constraintoviewport:true,
			underlay:"none",
			close:true,
			visible:false,
			draggable:false,
			modal:true,
			contentSource:"../docs/catalogues.html",
			width:"280px"
		} );




                YAHOO.example.container.tellafriendDialog = new YAHOO.widget.ModalDialog("tellafriendDialog",
		{
			effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.45},
                         fixedcenter:true,
                         top:"20px",
			constraintoviewport:true,
			underlay:"none",
			close:true,
			visible:false,
			draggable:false,
			modal:true,
			contentSource:"../docs/TellAFriend.html",
			width:"280px"
		} );





                YAHOO.example.container.friendsDialog = new YAHOO.widget.ModalDialog("friendsDialog",
		{
			effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.45},
			fixedcenter:true,
			constraintoviewport:true,
			underlay:"none",
			close:true,
			visible:false,
			draggable:false,
			modal:true,
			contentSource:"../docs/ourFriends.html",
			width:"280px"
		} );
                YAHOO.example.container.exchangeDialog = new YAHOO.widget.ModalDialog("exchangeDialog",
		{
			effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.45},
			fixedcenter:true,
			constraintoviewport:true,
			underlay:"none",
			close:true,
			visible:false,
			draggable:false,
			modal:true,
			contentSource:"../docs/exchangePolicy.html",
			width:"320px"
		} );
		YAHOO.example.container.contactDialog = new YAHOO.widget.ModalDialog("contactDialog",
		{ 
			effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.45}, 
			fixedcenter:true,
			constraintoviewport:true,
			underlay:"none",
			close:true,
			visible:false,
			draggable:false,
			modal:true, 
			contentSource:"../docs/contactUs.html",
			width:"280px"
		} );
		YAHOO.example.container.privacyDialog = new YAHOO.widget.ModalDialog("privacyDialog", 
		{
			effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.45},
			fixedcenter:true,
			constraintoviewport:true,
			underlay:"none",
			close:true,
			visible:false,
			draggable:false,
			modal:true,
			contentSource:"../docs/privacyPolicy.html",
			width:"280px"
		} );
		YAHOO.example.container.feedbackDialog = new YAHOO.widget.ModalDialog("feedbackDialog",
		{
			effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.45},
	                fixedcenter:true,
			constraintoviewport:true,
			underlay:"none",
			close:true,
		//	top:"20px",
			visible:false,
			draggable:false,
			modal:true,
			contentSource:"../docs/feedback.html",
			width:"280px"
		} );


                 YAHOO.example.container.cataloguesDialog.render();
                YAHOO.example.container.tellafriendDialog.render();
		YAHOO.example.container.friendsDialog.render();
		YAHOO.example.container.exchangeDialog.render();
		YAHOO.example.container.contactDialog.render();
		YAHOO.example.container.privacyDialog.render();
		YAHOO.example.container.feedbackDialog.render();

                YAHOO.util.Event.addListener("catalogues", "click", YAHOO.example.container.cataloguesDialog.show, YAHOO.example.container.cataloguesDialog, true);
		YAHOO.util.Event.addListener("friends", "click", YAHOO.example.container.friendsDialog.show, YAHOO.example.container.friendsDialog, true);
		YAHOO.util.Event.addListener("exchange", "click", YAHOO.example.container.exchangeDialog.show, YAHOO.example.container.exchangeDialog, true);
		YAHOO.util.Event.addListener("contact", "click", YAHOO.example.container.contactDialog.show, YAHOO.example.container.contactDialog, true);
		YAHOO.util.Event.addListener("privacy", "click", YAHOO.example.container.privacyDialog.show, YAHOO.example.container.privacyDialog, true);
		YAHOO.util.Event.addListener("feedback", "click", YAHOO.example.container.feedbackDialog.show, YAHOO.example.container.feedbackDialog, true);
		YAHOO.util.Event.addListener("tellafriend", "click", YAHOO.example.container.tellafriendDialog.show, YAHOO.example.container.tellafriendDialog , true);

	}

	YAHOO.util.Event.addListener(window, "load", init);


function setSizeChart (SizeChartDoc) {
  // alert("Size Chart init");

    //  SizeChartDoc = "../templates/sizechartWomensTopsBottoms.html";
YAHOO.example.container.sizeChartDialog = new YAHOO.widget.ModalDialog("sizeChartDialog",
{
	effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.45},
	fixedcenter:true,
	constraintoviewport:true,
	underlay:"none",
	close:true,
	visible:false,
	draggable:false,
	modal:true,
	contentSource:SizeChartDoc,
	width:"280px"
} );



 YAHOO.util.Event.onContentReady("sizeChart", function () {
   YAHOO.example.container.sizeChartDialog.render();
    YAHOO.util.Event.addListener("sizeChart", "click",
               YAHOO.example.container.sizeChartDialog.show,
               YAHOO.example.container.sizeChartDialog, true); } );
               



}


function AjaxSubmitForm (frmId) {
var formObject = document.getElementById(frmId);
YAHOO.util.Connect.setForm(formObject);
//var cObj = YAHOO.util.Connect.asyncRequest('POST', 'index?page=SendFeedback');
var cObj = YAHOO.util.Connect.asyncRequest('POST', formObject.action);
}


function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

function submitFeedbackForm() {

var myForm = $("#frmFeedback");
myForm.validation();


if(myForm.validate()) {
  AjaxSubmitForm('frmFeedback');
  YAHOO.example.container.feedbackDialog.hide();
}


}

if (typeof jQuery == 'undefined') {   loadjscssfile("../js/jquery.min.js","js"); }
loadjscssfile("../js/jquery.cycle.all.js","js");
loadjscssfile("../js/jquery.validation.js","js");



