function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false}
else {return true}
}
}

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false}
else {return true}
}
}



function validate_form(thisform)
{
with (thisform)
{
	





if (validate_required(name,"Please enter your Full Name!")==false)
{name.focus();return false}

if (validate_required(address,"Please enter valid Address!")==false)
{address.focus();return false}

if (validate_required(city,"Please enter valid City!")==false)
{city.focus();return false}

if (validate_required(state,"Please enter valid State!")==false)
{state.focus();return false}

if (validate_required(zip,"Please enter valid Zip Code!")==false)
{zip.focus();return false}



if (email.value!=cemail.value)
{alert("Your e-mail address should match");cemail.focus(); return false;}

if (validate_required(username,"You need to provide a Login Name!")==false)
{username.focus();return false}


if (username.value != "") {
  strng=username.value;
    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 5) || (strng.length > 20)) {
       alert("The Login Name should be between 5 to 20 characters.\n");
      username.focus();
	  return false;
    }
    else if (illegalChars.test(strng)) {
     alert("The Login Name should contain only alphabets, numbers and \"_\".");
       username.focus();
	   return false;
    } 

}


if (validate_required(Password,"You need to provide a Password!")==false)
{Password.focus();return false}

if (validate_required(repassword,"Enter the password again!")==false)
{repassword.focus();return false}



if (Password.value != "") {
  strng=Password.value;
    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 5) || (strng.length > 20)) {
       alert("The password should be between 5 to 20 characters.\n");
      Password.focus();
	  return false;
    }
    else if (illegalChars.test(strng)) {
     alert("The password should contain only alphabets, numbers and \"_\".");
       Password.focus();
	   return false;
    } 

}

if (Password.value!=repassword.value)
{alert("Your passwords should match");repassword.focus();return false;}

if (validate_email(email,"Not a valid e-mail address!")==false)
{email.focus();return false}

if (validate_required(cemail,"You need to retype you e-mail address!")==false)
{cemail.focus();return false}




if (document.getElementById("chargeback") && (validate_required(chargeback,"Please enter your initials in the box provided!")==false))
{chargeback.focus();return false}


var message=name.value
var mytool_array=message.split(" ");
var arrinitial = new Array(mytool_array.length);
var part_num=0;
while (part_num < mytool_array.length)
 {
	message=mytool_array[part_num];
	arrinitial[part_num]=message.charAt(0)
	part_num+=1;

  }
myVar2=arrinitial.join(",");
var myNewString = myVar2.replace(",", "");
var myNewString = myNewString.replace(",", "");
var casechanged=myNewString.toUpperCase(); 
//alert(myNewString);
//alert(casechanged);
//if (chargeback.value!=casechanged)
//{alert("Your Initials and name should match");chargeback.focus(); return false;}




}
}





function compare_email()
{
if (document.register.email.value!=document.register.cemail.value)
{alert("Your e-mail address should match");document.register.cemail.focus()}
}

function checkUsername(strng) {
var error = "";
if (strng == "") {
   alert("You didn't enter a username.\n");
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 5) || (strng.length > 20)) {
       alert("The username should be between 5 to 20 characters.\n");
       document.register.username.focus();
    }
    else if (illegalChars.test(strng)) {
     alert("The username should contain only alphabets, numbers and \"_\".");
       document.register.username.focus();
    } 


}       


function checkPassword(strng) {
var error = "";
if (strng == "") {
   alert("You didn't enter a Password.\n");
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 5) || (strng.length > 20)) {
       alert("The Password should be between 5 to 20 characters.\n");
       
    }
    else if (illegalChars.test(strng)) {
     alert("The Password should contain only alphabets, numbers and \"_\".");
       
    } 


} 

function compare_password()
{
if (document.register.Password.value!=document.register.repassword.value)
{alert("Your passwords should match");document.register.repassword.focus()}
}


function validate_form_login(thisform)
{
with (thisform)
{

	if (validate_required(name,"Please enter your user name!")==false)
	{name.focus();return false}

	if (validate_required(pwd,"Please enter your password!")==false)
	{pwd.focus();return false}

}
}

function validate_form_addorg(thisform)
{
with (thisform)
{

	if (validate_required(organization,"Please enter organization name!")==false)
	{organization.focus();return false}

	if(isNaN(credit_units.value)){
		alert("Please enter only Numeric values")
			credit_units.focus();
			return false;
	}

}
}

function validate_form_addcoupon(thisform){
with (thisform)
{
var objRegExp  = /(^\d{1,10}$)|(^\d{1,10}.\d{2}$)/;
//var objRegExpDate  = /(^\d{2}$)|(^\d{1,10}/\d{2}$)/;


  //check for valid US Zipcode
  valss=objRegExp.test(discount.value);
	  if(!valss){
		  alert("Discount value is wrong Not allowed");
		  discount.focus();
		  return false;
	  }

  //if(!validatecoupon(discount.value)){alert('please enter valid discount coupon value');

}
}

function confirmdelete(orgid){

if(confirm ('Are you sure you want to delete this record?'))
	window.location.href="?orgID="+orgid;

}

function confirmdeleteuser(orgid){

if(confirm ('Are you sure you want to delete this record?'))
	window.location.href="?userID="+orgid;

}
function confirmdeletecoupon(orgid){

if(confirm ('Are you sure you want to delete this record?'))
	window.location.href="?couponID="+orgid;

}
