// JavaScript Document

var panelController;

$(document).ready(function() {

panelController = new function() {
	
	//var SUCCESS_MESSAGE = "Thanks for signing up!";
	
	var userFirstName = "";
	var userLastName = "";
	var userZip = "";
	var userEmail = "";
	
	this.displaySuccess = function(message) {
	}; 
	
	this.getFullPanelCode = function(panelContent) {
		var fullPanelCode = "<div style=\"padding-top:10px;padding-left:4px;padding-right:4px;\" class=\"dhtmlPanel\">" +
                "<div style=\"background:url(images/dhtmlPanel/bottom.gif) repeat-x bottom;float:left;position:relative;\">" +
                	"<div style=\"background:url(images/dhtmlPanel/top.gif) repeat-x top;float:left;\">" +
                        "<div style=\"background:url(images/dhtmlPanel/leftbottomcorner.gif) no-repeat left bottom; float:left;margin-left:-4px;padding:0;\">" +
                            "<div style=\"background:url(images/dhtmlPanel/rightbottomcorner.gif) no-repeat right bottom;float:left;\">" +
                                "<div style=\"background:url(images/dhtmlPanel/lefttopcorner.gif) no-repeat left top;float:left;\">" +
                                    "<div style=\"background:url(images/dhtmlPanel/righttopcorner.gif) no-repeat right top;float:left;\">" +
                                        "<div style=\"background:url(images/dhtmlPanel/leftborder.gif) repeat-y left top;float:left;margin-top:1px;margin-bottom:5px;\">" +
                                            "<div style=\"background:url(images/dhtmlPanel/rightborder.gif) repeat-y right top;height:100%;float:left;\">" +
                                                "<div style=\"background:url(images/dhtmlPanel/background.gif) repeat;margin-left:1px;margin-right:5px;position:relative;padding:10px;\">" +
													"<div id=\"panelMainContent\">" +
													panelContent +
													"</div>" +
													"<div id=\"panelAjaxResult\">" +
													"</div>" +
                                                "<div style=\"clear:both;\"></div>" +
												"</div>" +
                                                "<div style=\"clear:both;\"></div>" +
                                            "</div>" +
                                            "<div style=\"clear:both;\"></div>" +
                                        "</div>" +
                                        "<div style=\"clear:both;\"></div>" +
                                    "</div>" +
                                    "<div style=\"clear:both;\"></div>" +
                                "</div>" +
                                "<div style=\"clear:both;\"></div>" +
                            "</div>" +
                            "<div style=\"clear:both;\"></div>" +
                        "</div>" +
                        "<div style=\"clear:both;\"></div>" +
                    "</div>" +
            	"<div style=\"background:url(images/dhtmlPanel/closebutton.gif) no-repeat;width:20px;height:21px;position:absolute;top:-9px;right:-6px;cursor:pointer;\" onclick=\"UnTip();\"></div>" +
            	"</div>" +
            "</div>";
			
			return fullPanelCode;
	};
	
	this.getMailingListForm = function() {
		var mailingListFormCode = "<form action=\"/ajaxMLHandler.cfm\" method=\"post\" id=\"mailingListSignupForm\">" +
													"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"contentTable\">" +
														"<tr>" +
															"<td class=\"title\" colspan=\"2\">" +
																"Sign Up Here for our Mailing List!" +
															"</td>" +
                                                        "</tr>" +
														"<tr>" +
															"<td class=\"subtitle\" colspan=\"2\">" +
																"Get the latest news, seasonal specials, and great offers from Black Hound New York!" +
															"</td>" +
                                                        "</tr>" +
                                                        "<tr class=\"firstRow\">" +
                    										"<td class=\"formCell\"><label for=\"first_name\" class=\"formLabel\">First Name:</label><br /><input type=\"text\" name=\"first_name\" id=\"first_name\" class=\"inputText\" value=\"" + this.initialCap(this.userFirstName) + "\" /></td>" +
                    										"<td class=\"formCell\"><label for=\"last_name\" class=\"formLabel\">Last Name:</label><br /><input type=\"text\" name=\"last_name\" id=\"last_name\" class=\"inputText\" value=\"" + this.initialCap(this.userLastName) + "\" /></td>" +
                                                        "</tr>" +
                                                        "<tr>" +
                    										"<td class=\"formCell\"><label for=\"zip\" class=\"formLabel\">Zip Code:</label><br /><input type=\"text\" name=\"zip\" id=\"zip\" class=\"inputText\" value=\"" + this.userZip + "\" /></td>" +
                                                        "</tr>" +
                                                        "<tr>" +
                    										"<td class=\"formCell\"><label for=\"email\" class=\"formLabel\">Email:</label><br /><input type=\"text\" name=\"email\" id=\"email\" class=\"inputText\" value=\"" + this.userEmail.toLowerCase() + "\" /></td>" +
                                                        "</tr>" +
                                                        "<tr>" +
                    										"<td class=\"formCell\"><input type=\"image\" name=\"submit\" id=\"submit\" src=\"images/buttons/signup.gif\" class=\"submitButton\" value=\"" + "check" + "\" /></td>" +
                                                        "</tr>" +
                                                    "</table>" +
                                                	"</form>";
		return mailingListFormCode;
	};

	this.initialCap = function(field) {
		field = field.substr(0, 1).toUpperCase() + field.substr(1).toLowerCase();
		return field;
	};

	this.displayMailingListForm = function(userFirstName,userLastName,userZip,userEmail) {
		this.userFirstName = userFirstName;
		this.userLastName = userLastName;
		this.userZip = userZip;
		this.userEmail = userEmail;
		
		var formCode = this.getMailingListForm();
		this.generatePanel(formCode);
	};
	
	this.CalcFixXY = function() {
		var viewportwidth;
		var viewportheight;
		
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		
		if (typeof window.innerWidth != 'undefined')
		{
			viewportwidth = window.innerWidth,
			viewportheight = window.innerHeight
		}
		
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		
		else if (typeof document.documentElement != 'undefined'
		   && typeof document.documentElement.clientWidth !=
		   'undefined' && document.documentElement.clientWidth != 0)
		{
			 viewportwidth = document.documentElement.clientWidth,
			 viewportheight = document.documentElement.clientHeight
		}
		
		// older versions of IE
		
		else
		{
			 viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
			 viewportheight = document.getElementsByTagName('body')[0].clientHeight
		}
		
		
		results = new Array(300,viewportheight - 600);
		return results;
	};
	
	this.generatePanel = function(panelContentCode) {
		var fullPanelCode = this.getFullPanelCode(panelContentCode);
		Tip(fullPanelCode, ABOVE, true, BGCOLOR, '', BORDERWIDTH, 0, CLICKCLOSE, false, FOLLOWMOUSE, false/*,  FIX, this.CalcFixXY()*/);
		var options = {
			//target:			'#ajaxReturnValue',
			beforeSubmit:	this.showRequest, 
			success:		this.showSuccess// post-submit callback 
			// other available options: 
			//url:       url         // override for form's 'action' attribute 
			//type:      type        // 'get' or 'post', override for form's 'method' attribute 
			//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
			//clearForm: true        // clear all form fields after successful submit 
			//resetForm: true        // reset the form after successful submit 
	 
			// $.ajax options can be used here too, for example: 
			//timeout:   3000 
		}; 
		$('#mailingListSignupForm').ajaxForm(options);
	};
	
	this.showSuccess = function(responseText, statusText) {
				alert(responseText);
				UnTip();
	};
	
	this.showRequest = function (formData, jqForm, options) { 
		// formData is an array; here we use $.param to convert it to a string to display it 
		// but the form plugin does this for you automatically when it submits the data 
		
		//var queryString = $.param(formData); 
	 
		// jqForm is a jQuery object encapsulating the form element.  To access the 
		// DOM element for the form do this: 
		// var formElement = jqForm[0]; 
	 
		//alert('About to submit: \n\n' + queryString); 
	 
		// here we could return false to prevent the form from being submitted; 
		// returning anything other than false will allow the form submit to continue 
		return true; 
	};
	
};

});