//Check Categories
function checkCategory(strng,msg) 
{
	  var error = "";
	  var illegalChars = /\W/; // allow letters, numbers, and underscores
		if (strng == "") 
		{
			if(msg=='none')
			{
		     error = "You didn't enter a category name.\n";
			}
			else
			{
				error = msg;
			}
		}
		else if ((strng.length < 1) || (strng.length > 30))
		{
		   error = "Th length.\n";
		}
		
return error;
}

//Check 2 Values
function isEqual(val1,val2,msg)
{
	var error = "";
	if (val1 != val2) 
		{
			error = msg;
		}
	return error;
}
// valid selector from dropdown list

function checkDropdown(choice,msg)
{
var error = "";
    if (choice == 0) 
	{
		//if(msg=='none')
       // error ="You didn't choose an option from the drop-down list.\n";
		//else
		error =msg;
		
    }    
	
return error;
}    

// non-empty textbox

function isEmpty(strng,msg) 
{
var error = "";
  if (strng.length == 0) 
  {
     error = msg;
  }
return error;	  
}

// email
function checkEmail (strng) 
{
	var error="";
	var emailFilter=/^.+@.+\..{2,3}$/;
		if (strng == "")
		{
		   error = "You didn't enter an email address.\n";
		}
		else if (!(emailFilter.test(strng))) 
		{ 
		   error = "Please enter a valid email address.\n";
		}
		else 
		{
	       //test email for illegal characters
		   var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			 if (strng.match(illegalChars)) 
			 {
			  error = "The email address contains illegal characters.\n";
		     }
		}
	return error;    
}


function checkCheckBoxes(strng,msg)
{
	var error="";
    	if (strng == false)
		 {
		 error=msg;
	     }
		 return error;
	
	}
// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) 
{
	var error = "";
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
		if (strng == "")
		{
		   error = "You didn't enter a phone number.\n";
		}
		else if (isNaN(parseInt(stripped))) 
		{
		   error = "The phone number contains illegal characters.";
	  
		}
		else (!(stripped.length == 10)) 
		{
		error = "The phone number is the wrong length. Make sure you included an area code.\n";
		} 
	return error;
}
//show hide
var shflag=false;
function showHide(val)
{
	if(shflag==false){
		document.getElementById(val).style.display=""; 
		shflag=true;
	}
	else{
		document.getElementById(val).style.display="none";
		shflag=false;
	}
}
// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) 
{
	var error = "";
	var illegalChars = /[\W_]/; // allow only letters and numbers
		if (strng == "") 
		{
		   error = "You didn't enter a password.\n";
		}
      else if (illegalChars.test(strng))
		{
		  error = "The password contains illegal characters.\n";
		} 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/))))
		{
		   error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
		}  
return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) 
{
	var error = "";
	  var illegalChars = /\W/; // allow letters, numbers, and underscores
		if (strng == "") 
		{
		   error = "You didn't enter a username.\n";
		}
		else if ((strng.length < 4) || (strng.length > 10))
		{
		   error = "The username is the wrong length.\n";
		}
		else if (illegalChars.test(strng))
		{
		error = "The username contains illegal characters.\n";
		} 
return error;
}       




// was textbox altered

function isDifferent(strng) 
{
var error = ""; 
  if (strng != "Can\'t touch this!")
  {
    error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) 
{
var error = "";
   if (!(checkvalue))
    {
       error = "Please check a radio button.\n";
    }
return error;
}
function checkPromo(strng)
{
var	error='';
//val=document.getElementById("textfile").value;
val =strng;
var Validalpha="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
var Alpha;

  if (strng.length == 0) 
  {
     //error = "You didn't enter the promocode.\n";
	 //return true;
  }
else if (strng.length <5) 
  {
	  
     error = "the length of promocode should be 5. \n";
  }
else 
  {
	for (i = 0; i < val.length && IsNumber == true; i++)
	{
	
	   Alpha = val.charAt(0);
		//alert(Alpha)
		Char = val.charAt(++i);
		//alert(Char )
		if (Validalpha.indexOf(Alpha) == -1)
		{
		error="In the promocode enter the 1st character Aplhabets only.\n";
		}
		else if (ValidChars.indexOf(Char) == -1)
		{
		error="In the promocode enter the numbers only After 1st Character.\n";
		}
		--i;
	}
  }
  
return error;

}





