// Used to change the order by. Used in all listing where we used ORDER BY 
function order_list (strOrderBy)
{
	//Get the original sequence of ordering (Asc/Desc)
	state = document.myform.order_seq.value

	//If the "order by" field is empty or the sequence is "Desc" then make the sequence "Asc"
	//If "order by" clause is not the same as the one selected now then make the sequence "Asc"
	//Else make the sequence "Desc"
	
	if (document.myform.order_by.value == "" || state == "Desc")
		sequence = "Asc";
	else if (document.myform.order_by.value != strOrderBy)
		sequence = "Asc";
	else
		sequence = "Desc";
	
	document.myform.order_by.value = strOrderBy;
	document.myform.order_seq.value = sequence;
	
	document.myform.submit();

}
// Used to check all check box
function callActionPage(strAction)
{
	//Code to check if any of the checkbox is selected else the form will not be submitted
	chk_checked = "false";
	if (document.myform.chk_all.length)
	{
		total = document.myform.chk_all.length;

		for (i=0;i<total;i++)
		{
			if (document.myform.chk_all[i].checked)
			{
				chk_checked = "true";
				break;
			}
		}
	}
	else
	{
		if (document.myform.chk_all.checked)
				chk_checked = "true";
	}
	//End of code to check if any of the checkbox is selected

	if (chk_checked == "true")
	{
		if (confirm("Are you sure to delete the selected record(s)?"))
		{
			
			document.myform.h_pageAction.value = "Delete";
			
			if(strAction == "SA")
			{				
				document.myform.action = "storedAuctions.php";
				document.myform.submit();
			}
			else if(strAction == "RSW")
			{
				document.forms[0].action = "rinkyaStoreWatchlist";
				document.forms[0].submit();
			}
			else if(strAction == "SS")
			{
				document.myform.action = "storedSearches.php";
				document.myform.submit();
			}
			else if(strAction == "RSS")
			{
				document.myform.action = "rinkyaStoreSearches.php";
				document.myform.submit();
			}
			else if(strAction == "BD")
			{
				document.myform.action = "bidList.php";
				document.myform.submit();
			}
		}
		else
		{
			return false;
		}
	}
	else if (chk_checked == "false")
	{
		alert("Please select the record(s) to be deleted");
		return false;
	}
}
// Function used to to check user select the check atleast one check box and if check then submit the page
//added code for deleting record 11 July 2007 
function actionPageDelete(strAction,id)
{	
	if(strAction != "MEMBER")
	{
		var msg = "Are you sure to delete the selected record(s)?";	
	}
	else
	{
		var msg = "Are you sure to delete the selected record ?";	
	}
	
	if (confirm(msg))
	{
		document.myform.h_pageAction.value = "Delete";
			
		if(strAction == "SA")
		{				
			document.myform.action = "storedAuctions.php?id="+id;
			document.myform.submit();
		}
		else if(strAction == "RSW")
		{
			document.myform.action = "rinkyaStoreWatchlist.php?id="+id;
			document.myform.submit();
		}
		else if(strAction == "SS")
		{
			document.myform.action = "storedSearches.php?id="+id;
			document.myform.submit();
		}
		else if(strAction == "RSS")
		{
			document.myform.action = "rinkyaStoreSearches.php?id="+id;
			document.myform.submit();
		}
		else if(strAction == "BD")
		{
			document.myform.action = "bidList.php?id="+id;
			document.myform.submit();
		}
		else if(strAction == "MEMBER")
		{
		   window.location="userDelete.php?id="+id+"&Delete=yes";
		   return false;
		}

	}
	else
	{
		return false;
	}
	
}

function popupWindow(url, BiddingAccount) 
{
	if ( BiddingAccount == "1" )
	{
		alert("Please provide your bidding account information to set auto bid.");
		window.location="biddingAccount.php";
	}
	else
	{
		window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=No,copyhistory=no,width=650,height=650,screenX=150,screenY=150,top=150,left=150');
	}
	return false;
}

var isNS4 = (navigator.appName=="Netscape")?1:0;
function validateMaxLenght(element, event, maxlength) 
{

	var iKey = (!isNS4?event.keyCode:event.which);
	var re = new RegExp("\r\n","g");
	var x = element.value.replace(re,"").length;
	if ((x>=maxlength) && ((iKey > 31 && iKey < 1200) || (iKey > 95 && iKey < 106)) && (iKey != 13)) 
	{
		return false;
	} 
	else 
	{
		return true;
	}
}

function selectAllCheckbox(frmObj, chk_state)
{
	var chk;
	
	if(chk_state == "" || chk_state == "false")
	{
		chk = true;
		document.myform.SelectAll.value = "Uncheck All";
	}
	else
	{
		chk = false;
		document.myform.SelectAll.value = "Check All";
	}
	
	
	totalElem = document.myform.length;

	for (i=0;i<totalElem;i++)
	{
		type = document.myform.elements[i].type;
		if (type == "checkbox")
		{
			document.myform.elements[i].checked = chk;
		}
	}
	document.myform.h_chk.value = chk;
}