/*
 * function changeBox() and restoreBox() allows password text to be displayed in the password type input box
 */

function changeBox()
{
	document.getElementById('password1').style.display='none';
	document.getElementById('password2').style.display='';
	document.getElementById('password').focus();
}
function restoreBox()
{
	if(document.getElementById('password').value=='')
	{
		document.getElementById('password1').style.display='';
		document.getElementById('password2').style.display='none';
	}
}

/*
 * MEGAMENU
 */

$(document).ready(function() {	// jQuery calls start here 
	if ($('ul.sf-menu').length > 0){
		$.getScript('/js/superfish.js', function() {
			$.getScript('/js/jquery.hoverIntent.minified.js', function() {
				$('ul.sf-menu').superfish({
					autoArrows:  false, 
					animation:   {height:'show'},
					animation:   {opacity:'show',height:'show'},
					speed: 'fast'
					});
				}); 
			});
		}
	}
);

/*
 * TABS
 */

$(document).ready(function() {
	if ($('ul.tabs').length > 0){
		$.getScript('/js/jquery.tools.min.js', function() {
			$("ul.tabs").tabs("div.panes > div");
		});
	}
});

/*
 * SLIDER
 */
 
$(document).ready(function() {
	if ($('ul.tabs').length > 0){
		$.getScript('/js/jquery.nivo.slider.pack.js', function() {
			$('#slider').nivoSlider({
				effect:'boxRain',
				directionNav:false,
				directionNavHide:false,
				pauseTime:4500
			});
		});
	}
});

// Paypal

	$(document).ready(function() {
		if ($('#paypal_form').length > 0){
			$('#paypal_form form').submit();
		}
	});

/*
 * ALL AJAX STARTS HERE
 */
 
function getXMLHTTP() { //fuction to return the xml http object
	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}
		
	return xmlhttp;
}

function getSubsection(strURL) {		
	
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('top_nav_container_blue').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}			
}

function getCK(strURL) {		
	
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('CK').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}			
}

function getSubCategory(strURL) {		
	
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('sub_cat_change').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}			
}

function getclientfirstname(strURL) {		
	
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('clientfirstname_ajax').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}			
}

function getDeliveryCountry(strURL) {		
	
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('change_delivery').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}			
}

function getState(strURL) {		
	
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('state_change').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}			
}

function performdelete(DestURL) {
var ok = confirm("Are you sure you want to delete?");
if (ok) {location.href = DestURL;}
return ok;
}

function showDiv(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementsByTagName("div"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="helpclass") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}		

// Copy Delivery Addtess 

function updateBillingAddress() { 
	if ($("#copyaddress").is(':checked')) { 
		// Checked, copy values 	
		$("input#clientfirstname").val($("input#delivery_firstname").val()); 
		$("input#clientlastname").val($("input#delivery_lastname").val()); 
		$("input#clientcompanyname").val($("input#delivery_companyname").val());
		$("input#clientaddressline1").val($("input#delivery_addressline1").val());
		$("input#clientaddressline2").val($("input#delivery_addressline2").val());
		$("input#clientcity").val($("input#delivery_city").val());
		$("select#clientcounty").val($("select#delivery_county").val());
		$("input#clientstate").val($("input#delivery_state").val());
		$("input#clientpostcode").val($("input#delivery_postcode").val());
	}
	else { 
		// Clear on uncheck 
		$("input#clientfirstname").val(""); 
		$("input#clientlastname").val(""); 
		$("input#clientcompanyname").val("");
		$("input#clientaddressline1").val("");
		$("input#clientaddressline2").val("");
		$("input#clientcity").val("");
		$("select#clientcounty").val("");
		$("input#clientstate").val("");
		$("input#clientpostcode").val("");
	} 
}

function updateShippingAddress() { 
	if ($("input#copyaddress").is(':checked')) { 
		// Checked, copy values 	
		$("input#delivery_firstname").val($("input#clientfirstname").val()); 
		$("input#delivery_lastname").val($("input#clientlastname").val()); 
		$("input#delivery_companyname").val($("input#clientcompanyname").val());
		$("input#delivery_addressline1").val($("input#clientaddressline1").val());
		$("input#delivery_addressline2").val($("input#clientaddressline2").val());
		$("input#delivery_city").val($("input#clientcity").val());
		$("select#delivery_county").val($("select#clientcounty").val());
		$("input#delivery_state").val($("input#clientstate").val());
		$("input#delivery_postcode").val($("input#clientpostcode").val());
	} 
}

// Hide Billing Address

function showBillingAddress() {
	if ($("#copyaddress").is(':checked')) {
		$('#billing_dets').hide(400);
		return false;
	}
	else {
		$('#billing_dets').show(400);
		return false;
	}
}

$(document).ready(function(){ 
						   
    $("#billing_dets").hide();
	
	$("#copyaddress").change(updateBillingAddress);
	
	$("#copyaddress").change(showBillingAddress);
	
	$("#billing_dets input").keyup(updateShippingAddress);
	
	$("#billing_dets select").change(updateShippingAddress);
	
	$("#shipping_dets input").keyup(updateBillingAddress);
	
	$("#shipping_dets select").change(updateBillingAddress);
	
	$("#copyaddress").click(function(){
		if($.browser.msie){
			this.blur();
		}
	});
	
});

$(document).ready(function(){
	$('#gobrand').change(function() {
		var url = $(this).val();
		window.location = url;
	});
});
