jQuery.noConflict();
jQuery(document).ready(function(){

	jQuery("textarea").maxLengthFormControls();
	
	var fff = 0;

	jQuery("a").filter(function(index) { 
		//alert((jQuery(this).text() == "foot" &&  !jQuery(this).hasClass("foot")));
		return (jQuery(this).text() == "foot" &&  jQuery(this).hasClass("foot"));
		}).addClass("foot");
		
	
	jQuery(".foot").attr("id", function(arr) { return fff++;});
	fff = 0;
	jQuery("p,.image-block").attr("id", function(arr) { if (fff < 5) return fff++; else return "noprint"});
	jQuery(".foot").click(function(event) {
       var footid = "foot-"+this.id;
       jQuery.getJSON("/footprint-ugc/register/checkCapability",
         	function(data) {
         	   if (!data.capability || data.capability == "NOTLOGGEDIN") {
         		  top.location.href="/footprint-ugc/register/showLogin";
         	   } else {
         		   enlarge(footid);
         	   }
       });
       
       event.preventDefault();
	});
	
	if (!sectionId || sectionId == null) {
	   sectionId = 1122;
	}

    jQuery.get("/footprint-ugc/register/showSideBar/"+sectionId+"?returnURL="+top.location.href,
       		function(data) {
       		  jQuery("#sidebar").html(data);
    });

       		  

    jQuery.get("/footprint-ugc/register/showCapability/"+sectionId,
       		function(data) {
       		  jQuery("#popup").html(data);
       		  jQuery("#url").attr("value",top.location.href);
       		  
    });
    
    jQuery(".returnURL").attr("value",top.location.href);

	jQuery(".print-box").click(function(event) { showPrintPopup();});
	
	jQuery(".prev").find("a").css("color","grey");

	jQuery("#smaller").click(function(event) { 
		jQuery(".primary").find("h2").css("fontSize","16px");
		jQuery(".primary").find("p").css("fontSize","10px");
		jQuery("#smaller > img").attr("src","/footprint-ugc/images/font01-active.gif");
		jQuery("#normal > img").attr("src","/footprint-ugc/images/font02.gif");
		jQuery("#bigger > img").attr("src","/footprint-ugc/images/font03.gif");
	});

	jQuery("#normal").click(function(event) { 
		jQuery(".primary").find("h2").css("fontSize","18px");
		jQuery(".primary").find("p").css("fontSize","13px");
		jQuery("#smaller > img").attr("src","/footprint-ugc/images/font01.gif");
		jQuery("#normal > img").attr("src","/footprint-ugc/images/font02-active.gif");
		jQuery("#bigger > img").attr("src","/footprint-ugc/images/font03.gif");

	});

	jQuery("#bigger").click(function(event) { 
		jQuery(".primary").find("h2").css("fontSize","21px");
		jQuery(".primary").find("p").css("fontSize","15px");
		jQuery("#smaller > img").attr("src","/footprint-ugc/images/font01.gif");
		jQuery("#normal > img").attr("src","/footprint-ugc/images/font02.gif");
		jQuery("#bigger > img").attr("src","/footprint-ugc/images/font03-active.gif");

	});
	
	jQuery("#tokensPopupSubmit").click(function(event) { 
		hideTokenPopup();
		jQuery("#tokensPopupForm").submit();
		
	});
	
	jQuery("#contactTonySubmit").click(function(event) { 
		if (!areTheyBlank(["sender","email","phone"])) {
			if (doTheyMatch("email","confirmEmail")) {
			  jQuery("#contactTonyForm").submit();
			} else {
				jQuery(".errors").html("<ul><li>Please ensure that Email and Confirm email match.</li></ul>");
				return false;
			}
		} else {
			jQuery(".errors").html("<ul><li>Please ensure that Name, Email and Contact Number are supplied.</li></ul>");
			return false;
			
		}
	});
    	
});


function areTheyBlank(fields) {
	if (fields && fields.length > 0) {
		for (var i = 0; i < fields.length; i++) {
			if (jQuery("input[name='"+fields[i]+"']").val() == "") {
			  return true;
			}		
		}
	}
	return false;
}

function doTheyMatch(field1,field2) {
	if (field1 && field2) {
		if (jQuery("input[name='"+field1+"']").val() ==jQuery("input[name='"+field2+"']").val() ) {
			return true;
		}		
	}
	return false;
}
