// browser detection - load css file
function loadCSSFile() {
  	/* this script determines the user browser and loads an appropriate external cascading style sheet.
	   If the browser is an Internet Explorer browser then an IE compatible external css file is loaded.
	   If the browser is a Netscape browser then a Netscape compatible external css file is loaded.
	   If the browser is an Opera browser then an an Internet Explorer compatible external css file is loaded.
	   If the browser is anything else no css file is loaded.
	   You can add more browser types by adding another case and a related css file. Based on an analysis 
	   of website traffic most surfers use recent browser versions. You can add specific versioning if you want
	   but the traffic that will use it will be negligible.
	   Richard Creech info@dreamriver.com http://www.dreamriver.com
	*/
	var cssFileName = "";
	var browser = navigator.appName;
	switch(browser) {
		case "Microsoft Internet Explorer":
			cssFileName = "yellow.css";
			//cssFileName = "netscape.css";
			break;
		case "Netscape":
			cssFileName = "netscape.css";
			break;
		case "Opera":
			cssFileName = "yellow.css";		
			break;	
		default:
			/* if there is no switch(browser) match then no css file is loaded */
	}
	document.write("<link rel=stylesheet type=\"text/css\" href=\"" + cssFileName + "\">");
  }


// phpYellow javascript by Dreamriver.com
// CHECK EMAIL AND PASSWORD fields from login.php3 and admin-login.php3
// Credit: This function by dannyg@dannyg.com
// all fields are required
function checkForm(form) {
for (var i=0; i < form.elements.length; i++) {
	if (form.elements[i].value == "") {
		alert("Fill out all fields please.")
		form.elements[i].focus()
		return false
	}
}
return true
}



// VALIDATE THE STANDARD FORM used for insert and edit of listings
// Credit: This function by info@dreamriver.com
function validate(form) {

var myForm = document.forms[0];

	for (var i=0; i < form.elements.length; i++) {
		if(form.elements[i].type == "text" && form.elements[i].value == "") { // do only if a text input type
			alert("Fill out all fields please.\nEnter an empty space if not applicable.");

			form.elements[i].focus();
			return false;
		}
	}

// Company 
if ( myForm.ycompany.value.length <= 2 ) {
	alert("Enter a complete company name.\nEnter 3 spaces if not applicable..");
	myForm.ycompany.focus()
	return false;
	}




// Url
/*
if ( myForm.yurl.value.substring(0,7) != "http://" ) {
	alert("You must enter a valid url.");
	myForm.yurl.focus();
	return false;
	}
*/


// Phone
if ( myForm.yphone.value.length < 7 ) {
	alert("Your phone number must be at least 7 numbers or longer.\nEnter 7 spaces if not applicable.");
	myForm.yphone.focus()
	return false;
	//needs validation for a number value, but allowing hyphens or dots
	}
	
// Fax
/*
if ( myForm.yfax.value.length < 7 ) {
	alert("Your fax number must be at least 7 numbers or longer.");
	myForm.yfax.focus()
	return false;
	}
*/	

// Email
/*
if ( myForm.yemail.value.length < 6) {
	alert("Your email address must be valid.\nEnter 6 spaces if not applicable.");
	myForm.yemail.focus()
	return false;
	// needs better validation
	}
*/


// Street Address
if ( myForm.yaddress.value.length < 6 ) {
	alert("Your street address appears invalid.\nEnter 6 spaces if not applicable.");
	myForm.yaddress.focus()
	return false;
	}

// City
if ( myForm.ycity.value.length < 3 ) {
	alert("The city appears invalid.\nEnter 3 spaces if not applicable.");
	myForm.ycity.focus()
	return false;
	}

// ZIP or Postal code
if ( myForm.ypostalcode.value.length < 5 ) {
	alert("Your ZIP or postal code must contain at least 5 characters.\nEnter 5 spaces if not applicable.");
	myForm.ypostalcode.focus()
	return false;
	}


// State or Province
	var mySelectList = myForm.ystateprov;
	var mySelectedIndex= mySelectList.selectedIndex;
	chosenItem = mySelectList.options[mySelectedIndex].value;
	if(chosenItem == "*") {
		chosenItem = " ";
		//alert("Choose a state or province.");
		//return false;
	}
	/*
	if(chosenItem == "") {
		alert("Choose a state or province.");
		return false;
	}	
	*/

/*	
	// Country
	var myCountryList = myForm.ycountry;
	var mySelectedCountryIndex= myCountryList.selectedIndex;
	countryItem = myCountryList.options[mySelectedCountryIndex].value;
	if(countryItem == "*") {
		alert("Choose a country.");
		myCountryList.focus();
		return false;
	}
	if(countryItem == "") {
		alert("Choose a country.");
		myCountryList.focus();
		return false;
	}
*/	
	return true
}



function checkCategoryForm(form) {
var myForm = document.forms[0];
// Category
	var mySelectList = myForm.category;
	var mySelectedIndex= mySelectList.selectedIndex;
	chosenItem = mySelectList.options[mySelectedIndex].value;
	if(chosenItem == "*") {
		alert("Choose a category.");
		mySelectList.focus();
		return false;
	}
	if(chosenItem == "") {
		alert("Choose a category.");
		mySelectList.focus();
		return false;
	}

// Description
if ( myForm.description.value.length <= 9 ) {
	alert("Make your description 10 characters or longer.");
	myForm.description.focus();
	return false;
	}

}

