var TimerIDStock;
var TimerIDTrolley;
var lastStockID = -1
var lastOpenPanel = "close"
var TimerIDCur;
var TimerIDListing;

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='400pox'><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.height = "650px"
	StockDetails.style.width = "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";
}

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);
	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()
	e_StudioMax_initEditables()
}

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()
	e_StudioMax_initEditables()
}

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 = "-100px";
	StockDetails.style.top = "-100px";
}

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 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 OrderStockQty = getFrmObj('txtOrderStockQty')
	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"
	var c = getAnchorPosition("AnchorStock" + stockid);
	TrolleyDiv.style.left = c.x + "px";
	TrolleyDiv.style.top = c.y + "px";
	//alert(TrolleyDiv.innerHTML)
}

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 = "-100px";
	TrolleyDiv.style.top = "-100px";
}

function btnDelClick(which){
	httpRequest('GetTrolley.asp?Save=deleteItem&OrderItemID=' + which, DisplayTrolley, "data");
}

function clearTrolley(){
	httpRequest('GetTrolley.asp?Save=clearTrolley', DisplayTrolley, "data");
}

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 btnEditStockFields(stockid){
	window.open('EditStockFields.asp?StockID=' + stockid + "&PageNo=" + intPageNo,'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="edit.asp?PageNo=" + intPageNo + "&Save=updateStockFullDetails&StockID=" + stockid
		objFrm.submit()
	}else{
		alert("You must have double clicked to edit full details first!")
	}
}

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(){
	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" : "" );
}

function ShowEventData(id,gopage){
	var EventInfo = getFrmObj('EditEventFields')
	OpenPanelEventInfo(id)
	EventInfo.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' bgcolor='" + strPageBKColor + "' width='373px' height='250px'><tr><td align='center' valign='middle'><img src='/w/images/29.gif' border=0></td></tr></table>"
	RoundCornerEvent()
	//alert('GetEventInfo.asp?id=' + id + '&GoPage=' + gopage)
	httpRequest('GetEventInfo.asp?id=' + id + '&GoPage=' + gopage, DisplayEventInfo, "data");
}

function OpenPanelEventInfo(id){
	var StockDetails = getFrmObj('EditEventFields')
	StockDetails.style.visibility = "visible"
	StockDetails.style.zIndex = "300"
	StockDetails.style.height = "370px"
	StockDetails.style.width = "373px"
	var c = getAnchorPosition("AnchorEvent" + id);
	StockDetails.style.left = c.x + "px"
	StockDetails.style.top = (parseInt(c.y) + 20) + "px";
}

function RoundCornerEvent(){
	if(!NiftyCheck()){
		return;
	}

	Rounded("div#EditEventFields","top","transparent",strPageBKColor,"border #C0C0C0");
	Rounded("div#EditEventFields","bottom","transparent",strPageBKColor,"border #C0C0C0");
}

function DisplayEventInfo(data){
	//alert(data)
	var StockDetails = getFrmObj('EditEventFields')
	StockDetails.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' width='373px' bgcolor='" + strPageBKColor + "' cellpadding=10><tr><td valign=top>" + data + "</td></tr></table>"
	//alert(StockDetails.innerHTML)
	RoundCornerEvent()
}

function ClosePanelEvent(){
	var StockDetails = getFrmObj('EditEventFields')
	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 ShowListingData(id,gopage){
	var ListingInfo = getFrmObj('EditListingFields')
	OpenPanelListingInfo(id)
	ListingInfo.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' bgcolor='" + strPageBKColor + "' width='373px' height='250px'><tr><td align='center' valign='middle'><img src='/w/images/29.gif' border=0></td></tr></table>"
	RoundCornerList()
	httpRequest('GetListingInfo.asp?id=' + id + '&GoPage=' + gopage, DisplayListingInfo, "data");
}

function OpenPanelListingInfo(id){
	var StockDetails = getFrmObj('EditListingFields')
	StockDetails.style.visibility = "visible"
	StockDetails.style.zIndex = "300"
	StockDetails.style.height = "370px"
	StockDetails.style.width = "373px"
	var c = getAnchorPosition("AnchorListing" + id);
	StockDetails.style.left = c.x + "px"
	StockDetails.style.top = (parseInt(c.y) + 20) + "px";
}

function RoundCornerList(){
	if(!NiftyCheck()){
		return;
	}

	Rounded("div#EditListingFields","top","transparent",strPageBKColor,"border #C0C0C0");
	Rounded("div#EditListingFields","bottom","transparent",strPageBKColor,"border #C0C0C0");
}

function DisplayListingInfo(data){
	var StockDetails = getFrmObj('EditListingFields')
	StockDetails.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' width='373px' bgcolor='" + strPageBKColor + "' cellpadding=10><tr><td valign=top>" + data + "</td></tr></table>"
	RoundCornerList()
}

function ClosePanelListing(){
	var StockDetails = getFrmObj('EditListingFields')
	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 ShowCategoryData(id,gopage){
	var ListingInfo = getFrmObj('EditCatagoryFields')
	OpenPanelCategoryInfo(id)
	ListingInfo.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' bgcolor='" + strPageBKColor + "' width='373px' height='250px'><tr><td align='center' valign='middle'><img src='/w/images/29.gif' border=0></td></tr></table>"
	RoundCornerCategory()
	httpRequest('GetGategoryInfo.asp?id=' + id + '&GoPage=' + gopage, DisplayCategoryInfo, "data");
}

function OpenPanelCategoryInfo(id){
	var StockDetails = getFrmObj('EditCatagoryFields')
	StockDetails.style.visibility = "visible"
	StockDetails.style.zIndex = "300"
	StockDetails.style.height = "370px"
	StockDetails.style.width = "373px"
	var c = getAnchorPosition("AnchorCategory" + id);
	StockDetails.style.left = c.x + "px";
	StockDetails.style.top = (parseInt(c.y) + 20) + "px";
}

function RoundCornerCategory(){
	if(!NiftyCheck()){
		return;
	}

	Rounded("div#EditCatagoryFields","top","transparent",strPageBKColor,"border #C0C0C0");
	Rounded("div#EditCatagoryFields","bottom","transparent",strPageBKColor,"border #C0C0C0");
}

function DisplayCategoryInfo(data){
	var StockDetails = getFrmObj('EditCatagoryFields')
	StockDetails.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' width='373px' bgcolor='" + strPageBKColor + "' cellpadding=10><tr><td valign='top'>" + data + "</td></tr></table>"
	RoundCornerCategory()
}

function ClosePanelCategory(){
	var StockDetails = getFrmObj('EditCatagoryFields')
	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 ShowImageGalleryData(id,gopage){
	var ListingInfo = getFrmObj('EditImageGFields')
	OpenPanelImageGalleryInfo(id)
	ListingInfo.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' bgcolor='" + strPageBKColor + "' width='373px' height='250px'><tr><td align=center valign=middle><img src='/w/images/29.gif' border=0></td></tr></table>"
	RoundCornerImageGallery()
	httpRequest('GetImageGalleryInfo.asp?id=' + id + '&GoPage=' + gopage, DisplayImageGalleryInfo, "data");
}

function OpenPanelImageGalleryInfo(id){
	var StockDetails = getFrmObj('EditImageGFields')
	StockDetails.style.visibility = "visible"
	StockDetails.style.zIndex = "300"
	StockDetails.style.height = "370px"
	StockDetails.style.width = "373px"
	var c = getAnchorPosition("AnchorGI" + id);
	StockDetails.style.left = c.x + "px";
	StockDetails.style.top = (parseInt(c.y) + 20) + "px";
}

function RoundCornerImageGallery(){
	if(!NiftyCheck()){
		return;
	}

	Rounded("div#EditImageGFields","top","transparent",strPageBKColor,"border #C0C0C0");
	Rounded("div#EditImageGFields","bottom","transparent",strPageBKColor,"border #C0C0C0");
}

function DisplayImageGalleryInfo(data){
	var StockDetails = getFrmObj('EditImageGFields')
	StockDetails.innerHTML = "<table border=0 style='border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;' width=373 bgcolor='" + strPageBKColor + "' cellpadding=10><tr><td valign=top>" + data + "</td></tr></table>"
	RoundCornerImageGallery()
}

function ClosePanelImageGallery(){
	var StockDetails = getFrmObj('EditImageGFields')
	StockDetails.style.visibility = "hidden"
	StockDetails.style.zIndex = "0"
	StockDetails.style.height = "0"
	StockDetails.style.width = "0"
	StockDetails.style.left = "-100px";
	StockDetails.style.top = "-100px";
}

var ArrowTime;
var ArrowVis;
var ShowArrow = false

function btnShowArrow(){
	var ArrowDiv = getFrmObj('ArrowDiv')
	if (ArrowDiv.style.visibility == "visible"){
		ShowArrow = false
		ArrowDiv.style.visibility = "hidden"
		ArrowDiv.style.zIndex = "0"
		ArrowDiv.style.left = "0px";
		ArrowDiv.style.top = "0px";
	}else{
		ShowArrow = true
		ArrowDiv.style.visibility = "visible"
		ArrowDiv.style.zIndex = "10000"
		ArrowDiv.style.left = "250px";
		ArrowDiv.style.top = "250px";
	}
	httpRequest('SetArrowVis.asp?vis=1', DisplayHelpArrow, "data");
}

function DisplayHelpArrow(data){
  //do nothing
}

function CheckArrowVis(){
	if (!ShowArrow){
		httpRequest('GetArrowVis.asp', DisplayArrow, "data");
	}
}

function DisplayArrow(data){
	//alert(data)
	if (data == "on"){
		var ArrowDiv = getFrmObj('ArrowDiv')
		ArrowDiv.style.visibility = "visible"
		ArrowDiv.style.zIndex = "10000"
		httpRequest('GetArrowPos.asp', ShowTheArrow, "data");
	}else{
		var ArrowDiv = getFrmObj('ArrowDiv')
		ArrowDiv.style.visibility = "hidden"
		ArrowDiv.style.zIndex = "0"
		ArrowDiv.style.left = "0px";
		ArrowDiv.style.top = "-0px";
		clearTimeout(ArrowTime);
		ArrowTime = setTimeout('CheckArrowVis()', 15000)
	}
}

function ShowTheArrow(data){
	var arrTopLeft = data.split(":")
	var ArrowDiv = getFrmObj('ArrowDiv')
	ArrowDiv.style.left = arrTopLeft[1] + "px";
	ArrowDiv.style.top = arrTopLeft[0] + "px";
	clearTimeout(ArrowTime);
	ArrowTime = setTimeout('CheckArrowVis()', 5)
}


