var TimerIDCur = 0;
var TimerIDStock;
var TimerIDTrolley;
var lastStockID = -1
var lastOpenPanel = "close"

function ShowStockDetails(stockid){
	var StockDetails = getFrmObj('StockDetails')
	OpenPanel(stockid)
	lastOpenPanel = "close"
	StockDetails.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' bgcolor='" + strPageBKColor + "' width='575px' height='400px'><tr><td align=center valign=middle onmouseover='OpenPanel(" + stockid + ")' onmouseout='MouseOutPanel()'><img src='/w/images/29.gif' border=0></td></tr></table>"
	RoundCornerOne()
	httpRequest('GetStockDetails.asp?StockID=' + stockid + '&PageNo=' + intPageNo, DisplayStockData, "data");
}


function ShowStockDetailsDown(stockid){
	var StockDetails = getFrmObj('StockDetails')
	OpenPanelDown(stockid)
	lastOpenPanel = "close"
	StockDetails.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' bgcolor='" + strPageBKColor + "' width='575px' height='400px'><tr><td align=center valign=middle onmouseover='OpenPanelDown(" + stockid + ")' onmouseout='MouseOutPanel()'><img src='/w/images/29.gif' border=0></td></tr></table>"
	RoundCornerOne()
	httpRequest('GetStockDetails.asp?StockID=' + stockid + '&PageNo=' + intPageNo, DisplayStockDataDown, "data");
}

function RoundCornerOne(){
	if(!NiftyCheck()){
		return;
	}

	Rounded("div#StockDetails","top","transparent",strPageBKColor,"border #C0C0C0");
	Rounded("div#StockDetails","bottom","transparent",strPageBKColor,"border #C0C0C0");
}

function OpenPanel(stockid){
	clearTimeout(TimerIDStock);
	var StockDetails = getFrmObj('StockDetails')
	lastStockID = stockid
	StockDetails.style.visibility = "visible"
	StockDetails.style.zIndex = "300"
	StockDetails.style.minHeight = "350px"
	StockDetails.style.minWidth = "580px"
	//var c = getAnchorPosition("AnchorStock" + stockid);
	//StockDetails.style.left = c.x + "px"
	//alert(getScrollYPosition())
	//alert(parseInt(c.y) + ", " + parseInt(c.y) + parseInt(20))
	//StockDetails.style.top = (parseInt(c.y) + 20) + "px";
	
	var anchorObjID = "#AnchorStock" + stockid;
	var anchorPosTop = $(anchorObjID).offset().top;
	var anchorPosLeft = $(anchorObjID).position().left;
	//alert(anchorPos.top + ":" + anchorPos.left);
	$("#StockDetails").css({"top":anchorPosTop, "left":anchorPosLeft + MContLeft});
}

function OpenPanelDown(stockid){
	clearTimeout(TimerIDStock);
	var StockDetails = getFrmObj('StockDetails')
	lastStockID = stockid
	StockDetails.style.visibility = "visible"
	StockDetails.style.zIndex = "300"
	StockDetails.style.height = "650px"
	StockDetails.style.width = "580px"
	var c = getAnchorPosition("AnchorStockScroll");
	//StockDetails.style.left = (parseInt(c.x) - 5);
	StockDetails.style.left = c.x + "px";
	//alert(getScrollYPosition())
	//alert(parseInt(c.y) + ", " + parseInt(c.y) + parseInt(20))
	//StockDetails.style.top = (parseInt(c.y) - 5) + "px";
	StockDetails.style.top = c.y + "px";
}

function DisplayStockData(data){
	var StockDetails = getFrmObj('StockDetails')
	StockDetails.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' width='575px' bgcolor='" + strPageBKColor + "' cellpadding=10><tr><td valign=top onmouseover='OpenPanel(" + lastStockID + ")' onmouseout='MouseOutPanel()'>" + data + "</td></tr></table>"
	RoundCornerOne()
}

function DisplayStockDataDown(data){
	var StockDetails = getFrmObj('StockDetails')
	StockDetails.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' width='575px' bgcolor='" + strPageBKColor + "' cellpadding=10><tr><td valign=top onmouseover='OpenPanelDown(" + lastStockID + ")' onmouseout='MouseOutPanel()'>" + data + "</td></tr></table>"
	RoundCornerOne()
}

function MouseOutPanel(){
	clearTimeout(TimerIDStock);
	if(lastOpenPanel=="close"){
    	TimerIDStock = setTimeout('ClosePanel(lastStockID)', 1200)
	}
}

function ClosePanel(stockid){
	var StockDetails = getFrmObj('StockDetails')
	StockDetails.style.visibility = "hidden"
	StockDetails.style.zIndex = "0"
	StockDetails.style.height = "0px"
	StockDetails.style.width = "0px"
	StockDetails.style.left = "-1000px";
	StockDetails.style.top = "-1000px";
}

function btnAddToTrolleyClick(){
	alert("You must first login or register to add items to the Trolley!")
}

function btnViewTrolleyNotClick(){
	alert("You must first login or register to view the Trolley!")
}

function btnAddToTrolleySaveClick(stockid){
	var minQTY = getFrmObj('minQTY')
	var OrderStockQty = getFrmObj('txtOrderStockQty')
	if (OrderStockQty.value < minQTY.value){
		alert("You cannot purchase less than " + minQTY.value + " of this item!");
	}else{
		var TrolleyDiv = getFrmObj('TrolleyDiv')
		TrolleyDiv.innerHTML = "<table border=1 bgcolor=white width='345px' height='200px'><tr><td align=center valign=middle><img src='/w/images/29.gif' border=0></td></tr></table>"
		//alert(stockid)
		OpenTrolley(stockid)
		var ItemPrice = getFrmObj('txtItemPrice')
		var VariationID = getFrmObj('txtVariations')
		//alert('GetTrolley.asp?Save=addItemsToTrolley&StockID=' + stockid + '&OrderQty=' + OrderStockQty.value + '&ItemPrice=' + ItemPrice.value + '&VariationID=' + VariationID.value)
		httpRequest('GetTrolley.asp?Save=addItemsToTrolley&StockID=' + stockid + '&OrderQty=' + OrderStockQty.value + '&ItemPrice=' + ItemPrice.value + '&VariationID=' + VariationID.value, DisplayTrolley, "data");
	}
}

function btnViewTrolleyClick(){
	var TrolleyDiv = getFrmObj('TrolleyDiv')
	TrolleyDiv.innerHTML = "<table border=1 bgcolor=white width='345px' height='200px'><tr><td align=center valign=middle><img src='/w/images/29.gif' border=0></td></tr></table>"
	OpenTrolley(lastStockID)
	httpRequest('GetTrolley.asp', DisplayTrolley, "data");

}

function DisplayTrolley(data){
	var TrolleyDiv = getFrmObj('TrolleyDiv')
	TrolleyDiv.innerHTML = data
}

function OpenTrolley(stockid){
	clearTimeout(TimerIDTrolley);
	var TrolleyDiv = getFrmObj('TrolleyDiv')
	lastStockID = stockid
	TrolleyDiv.style.visibility = "visible"
	TrolleyDiv.style.zIndex = "302"
	TrolleyDiv.style.height = "100px"
	TrolleyDiv.style.width = "345px"
	if (stockid > 0){
		//var c = getAnchorPosition("AnchorStock" + stockid);
		//TrolleyDiv.style.left = c.x + "px";
		//TrolleyDiv.style.top = c.y + "px";
		var anchorObjID = "#AnchorStock" + stockid;
		var anchorPosTop = $(anchorObjID).offset().top;
		var anchorPosLeft = $(anchorObjID).position().left;
		//alert(anchorPos.top + ":" + anchorPos.left);
		$("#TrolleyDiv").css({"top":anchorPosTop, "left":anchorPosLeft + MContLeft});
		//alert(TrolleyDiv.innerHTML)
	}else{
		TrolleyDiv.style.left = "200px";
		TrolleyDiv.style.top = "200px";
	}
}

function btnTrolley(){
	var TrolleyDiv = getFrmObj('TrolleyDiv')
	TrolleyDiv.style.visibility = "hidden"
	TrolleyDiv.style.zIndex = "0"
	TrolleyDiv.style.height = "0px"
	TrolleyDiv.style.width = "0px"
	TrolleyDiv.style.left = "-1000px";
	TrolleyDiv.style.top = "-1000px";
}

function btnDelClick(which){
	httpRequest('GetTrolley.asp?Save=deleteItem&OrderItemID=' + which, DisplayTrolley, "data");
}

function clearTrolley(){
	httpRequest('GetTrolley.asp?Save=clearTrolley', DisplayTrolley, "data");
}

function btnEditStockFields(stockid){
	window.open('EditStockFields.asp?StockID=' + stockid + "&PageNo=" + intPageNo + "&d=y",'StockEditor','width=400,height=650,scrollbars=1,resizable=1, status=1')
}

function btnAddVariation(stockid){
	window.open('EditStockVariations.asp?StockID=' + stockid + "&PageNo=" + intPageNo,'StockVEditor','width=450,height=300,scrollbars=1,resizable=1, status=1')
}

function btnSaveStockDetails(stockid){
	if (lastOpenPanel == "open"){
		//var editFullDetails = getFrmObj("editFullDetails")
		//var editFullDetailsDiv = getFrmObj("editable-9")
		//alert(editFullDetailsDiv.innerHTML)
		//editFullDetails.value = editFullDetailsDiv.innerHTML
		//alert(editFullDetails.value)
		var objFrm = getFrmObj('frmEdit');
		objFrm.action="default.asp?PageNo=" + intPageNo + "&Save=updateStockFullDetails&StockID=" + stockid
		objFrm.submit()
	}else{
		alert("You must have double clicked to edit full details first!")
	}
}

function btnDeleteStockClick(which){
	var objFrm = getFrmObj('frmEdit');
	objFrm.action="default.asp?PageNo=" + intPageNo + "&Save=deleteStock&StockID=" + which
	objFrm.submit()
}

function btnDeleteStockFromPageClick(which){
	var objFrm = getFrmObj('frmEdit');
	objFrm.action="default.asp?PageNo=" + intPageNo + "&Save=deleteStockFromPage&StockID=" + which
	objFrm.submit()
}

function btnAddStockClick(){
	var objFrm = getFrmObj('frmEdit');
	objFrm.action="default.asp?PageNo=" + intPageNo + "&Save=addStock"
	objFrm.submit()
}

function SendOrder(){
	var TotalOrderPrice = getFrmObj('txtTotalOrderPrice')
	var FreightCharge = getFrmObj('txtFreightCharge')
	var FZ1 = getFrmObj('txtFreightZone1')
	var FZ2 = getFrmObj('txtFreightZone2')
	var FZ3 = getFrmObj('txtFreightZone3')
	var CustOrderId = getFrmObj('txtCustOrderId')
	window.location.href='GetTrolley.asp?Save=fromTrolley&FZ1=' + FZ1.value + '&FZ2=' + FZ2.value + '&FZ3=' + FZ3.value + '&TotalOrderPrice=' + TotalOrderPrice.value + '&FreightCharge=' + FreightCharge.value + '&CustOrderId=' + CustOrderId.value
}

function ShowCurrencyInfo(){
	var CurrencyInfo = getFrmObj('CurrencyInfo')
	OpenPanelCurrencyInfo()
	CurrencyInfo.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' bgcolor='" + strPageBKColor + "' width='300px' height='250px'><tr><td align=center valign=middle onmouseover='OpenPanelCurrencyInfo()' onmouseout='MouseOutPanelCur()'><img src='/w/images/29.gif' border=0></td></tr></table>"
	RoundCornerCur()
	httpRequest('GetCurrencyInfo.asp', DisplayCurrencyInfo, "data");

}

function RoundCornerCur(){
	if(!NiftyCheck()){
		return;
	}

	Rounded("div#CurrencyInfo","top","transparent",strPageBKColor,"border #C0C0C0");
	Rounded("div#CurrencyInfo","bottom","transparent",strPageBKColor,"border #C0C0C0");
}

function OpenPanelCurrencyInfo(stockid){
	clearTimeout(TimerIDCur);
	var StockDetails = getFrmObj('CurrencyInfo')
	StockDetails.style.visibility = "visible"
	StockDetails.style.zIndex = "300"
	StockDetails.style.height = "350px"
	StockDetails.style.width = "305px"
	var c = getAnchorPosition("AnCurrencyInfo");
	StockDetails.style.left = c.x + "px";
	//alert(getScrollYPosition())
	//alert(parseInt(c.y) + ", " + parseInt(c.y) + parseInt(20))
	StockDetails.style.top = (parseInt(c.y) + 20) + "px";
}

function DisplayCurrencyInfo(data){
	var StockDetails = getFrmObj('CurrencyInfo')
	StockDetails.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' width='300px' bgcolor='" + strPageBKColor + "' cellpadding=10><tr><td valign=top onmouseover='OpenPanelCurrencyInfo()' onmouseout='MouseOutPanelCur()'>" + data + "</td></tr></table>"
	RoundCornerCur()
}

function MouseOutPanelCur(){
	clearTimeout(TimerIDCur);
    	TimerIDCur = setTimeout('ClosePanelCur()', 1000)
}

function ClosePanelCur(){
	var StockDetails = getFrmObj('CurrencyInfo')
	StockDetails.style.visibility = "hidden"
	StockDetails.style.zIndex = "0"
	StockDetails.style.height = "0px"
	StockDetails.style.width = "0px"
	StockDetails.style.left = "-100px";
	StockDetails.style.top = "-100px";
}

function ChangeCurrency(){
	var UserCurrencyChoice = getFrmObj('UserCurrencyID')
	Set_Cookie( 'curSelectValue', UserCurrencyChoice.value, '360', '/', '', '' );
	window.location.reload()
}

function Set_Cookie( name, value, expires, path, domain, secure ){
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

