// Author: Dave Coop, COOP Web Development; Web: http://www.coop.za.com
// A COOP tip of the hat to JavaScript programmers all over the world who assisted with this.

// Remove spaces around a sent string
function trim (str){
	while (str.charAt(0) == ' ')
		str = str.substring(1);
	while (str.charAt(str.length - 1) == ' ')
		str = str.substring(0, str.length - 1);
return str;}

// Check the form fields on the login page (/admin/default.asp)
function ChkLoginForm(theForm){
	if (trim(theForm.username.value) == ""){
		alert("Please enter your User Name (e-mail address).");
		theForm.username.focus();
		return (false);}
	if (trim(theForm.passwd.value) == ""){
		alert("Please enter your Password.");
		theForm.passwd.focus();
		return (false);}
return (true);}

// Check that a valid option was selected when selecting from the drop-downs
function ChkUpdForm(){
	if (trim(document.forms.UpdSelect.UpdThis.value) == "")
	{return (false);}
	document.forms.UpdSelect.submit();
	return (true)}

// Go to requested URL
function NavRedirect(theUrl){document.location.href = theUrl;}

// Write contact stuff
function jsContactAddress(){
	var string123 = "&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#108;&#121;&#110;&#110;&#64;&#108;&#121;&#110;&#110;&#115;&#108;&#105;&#110;&#103;&#101;&#114;&#105;&#101;&#46;&#99;&#111;&#46;&#122;&#97;";
	var string234 = "&#108;&#121;&#110;&#110;&#64;&#108;&#121;&#110;&#110;&#115;&#108;&#105;&#110;&#103;&#101;&#114;&#105;&#101;&#46;&#99;&#111;&#46;&#122;&#97;";
	document.write("<a href=" + string123 + ">" + string234 + "</a>");}

// Bookmark / Add to Favourites
function CreateBookmark(){
	title="Lynn's Lingerie";
	url="http://www.lynnslingerie.co.za";
	// Mozilla Firefox Bookmark		
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");}
	// IE Favorite		
	else if(window.external ) { 
		window.external.AddFavorite(url, title);}
	// Opera Hotlist		
	else if(window.opera && window.print){
		return true;}}

// Update the chars remaining field 
function cntFormField(field,cntfield,maxlimit){
if (field.value.length > maxlimit)
	field.value = field.value.substring(0, maxlimit);
else
	cntfield.value = maxlimit - field.value.length;}

// Check that a valid option was selected when updating user details (/admin/upduser.asp)
function ChkUpdUserForm(){
	if (trim(document.forms.UpdUserSelect.UpdThisUser.value) == "")
	{return (false);}
	document.forms.UpdUserSelect.submit();
	return (true)}

// Add this site to favourites/bookmarks
function addBookmark(title,url){
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");}
	else if( document.all ){
		window.external.AddFavorite(url, title);}
	else if(window.opera && window.print ){
		return true;}}

// Check the form fields on the Add Customer and Edit Customer forms
function ChkCustomerForm(theForm){
	if (trim(theForm.fname.value) == ""){
		alert("Please enter a First Name.");
		theForm.fname.focus();
		return (false);}
	if (trim(theForm.sname.value) == ""){
		alert("Please enter a Surname.");
		theForm.sname.focus();
		return (false);}
	if (trim(theForm.email.value) == ""){
		alert("Please enter a valid E-mail Address.");
		theForm.email.focus();
		return (false);}
	if (trim(theForm.email.value) != ""){
		if (theForm.email.value.indexOf("@")==-1 || theForm.email.value.indexOf(".")==-1 || theForm.email.value.indexOf(" ")!=-1 || theForm.email.value.length<6){
			alert("Sorry, this e-mail address does not appear to be valid.");
			theForm.email.focus();
			return (false);}}
	if (trim(theForm.passwd1.value) == ""){
		alert("Please enter a Password to log into the site.");
		theForm.passwd1.focus();
		return (false);}
	if (trim(theForm.passwd2.value) == ""){
		alert("Please confirm your chosen Password.");
		theForm.passwd2.focus();
		return (false);}
	if (trim(theForm.deladd.value) == ""){
		alert("Please enter a Delivery Address.");
		theForm.deladd.focus();
		return (false);}
	return (true)}

// Check the form fields on the admin AddUser page (/admin/adduser.asp)
function ChkadminUserForm(theForm){
	if (trim(theForm.fname.value) == ""){
		alert("Please enter a First Name.");
		theForm.fname.focus();
		return (false);}
	if (trim(theForm.sname.value) == ""){
		alert("Please enter a Surname.");
		theForm.sname.focus();
		return (false);}
	if (trim(theForm.cellno.value) == ""){
		alert("Please enter a contact Cell-phone Number.");
		theForm.cellno.focus();
		return (false);}
	if (trim(theForm.email.value) == ""){
		alert("Please enter an E-mail Address for this user.");
		theForm.email.focus();
		return (false);}
	if (trim(theForm.email.value) != ""){
		if (theForm.email.value.indexOf("@")==-1 || theForm.email.value.indexOf(".")==-1 || theForm.email.value.indexOf(" ")!=-1 || theForm.email.value.length<6){
			alert("Sorry, this e-mail address does not appear to be valid.");
			theForm.email.focus();
			return (false);}}
	if (trim(theForm.username.value) == ""){
		alert("Please enter a Username to log into the site.");
		theForm.username.focus();
		return (false);}
	if (trim(theForm.passwd1.value) == ""){
		alert("Please enter a Password to log into the site.");
		theForm.passwd1.focus();
		return (false);}
	if (trim(theForm.passwd2.value) == ""){
		alert("Please confirm your chosen Password.");
		theForm.passwd2.focus();
		return (false);}
	return (true)}



// Round off numbers to two decimal places
 function roundoff(number){
	return Math.round(number*Math.pow(10,2))/Math.pow(10,2)}

// Set different styles for Microsofto Exploder and other browsers
var sSubHeader="subheader";
if (navigator.appName != "Microsoft Internet Explorer"){
	sSubHeader += "N"}

// Check that a valid search is being made (comment.html in top frame)
function chkSearchForm(theForm){
if(theForm.SearchWord.value == "" || trim(theForm.SearchWord.value) == "" || theForm.SearchWord.value.length <= 3){
	alert("Please enter a Search word or phrase.\nWords under 3 letters are not valid search terms.");
	theForm.SearchWord.focus();
	return (false)}
return (true)}

// Check that a valid option was selected on a drop-down
function ChkSelectForm(){
	if (document.forms.SelectForm.ST.value == "")
	{return (false)}
	document.forms.SelectForm.submit();
	return (true)}


