//------------------------------------------------------------------------------
function setupCalendar(input_fld, trigger_id)
{
 Calendar.setup(
    {
      inputField  : input_fld,
      ifFormat    : "%Y-%m-%d",
      button      : trigger_id
    }
  );
}
//------------------------------------------------------------------------------
function navigatePaging(url, page, totalPages)
{

	if(!isNumeric(page))
	{
		alert('Please enter only numbers'); page.focus(); return false;
	}
	pageId	=	trimAll(page.value);

	if(pageId > totalPages || pageId < 1)
	{
		alert('Invalid Page'); page.focus(); return false;
	}
	//window.location	=	url+pageId+"/";
	window.location	=	url+pageId;
	return false;
}
//------------------------------------------------------------------------------
function goBack(url)
{
	if(url == "")
		history.go(-1);
	else
		window.location	=	url;
}
//------------------------------------------------------------------------------
function goToPage(url)
{
	window.location	=	url;
}
//------------------------------------------------------------------------------
function delAlert(url)
{
	if(confirm("Are you sure you want to delete?"))
	{
		window.location	=	url;
	}
	else
	{
		return false;
	}
}
//------------------------------------------------------------------------------
function swapLNimg(imgObj)
{
	//imgObj	=	document.getElementById(imgID);
	imgPath =	imgObj.src;
	arrImg	=	imgPath.split("_");
	//alert(imgObj.src);
	//alert(arrImg[0]);
	//alert(arrImg[1]);
	cmdLN	=	document.getElementById("lcmd").src;
	//if(cmdLN.indexOf("artist") != -1 ||  cmdLN.indexOf("album") != -1 || cmdLN.indexOf("tracks") != -1 || cmdLN.indexOf("label") != -1)
	//cmdLN	=	cmdLN.replace(/artist|album|tracks|label/, "browse");
	//alert(cmdLN);
	//if(imgPath.indexOf(cmdLN) == -1)
	if(arrImg[0] != cmdLN)
	{
		if(arrImg[1]	==	"on.gif")
			imgObj.src	=	eval("'" + arrImg[0] + "_off.gif'");
		else
			imgObj.src	=	eval("'" + arrImg[0] + "_on.gif'");
	}

	//alert(imgObj.src);
}
//------------------------------------------------------------------------------
function showImgError(imgObj, mode)
{
	alert(mode);
	if  ( mode == "product" )
	{
		imgObj.src = '/store/templates/image_not_found.jpg';
	}
	else if  ( mode == "category" )
	{
		//imgObj.src = '/templates/image_not_found.jpg';
	}
}
//------------------------------------------------------------------------------
function swapImage(imgObj, id)
{
	imgPath	=	imgObj.src;

	if(id != undefined)
	{
		if(imgPath.indexOf(id.toLowerCase()) > 0)
		{
			return true;
		}
	}
	arrPath	=	imgPath.split("_");

	if(arrPath[1]	==	"on.gif")
		imgObj.src	=	eval("'" + arrPath[0] + "_off.gif'");
	else
		imgObj.src	=	eval("'" + arrPath[0] + "_on.gif'");
}
//------------------------------------------------------------------------------
function searchCatalogData(period)
{
	form			=	document.searchCatalog;
	form.when.value	=	period;
	if(period == "X" && isEmpty(form.frequency))
	{
		alert('Please enter the number of weeks');
		form.frequency.focus();
		return false;
	}
	else
	{
		form.submit();
	}
}
//------------------------------------------------------------------------------
function searchCatalogUsingFilters(form)
{
	rbPeriodOptions = RadioCheck(form, "when");
	if(rbPeriodOptions == 0)
	{
		alert('Please choose a period');
		form.when[0].focus();
		return false;
	}
	rbValue	=	getRadioValue(form.when);
	if(rbValue == "X" && isEmpty(form.frequency))
	{
		alert('Please enter the number of weeks');
		form.frequency.focus();
		return false;
	}
}
//------------------------------------------------------------------------------
function searchTop100(period)
{
	form			=	document.searchTop10;
	form.when.value	=	period;
	if(period == "X" && isEmpty(form.frequency))
	{
		alert('Please enter the number of weeks');
		form.frequency.focus();
		return false;
	}
	else
	{
		form.submit();
	}
}
//------------------------------------------------------------------------------
function validateSearch(form)
{
	if(isEmpty(form.filter_value)) { alert('Please enter keywords'); return false; }
}
//------------------------------------------------------------------------------
function setResultsPerPage(records)
{
	form	=	document.forms["resultsPerPage"];
	form.perPage.value	=	records;
	form.submit();
}
//------------------------------------------------------------------------------
function chkLocationAvailability(form, mode)
{
	if(!chkListbox(form.featured_in, 'Featured Location')) { return false; }
	
	location_id		=	form.featured_in.value;
	location_name	=	getSelectedItemText(form.featured_in);

	process		=	'chkLocation';
	output		=	'text';
	
	if (mode == "Label")
		url			=	getURL() + "/admin/labels.php";
	else if (mode == "Artist")
		url			=	getURL() + "/admin/artists.php";
	else if (mode == "Album")
		url			=	getURL() + "/admin/albums.php";
	
	fields			=	new Array();
	location_id		=	encodeURI(location_id);
	location_name	=	encodeURI(location_name);

	act				=	encodeURI("chkFeaturedLocation");

	responseHandler	=	"processVerificationChk";

	fields.push("location_id="+location_id);
	fields.push("location_name="+location_name);
	fields.push("act="+act);

	ajaxParams	=	fields.join('&');

	ajaxPostRequest(url, ajaxParams);
	return false;
}
//------------------------------------------------------------------------------
function processVerificationChk(responseText)
{
	window.parent.content.inlineWindow("<center>"+responseText+"</center>", "Verify Featured Location", "width=300px,height=150px,left=20px,top=30px,resize=0,scrolling=0,center=0");
}
//------------------------------------------------------------------------------
function controlDiv(id, mode)
{
	obj	= document.getElementById(id);
	if ( mode == "show" )
	{
		obj.style.display =	"block";
	}
	else if ( mode == "hide" )
	{
		obj.style.display =	"none";
	}
}
//------------------------------------------------------------------------------
function controlDiv1(id, noOfItems)
{
	for(i=1;i<=noOfItems;i++)
	{
		ciobj	=	document.getElementById("show"+i);
		ccobj	=	document.getElementById("ans"+i);
		ccimg	=	document.getElementById("pl_min"+i);

		if(id != i)
		{
			ccobj.style.display = "none";
			ccimg.src = "templates/images/expand.gif";
		}
		else{
			//ciobj.style.background="#FFFFFF";
			ccobj.style.background="#FFFFFF";
			ccimg.src = "templates/images/collapse.gif";
		}
	}

	ciobj	=	document.getElementById("show"+id);
	ccobj	=	document.getElementById("ans"+id);
	ccimg	=	document.getElementById("pl_min"+id);

	if(ccobj.style.display == "")
	{
		ccobj.style.display = "none";
		ccimg.src = "templates/images/expand.gif";

	}
	else
	{
		ccobj.style.display = "";
	}
}
//------------------------------------------------------------------------------
function controlDiv2(id, noOfItems,selectedcolor, status)
{
	var existing_id = document.getElementById("selected_id").value;
	var existing_color= document.getElementById("selected_color").value;
	for(i=1;i<=noOfItems;i++)
	{
		ciobj	=	document.getElementById("show"+i);
		ccobj	=	document.getElementById("ans"+i);
		ccimg	=	document.getElementById("pl_min"+i);

		if(id != i)
		{
			ccobj.style.display = "none";
			ccimg.src = "templates/images/expand.gif";
			document.testautorefresh.refreshStatus.value	=	"0";
		}
		else{
			ciobj.style.backgroundColor = "#FFFFFF";
			ccobj.style.backgroundColor = "#FFFFFF";
			ccimg.src = "templates/images/collapse.gif";
		}
	}

	if (( existing_id != "" && existing_id != id) || (existing_id != "" && existing_id == id))
	//if ((existing_id != "" && existing_id != id))
	{
		var curr_obj = document.getElementById("show"+existing_id);
		if (existing_color=="hd_new")
		{
			curr_obj.style.backgroundColor = "#D9E5E5";
		}
		else if(existing_color=="hd_blue")
		{
			curr_obj.style.backgroundColor = "#E0F7FF";
		}
		else if(existing_color=="hd_yellow")
		{
			curr_obj.style.backgroundColor = "#FFFFD7";
		}
		else if(existing_color=="hd_red")
		{
			curr_obj.style.backgroundColor = "#FFDCDC";
		}
		else if(existing_color=="hd_green")
		{
			curr_obj.style.backgroundColor = "#EAFFEA";
		}
		else if(existing_color=="hd_amber")
		{
			curr_obj.style.backgroundColor = "#F8EAB5";
		}
		else if(existing_color=="hd1")
		{
			curr_obj.style.backgroundColor = "#EDE7D0";
		}
		else if(existing_color=="hd2")
		{
			curr_obj.style.backgroundColor = "#E4EDF9";
		}
	
	}
	if ( existing_id != id && existing_id != "")
	{
		document.getElementById("selected_id").value= id;
		document.getElementById("selected_color").value= selectedcolor;
	}

	ciobj	=	document.getElementById("show"+id);
	ccobj	=	document.getElementById("ans"+id);
	ccimg	=	document.getElementById("pl_min"+id);

	if(ccobj.style.display == "")
	{
		ccobj.style.display = "none";
		ccimg.src = "templates/images/expand.gif";
		document.testautorefresh.refreshStatus.value	=	"0";
	}
	else
	{
		ccobj.style.display = "";
		if ( status == "Processing" || status == "QA" || status == "Ready")
		{
			document.testautorefresh.refreshStatus.value	=	"1";
		}
		else
		{
			document.testautorefresh.refreshStatus.value	=	"0";
			//ajaxSupplierLoad();
		}
	}

	document.getElementById("selected_id").value= id;
	document.getElementById("selected_color").value= selectedcolor;
}
//------------------------------------------------------------------------------
function popUp(url, win_name, width, height)
{
	popWin	=	window.open(url, win_name, "toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=YES, copyhistory=no, scrollbars=Yes, width=" + width + ", height=" + height + ", top=50, left=50");
	popWin.focus();
}
//------------------------------------------------------------------------------
