/**
 * @author Fred
 */

diagnose("products_controller loaded");

diagnose(dName4Hosting+" "+ dExt4Hosting, true);

$("div#data_options a").unbind("click");
$("div#data_options a").bind("click",function(){
    var pLabel = $(this).attr("pLabel");
    var fullLeft = 143;
	var fullWidth = 140;
	
	if($("#pco_thank_you_container:visible")){$("#pco_thank_you_container").fadeOut("fast").remove()};
	if($("#before_you_do_container:visible")){$("#before_you_do_container").fadeOut("fast");}
		
    if ($("a.dataSelected").length < 1) {
		
        $("img#prod_start").fadeOut("fast");
		$("img#prod_next").fadeOut("fast");
		$("#product_blurb").fadeOut("fast");
		$("#workbench").css({"background":'url("/html/new_images/3G/workbench_bg.png") no-repeat center'});
		$("#price_table").fadeIn("fast");
		$("#add2cart_btn").fadeIn("fast");
		$("img.bundle_plus").hide();
    }
    if ($("a.modemSelected").length > 0 || $("a.lineSelected").length > 0 || $("a.routerSelected").length > 0) {
        fullLeft = 67;
    }
	if ($("a.lineSelected").length > 0 && $("a.routerSelected").length > 0) {
		fullLeft = -5;
		fullWidth = 135;
	}
	
    swopProducts("data", "data_options", this, 0, fullLeft, pLabel, fullWidth);
	
    if ($("input.package_input").length == 1) {
        $("input.package_input").attr({
			"id": "data2cart"
		});
    }
    $("input#data2cart").attr({
        "value": pLabel
    });
})

$("div#modem_options a").unbind("click");
$("div#modem_options a").bind("click",function(){
    if ($("a.dataSelected").length < 1) {
        $("#before_you_do_container").fadeIn("fast");
    }
    else {
        var pLabel = $(this).attr("pLabel");
        if ($("a.modemSelected").length == 0) {
           $("div#data").animate({
                left: 67
            }, "fast", function(){
                fadeInPlus()
            });
        }
        
		swopProducts("modem", "modem_options", this, 330, 226, pLabel);
		
        if ($("#modem2cart").length < 1) {
            $("input#data2cart").clone().insertAfter("input#data2cart").attr({"id":"modem2cart"})
        }
        $("input#modem2cart").attr({
            "value": pLabel
        });
    }
})

$("#router_menu a").unbind("click");
$("#router_menu a").bind("click",function(){
    if ($("a.dataSelected").length < 1) {
    	$("#before_you_do_container").fadeIn("fast");
    }
    else {
        var pLabel = $(this).attr("pLabel");
		fullWidth = 140;
		fullLeft = 226;
		
        if ($("a.lineSelected").length > 0) {
           $("div#data").animate({
                left: -5,
				width:135
            }, "fast", function(){
                fadeInPlus()
            });
			$("div#line").animate({
                left: 292,
				width:135
            }, "fast", function(){
                fadeInPlus()
            });
			fullLeft = 143;
			fullWidth = 135;
			if($("img.bundle_plus").length==1){
				$("img.bundle_plus").animate({
					left:118,
					width:37
				},"fast",function(){
					$(this).clone().appendTo("#workbench")
					.css({
						left:266,
						width:37,
						opacity:1
					}).fadeIn("fast");
				});
			}
        }else if ($("a.routerSelected").length < 1) {
           $("div#data").animate({
                left: 67
            }, "fast", function(){
                fadeInPlus()
            });
        }
        
		swopProducts("router", "router_menu", this, 330,  fullLeft, pLabel, fullWidth);
			
        if ($("#router2cart").length < 1) {
            $("input#data2cart").clone().insertAfter("input#data2cart").attr({"id":"router2cart"})
        }
        $("input#router2cart").attr({
            "value": pLabel
        });
    }
})

$("#line_menu a").unbind("click");
$("#line_menu a").bind("click",function(){
    if ($("a.dataSelected").length < 1) {
        $("#before_you_do_container").fadeIn("fast");
    }
    else {
	
		fullWidth = 140;
		fullLeft = 226;
		
        var pLabel = $(this).attr("pLabel");
         if ($("a.routerSelected").length > 0) {
           $("div#data").animate({
                left: -5,
				width:135
            }, "fast", function(){
                fadeInPlus()
            });
			$("div#router").animate({
                left: 143,
				width:135
            }, "fast", function(){
                fadeInPlus()
            });
			fullLeft = 292;
			fullWidth = 135;
			
			if($("img.bundle_plus").length==1){
				$("img.bundle_plus").animate({
					left:118,
					width:37
				},"fast",function(){
					$(this).clone().appendTo("#workbench")
					.css({
						left:266,
						width:37,
						opacity:1
					}).fadeIn("fast");
				});
			}
        }else if ($("a.lineSelected").length == 0) {
           $("div#data").animate({
                left: 67
            }, "fast", function(){
                fadeInPlus()
            });
        }
        
		swopProducts("line", "line_menu", this, 330, fullLeft, pLabel, fullWidth);
		
		if ($("#line2cart").length < 1) {
            $("input#data2cart").clone().insertAfter("input#data2cart").attr({"id":"line2cart"})
        }
        $("input#line2cart").attr({
            "value": pLabel
        });
    }
})


$("#need_hardware_back").unbind("click");
$("#need_hardware_back").bind("click",function(){
	$("#need_hardware").fadeOut("fast");
});

$("#need_hardware_forward").unbind("click");
$("#need_hardware_forward").bind("click",function(){
		
		if ("#my_dot_webmail_menu:visible") {
			$("#my_dot_webmail_menu").fadeOut("fast");
			$("#cart_summary").fadeIn("fast");
		}
		
		var btnObj = $(this);
		var packageArray = new Array();
		var domainArray = new Array();
		
		var Rdata;
		$("#workbench").find("form").find("input.package_input").each(function(){
			packageArray.push($(this).attr("value"));
		})
		
		diagnose(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + packageArray)
		
		$.post("/html/pages/cart_functions.php", {
			"package_label[]": packageArray,
			"action": "add"
		}, function(data){
			if ($("img.bundle_plus:visible")) {
				$("img.bundle_plus:visible").hide();
			};
			
			$("#need_hardware").fadeOut("fast");
			
			$("div.product_container:visible").each(function(){
				thisPos = $(this).position();
				$(this).hide().clone().show().insertAfter("#content_container").css({
					"left": (thisPos.left + 210)
				}).animate({
					"top": -92,
					"left": 500,
					"width": 40,
					opacity: 0
				}, 300, function(){
					$("div.product_container").remove();
					$("a.dataSelected").removeClass("dataSelected");
					$("a.modemSelected").removeClass("modemSelected");
					$("a.lineSelected").removeClass("lineSelected");
					$("a.routerSelected").removeClass("routerSelected");
					
					$("#add2cart_btn").fadeOut("fast");
					$("#price_table").fadeOut("fast", function(){
						$("#workbench").css({
							"background": "none"
						}).append("<span id='temp'></span>");
						$("span#temp").load("/html/pages/checkout/pre_checkout_thank_you.php?curLoc=" + curLoc.toUpperCase(), function(){
							$("#workbench").append($("span#temp").html());
							$("span#temp").remove();
						});
					});
				});
				$("td#firstMonth b").text("R0.00");
				$("td#priceThereafter b").text("R0.00");
			})
			$("b#cart_count").load("/html/pages/cart_count.php");
		});
});

$("input#add2cart_btn").unbind("click");
$("input#add2cart_btn").bind("click",function(e){
    e.preventDefault();
	
	var typeArray = new Array();
	
	$(this).parent("form").find("input.package_input").each(function(){
		typeArray.push($(this).attr("id"));
	});
	
	if (typeArray.join("") == "data2cart") {
		$("#need_hardware").fadeIn("fast");
	}
	else {
	
		if ("#my_dot_webmail_menu:visible") {
			$("#my_dot_webmail_menu").fadeOut("fast");
			$("#cart_summary").fadeIn("fast");
		}
		
		var btnObj = $(this);
		var packageArray = new Array();
		var domainArray = new Array();
		
		var Rdata;
		$(this).parent("form").find("input.package_input").each(function(){
			packageArray.push($(this).attr("value"));
		})
		
		diagnose(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + packageArray)
		
		$.post("/html/pages/cart_functions.php", {
			"package_label[]": packageArray,
			"action": "add"
		}, function(data){
		
			if (curLoc.toUpperCase() == "DIALUP") {
				$("#product_info").fadeOut("fast", function(){
					$("#product_info_container").load("/html/pages/checkout/pre_checkout_thank_you.php?curLoc=" + curLoc.toUpperCase());
				})
			}
			else 
				if (curLoc.toUpperCase() != "HOSTING") {
					if ($("img.bundle_plus:visible")) {
						$("img.bundle_plus:visible").hide();
					};
					$("div.product_container:visible").each(function(){
						thisPos = $(this).position();
						$(this).hide().clone().show().insertAfter("#content_container").css({
							"left": (thisPos.left + 210)
						}).animate({
							"top": -92,
							"left": 500,
							"width": 40,
							opacity: 0
						}, 300, function(){
							$("div.product_container").remove();
							$("a.dataSelected").removeClass("dataSelected");
							$("a.modemSelected").removeClass("modemSelected");
							$("a.lineSelected").removeClass("lineSelected");
							$("a.routerSelected").removeClass("routerSelected");
							
							$("#add2cart_btn").fadeOut("fast");
							$("#price_table").fadeOut("fast", function(){
								$("#workbench").css({
									"background": "none"
								}).append("<span id='temp'></span>");
								$("span#temp").load("/html/pages/checkout/pre_checkout_thank_you.php?curLoc=" + curLoc.toUpperCase(), function(){
									$("#workbench").append($("span#temp").html());
									$("span#temp").remove();
								});
							});
						});
						$("td#firstMonth b").text("R0.00");
						$("td#priceThereafter b").text("R0.00");
					})
				}
			
			$("b#cart_count").load("/html/pages/cart_count.php");
		});
		if (curLoc.toUpperCase() != "HOSTING") {
			$("input.package_input").each(function(){
				if ($("input.package_input").length > 1) {
					$(this).remove();
				}
				else {
					$(this).attr({
						"value": ""
					});
				}
				$("input.package_input").attr({
					"class": "package_input data2cart"
				});
			})
		}
	}
    return false;
})

$("input.hosting2cart_btn").unbind("click");
$("input.hosting2cart_btn").bind("click", function(ev){
	
	ev.preventDefault();
	
	var currentBtn = this;
    	var sliderRef = $(this).attr("ref");
    	//alert(dName4Hosting);
	if(!dName4Hosting){ 
		dName4Hosting = "";
	}
	
	if (dName4Hosting != "") {
	    		
		$("#my_dot_webmail_menu").fadeOut("fast");
		$("#cart_summary").fadeIn("fast");
		
	    var packageArray 	= new Array();
	    var Rdata;
	    
	    $(this).parent("form").find("input.package_input").each(function(){
	        packageArray.push($(this).attr("value"));
	    })
						
	    $.post("/html/pages/cart_functions.php", {
	        "package_label[]": packageArray,
	        "action": "add",
		 "new_domain": dName4Hosting
	    }, function(data){
			
			$("b#cart_count").load("/html/pages/cart_count.php");
			
			$("#hosting_nav").hide();
			$("#"+sliderRef+"_slider").fadeOut("fast", function(){
			
				$.get("/html/pages/hosting/hosting_pco_thank_you.php?withDomain=true", function(data){
					$("#"+sliderRef+"_container").append(data);
					$.getScript("/html/javascript/hosting_ty_controller.js");
				});
				
			});	
	    });
	}
	else {
		$("#hosting_nav").hide();
		$("#"+sliderRef+"_slider").fadeOut("fast", function(){
		
			var hostingPackage = $(currentBtn).parent().find("input.package_input").val();
			
			$.get("/html/pages/hosting/hosting_pco_thank_you.php?hostingPackage=" + hostingPackage, function(data){
				$("#"+sliderRef+"_container").append(data);
				$.getScript("/html/javascript/hosting_ty_controller.js");
			});
		});
	}
	return false;
	
});
$("div.range_inner_container a").unbind("click");
$("div.range_inner_container a").bind("click",function(ev){
		try {
			content[$(this).attr("content")].load();
		} 
		catch (err) {
			var content = new Object();
			content[$(this).attr("content")] = new contentObj($(this));
			content[$(this).attr("content")].load();
		}
		$("#title_tab").fadeOut("fast");
		$("#mProducts").fadeOut("fast",function(){
			$("#product_range_menu").fadeIn("fast");
		})
});

$("p.range_hs").unbind("click");
$("p.range_hs").bind("click",function(){
		
	var link = $(this).attr("link");
	diagnose(link);
	var parent = $(this).parent().attr("id");	
	
	if ($("#" + link).height() > 0) {
		$("#" + link).animate({
			height: 0
		}, "fast").removeClass("open_range");
	}
	else {
		$("#" + parent + " span.shape_container.open_range").animate({
			height: 0
		}, "fast").removeClass("open_range");
		
		$("#" + link).animate({
			height: $(this).attr("fullHeight")
		}, "fast").addClass("open_range");
	}
	
})

$("a.other_hardware").unbind("click");
$("a.other_hardware").bind("click",function(){
	
	var target_content = $(this).attr("content");
	
	$(this).parent().parent().fadeOut("fast", function(){
		$("#"+target_content+"_container").fadeIn("fast");
	});
	
})

$("a.range_change").unbind("click");
$("a.range_change").bind("click",function(){
	target=$(this).attr("content");
	if(target=="static_ip_range"){
		$("#static_ip_range").slideDown("fast");
		$("#dynamic_ip_range").slideUp("fast");
	}else{
		$("#dynamic_ip_range").slideDown("fast");
		$("#static_ip_range").slideUp("fast");
	}
});

var slideCount = 1;
$("#smaller_packages img").css({"display":"block",opacity:0.5})

$("#smaller_packages").unbind("click");
$("#smaller_packages").bind("click",function(){
	
	if (slideCount > 1 ) {
		
		$("#page_"+slideCount).attr({"src":"/html/new_images/HOSTING/page_"+slideCount+".png"});
		
		slideCount--;
		
		$("#page_"+slideCount).attr({"src":"/html/new_images/HOSTING/page_"+slideCount+"_active.png"});
		
		var sliderRef 	= $(this).attr("ref");
		var slider		= $("#"+sliderRef+"_slider");
		var sliderPos 	= slider.position();
		var slideMax		= Number($(slider).attr("slideMax"));

		if (slideCount == (slideMax - 1)) {
			$("#bigger_packages img").fadeTo("fast",1);
		}
		
		if (slideCount == 1) {
			$("#smaller_packages img").fadeTo("fast",0.5);
		}
			
		nextPos = $("#hosting_prod_" + slideCount).position();
		
		slider.animate({
			"left": "-" + nextPos.left
		}, "slow");
		
		$("div.hosting_product_container").each(function(){
			if ($(this).hasClass("right")) {
				$(this).removeClass("right");
			}
			else {
				$(this).addClass("right");
			}
		});
		
	}
});

$("#bigger_packages").unbind("click");
$("#bigger_packages").bind("click",function(){
	
	var sliderRef 	= $(this).attr("ref");
	var slider		= $("#"+sliderRef+"_slider");
	var sliderPos 	= slider.position();
	var slideMax		= Number($(slider).attr("slideMax"));

	if(slideCount < slideMax){
	
		$("#page_"+slideCount).attr({"src":"/html/new_images/HOSTING/page_"+slideCount+".png"});
		
		slideCount++;
		
		$("#page_"+slideCount).attr({"src":"/html/new_images/HOSTING/page_"+slideCount+"_active.png"});
				
		if (slideCount == 2) {
			$("#smaller_packages img").fadeTo("fast",1);
		}
		
		if (slideCount == slideMax) {
			$("#bigger_packages img").fadeTo("fast",0.5);
		}
	
		nextPos = $("#hosting_prod_" + slideCount).position();
		
		slider.animate({
			"left": "-" + nextPos.left
		}, "slow");
		
		$("div.hosting_product_container").each(function(){
			if ($(this).hasClass("right")) {
				$(this).removeClass("right");
			}
			else {
				$(this).addClass("right");
			}
		});
		
	}
});
$("a.page_link").unbind("click");
$("a.page_link").click(function(){
	
	$("#page_"+slideCount).attr({"src":"/html/new_images/HOSTING/page_"+slideCount+".png"});
	slideCount = $(this).attr("pageNo");
	$("#page_"+slideCount).attr({"src":"/html/new_images/HOSTING/page_"+slideCount+"_active.png"});
	
	var sliderRef 	= $(this).attr("ref");
	var slider		= $("#"+sliderRef+"_slider");
	var sliderPos 	= slider.position();
	var slideMax		= Number($(slider).attr("slideMax"));
	
	nextPos = $("#hosting_prod_" + slideCount).position();
	
	if (slideCount > 1) {
		$("#smaller_packages img").fadeTo("fast",1);
	}
	if (slideCount == 1) {
		$("#smaller_packages img").fadeTo("fast",0.5);
	}
	if (slideCount < slideMax) {
		$("#bigger_packages img").fadeTo("fast",1);
	}
	if (slideCount == slideMax) {
		$("#bigger_packages img").fadeTo("fast",0.5);
	}
		
	slider.animate({
		"left": "-" + nextPos.left
	}, "slow");
	
	if ($("#hosting_prod_" + slideCount).hasClass("right")) {
		$("div.hosting_product_container").each(function(){
			if ($(this).hasClass("right")) {
				$(this).removeClass("right");
			}
			else {
				$(this).addClass("right");
			}
		});
	}
});

$("a.show_extra_landing_content").unbind("click");
$("a.show_extra_landing_content").bind("click",function(){
	
	var parent = $(this).parent().parent().parent();
	
	$(this).hide();
	$("#choose_blurb").css({"position":"absolute", "top":"282px"});
	
	parent.find("img.choose_choose").fadeOut("fast", function(){
		
		chooseTop = "130px";
		if(curHash == "#premium_products"){
			chooseTop = "100px";
		}else if(curLoc.toUpperCase()=="3G"){
			chooseTop = "41px";
		}
				
		$("#choose_blurb").animate({
			"top":chooseTop
		}, "fast", function(){
			
			parent.find("p.extra_landing_content").slideDown("fast");
				
		});
			
	});
				
});
$("a.hide_extra_landing_content").unbind("click");
$("a.hide_extra_landing_content").bind("click",function(){
	
	var parent = $(this).parent().parent().parent();
	
	
	parent.find("p.extra_landing_content").slideUp("fast",function(){
		$("#choose_blurb").animate({
			"top":"282px"
		}, "fast", function(){
			
			$(this).css({"position":"relative", "top":"0"});
			
			parent.find("img.choose_choose").fadeIn("fast", function(){
			
				parent.find("a.show_extra_landing_content").show();
						
			});	
		});
	});
			
});
function swopProducts(product, menuSection, tabSelected, minLeft, fullLeft, pLabel, fullWidthArg){

	if($("div#"+product).length < 1){
		create_container(product, tabSelected, pLabel);
	}
	
    var prodObj = $("div#" + product);
    var pClone = $("div#" + product + "Clone");
    var fullWidth;
	if(!fullWidthArg){ fullWidth = 140;}else{ fullWidth = fullWidthArg}
    var minWidth = 100;
    var fullTop = 4;
    var minTop = 33;    
	
    if ($("div#" + product + "Clone").length == 0) {
        pClone = prodObj.clone().insertAfter("div#" + product).attr({
            "id": product + "Clone"
        });
    }
    else {        
        prodObj.css({
            "z-index": 1,
            width: fullWidth,
            left: fullLeft,
            opacity: 1,
            top: fullTop
        }).animate({
            width: minWidth,
            left: minLeft,
            opacity: 0,
            top: minTop
        }, "fast").find("p").hide();
    }
	
    pClone.find("span").attr({"pLabel":pLabel});
    pClone.find("p.detail_1").text($(tabSelected).attr("detail_1"));
    pClone.find("p.detail_2").text($(tabSelected).attr("detail_2"));
    pClone.find("p.pPrice b").text("R"+$(tabSelected).attr("pPrice")+$(tabSelected).attr("pSuffix"));
	
	diagnose(menuSection);
    
	$("#" + menuSection + " a." + product + "Selected").removeClass(product + "Selected").removeClass("itemSelected");
    $(tabSelected).addClass(product + "Selected").addClass("itemSelected");
    
    pClone
	.find("#product_label_img").attr({
        "src": "/html/new_images/"+curLoc.toUpperCase()+"/products/" + pLabel.toLowerCase() + ".png"
    }).end()
	.css({
        "z-index": 2,
        left: minLeft,
        width: minWidth,
        opacity: 0,
        top: minTop
    }).animate({
        width: fullWidth,
        left: fullLeft,
        opacity: 1,
        top: fullTop
    }, "fast", function(){
		pClone.find("#package_details").css({opacity:1}).find("p").show();
	})
	
	prodObj.attr({
        "id": "temp"
    });
    pClone.attr({
        "id": product
    });
    $("div#temp").attr({
        "id": product + "Clone"
    });
	
	updatePrice();
    var ogSrc,remove_hover;
	$("img.product_remove").unbind("mouseenter");
	$("img.product_remove").unbind("mouseleave");
	$("img.product_remove").unbind("click");
	$("img.product_remove").bind("mouseenter", function(){
		ogSrc = this.src;
			$(this).attr({
				"src": "/html/new_images/common/close_x_hover.png"
			}).css({
				width: 63,
				marginLeft: -65
			});
			remove_hover = true;
	})
	$("img.product_remove").bind("mouseleave", function(){
		$(this).attr({"src":ogSrc}).css({width:14,marginLeft:-17});
		remover_hover = false;
	})
	$("img.product_remove").bind("click", function(){
		remove_product($(this).parent());
		remover_hover = false;
	});
	$("div.product_container").unbind("click");
	$("div.product_container").bind("click", function(){
		if (remove_hover != true) {
			prodGoto = curLoc.toLowerCase() + "/common/product_info.php?product=" + $(this).find("span").attr("pLabel");
			showPfFloater(prodGoto);
		}
	});
}
function create_container(product, tabSelected, pLabel){
	
	var pLabel = $(tabSelected).attr("pLabel");
	if (product == "modem" || product == "router" || product == "line") {
		container_html = '<div class="product_container hardProd" id="'+product+'">'
	}else{	
		container_html = '<div class="product_container" id="'+product+'">'
	}
	container_html += '<img id="product_label_img" class="product_top trans_png" src="/html/new_images/'+curLoc.toUpperCase()+'/products/'+pLabel.toLowerCase()+'.png"/>'
	if(product=="line" || product=="router"){product_bottom="modem_bottom"}else{product_bottom=product+'_bottom'}
	container_html +='<img class="product_bottom trans_png" src="/html/new_images/3G/'+product_bottom+'.png"/>'
	container_html += '<span id="package_details" pLabel="'+pLabel+'">'
	container_html += '<p class="detail_1"></p>'
	container_html += '<p class="detail_2"></p>'
	container_html += '<p class="pPrice"><b></b></p>'
	container_html += '</span>'
	if(product == "modem" || product == "router" || product == "line"){
		container_html += '<img class="product_remove trans_png" src="/html/new_images/common/close_x_hardware.png"/>'
	}else{
		container_html += '<img class="product_remove trans_png" src="/html/new_images/common/close_x_new.png"/>'
	}
	container_html += '</div>';
	
	
	$("#workbench").prepend(container_html);
}



function updatePrice(){
	var Monthly = 0;
	var firstMonth = 0;
	var setupFee = 0;
	
	diagnose("updating site");
		
	if(curLoc=="ADSL" && $("a.routerSelected").length > 0){setupFee=100}
	if(curLoc=="3G"){setupFee=300}
	
	if(curHash == "#premium_products"){
		pLabel = $("#data").find("#package_details").attr("pLabel");
		
		if(pLabel.indexOf("PremiumExpress") == -1){
			setupFee = 1700;
		}
	}
	
	$("a.itemSelected").each(
		function(){
		if($(this).attr("pType")=="monthly"){
			Monthly = Number($(this).attr("pPrice").replace(/,/, ""))+Monthly ;
		}
		if($(this).attr("pType")=="once_off"){
			firstMonth = Number($(this).attr("pPrice").replace(/,/, ""))+firstMonth;
		}
	});
	
	firstMonth = firstMonth + Monthly + setupFee;
	
	$("td#setupFee").text("R" + add_commas(setupFee.toFixed(2)));
	$("td#firstMonth b").text("R" + add_commas(firstMonth.toFixed(2)));
    $("td#priceThereafter b").text("R" + add_commas(Monthly.toFixed(2)));
}

function remove_product(prod){
	
	product = prod.attr("id");
	
	if (product == "data") {
		$.each($("div.product_container"), function(){
			var item = this;
			diagnose(item);
			$(item).fadeOut("fast", function(){
				$(item).remove();
			});
			fadeOutPlus();
		});
		$.each($("input.package_input"),function(){
			if($(this).attr("id")=="data2cart"){
				$(this).val("");
			}else{
				$(this).remove();
			}
		})
		$.each($("a.itemSelected"),function(){
			$(this).removeClass("itemSelected");
			$(this).removeClass("dataSelected");
			$(this).removeClass("routerSelected");
			$(this).removeClass("lineSelected");
			$(this).removeClass("modemSelected");
		})
		
		$("#price_table").fadeOut();
		$("#add2cart_btn").fadeOut();
		$("#prod_start").fadeIn();
		$("#prod_next").fadeIn();
		$("#product_blurb").fadeIn();
		$("#workbench").css({"background":'none'});
		
	}
	else {
		
		$("a."+product+"Selected").removeClass("itemSelected").removeClass(product+"Selected");
		
		prod.fadeOut("fast", function(){
			$(this).remove();
			$("#" + product + "Clone").remove();
			
			if($("img.bundle_plus").length==2){
				$("img.bundle_plus:last").remove();
				$("img.bundle_plus").animate({
					left:197
				},"fast")
				$("#data").animate({
					width:140,
					left:67
				},"fast");
				$("div.hardProd:visible").animate({
					width:140,
					left:226
				},"fast")
				$("#"+product+"2cart").remove();
			}else if($("img.bundle_plus").length==1){
				fadeOutPlus();
				$("#data").animate({
					left:143
				},"fast");
				$("#"+product+"2cart").remove();
			}
			
		});
	}
	updatePrice();
}

$("a.more_info").unbind("click");
$("a.more_info").bind("click", function(){
			
	$(this).parent().parent().find("span.th_side_bar.nbl").removeClass("nbl");
	$(this).parent().addClass("nbl");
	
});

function fadeInPlus(){
    $("img.bundle_plus").css({
        opacity: 0
    }).show().animate({
        top: 144,
        opacity: 1
    }, "fast");
}

function fadeOutPlus(){
    $("img.bundle_plus").css({
        opacity: 1
    }).show().animate({
        top: 100,
        opacity: 0
    }, "fast");
}

function add_commas(nStr){
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
function showPfFloater(goto){
	cur_st = $(window).scrollTop();
	if ($(this).attr("gtData")) {
		gtData = $(this).attr("gtData");
	}
	else {
		gtData = "";
	}
	var scrollTop = $(document).scrollTop();
	$("#pf_container").css({
		"top": scrollTop
	}).show();	
	$("#darkener").show();
	$("#pf_container").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()
		});
	}
	$("html").css({
		"overflow-y": "hidden",
		"height": $(window).height(),
		"width": $(window).width()
	});
	$("#product_floater_container #product_float_middle").load("/html/pages/" + goto, function(){
		rTop = ($(window).height() - $("#product_floater_container").height()) / 2;
		
		if (rTop < 0) {
			rTop = 50
		};
		
		$("#product_floater_container").css({
			top: rTop
		}).show();
	});
}

$("#search_bar").unbind("click");
$("#search_bar").bind("click",
	function(){
		if($(this).val()=="www.yourdomain.co.za"){
			$(this).val("");
		}
		if($("#domains_error:visible")){$("#domains_error").fadeOut("fast");}
	}
);

$("#search_bar").focus(function(){
	$(this).val("");
})


var domain_checked = false;

$("#search_submit").unbind("click");
$("#search_submit").bind("click", function(e){
		
	e.preventDefault();
	
	var domainFound;
	var search_bar_val 	= $("#search_bar").val();
		
	for(i=0;i<=domain_array.length;i++){
		
		var domain_pos 		= search_bar_val.indexOf("."+domain_array[i]);
		
		if(domain_pos != -1){
			
			domainFound = true;
			
			var dName 			= search_bar_val.replace("."+domain_array[i],"");		
			var splitStr		= dName.split(".");
			var new_domain 		= splitStr[splitStr.length-1];
			var ext 			= domain_array[i];
			
			patt = /[^a-z0-9\.-]/g;
			if(new_domain.search(patt) != -1){
				searchPos = $("#search_bar").position();
				deTop = searchPos.top + 50;
				$("#domains_error").css({"top":deTop+"px"}).addClass("illegal_char").find("p").html("You have typed in a character that cannot be used in a domain name. Your domain name is allowed to have: <br/> - any letter from a to z (all lowercase)<br/> - Any number from 0 - 9 <br/> - And a dash '-' <br/><b>And that's all...</b>").end().fadeIn("fast");
				return false;	
			};
			
			if($("#domains_error:visible")){$("#domains_error").fadeOut("fast");}
			
			$("#search_bar").fadeOut("fast");
			$("#search_submit").fadeOut("fast",function(){
				
				$(this).parent().css({
					height:70,
					"background":"url(/html/new_images/common/domain_checking_anim.gif) no-repeat center center"
				})
				
				if (domain_checked == false) {
					
					domain_checked = true;
					
					$.post("/html/pages/hosting/common/check_domain.php", {
						domain_name: new_domain,
						ext: ext
					}, function(data){
						$("#domain_search_bar").append(data);
					});
				}
			
			});		
		}
	}
	
	if(domainFound!=true){
		searchPos = $("#search_bar").position();
		deTop = searchPos.top + 50;
		$("#domains_error").css({"top":deTop+"px"})
		.find("p").html("Please make sure that your domain ends with a domain listed under AVAILABLE DOMAINS.")
		.end().fadeIn("fast");
	}
	
	return false;
});
$("input#search_bar").keypress(function(e){
	if(e.which == 13){
		e.preventDefault();
	
		var domainFound;
		var search_bar_val 	= $("#search_bar").val();
			
		for(i=0;i<=domain_array.length;i++){
			
			var domain_pos 		= search_bar_val.indexOf("."+domain_array[i]);
			
			if(domain_pos != -1){
				
				domainFound = true;
				
				var dName 			= search_bar_val.replace("."+domain_array[i],"");		
				var splitStr		= dName.split(".");
				var new_domain 		= splitStr[splitStr.length-1];
				var ext 			= domain_array[i];
				
				if($("#domains_error:visible")){$("#domains_error").fadeOut("fast");}
				
				$("#search_bar").fadeOut("fast");
				$("#search_submit").fadeOut("fast",function(){
					
					$(this).parent().css({
						height:70,
						"background":"url(/html/new_images/common/domain_checking_anim.gif) no-repeat center center"
					})
					
					if (domain_checked == false) {
						
						domain_checked = true;
						
						$.post("/html/pages/hosting/common/check_domain.php", {
							domain_name: new_domain,
							ext: ext
						}, function(data){
							$("#domain_search_bar").append(data);
						});
					}
				
				});		
			}
		}
		
		if(domainFound!=true){
			searchPos = $("#search_bar").position();
			deTop = searchPos.top + 50;
			$("#domains_error").css({"top":deTop+"px"})
			.find("p").html("Please make sure that your domain ends with a domain listed under AVAILABLE DOMAINS.")
			.end().fadeIn("fast");
		}
		
		return false;
	}
})
var icWarningShown = 0;
	
$("#domain_search_bar").keypress(function(e){
	
	var kC = false;
	
	if (e.keyCode) {
		var charCode = e.keyCode;
		diagnose("Keycode: "+charCode)
		kC = true;
	}else{
		var charCode = e.which;
		diagnose("e.which: "+charCode)
	}
	
	char = String.fromCharCode(charCode);
	patt = /[a-z0-9\.-]/g;
	isValid = char.search(patt);
	
	if(isValid == -1 && kC == false){
		if (icWarningShown < 3) {
			searchPos = $("#search_bar").position();
			deTop = searchPos.top + 50;
			$("#domains_error").css({"top":deTop+"px"}).addClass("illegal_char").find("p").html("You have typed in a character that cannot be used in a domain name. Your domain name is allowed to have: <br/> - any letter from a to z (all lowercase)<br/> - Any number from 0 - 9 <br/> - And a dash '-' <br/><b>And that's all...</b>").end().fadeIn("fast");
			icWarningShown++;
		}
		return false;
	}
	
	if(icWarningShown > 0){
		$("#domains_error").fadeOut("fast").removeClass("illegal_char");
	}
	
});