//CHECK JAVASCRIPT
function IsJavascriptEnabled() {

    if (navigator.JavaEnabled()) {
        return true;
    }
    else {
        return false;
    }
}


//START AJAX FUNCTION
// obslete, before remove it make sure no one use it
function GetShippingMethodDescription_CallBack(response)
{
	if (response.error != null)
	{
//		alert(response.error);
///		alert(response.statusCode);
//		alert("Unable to contact the server!");
		return;
	}
  
	if (response.value != null)
	{
		var div = document.getElementById("DivShippingMessage");
		div.innerHTML = response.value;
		div.style.display = "block";

		if (response.value.indexOf("Australian Air Express")>=0)
		{
			GetObject("DivAgree").style.display = "block";
			GetObject("cbAgree").checked = false;
		}
		else
		{
			GetObject("DivAgree").style.display = "none";
			GetObject("cbAgree").checked = true;	
		}		
	}
}

// obslete, before remove it make sure no one use it
function GetShippingMethod_CallBack(response)
{
	if (response.error != null)
	{
		alert(response.error);	
		alert("Unable to contact the server!");
		return;
	}
 
 	if (response.value == null)
	{
		alert('Please select your shipping method!');
	}
	else
	{
		GoToPage(response.value)
	}	
}

function SetPaymentMethod_CallBack(response)
{
	if (response.error != null)
	{
		alert(response.error);	
		alert("Unable to contact the server!");
		return;
	}
}
//END AJAX FUNCTION

//START NAVIGATION FUNCTION
function RefreshPage(pCurrentUrl)
{
	location.replace(pCurrentUrl);
}
function GoToPage(pTargetUrl)
{
	location.href=pTargetUrl;
}
//END NAVIGATION FUNCTION

function NewWindow(mypage, myname, w, h, scroll) 
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

//This method toggles the summary box in ExpertRepairSVC user control
function ToggleSummary(evt)
{
	if (evt.title == "Summary")
	{
		document.getElementById('DivSummary').style.display='none';
		document.getElementById('DivComplete').style.display='block';
		document.getElementById('btnComplete').style.display='block';
		evt.style.display='none';
	}
	else
	{
		document.getElementById('DivSummary').style.display='block';
		document.getElementById('DivComplete').style.display='none';
		document.getElementById('btnSummary').style.display='block';
		evt.style.display='none';	
	}
}

function GetObject(pDivId)
{
	if (document.getElementById)
		theDiv = document.getElementById(pDivId);
	else
		theDiv = document.all(pDivId);
		
	if (theDiv == null)
	{
		//alert("Your browser does not support this feature!");
	}
	
	return theDiv;
}
/*
function ShowDivByCursor(pDivId, pMouseX, pMouseY)
{
	theDiv = GetObject(pDivId);

	if ((screen.height / 2) < window.event.y)
		posY = document.body.scrollTop - 190 + window.event.y;
	else
		posY = document.body.scrollTop + 25 + window.event.y;

	theDiv.style.left = window.event.x;
	theDiv.style.top = posY;
	theDiv.style.display='block';
}
*/
function FillDiv(pTarget, pDataSource)
{
	theTarget = GetObject(pTarget);
	theSource = GetObject(pDataSource);
	theTarget.innerHTML = theSource.innerHTML;
}
function ShowDiv(pDivId)
{
	theDiv = GetObject(pDivId);
	theDiv.style.display='block';
}

function HideDiv(pDivId)
{
	theDiv = GetObject(pDivId);
	theDiv.style.display='none'
}

function SwapButton(pButtonToHide, pButtonToShow)
{
	btnToHide = GetObject(pButtonToHide);
	btnToShow = GetObject(pButtonToShow);
	btnToHide.style.display='none';
	btnToShow.style.display='inline';
}

function CopyText(pCopyTo, pText)
{
	txtToCopy = GetObject(pCopyTo);
	txtToCopy.value = pText;
}

function CopyTextBox(pCopyFrom, pCopyTo)
{
	target = GetObject(pCopyTo)
	target.value = GetObject(pCopyFrom).value
	target.disabled = true	
}

function ClearTextBox(pToClear)
{
	target = GetObject(pToClear)
	target.value = ""
	target.disabled = false	
}

function ClearDropDown(pToClear)
{
	target = GetObject(pToClear)
	target.options[0].selected = true;
	target.disabled = false
}

function UpdateDeliveryAddress(cbStatus)
{
	if (cbStatus)
	{
		CopyTextBox("txtNameBilling", "txtName")
		CopyTextBox("txtAddressBilling", "txtAddress")
		CopyTextBox("txtAddress2Billing", "txtAddress2")
//		CopyTextBox("txtAddress3Billing", "txtAddress3")
		CopyTextBox("txtCityBilling", "txtCity")
		CopyTextBox("txtStateBilling", "txtState")
		CopyTextBox("txtPostCodeBilling", "txtPostCode")
		CopyTextBox("ddCountryBilling", "ddCountry")		
	}
	else
	{
		ClearTextBox("txtName")
		ClearTextBox("txtAddress")
		ClearTextBox("txtAddress2")
//		ClearTextBox("txtAddress3")
		ClearTextBox("txtCity")
		ClearTextBox("txtState")
		ClearTextBox("txtPostCode")
		ClearDropDown("ddCountry")
	}
}

function ToggleDiv(pDivToggle, pDivController)
{
	divToggle = GetObject(pDivToggle);
	if (divToggle.style.display=='block')
	{
		divToggle.style.display = "none";
//		pDivController.className = "tdUp"
	}
	else
	{
		divToggle.style.display = "block";
//		pDivController.className = "tdDown"
	}	
}

function ToggleImage(source, pDivImage)
{
	divToggle = GetObject(pDivImage);	
	if (divToggle.style.display=='block')
	{
		divToggle.style.display = 'none'
		source.innerHTML = "View";
		source.title = source.href;
		source.href = "#top";
	}
	else
	{
		divToggle.style.display = 'block';
		source.innerHTML = "Hide";
		source.href = source.title;
		source.style.cursor = "pointer";
	}
}

function ShowAbout(pDivToDisplay)
{
	var DivGeneral = GetObject("DivGeneral");
	var DivStaff = GetObject("DivStaff");
	var DivNow = GetObject("DivNow");
	
	DivGeneral.style.display = "none";
	DivStaff.style.display = "none";
	DivNow.style.display = "none";
	
	var theDiv = GetObject(pDivToDisplay);
	theDiv.style.display = "block";
}

//Handling Enter to submit assosiate activity
function SubmitData(pButtonId, event)
{
	if (event.keyCode==13)
	{
		GetObject(pButtonId).click();
		event.returnValue=false;
	}
}

//Shopping Cart Function to monitor delete scheme
function MonitorShoppingCart(isChecked)
{
	if (isChecked)
		itemToRemove++;
	else
		itemToRemove--;	
}

function ShowDeleteConfirmation()
{
	if (itemToRemove > 0)
	{
		if (!confirm("You are about to remove " + itemToRemove + " item(s) from your shopping cart. Click 'OK' to confirm!"))
		{
			event.returnValue = false;	
			return false;		
		}
	}
}

function DisplayTable(controlId, mode)
{
	document.getElementById(controlId).style.display = mode;
}

/* The Code Below is to handle PopUp information for displaying shipping info
 * ---------------------------------------------------------------------------
 * Last Update: 07 October 2005 16:37
 */
var offsetxpoint=-5; //Customize x offset of tooltip
var offsetypoint=25; //Customize y offset of tooltip

var ie = document.all;
var ns6 = document.getElementById && !document.all;
var enableTips = false;
var theObj;

function GetObject(pObjId)
{
	var theObj;
	if (ie||ns6)
		theObj = document.all ? document.all[pObjId] : document.getElementById ? document.getElementById(pObjId) : "";	
	return theObj;
}

function ieTrueBody()
{
	return (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;
}

function ShowDivHelp(pObjId)
{
	if (ns6||ie)
	{
		theObj = GetObject(pObjId);
		enableTips = true;
		return false;
	}
}

function TipsOnMove(e)
{
	if (enableTips)
	{		
		var curX=(ns6) ? e.pageX : event.clientX + ieTrueBody().scrollLeft;
		var curY=(ns6) ? e.pageY : event.clientY + ieTrueBody().scrollTop;
		
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ieTrueBody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20;
		var bottomedge=ie&&!window.opera? ieTrueBody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20;

		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<theObj.offsetWidth)
		{
			//move the horizontal position of the menu to the left by it's width
			theObj.style.left=ie? ieTrueBody().scrollLeft+event.clientX-theObj.offsetWidth+"px" : window.pageXOffset+e.clientX-theObj.offsetWidth+"px";
		}
		else if (curX<leftedge)
			theObj.style.left = "5px"
		else
			//position the horizontal position of the menu where the mouse is positioned
			theObj.style.left = curX + offsetxpoint+"px"

		//same concept with the vertical position
		if (bottomedge<theObj.offsetHeight)
			theObj.style.top=ie? ieTrueBody().scrollTop+event.clientY-theObj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-theObj.offsetHeight-offsetypoint+"px"
		else
			theObj.style.top=curY+offsetypoint+"px"
		theObj.style.visibility="visible"
	}
}

function HideDivHelp()
{
	if (ns6||ie)
	{
		enableTips=false;
		
		theObj.style.visibility="hidden";
		theObj.style.left="-1000px";
	}
}

document.onmousemove = TipsOnMove


/*************************************************************
	Javascript for Admin
*************************************************************/
function ToggleCheckBox(val)
{
	if (val == "Check all")
	{
		isChecked = true;
		GetObject("ButtonCheck").value = "Uncheck all";
	}
	else
	{
		isChecked = false;
		GetObject("ButtonCheck").value = "Check all";		
	}
	
	GetObject("_ctl1_Cust_A").checked = isChecked;
	GetObject("_ctl1_Cust_B").checked = isChecked;
	GetObject("_ctl1_Cust_C").checked = isChecked;
	GetObject("_ctl1_Cust_D").checked = isChecked;
	GetObject("_ctl1_Cust_E").checked = isChecked;
//	GetObject("_ctl1_Cust_F").checked = isChecked;
	GetObject("_ctl1_Cust_G").checked = isChecked;	
	GetObject("_ctl1_Cust_H").checked = isChecked;
	GetObject("_ctl1_Cust_I").checked = isChecked;
	GetObject("_ctl1_Cust_J").checked = isChecked;
	GetObject("_ctl1_Cust_K").checked = isChecked;
	GetObject("_ctl1_Cust_L").checked = isChecked;
	GetObject("_ctl1_Cust_M").checked = isChecked;
	GetObject("_ctl1_Cust_N").checked = isChecked;		
	GetObject("_ctl1_Cust_O").checked = isChecked;
	GetObject("_ctl1_Cust_P").checked = isChecked;			
	GetObject("_ctl1_Cust_Q").checked = isChecked;		
	GetObject("_ctl1_Cust_R").checked = isChecked;		
	GetObject("_ctl1_Cust_S").checked = isChecked;		
	GetObject("_ctl1_Cust_T").checked = isChecked;		
	GetObject("_ctl1_Cust_U").checked = isChecked;		
	GetObject("_ctl1_Cust_V").checked = isChecked;		
	GetObject("_ctl1_Cust_W").checked = isChecked;		
//	GetObject("_ctl1_Cust_X").checked = isChecked;		
	GetObject("_ctl1_Cust_Y").checked = isChecked;		
	GetObject("_ctl1_Cust_Z").checked = isChecked;		
}

EnableCustType = function(senderID, targetID)
{
	var cb = document.getElementById(senderID);
	if (!cb) return;
	var target = document.getElementById(targetID);
	target.disabled = !cb.checked;
	target.checked = false;
}

ToggleDivState = function(senderID, targetID)
{
	var sender = document.getElementById(senderID);
	if (!sender) return;
	var target = document.getElementById(targetID);
	
	if (sender.checked)
		target.style.display = "block";
	else
		target.style.display = "none";
}

ToggleCheckBoxInDataGrid = function(dg, status)
{
	var parent = document.getElementById(dg);
	if (!parent) return;
	
	var cbList = parent.getElementsByTagName("INPUT");
	for (var i=0; i<cbList.length; i++)
	{
		if (cbList[i].type == "checkbox")
		{			
			cbList[i].checked = status;
		}
	}
}

ShowMenuToolTip = function(sender, text)
{
	var div = document.createElement("DIV");
	div.className = "ToolTip"
	div.innerHTML = text;	
	if (document.all)
		div.style.left = sender.offsetWidth - 14;
	else
		div.style.left = sender.offsetWidth;
	div.style.position = "absolute";

	sender.style.position = "relative";
	sender.onmouseout = function() {
		sender.removeChild(div); 
	};
	sender.appendChild(div);
}

ShowToolTip = function(sender, text)
{
	var div = document.createElement("DIV");
	div.className = "ToolTip"
	div.innerHTML = text;				
	
	div.style.top = sender.scrollHeight + 2;
	div.style.left = 10;			

	div.style.position = "absolute";
	sender.style.position = "relative";
	sender.onmouseout = function() {
		sender.removeChild(div); 
	};
	sender.appendChild(div);
}