// Main JavaScript Functions - The Wine Company NI
<!--
// AJAX INIT
function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e){
	//Internet Explorer
		try	{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}


function chkKeyFrm(){
	var field = window.document.getElementById('key_search_txt');
	if(field.value=='keyword search'){
		key_val_len = 0;
	}else{
		key_val_len = field.value.length;
	}
	if(key_val_len<3){
		window.document.getElementById('key_error').style.visibility = 'visible';
		field.focus();
		return false;
	}
	return true;
}

//browseby menu panel region population
function showRegions(country, selected, relational){ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Browser does not support AJAX - Please update");
		return;
	}
	var url=relational+"_includes/phpajax/populateregions.inc.php";
	url=url+"?c="+country+"&s="+selected;
	xmlHttp.onreadystatechange=function() { ajaxStateChanged("regioncell"); };
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ajaxStateChanged(obj) {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		window.document.getElementById(obj).innerHTML=xmlHttp.responseText 
	}
}

function validateBottles(bottles){
	if(parseInt(bottles)<12){
		window.document.getElementById('cartBottleError').style.backgroundColor = '#9A0000';
		window.document.getElementById('cartBottleError').style.color = '#FFFFFF';
	}
	return;
}

function hideToolTip(){
	//MOUSE OVER
	var targetDIV = window.document.getElementById('javascript_errorTip');
	targetDIV.style.display = 'none';	
	if(document.layers || document.all) document.onmousemove = null;
	if(document.addEventListener) document.removeEventListener('mousemove', getMouseXY, true);
}

function displayToolTip(content){
	//MOUSE OVER
	var targetDIV = window.document.getElementById('javascript_errorTip');
	targetDIV.style.position = 'absolute';
	targetDIV.innerHTML = content;
	
	if(document.layers) document.captureEvents(Event.MOUSEMOVE);
	if(document.layers || document.all) document.onmousemove = getMouseXY;
	if(document.addEventListener) document.addEventListener('mousemove', getMouseXY, true);
	return;
}

function getMouseXY (e) {
	//GET SCREEN POS
	var x = document.all ? event.clientX : document.layers ? e.x : e.clientX;
	var y = document.all ? event.clientY : document.layers ? e.y : e.clientY;
	if (x < 0){x = 0}
	if (y < 0){y = 0}
	//GET THE SCROLL DISTANCES
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	y += scrOfY;
	x += scrOfX;
	window.document.getElementById('javascript_errorTip').style.left = (x+10) + 'px';
	window.document.getElementById('javascript_errorTip').style.top = (y-10) + 'px';
	window.document.getElementById('javascript_errorTip').style.display = 'inline';
	return;
}

function sameAsAbove(){
	var selId = window.document.getElementById('billcountry').selectedIndex;
	if(selId==1){
		window.document.getElementById('roi_delivery_chk').checked = 'checked';
		roi_delivery_option(window.document.getElementById('roi_delivery_chk'));
	}else{
		window.document.getElementById('dcountry').options[selId].selected = 'selected';
		
		var a1 = window.document.getElementById('add1');
		var a2 = window.document.getElementById('billadd1');
		var b1 = window.document.getElementById('add2');
		var b2 = window.document.getElementById('billadd2');
		var c1 = window.document.getElementById('add3');
		var c2 = window.document.getElementById('billadd3');
		var d1 = window.document.getElementById('pcode');
		var d2 = window.document.getElementById('billpcode');
		var e1 = window.document.getElementById('county');
		var e2 = window.document.getElementById('billcounty');
		
		a1.value = a2.value;
		b1.value = b2.value;
		c1.value = c2.value;
		d1.value = d2.value;
		e1.value = e2.value;
	}
	return;
}

function roi_delivery_option(obj, autochk){
	if(autochk==true) obj.checked = true;
	var a1 = window.document.getElementById('name');
	var b1 = window.document.getElementById('email');
	var c1 = window.document.getElementById('tel');
	var d1 = window.document.getElementById('fax');
	var e1 = window.document.getElementById('add1');
	var f1 = window.document.getElementById('add2');
	var g1 = window.document.getElementById('add3');
	var h1 = window.document.getElementById('pcode');
	var i1 = window.document.getElementById('county');
	var j1 = window.document.getElementById('dcountry');
	
	if(obj.checked){
		window.document.getElementById('roi_delivery_details').style.display = 'block';
		window.document.getElementById('same').style.display = 'none';
		window.document.getElementById('delivery_details').style.display = 'none';
		e1.disabled = true;
		f1.disabled = true;
		g1.disabled = true;
		h1.disabled = true;
		i1.disabled = true;
		j1.disabled = true;
		e1.value = '';
		f1.value = '';
		g1.value = '';
		h1.value = '';
		i1.value = '';
		j1.value = '';
	}else{
		window.document.getElementById('roi_delivery_details').style.display = 'none';
		window.document.getElementById('same').style.display = 'block';
		window.document.getElementById('delivery_details').style.display = 'block';
		e1.disabled = false;
		f1.disabled = false;
		g1.disabled = false;
		h1.disabled = false;
		i1.disabled = false;
		j1.disabled = false;
	}
	
	return;
}
//-->