
function fValSubCatList(ActionType){

var radioSelected = false;
var iCatID;

if (!(ActionType == "a")) {
	for (var i=0; i < document.forms[0].catid.length; i++) {
		if (document.forms[0].catid[i].checked){
			radioSelected = true;
			iCatID = document.forms[0].catid[i].value;
		}
	}

	// cheap hack to handle only one item
	if (i == 0){
		if (document.forms[0].catid.checked){
			radioSelected = true;
			iCatID = document.forms[0].catid.value;
		}
	}

	if (!radioSelected) {
	alert("Please choose a category first.");
	return false;
	}

	// delete confirmation
	if (ActionType == "d"){
		var agree=confirm('This will delete this category and all of the products in it.\nDo you want to continue?');
		if (agree == false) return;
	}

	// delete confirmation
	if (ActionType == "s"){
		var agree=confirm('This will change the status of this category.\nDo you want to continue?');
		if (agree == false) return;
	}


}

// switch for form action
	switch(ActionType === 0 ? '' : ActionType){
		case 'a':
			// add new item
			// redirect to add page
			document.location.href = 'category.php';
			break;

		case 'e':
			// edit item
			// post user to edit page with id and edit status
			document.location.href = 'category.php?cat_id=' + iCatID + '&action=e';
			break;

		case 'd':
			// delete item
			// post user to edit page with id and delete status
			document.location.href = 'category.php?cat_id=' + iCatID + '&action=d';
			break;

		case 's':
			// change status
			// post user to edit page with id and status action
			document.location.href = 'category.php?cat_id=' + iCatID + '&action=s';
			break;

		case 'p':
			// products item
			// send user to products page with id
			document.location.href = 'productlist.php?cat_id=' + iCatID + '';
			break;

	}

}

function fValSubProdList(ActionType,iCatID){

var radioSelected = false;
var iProdID;

if (!(ActionType == "a")) {
	for (var i=0; i < document.forms[0].prod_id.length; i++) {
		if (document.forms[0].prod_id[i].checked){
			radioSelected = true;
			iProdID = document.forms[0].prod_id[i].value;
		}
	}

	// cheap hack to handle only one item
	if (i == 0){
		if (document.forms[0].prod_id.checked){
			radioSelected = true;
			iProdID = document.forms[0].prod_id.value;
		}
	}

	if (!radioSelected) {
	alert("Please choose a product first.");
	return false;
	}

	// delete confirmation
	if (ActionType == "d"){
		var agree=confirm('This will delete this product .\nDo you want to continue?');
		if (agree == false) return;
	}


}

// switch for form action
	switch(ActionType === 0 ? '' : ActionType){
		case 'a':
			// add new item
			// redirect to add page
			document.location.href = 'product.php?&cat_id=' + iCatID;
			break;

		case 'e':
			// edit item
			// post user to edit page with id and edit status
			document.location.href = 'product.php?prod_id=' + iProdID + '&action=e&cat_id=' + iCatID;
			break;

		case 'd':
			// delete item
			// post user to edit page with id and delete status
			document.location.href = 'product.php?prod_id=' + iProdID + '&action=d&cat_id=' + iCatID;
			break;

		case 'v':
			// view item
			// show user client side product page
			document.location.href = '/productdetail.php?prod_id=' + iProdID + '&cat_id=' + iCatID;
			break;

		case 'i':
			// images item
			// send user to image manage page with id
			document.location.href = 'images.php?prod_id=' + iProdID + '&cat_id=' + iCatID;
			break;

		case 'm':
			// specs
			// send user to specs manage page with id
			document.location.href = 'specs.php?prod_id=' + iProdID + '&cat_id=' + iCatID;
			break;

		case 'o':
			// specs
			// send user to specs manage page with id
			document.location.href = 'options.php?prod_id=' + iProdID + '&cat_id=' + iCatID;
			break;

		case 's':
			// change status
			// post user to edit page with id and status action
			document.location.href = 'product.php?prod_id=' + iProdID + '&cat_id=' + iCatID + '&action=s';
			break;

	}

}


// function to highlight selected item
function change(id, newClass) {
	rst();
	identity=document.getElementById(id);
	identity.className=newClass;
}

// function to reset styled tr
function rst() {
  var j;
  var tmp = document.getElementsByTagName("tr");
  for (j = 0; j < tmp.length; j++) {
  		if(tmp[j].id != "trhead"){
		tmp[j].className = 'inactiverow';
		}
   }

}

// admin form validation

// val for login
function valchangelogin(form) {
if (document.forms[0].u.value.length==0 || document.forms[0].u.value.length < 5)
{
alert('Please enter a Username that is atleast 5 characters long.');
document.forms[0].u.focus();
return (false);
}
if (document.forms[0].p.value.length==0 || document.forms[0].p.value.length < 5)
{
alert('Please enter a Password that is atleast 5 characters long.');
document.forms[0].p.focus();
return (false);
}
if (document.forms[0].pc.value.length==0)
{
alert('Please confirm your password.');
document.forms[0].p.focus();
return (false);
}
if (document.forms[0].p.value != document.forms[0].pc.value)
{
alert('Your passwords do not match. Try Again.');
document.forms[0].p.focus();
return (false);
}
else return true;
}

// val for login
function vallogin(form) {
if (document.forms["login"].u.value.length==0)
{
alert('Please enter your Username.');
document.forms["login"].u.focus();
return (false);
}
if (document.forms["login"].p.value.length==0)
{
alert('Please enter your password.');
document.forms["login"].p.focus();
return (false);
}
else return true;
}

// val for category
function valcategory(form) {
if (document.forms[0].category.value.length==0)
{
alert('Please enter a category.');
document.forms[0].category.focus();
return (false);
}
else return true;
}

// val for options
function valoption(form) {
if (document.forms[0].product_option.value.length==0)
{
alert('Please enter an option.');
document.forms[0].product_option.focus();
return (false);
}
else return true;
}

//val for product
function valproduct(form){
if (document.forms[0].product_name.value.length==0)
{
alert('Please enter the name of the product.');
document.forms[0].product_name.focus();
return (false);
}
if (document.forms[0].product_price.value.length==0)
{
alert('Please enter the Selling Price the product.');
document.forms[0].product_price.focus();
return (false);
}
if (document.forms[0].product_msrp.value.length==0)
{
alert('Please enter the MSRP for the product.');
document.forms[0].product_msrp.focus();
return (false);
}
if (document.forms[0].product_description.value.length==0)
{
alert('Please enter a Description for the product.');
document.forms[0].product_description.focus();
return (false);
}
if (document.forms[0].image.value.length==0 && document.forms[0].oldimage.value.length==0)
{
alert('Please select an image for the product from your hard drive.');
return (false);
}
else return true;
}

//val for image gallery upload
function valimageupload(form) {
if (document.forms[0].image.value.length==0)
{
alert('Please select an image from your hard drive to represent this product.');
return (false);
}
else return true;
}

// delete specs funtion
function deleteSpecs(prodid,catid){
var agree=confirm("Are you sure you want to permanently delete the specs for this item?");
if (agree){
document.location.href = 'specs.php?prod_id=' + prodid + '&action=d&cat_id=' + catid;
return true;

}
else return false ;
}


function confirmDeleteGeneric()
{
var agree=confirm("Are you sure you want to permanently remove this item?");
if (agree)
return true ;
else
return false ;
}

function TR_OnMouseOver(srcEle) {
if (srcEle.style.backgroundColor != "highlight")
srcEle.style.backgroundColor = "cornsilk";
}
function TR_OnMouseOut(srcEle) {
if (srcEle.style.backgroundColor == "cornsilk")
srcEle.style.backgroundColor = "";
}

function newWin(_url)
{
  window.open(_url);
}

function viewCart(){
	//document.forms["cart"].href = "https://www.paypal.com/cgi-bin/webscr";
	//newWin("https://www.paypal.com/cgi-bin/webscr");
	newWin = window.open("",  "PayPal", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=600,height=300");
    document.forms["cart"].target = "PayPal";
	//document.forms["cart"].target = "_new";
	document.forms["cart"].submit();

}

function addCart(form){
	//document.forms["cart"].href = "https://www.paypal.com/cgi-bin/webscr";
	//newWin("https://www.paypal.com/cgi-bin/webscr");
	newWin = window.open("",  "PayPal", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=600,height=300");
    document.forms["addtocart"].target = "PayPal";
	//document.forms["cart"].target = "_new";
	document.forms["addtocart"].submit(form);


}



