/*!
 * Copyright (c) 2007-2010 Bractus, Inc.
 * 10538 Eastborne Ave #102, Los Angeles, California, 90024, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of Bractus ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Bractus.
 */
var UA = YAHOO.env.ua;
var blank = new Image();
blank.src = 'images/blank.gif';
 
 function fixPng(png) {
   // get src
   var src = png.src;
   // set width and height
   if (!png.style.width) { png.style.width = $(png).width(); }
   if (!png.style.height) { png.style.height = $(png).height(); }
   // replace by blank image
   png.src = blank.src;
   // set filter (display original image)
   png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
 }

function init() {
	  var loginBtn = new YAHOO.widget.Button("login_btn", {type: "submit"});
	 // loginBtn.on("click",login);

	  $("input[type='text']:first", document.forms[0]).focus();
	  $(".menu a").hover(function() {
			$(this).next("em").animate({opacity: "show", top: "-75"}, "slow");
		}, function() {
			$(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");
		});

	// Define various event handlers for Dialog
	var handleSubmit = function() {
			YAHOO.util.Connect.setForm("resetPasswordForm");
			YAHOO.util.Connect.asyncRequest('POST', 'signup/signup.html?action=resetPassword',
    		{success: handleSuccess, failure: handleFailure});

	};

	var handleCancel = function() {
		$("input[type='text']:first", document.forms[0]).focus();
		this.cancel();
	};
	var handleSuccess = function(o) {
		var response = o.responseText;

		if (response.indexOf("Error")>-1){
			$('#reset_error').html(o.responseText);
			$("#reset_error_area").show("slow");


		}else{
			ProfileDlg.hide();
			//new Effect.Appear($('resp'));
			$("resp").show("slow");
		}
		/*response = response.split("<!")[0];
		document.getElementById("resp").innerHTML = response;*/

	};
	var handleFailure = function(o) {

		$('#reset_error').html(o.responseText);
		$("#reset_error_area").show("slow");
	};

	// Instantiate the Dialog
	ProfileDlg = new YAHOO.widget.Dialog("Profile_Dlg",
										{ width : "490px",
										  fixedcenter : true,
										  visible : false,
										  modal: true,
										  constraintoviewport : true,
										  buttons : [ { text:"Submit", handler:handleSubmit, isDefault:true },
													  { text:"Cancel", handler:handleCancel } ]
										 } );

	// Validate the entries in the form to require that both first and last name are entered
	ProfileDlg.validate = function() {
		var data = this.getData();
		if (data.email == "" && data.user == "" ) {
			alert("Please enter your email address.");
			return false;
		} else {
			return true;
		}
	};

	// Wire up the success and failure handlers
	ProfileDlg.callback = { success: handleSuccess,
							failure: handleFailure };

	// Render the Dialog
	ProfileDlg.render();
	$("#forget_password").click( function(){ $('#Profile_Dlg').show(); ProfileDlg.show() });
	var viewWidth = document.body.clientWidth;

	if (viewWidth >= 800 || UA.ie){

	/*	var imageGroup = new YAHOO.util.ImageLoader.group(window, 'focus', 1);
		var findImg = imageGroup.registerPngBgImage('find_image', 'images/Find.png');
		var mobileImg = imageGroup.registerPngBgImage('mobile_image', 'images/mobile.png');
		findImg.setVisible = true;
		mobileImg.setVisible = true;
		imageGroup.foldConditional = true;*/
		if ($('#title_image_div')) $('#title_image_div').show().css({'max-height': '50%'});

	}
	
	var oldBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
 	if (oldBrowser) {
     // get all pngs on page
     $('img[src$=.png]').each(function() {    	 	
       fixPng(this);
     });
   	}

	var dlg ;
	$('#services_link').click(function(){

		var openDialog = function (){

			if (!dlg) {
				dlg = $("#service_dialog").dialog({
					bgiframe: true,
					minWidth: 400,
					width: 600,
					modal: true
				});
			}else{
				$("#service_dialog").dialog('open')

			}

		}
		var handleShowServices = function (text){
			$("#service_dialog").html(text);

			openDialog();
		}
		if ($("#service_dialog").html() === ''){
			$.ajax({
			  type: "GET",
			  url: "services.html?action=view-profile",
			  dataType: "html",
			  success: handleShowServices
			});
		}else{
			openDialog();
		}
		return false;
	});
}
