
//Store Locator
function ChkField(TheFormName,TheTextName,MessageOnError,TheFormAction)
	{
	if (document.forms[TheFormName].elements[TheTextName].value == "" || document.forms[TheFormName].elements[TheTextName].value == "Select City" || document.forms[TheFormName].elements[TheTextName].value == "Select Province")
		{
		alert (MessageOnError);
		document.forms[TheFormName].elements[TheTextName].focus();
		}
	else
		{
		document.forms[TheFormName].action= TheFormAction;
		document.forms[TheFormName].submit();
		}

	}




function changeImages(FirstImg,SecondImage,FirstImgName,SecongImageName)
 {
 
 	 if (document.images) 
		{
		
		image1on = new Image();
		image1on.src = "HomePage/" + FirstImgName ;
		
		
		image1off = new Image();
		image1off.src = "HomePage/" + SecongImageName ;
				 
		}

	  document[FirstImg].src = image1off.src
}


function checkCatName(whattodo)
{
var ErrorThere = "0";
	if (document.PW.title.value == "")
		{
		alert ("Category cannot be empty");
		document.PW.title.focus();
		ErrorThere = "1";
		}
	
	if (ErrorThere == "0")
		{
		if (whattodo == "delete")
			{
			document.PW.del.value = "delete";
			}
			document.PW.submit();
		}
}

var calFormat = "mm/dd/yyyy";

function validate_extension(phone)
{
var count = 0;
var phonenumber = "";
for (k = 0; k < phone.length; k++) {
      if (phone.charAt(k) != " " && phone.charAt(k) != "-") { 
        phonenumber = phonenumber + phone.charAt(k);     
        count++;
      }
   }
   if (count < 3 || count > 3)
     return false;
   else {
     if (isNumber(phonenumber))
       return phonenumber;
     else
       return false;
   } 
} 

// check to see if we have a number
function isNumber(number) {
  for (i = 0; i < parseInt(number.length); i++)
    if( number.charAt(i) > "9" || number.charAt(i) < "0")
      return false;
  return true;
}

function validate_phone(phone)
{
var count = 0;
var phonenumber = "";
for (k = 0; k < phone.length; k++) {
      if (phone.charAt(k) != " " && phone.charAt(k) != "-") { 
        phonenumber = phonenumber + phone.charAt(k);     
        count++;
      }
   }
   if (count < 10 || count > 10)
     return false;
   else {
     if (isNumber(phonenumber))
       return phonenumber;
     else
       return false;
   } 
} 


function checkEntries(TheValue)
{

var chkme="1"

	
if (TheValue != "delete")
{

//Seller Name
if (document.PW.SelName.value == "")
	{
	alert ("Seller Name cannot be empty")
	chkme = "2"
	document.PW.SelName.focus();
	}
else
	{
	chkme="1"
	}

//extension
if (chkme == "1")
{
	if (document.PW.SelPhone.value == "")
		{
		alert ("Seller Phone cannot be empty")
		chkme = "2"
		document.PW.SelPhone.focus();
		}
	else
		{
	
		cphone = validate_phone(document.PW.SelPhone.value);
		
		if (cphone == false)
			{	
			alert ("Invalid Phone Number");
			chkme="2"
			document.PW.SelPhone.value = "";
			document.PW.SelPhone.focus();
			}
		else
			{
			chkme="1"
			}
		
		}
}	
//extension
if (chkme == "1")
{
	if (document.PW.SelExt.value == "")
	{
	chkme = "1"
	}
else
	{
	chkme="1"
	
	cphone = validate_extension(document.PW.SelExt.value);
		
		if (cphone == false)
			{	
			alert ("Invalid Extension Number");
			chkme="2"
			document.PW.SelExt.value = "";
			document.PW.SelExt.focus();
			}
		else
			{
			chkme="1"
			}
		
	}
}

//email
if (chkme == "1")
{
	if (document.PW.SelEmail.value == "")
	{
	alert ("Seller Email cannot be empty")
	chkme = "2"
	document.PW.SelEmail.focus();
	}
else
	{
	chkme="1"
	
	cphone = validate_email(document.PW.SelEmail.value);
		
		if (cphone == false)
			{	
			alert ("Invalid Email Address");
			chkme="2"
			document.PW.SelEmail.value = "";
			document.PW.SelEmail.focus();
			}
		else
			{
			chkme="1"
			}
		
	}
}


//Item Name
if (chkme == "1")
{
	if (document.PW.ItemName.value == "")
	{
	alert ("Item Title cannot be empty")
	chkme = "2"
	document.PW.ItemName.focus();
	}
else
	{
	chkme="1"
	}
}

if (chkme == "1")
{
	if (document.PW.ItemPrice.value == "")
	{
	alert ("Item Price cannot be empty")
	chkme = "2"
	document.PW.ItemPrice.focus();
	}
else
	{
	chkme="1"
	}
}

//Item Category	
if (chkme == "1")
	{
	TheCat = document.PW.ItemCat.selectedIndex;
	
	if (TheCat == 0)
		{
		alert ("Please select an Item category")
		chkme = "2"
		document.PW.ItemCat.focus();
		}
	else
		{
		chkme="1"
		}	
	}

}
else
{
document.PW.del.value = TheValue;
}
//End of validating if delete not selected


if (chkme == "1")
	{
		document.PW.submit();
	}

}

		



function validate_email(checkThisEmail)
{	
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}


// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

if (mySpaceAt != -1) 
 {myEMailIsValid = false}


if (myEMailIsValid == true)
 {}
else
 {}


return myEMailIsValid
}


function convertString(thisString)
{
convertedString = parseInt(thisString);
return convertedString;
}

