/**
 * @author Fred
 */


var t;
var line_no = 0;
var loadStart;
var oImg = new Array();
var contentLoadStart = (+new Date);
var loadedImages = new Array();
var contentHolder = new Array();
var hashInterval;

var curUrl = "" + window.location;
var curUrlArr = curUrl.split("/");
var curLoc = curUrlArr[3];
var calledBack;
var curHash;
var tempDiv;

var dName4Hosting;
var dExt4Hosting;

// Used to diagnose variables and functions.
// Appends the sent string to a diagnostics panel which can be seen
// by pressing the tilda key.

var diagnose = function(str, hl){
			
	if (str == "hr") {
		var output = "<hr />";
	}else{
		var output = line_no+". "+str;
		line_no++;
	}
	
	if(hl==true){
		output = '<b style="background:#00cc00; width:100%;">'+output+'</b>';
	}
		
	$("#diagnostics_container").prepend("<br/>"+output);
}
// Controls the visibility of the diagnostics panel.

var Ctrl = false;
$(document).keypress(function(e){	
	if(e.which==96){
		if($("#diagnostics").attr("curIp")=="196.15.145"){
			$("#diagnostics").toggle();
			$("#diagnostics").css({"height":"150px","top":"35%"});
			$("#diagnostics_nav").show();
		}
	}
});

var alreadyLoaded = new Array();
var currentlyLoaded;

var firstHash;

function checkHash(hash, force){
	if(hash != curHash || force == true){
		var crntUrl = window.location.protocol+"//"+window.location.hostname+window.location.pathname+curHash;
		$.post("/html/analytics/analytics.php", 
			{
				action:"track_page_out",
				url:crntUrl,
				vid:vid,
				viewNumber:pagesViewed
			}
		);
		clickNumber = 0;
		pagesViewed++;
		$.post("/html/analytics/analytics.php", 
			{
				action:"get_vid",
				session_id:session_id
			},
			function(data){
				vid = data;
				var current_url = window.location.href;
				$.post("/html/analytics/analytics.php", 
					{
						action:"track_page_in",
						url:current_url,
						vid:vid,
						viewNumber:pagesViewed
					}
				);
			}
		);
	}
	if(hash != curHash && hash==""){
		var curLocUC = curLoc.toUpperCase()
		if(curLocUC=="ADSL" || curLocUC=="HOSTING"){
			hash = "#products_landing";
		}else if(curLocUC=="3G" || curLocUC=="DIALUP"){
			hash = "#products";
		}
	}
	if (hash) {
		if (hash != curHash || force == true) {
									
			if(hash == "#domains"){
				hash = "#domains_products";
				window.location.hash = hash;
			}
			
			diagnose("Hash has changed");
									
			var noHash = hash.replace("#", "");
			
			var menuObj;
			
			if (noHash == "products") {
				menuObj = $("#mProducts");
				//noHash = menuObj.attr("content");
			}
			else {
				$("#page_menu a").each(function(){
				
					if ($(this).attr("content") == noHash) {
						menuObj = $(this);
					}
					
				})
				
			}
			
			var parentContainer = "content_container";
			
			diagnose(noHash);
						
			if (noHash == "domain_transfers" || noHash == "dns_pointing" || noHash == "domains_products") {
				
				diagnose("domain transfer has been found in checkHash");
								
				if($("#domains_products_container:visible").length > 0){
					
					diagnose("domains_main_container is visible")
					parentContainer = "domains_main_container";
					
					if(noHash=="domains_products"){
						content = "domains";
					}else{
						content = noHash;	
					}
										
					menuObj = null;
					diagnose("domains products has been loaded", true)
					
				}else{
					
					if(noHash=="domains_products"){
						extraLoadInfo = "domains";
					}else{
						extraLoadInfo = noHash;	
					}
					
					content = "domains_products";
					menuObj = $("#domains");
					diagnose("loading domains products from scratch", true)
					
				}
				
			}else if(noHash == "premium_landing"){
				content = "premium_landing";
				menuObj = null;
			}
			else {
			
				var content = menuObj.attr("content");
				var extraLoadInfo = menuObj.attr("ali");
				
				if (menuObj.attr("parentContainer")) {
					parentContainer = menuObj.attr("parentContainer");
				}
				
				if (parentContainer == "data_options") {
					if($("#products_container").length < 1){
						extraLoadInfo = content;
						content = "products";
						parentContainer = "content_container";
					}
				}
					
				if (extraLoadInfo) {
					if($("#" + extraLoadInfo).length > 0){
						menuObj = $("#" + extraLoadInfo);	
					}					
				}
				
			}
						
			preContentLoad(menuObj, parentContainer, content, extraLoadInfo);
						
		}
	}
}

function preContentLoad(menuObj, parent, content, extraLoadInfo){

	diagnose("");
	diagnose("");
	diagnose("");
	diagnose("[ ------------- " + content + " ------------------------------------------------------ ]");
	diagnose(alreadyLoaded);
	diagnose("");
	
	var content = content;
	
	if (extraLoadInfo) {
		curHash = "#" + extraLoadInfo;
	}
	else {
		curHash = "#" + content;
	}
	
	if (curHash == "#domains") {
		curHash = "#domains_products"
	}
	
	if (curHash != "#products" && curHash != "#products_landing"){ 
		window.location.hash = curHash;
	}
	
	alreadyLoadedStr = alreadyLoaded.join(",");
	
	if ($.browser.msie) {
		alreadyLoadedStr = "";
	}	
	
		
	if(alreadyLoadedStr.indexOf(content) < 0 && $("#"+content+"_container").length < 1){
		
		diagnose("Loading Content from scratch")
						
		var newContent 		= new contentObj();		
									
		newContent.load(parent, content, content+"_container" , extraLoadInfo);
		
		var pushArray = true;
		
		if($.browser.msie){
			msieVersion = parseInt($.browser.version);
			if(msieVersion == 6){
				pushArray = false;
			}
		}
		
		if (pushArray == true) {
			
			if (extraLoadInfo) {
				alreadyLoaded.push(extraLoadInfo);
			}else{
				alreadyLoaded.push(content);
			}
			
		}	
		
		currentlyLoaded = content;
		
	}else{
		
		diagnose("Reloading Content: "+content);
		
		if(content == "domains_products"){
			$("#domains_container").fadeIn("fast");
		}
		
		if(content == "dns_pointing" || content == "domain_transfers" || content == "domains"){
			vDiv = $("#domains_main_container").children(":visible").attr("id"); 
			currentlyLoaded =  vDiv.replace("_container", "");	
		}else{
			currentlyLoaded =  $("#content_container").attr("current_content");
		}
		
		diagnose("Currently loaded content: "+currentlyLoaded+" -- New Content :"+content);
		var newLoadContent = content;
		
		if (currentlyLoaded != "") {
			
			if (newLoadContent == "express_products" || newLoadContent == "freestyle_products" || newLoadContent == "premium_products" || newLoadContent == "uncapped_products") {
			
				if ($("#products_container:visible").length < 1) {
				
					$("#" + currentlyLoaded + "_container").fadeOut("fast", function(){
					
						if (newLoadContent == "express_products" || newLoadContent == "freestyle_products" || newLoadContent == "premium_products" || newLoadContent == "uncapped_products") {
							$("#products_container").fadeIn("fast");
							$("#content_container").attr({
								"current_content": "products"
							});
						}
						
						$("#data_options").children(":visible").fadeOut("fast",function(){	
							$("#" + newLoadContent + "_container").fadeIn("fast");
						});
						
					});
					
				}
				else {
					
					$("#data_options").children(":visible").fadeOut("fast",function(){	
						$("#" + newLoadContent + "_container").fadeIn("fast");
					});
				}
				
			}
			else {
			
				$("#" + currentlyLoaded + "_container").fadeOut("fast", function(){
				
					$("#" + newLoadContent + "_container").fadeIn("fast");
					
				});
			}
			
		}else{
			
			$("#" + newLoadContent + "_container").fadeIn("fast");
		
		}
		
	}
	
	if(parent == "data_options"){
		if(!$("#products_container:visible")){
			$("#products_container").fadeIn("fast");
		}
	}
			
	if (menuObj) {
		
		if (!$.browser.msie && parseInt($.browser.version) != 6) {
			swopPageTabs(menuObj.attr("content"));
		}
		
		swopTabs(menuObj);
		
	}
	
	if(content == "domains" || content == "domain_transfers" || content == "dns_pointing"){content = "domains_products"};
	if(content == "express_products" || content == "freestyle_products" || content == "premium_products" || content == "uncapped_products"){content="products"};
	$("#content_container").attr({"current_content":content});
	
}

// Controller class for the loading and showing of content
// in the main content container area.

function showHtmlPopup(html) {
	newwindow2=window.open('','name');
	var tmp = newwindow2.document;
	tmp.clear();
	tmp.write(html);
}


var contentObj = function() {
		
	this.load = function(t, c, cc, cl){
		
		diagnose(t+" | "+c+" | "+cc+" | "+cl);
		
		var cl = cl;
		var ali;
		
		if(cl){
			ali="?ali="+cl;
		}else{
			ali="";
		}
		
		 var tar = t;
		 var target=$("#"+tar)
		 var lContent = c;
		 var cContainer = cc;
		 		 
		 diagnose("cContainer = "+cContainer);
		 diagnose(tar);
		 		 
		//Clear the current content in the container.
			target.children(":visible").fadeOut("fast", function(){
																
				target.addClass("loading");
				
				$("#temp").remove();
				
				$("body").append('<div id="temp"></div>');
				
				tempDiv = $("#temp");
				
				tempDiv.html("");
				
				tempDiv.load("/html/pages/" + curLoc.toLowerCase() + "/" + lContent + ".php" + ali, function(){
				
					checkLoad($(this), function(){
						
						diagnose("callback being run")
							
						tempDiv.hide();
						
						if ($.browser.msie) {
							target.removeClass("loading").html(tempDiv.html());
						}
						else {
							target.removeClass("loading").append(tempDiv.html());
						}
														
						tempDiv.remove();
													
						$("#" + cContainer).fadeIn("fast");
												
						if($("#main_container:visible") != true){
							diagnose("fading in main container");
							pageLoad();
						}
						
						var contArr = lContent.split("_");
						
						diagnose(contArr);
						diagnose(ali);
		
					 	var d = new Date();
						var ll = d.getMilliseconds()+"";
						
						if(cl!=""){
							$.getScript("/html/javascript/" + cl + "_controller.js?id="+ll)
						}
													
						if (contArr[1]) {
							$.getScript("/html/javascript/" + contArr[1] + "_controller.js?id="+ll);
						}
						else {
							$.getScript("/html/javascript/" + contArr[0] + "_controller.js?id="+ll);
						}
						
					});
				});				
			});	
	}
}


function removeItem(originalArray, itemToRemove) {

	var j = 0;
	
	while (j < originalArray.length) {
	
		// alert(originalArray[j]);
		
		if (originalArray[j] == itemToRemove) {
		
			originalArray.splice(j, 1);
		
		} else { j++; }
	
	}
	
	// assert('hi');
	
	return originalArray;

}

var swopPageTabs = function(content){
		
	var tabName, newMarginL;
	var display		= "block";
	
	if (content == "products_landing") {
			
			tabName 	= "product_ranges_tab";
			newMarginL 	= 568;

			if(curLoc.toUpperCase() == "3G" || curLoc.toUpperCase() == "DIALUP" ){
				display = "none";
			}
			if (curLoc.toUpperCase() == "HOSTING") {
				tabName 	= "products_tab";
				newMarginL 	= 307;
			}
						
	}else if (content == "products") {
			
			tabName 	= "products_tab";
			
			if (curLoc.toUpperCase() == "3G") {
				newMarginL = 323;					
			}else if(curLoc.toUpperCase() == "DIALUP"){
				newMarginL 	= 539;					
			}
			
	}else if (content == "whatisit") {
			
			tabName 	= "what_is_it_tab";
			newMarginL 	= 324;
			
	}else if (content == "whatdoineed") {
			
			tabName 	= "what_do_i_need_tab";
			newMarginL 	= 568;
				
	}
	
	if (tabName) {
		$("#title_tab").show().attr({
			"src": "/html/new_images/" + curLoc.toUpperCase() + "/" + tabName + ".png"
		}).css({
			marginLeft: newMarginL,
			"display": display
		});
	}else{
		$("#title_tab").hide()
	}
		
}

var swopTabs = function(obj){
	
	var parent = obj.parent();
	var imgs = $("#product_range_menu img");

	$.each(imgs, function(){
		var img = $(this);
		var src = img.attr("src");
		if (src.indexOf("unselected") == -1) {
			img.attr({
				"src": src.replace("selected", "unselected")
			});
		}
	});
		
	if(parent.attr("id")=="product_range_menu"){
		curImg = obj.find("img");
		curSrc = curImg.attr("src");
		curImg.attr({"src":curSrc.replace("unselected","selected")})
		$("#mProducts").fadeOut("fast", function(){
			$("#product_range_menu").fadeIn("fast");
		})
	};
	$("#page_menu a.selected").removeClass("selected");
	obj.addClass("selected");
	
	// Set products tab background if it is the selected tab.
	if (obj.attr("id") == "mProducts") {
		$("img#products_title").attr({
			"src": "/html/new_images/"+curLoc.toUpperCase()+"/products_title_selected.png"
		});
	}
	else {
		$("img#products_title").attr({
			"src": "/html/new_images/3G/products_title.png"
		});
	}
}

// Check to see if all images in an object have been loaded.

var checkLoad = function(obj, callback){
		
	this.images 		= new Array();				// The array of all the images that need to be loaded.
	this.obj			= obj;						// The object that has just been loaded.
	this.sheets 		= document.styleSheets;		// The style sheets associated with the page.
	this.sheetRules 	= "";						// Variable to take the rules from the style sheet.
	this.iUrl			= new Array();				// Array of urls for images that need to be loaded.
	this.uImg			= new Array();				// Array of unique images that need to be loaded.
	this.uImg			= [];
	this.oImg			= new Array();				// Placeholder for image objects.
	var checkImgTimer;
	this.timer			= "";						// Placeholder variable for timer used in IE.
	this.totalComplete 	= 0;						// Total number of loaded images.
	if (callback) {
		this.callback = callback; // Function to call after everything is loaded.
	}else{
		this.callback = function(){};
	}	
	
	diagnose(">>>>>>>>>>>>>>>>>>>>>>>"+this.callback, true)
	
	var curObj = this;								// Globalise the object.
	var imagesLoadStart = (+new Date);
					
	// First thing we need to do is get all the images that need to be loaded.
	this.getImages = function()
	{
		diagnose(this.sheets.length);
		
		var loadedImagesStr = loadedImages.toString();
		
		//Get all the images from the CSS.
		for (var i = 0; i < this.sheets.length; i++) {
			if (this.sheets[i].cssRules) {
				this.sheetRules = this.sheets[i].cssRules;
			}else if(this.sheets[i].rules){
				this.sheetRules = this.sheets[i].rules;
			}
			
			for (var j = 0; j < this.sheetRules.length; j++) {
				if (this.sheetRules[j].cssText) {
					this.iUrl = this.sheetRules[j].cssText.match(/\/html\/(.*)(gif|jpg|png)/);
				}else if (this.sheetRules[j].style.cssText){
					this.iUrl = this.sheetRules[j].style.cssText.match(/\/html\/(.*)(gif|jpg|png)/);
				}
				if (this.iUrl != null && loadedImagesStr.indexOf(iUrl[0]) == -1) {
					this.images.push(this.iUrl[0]);
					loadedImages.push(iUrl[0]);
					diagnose(iUrl[0]);
				}
			}
		}		
		// Get the rest of the images not in the CSS.
		this.obj.find("img").each(function(){
			if (loadedImagesStr.indexOf($(this).attr("src")) == -1) {
				curObj.images.push($(this).attr("src"));
				loadedImages.push($(this).attr("src"));
				diagnose($(this).attr("src"));
			}
		});
		
		this.uImg = unique(this.images);
		this.loadImages(this.uImg);
	}
	// Create image objects for each image that needs to be loaded,
	// and attach the image to the object to load.
	this.loadImages = function(images)
	{
		if(images==""){
			this.callback();
		}
		// Create image objects for each image that needs to be loaded.
		diagnose("----- IMAGE LIST -----");
		for (var i in images) {
			this.oImg[i] = new Image();
			this.oImg[i].src = uImg[i];
			diagnose(i+". "+uImg[i])
			loadedImages.push(uImg[i]);
		}
				
		if (document.all && i == (this.uImg.length - 1) || $.browser.opera || $.browser.safari) { // If IE, which doesn't handle image events to well, use timer.
			calledBack = false;
			checkImgTimer = setInterval(function(){
				curObj.checkImgLoad();
			}, 25);
		}
		else {
			for (var i in images) {
				var imgNo = i;
				this.oImg[i].onload = function(){
					curObj.imageComplete();
				};
				
				this.oImg[i].onerror = function(){
					diagnose("ERROR: "+curObj.oImg[imgNo].src);
					curObj.imageComplete();
				}
			}
		}
	}
	
	// Check how many images have finished loading.
	// This is used in IE.
	this.checkImgLoad = function()
	{
		//this.checkIEcss();
		if (calledBack != true) {
			diagnose("uImg length : " + this.uImg.length + " / " + totalComplete)
			if (uImg.length > 0 && totalComplete < this.uImg.length) {
				for (i = 0; i < this.uImg.length; i++) {
					if (this.oImg[i].complete) {
						totalComplete++;
					}
				}
			}
			else {
				diagnose("All images have been loaded",true)
				clearInterval(checkImgTimer);
				this.callback();
				calledBack = true;
				diagnose("timer cleared");
			}
		}
	}
	
	// Check how many images have finished loading.
	// Used in non-IE browsers.
	this.imageComplete = function()
	{
		this.totalComplete++;
		diagnose("loaded images : "+totalComplete+" of "+this.uImg.length)
		if (totalComplete == this.uImg.length) {
			//this.checkIEcss();
			diagnose("running callback "+this.callback)
			this.callback();
			$("#footer_spacer #main_container").fadeIn("slow");
			diagnose($("#main_container").css("display"));
			diagnose("main_controller faded in");
		}
	}
	
	// Start the whole thing :)
	this.getImages();
		
}

// Remove duplicate entries in an array
// and return only unique elements
function unique(arrayName)
{
    var newArray=new Array();
    label:for(var i=0; i<arrayName.length;i++ )
    {  
        for(var j=0; j<newArray.length;j++ )
        {
            if(newArray[j]==arrayName[i]) 
                continue label;
        }
        newArray[newArray.length] = arrayName[i];
    }
    return newArray;
}

function createInterval(){
	
	hashInterval = setInterval(function(){
		
		checkHash(window.location.hash);
		
		}, 350);
}

function showPfFloater(goto){
	cur_st = $(window).scrollTop();
	
	if($(this).attr("gtData")){
		gtData=$(this).attr("gtData");
	}else{
		gtData="";
	}
	
	$("#darkener").show();
	var scrollTop = $(document).scrollTop();
	$("#pf_container").css({
		"top": scrollTop
	}).show();	
	$("#darkener").css({"width":$(window).width()});
	if($.browser.msie){	   
		if($.browser.version>6.0 && $.browser.version < 7.0){
			$("#pf_container").css({"top":cur_st});
		}
		$("#pf_container").css({"height":$(window).height()});
	}
	
	$("#product_floater_container #product_float_middle").load("/html/pages/"+goto, function(){
		var wH = $(window).height();
		var pfH = $("#product_floater_container").height()
			
			heightDif = wH - pfH;
												
			rTop = parseInt(heightDif / 2);
			
			if (rTop < 0) {
				rTop = 50
			};
		
		$("#product_floater_container").css({top:rTop}).show();
		
	});
};
function updateCompliments(){
	
	$("#compliments").load("/html/pages/common/compliments.php", function(){
		setTimeout(function(){updateCompliments()},10000);
	});
	
};

$(document).ready(function(){

	curHash	= window.location.hash;
	
	if(curHash != $("#content_container").attr("current_content")){
		var noHash = curHash.replace("#","");
		if ($.browser.safari) {
			setTimeout(function(){
				checkHash(curHash, true)
			}, 100);
		}else{
			checkHash(curHash, true);
		}
	}else{
		pagesViewed++;
		$.post("/html/analytics/analytics.php", 
			{
				action:"get_vid",
				session_id:session_id
			},
			function(data){
				vid = data;
				var current_url = window.location.href;
				$.post("/html/analytics/analytics.php", 
					{
						action:"track_page_in",
						url:current_url,
						vid:vid,
						viewNumber:pagesViewed
					}
				);
			}
		);
	}
	
	$(window).unload(function(){
		var crntUrl = window.location.protocol+"//"+window.location.hostname+window.location.pathname+curHash;
		$.post("/html/analytics/analytics.php", 
			{
				action:"track_page_out",
				url:crntUrl,
				vid:vid,
				viewNumber:pagesViewed
			}
		);
	});
	
	createInterval();
 updateCompliments();		
	$.each(
		$.browser, function(i,v){
			diagnose(i+" - "+v);
		}
	)
	
    $("#what_is_it_menu a").click(function(){
        var content = "#" + $(this).attr("content");
        var cur_content = "#" + $("#what_is_it_menu a.selected").attr("content");
        $(cur_content).fadeOut("fast", function(){
            $(content).fadeIn("fast").css({
                "display": "block"
            });
        })
        $("#what_is_it_menu a.selected").removeClass("selected");
        $(this).addClass("selected");
    })
	
	$("#page_menu a").each(function(){
			$(this).attr({
				"href": "#" + $(this).attr("content")
			});
	});
	
	$("#page_menu a").click(function(ev){
		
		ev.preventDefault();
		
		window.location.hash = $(this).attr("href");
						
		return false;
		
    })
	
	$("#product_range_menu a").click(function(ev){
		ev.preventDefault();
				
		$("#title_tab").hide();
		
		return false;
	})
	
    $("#empty_cart").click(function(){
        
		$.post("/html/pages/cart_functions.php", {
            "action": "empty"
        }, function(){
            $("span#cart_summary").find("div").slideUp("fast", function(){
                $("span#cart_summary").css({
                    "background-image": "url(/html/new_images/top_menu/cart_summary_bg.png)"
                })
            });
            $("#cart_view").text("VIEW");
            $("b#cart_count").load("/html/pages/cart_count.php");
			$("div#order_summary_content").load("/html/pages/cart_contents.php");
        });
		
    })
	
	$("a.remove_item").click(function(){
		var pLabel 	= $(this).attr("pLabel");
		var	dName 	= $(this).attr("dName")
		if (dName) {
			
			$.post("/html/pages/cart_functions.php", {
				"package_label[]": pLabel,
				"action": "remove",
				"domain_name[]": dName
			}, function(data){
				$("span#cart_content_container").load("/html/pages/cart_contents.php");
				$("div#order_summary_content").load("/html/pages/cart_contents.php");
				$("b#cart_count").load("/html/pages/cart_count.php");
			})
		}
		else {
			$.post("/html/pages/cart_functions.php", {
				"package_label[]": pLabel,
				"action": "remove"
			}, function(data){
				$("span#cart_content_container").load("/html/pages/cart_contents.php");
				$("div#order_summary_content").load("/html/pages/cart_contents.php");
				$("b#cart_count").load("/html/pages/cart_count.php");
			})
		}
	})
    
    $("#cart_view").click(function(){
        
		if ($(this).text() == "VIEW") {
            $("span#cart_content_container").load("/html/pages/cart_contents.php", function(){
                $("span#cart_summary").css({
                    "background-image": "url(/html/new_images/top_menu/cart_summary_view_bg.png)"
                }).find("div").slideDown("fast");
            });
            $(this).text("HIDE");
        }
        else {
            $("span#cart_summary").find("div").slideUp("fast", function(){
                $("span#cart_summary").css({
                    "background-image": "url(/html/new_images/top_menu/cart_summary_bg.png)"
                })
            });
            $(this).text("VIEW");
        }
        
        
    })
	
	$("#checkout_btn").click(function(){
		window.location = "/checkout/";
	});
    
	$("a.extra_info").click(function(){
		showPfFloater($(this).attr("goto"));
	})
	
	$("a.landing_extra_info").click(function(){
		showPfFloater($(this).attr("goto"));
	});
	
	
	
	$(".pf_close_btn")
	.click(function(e){
		$("#darkener").hide();
		$("#product_floater_container").hide().find("#product_float_middle").children().remove();
		$("html").css({"overflow-y":"auto","height":$(document).height()});
		$("#pf_container").hide();
	});
	$("#darkener")
	.click(function(){
		$("#darkener").hide();
		$("#product_floater_container").hide();
		$("html").css({"overflow-y":"auto","height":$(document).height()});
		$("#pf_container").hide();
	});
	
	/*Form traversal. Move to next available input field once current
	 * field's maxlength is reached*/
	
	$("form input.num_format")
	.keydown(function(e){
		if(e.keyCode>=48 && e.keyCode<=57 || e.keyCode>=96 && e.keyCode<=105 || e.which==13 || e.which == 8 || e.which == 9 || e.which == 16 || e.which == 39 || e.which == 37 || e.which == 38 || e.which == 40){
			return true;
		}else{
			return false;
		}
	});

	$("form input[type='text']")
	.keyup(function(e){
		var inputVal = $(this).val();
		var curLength = inputVal.length;
		var maxLength = $(this).attr("maxlength");
		if(e.which){
			//alert(e.keyCode);
			if(curLength==(maxLength)){
				$(this).next().focus();
			}
		}
	});
	
	$("#need_help_btn").click(function(){
		showPfFloater($(this).attr("goto"));
	});
	
	$("#show_log").click(function(){
		alert("click");
		$("#diagnostics_nav").hide();
		$("#diagnostics").css({"height":"100%", "top":"0"});
		$("#diagnostics_container").show();
	});
	
	$("#show_click_map").click(function(){
		var current_url = window.location.href;
		$.post("/html/analytics/analytics.php", 
			{
				action:"get_clicks",
				url:current_url
			},
			function(data){
				show_clicks(data);
			}
		);
		function show_clicks(coordinates){
			var coordinate_array = coordinates.split(":");
			//$("body").append('<div id="site_lightener"></div>')
			for(i=0; i<coordinate_array.length; i++){
				if(coordinate_array[i]!=""){
					var coordinates = coordinate_array[i].split(",");
					var main_container = $("#main_container");
					var main_container_offset = main_container.offset();
					var click_x = parseInt(coordinates[0])+main_container_offset.left;
					var click_y = parseInt(coordinates[1])+main_container_offset.top;
					if(coordinates[2]=="msie"){
						var background = "#3399ff";
						var border = "#336699";
					}else{
						var background = "#FF9900";
						var border = "#cc0000";
					}
					$("body").append('<div class="click_point" style="left:'+click_x+'px; top:'+click_y+'px; background:'+background+'; border-color:'+border+';" browser="'+coordinates[2]+'" version="'+coordinates[3]+'"></div>');
				}
			}
			
		}
		$("#diagnostics").hide();
	});
});
