
function emailvalidation(target, alertbox)
{
    var targetobj=document.getElementById(target);
    
    apos=targetobj.value.indexOf("@"); 
     
    dotpos=targetobj.value.lastIndexOf(".");
        
    lastpos=targetobj.value.length-1;
        
    if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
    {
        if (alertbox)
        {
            alert(alertbox);
        }
        return false;
    }
    else
    {
        return true;
    }
}

function emailvalidationConditional(target, alertbox)
{
    var targetobj=document.getElementById(target);
    
    apos=targetobj.value.indexOf("@"); 
     
    dotpos=targetobj.value.lastIndexOf(".");
        
    lastpos=targetobj.value.length-1;
     if( targetobj.value=="") 
     {
     return true;
     }
     else
     { 
    if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
    {
        if (alertbox)
        {
            alert(alertbox);
        }
        targetobj.focus();
        return false;
    }
    else
    {
        return true;
    }
    }
}




function emptyvalidation(target, alertbox)
{
    var targetobj=document.getElementById(target);
    //alert((targetobj.value).replace(/\s+/g,''));
    //alert(targetobj);
    if (targetobj.value==null || (targetobj.value).replace(/\s+/g,'')=="")
    {
        if (alertbox!="")
        {
            targetobj.focus();
            alert(alertbox);
        }
        return false;
    }
    else
    {
        return true;
    }
}
 //Hiddenfield validation
function hdnvalidation(target, alertbox)
{
    var targetobj=document.getElementById(target);
//    alert(target);
    //alert(targetobj);
    if (targetobj.value==null || targetobj.value=="")
    {
        if (alertbox!="")
        {
            //targetobj.focus();
            alert(alertbox);
        }
        return false;
    }
    else
    {
        return true;
    }
}


//to check textboxes
function customvalidation(target, alertbox1,numbers,alertbox2,flag)
{
    var targetobj=document.getElementById(target);
    var flg=flag;
//    alert(target);
//    alert(targetobj);

    if (targetobj.value==null || (targetobj.value > numbers && flg==0))
    {
        if (alertbox1!="")
        {
            alert(alertbox1);
        }
        return false;
    }
    else if(targetobj.value==null || (targetobj.value=="" && flg==1))
    {
        if (alertbox2!="")
        {
            alert(alertbox2);
        }
        return false;
    }
    else
    {
        return true;
    }
}
function CameraValidation(target1,target2,alertbox)
{
   var selected1 = document.getElementById(target1);
   var selected2=  document.getElementById(target2);

if (selected1.value ==0 && selected2.value =="") 
{
      if (alertbox!="")
        {
            alert(alertbox);
        }
       return false;
}

 else
 {
 return true;
 }

}
function emptyvalidationPASSWORD(target, lbl, alertbox)
{
    var targetlbl=document.getElementById(lbl);
    var targetobj=document.getElementById(target);
    
    if(targetobj.value==null || targetobj.value=="")
    {
        if(targetlbl.value==null || targetlbl.value=="")
        {        
            if (alertbox!="")
            {
                alert(alertbox);
            }
            return false;
        }
        else
        {
            return true;
        }
    }
    else
        return true;
}

//DropDownList Validation
function DropDownValidation()
{

if (document.getelementbyid("forum__ctl0_category").value == 0)
{
alert('Plese select value for dropdown')
return false;
}
return true;
}


 

function valuevalidation(entered, min, max, alertbox, datatype)
{
    with (entered)
    {
        checkvalue=parseFloat(value);
        if (datatype)
        {
            smalldatatype=datatype.toLowerCase();
            if (smalldatatype.charAt(0)=="i")
            {
                checkvalue=parseInt(value)
            };
        }
        if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
        {
            if (alertbox!="")
            {
                alert(alertbox);
            }
            return false;
        }
        else
        {
            return true;
        }
    }
}

function setfocus(a_field_id)
{
    $(a_field_id).focus()
}



 function isInteger (s)
   {
      var i;

//      if (isInteger.arguments.length == 1)
//        return 0;
//      else
//        return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }
    /*Numeric Validation*/
  function IsNumeric(sText,target)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
      if(IsNumber==false)
      alert(target);
   return IsNumber;
   
   }


//    function validateNumbers(obj,target)
//    {
//        alert('validateNumbers');
//      if (!IsNumeric(obj.value)) 
//      {
//      
//      alert('Please enter only numbers or decimal points in the account field'); 
//      //form.account_number.focus(); 
//      return false; 
//      } 
//        return true;
//    } 
  /*--------------------------------------------*/
    
	



 /*
 function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }
*/
   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }

 function validateInt(target, alertbox)
   {
     var o = document.getElementById(target);
     if (!isInteger(o.value)) 
        { 
         alert(alertbox);
         return false;
         }
         else
         {
         return true;
      }
   }
   
   function comparevalidation(first, second, alertbox)
{
    var firstobj=document.getElementById(first);
    var secondobj=document.getElementById(second);
    
    if(firstobj.value==secondobj.value)
        return true;
    else
    {
        if (alertbox!="")
        {
            alert(alertbox);
        }
        return false
    }
}

    function RPISettingValidation(FoodMinWage,Barallocation,Waiterspoints,BusboyPoints,RunnerPoints)
    {
        //alert(FoodMinWage);
       // emptyvalidation(Barallocation,'Barallocation Is Blanck!!') 
         
        return(validateInt(FoodMinWage,'FoodMinWage Must be numbers') && emptyvalidation(FoodMinWage,'FoodMinWage Is Blanck') && validateInt(Barallocation,'Barallocation Must be numbers')  && emptyvalidation(Barallocation,'Barallocation Is Blanck!!')  && emptyvalidation(Waiterspoints,'Waiterspoints Is  Blanck !!!')  && validateInt(Waiterspoints,'Waiterspoints Must be numbers') && validateInt(BusboyPoints,'BusboyPoints Must be numbers')  &&  emptyvalidation(BusboyPoints,'BusboyPoints Is Blanck!!')   && emptyvalidation(RunnerPoints,'RunnerPoints Is Blanck!!')  && validateInt(RunnerPoints,'RunnerPoints Must be numbers'));
        //return (IsNumeric(FoodMinWage) && IsNumeric(Barallocation) &&  IsNumeric(Waiterspoints) &&  IsNumeric(BusboyPoints) &&  IsNumeric(RunnerPoints));
    }

function login_validation(user, pass)
{
    
    return (emptyvalidation(user, 'Empty user name!') && emptyvalidation(pass, 'Empty password!'));
}

function Reserpassword_validation(user)
{
        return (emptyvalidation(user, 'Empty User ID!'));
}
//===========================================================================
function createuser_validation(pass, re_pass,name,website,url,address, city, state,zip,Tax, phone,fax, email)
{
//alert(Tax);
//alert(document.getElementById(zip).value);
   return (emptyvalidation(pass,'Password cannot be empty!') && comparevalidation(pass, re_pass, 'Password Mismatch!') && emptyvalidation(name, 'Name cannot be empty!') &&  emptyvalidation(website, 'WebSite Name cannot be empty!')  &&  emptyvalidation(url, 'Url cannot be empty!') &&  isURL(url)  &&  emptyvalidation(address, 'Address cannot be empty!') && emptyvalidation(city, 'City cannot be empty!') && emptyvalidation(state, 'State cannot be empty!')  && emptyvalidation(zip, 'Zip cannot be empty!') && IsNumeric(Tax) && validatePhone(phone, 'Invalid Phone no!') && validatePhone(fax, 'Invalid fax no!') && emptyvalidation(email, 'E-Mail cannot be empty!') && emailvalidation(email, 'Invalid Email Id!'));
}
function validateCommisiondate(frmdt,trdt)
{
 return (emptyvalidation(frmdt,'From Date cannot be empty!') && emptyvalidation(trdt,'To Date cannot be empty!'));
}

function UpdateUser_Validation(pass, re_pass,name,website,url,address, city, state,  zip,Tax, phone,fax, email)
{
   return (comparevalidation(pass, re_pass, 'Password Mismatch!') && emptyvalidation(name, 'Name cannot be empty!') &&  emptyvalidation(website, 'WebSite Name cannot be empty!')  &&  emptyvalidation(url, 'Url cannot be empty!') &&  isURL(url)  &&  emptyvalidation(address, 'Address cannot be empty!') && emptyvalidation(city, 'City cannot be empty!') && emptyvalidation(state, 'State cannot be empty!')  && emptyvalidation(zip, 'Zip cannot be empty!') && IsNumeric(Tax) && validatePhone(phone, 'Invalid Phone no!') && validatePhone(fax, 'Invalid fax no!') && emptyvalidation(email, 'E-Mail cannot be empty!') && emailvalidation(email, 'Invalid Email Id!'));
}

function ValidateRetailers(CompanyName,Email,Phone)
{
    return (emptyvalidation(CompanyName, 'Please enter company name') && emptyvalidation(Email, 'Please enter Email ID') && emailvalidation(Email, 'Invalid Email Id!') && emptyvalidation(Phone, 'Please enter phone no') && validatePhone(Phone, 'Phone no must be 10 digits!'));
}


//function createuser_validation(name, pass,lblpass, re_pass, address, city, state, country, zip, phone, email)
//{
//   return (emptyvalidation(name, 'Name cannot be empty!') && emptyvalidation(pass,lblpass, 'Password cannot be empty!') && comparevalidation(pass, re_pass, 'Password Mismatch!') && emptyvalidation(address, 'Address cannot be empty!') && emptyvalidation(city, 'City cannot be empty!') && emptyvalidation(state, 'State cannot be empty!') && emptyvalidation(country, 'Country cannot be empty!') && emptyvalidation(zip, 'Zip cannot be empty!') && emptyvalidation(phone, 'Phone cannot be empty!') && emptyvalidation(email, 'E-Mail cannot be empty!') && emailvalidation(email, 'Invalid Email Id!'));
//}

//=====================================================================================================

function createrestaurant_validation(REST_Name,REST_DESC,REST_Address,REST_City, State, Zip,Phone,REST_FAX, Email, REST_LOCATION,REST_HOUR,REST_FOOD_DELIVERY)
{
   return (emptyvalidation(REST_Name, 'Empty Restaurant Name!') && emptyvalidation(REST_DESC, 'Empty Restaurant Description!') && emptyvalidation(REST_Address, 'Empty Restaurant Address!') && valDropDownList(REST_City, 'Please Select City!') && emptyvalidation(State, 'Empty State value!') && emptyvalidation(Zip, 'Empty Zip Code!') && validateZip(zip, 'Zip should be 5 digit!') && emptyvalidation(Phone, 'Empty Phone No!') && validatePhone(Phone,'Check Phone No!') && emptyvalidation(REST_FAX, 'Empty Fax!') && emailvalidation(Email, 'Invalid Email Id!') && emptyvalidation(Email, 'Empty Email Id!') && emptyvalidation(REST_LOCATION, 'Empty Restaurant Location!') && emptyvalidation(REST_HOUR, 'Empty Restaurant Hour Operation!') && emptyvalidation(REST_FOOD_DELIVERY, 'Empty Delivery!'))
}



function createmenu_validation(menu_Name,menu_desc,price, restaurant, category)
{
   return (emptyvalidation(menu_Name, 'Empty Menu Name!') && emptyvalidation(menu_desc, 'Empty Menu Description!') && emptyvalidation(price, 'Empty Menu Price!') && formatNum(price, 'Price Should be 2 digit decimal!') && valDropDownList(restaurant, 'Select Restaurant!')&& valDropDownList(category, 'Select Category!'))
}
function createremployee_validation1(Emp_FName,Emp_LName)
{
   return (emptyvalidation(Emp_FName, 'Empty Employee First Name!') && emptyvalidation(Emp_LName, 'Empty Employee First Name!') )
}

        function SendEmail_Validation(FirstName,LastName,Phone,Email,Subject,Message)
        {
            return (emptyvalidation(FirstName, 'First name is blank') && emptyvalidation(LastName,'Last name is blank') && validatePhone(Phone,'Phone must be 10 digit number') && emptyvalidation(Email,'Email is blank') && emailvalidationConditional(Email,'Check email') && valDropDownList(Subject, 'Select subject') && emptyvalidation(Message,'Message is blank'))
        }
        
        function validateTotal(Name,LastName,Country,Address,ProvinceCanada,ProvinceUS,Phone,Email,radio2,radio3,radio5,radio6)
        { 
            
           //alert(document.getElementById(Country).selectedIndex); 
           return PurchasePageValidation(Name,LastName,Country,Address,ProvinceCanada,ProvinceUS,Phone,Email,radio2,radio3,radio5,radio6);                                                                                                                                                                                                                                                                                                                                                                                                                                                          

          
          
        }
        
        function PurchasePageValidation(Name,LastName,Country,Address,ProvinceCanada,ProvinceUS,Phone,Email,radio2,radio3,radio5,radio6)
        {
          //alert('purchase');
           if(document.getElementById(Country).selectedIndex==1)
          {
            //return (emptyvalidation(Name,'First Name is blank') && emptyvalidation(LastName,'Last Name is blank') && valDropDownList(Country,'Select any Country') && emptyvalidation(Address,'Address is blank') && valDropDownList(ProvinceCanada,'Select any povince') && emptyvalidation(Phone,'Empty Phone no') && validatePhone(Phone,'Phone must be 10 digit number') && emptyvalidation(Email,'Email is blank') && emailvalidationConditional(Email,'Check Email') && CheckShipping(radio2,radio3) && TestCheckBox());
            return (emptyvalidation(Name,'First Name is blank') && emptyvalidation(LastName,'Last Name is blank') && valDropDownList(Country,'Select any Country') && emptyvalidation(Address,'Address is blank') && valDropDownList(ProvinceCanada,'Select any povince') && emptyvalidation(Phone,'Empty Phone no') && validatePhone(Phone,'Phone must be 10 digit number') && emptyvalidation(Email,'Email is blank') && emailvalidationConditional(Email,'Check Email') && checkCheckBoxes());
          }
           if(document.getElementById(Country).selectedIndex==2)
          {
           //return (emptyvalidation(Name,'First Name is blank') && emptyvalidation(LastName,'Last Name is blank') && valDropDownList(Country,'Select any Country') && emptyvalidation(Address,'Address is blank') && valDropDownList(ProvinceUS,'Select any povince') && emptyvalidation(Phone,'Empty Phone no') && validatePhone(Phone,'Phone must be 10 digit number') && emptyvalidation(Email,'Email is blank') && emailvalidationConditional(Email,'Check Email') && CheckShipping(radio5,radio6) && TestCheckBox());
           return (emptyvalidation(Name,'First Name is blank') && emptyvalidation(LastName,'Last Name is blank') && valDropDownList(Country,'Select any Country') && emptyvalidation(Address,'Address is blank') && valDropDownList(ProvinceUS,'Select any povince') && emptyvalidation(Phone,'Empty Phone no') && validatePhone(Phone,'Phone must be 10 digit number') && emptyvalidation(Email,'Email is blank') && emailvalidationConditional(Email,'Check Email') && checkCheckBoxes());
          }
          if(document.getElementById(Country).selectedIndex==0)
          {
           alert('Please Select Country');
           return false;
          }
          
        }
        
      function CommentsValidation(Subject,Comments,Name)
      {
         return (emptyvalidation(Subject, 'Subject blank!') && emptyvalidation(Comments, 'Enter comments') && emptyvalidation(Name, 'Enter name'))
      }  
        
function createremployee_validation(Emp_FName,Emp_LName,Emp_SSN,Emp_Email,Emp_Phno,State,Emp_Zip)
{
   
   return (emptyvalidation(Emp_FName, 'Empty Employee First Name!') && emptyvalidation(Emp_LName, 'Empty Employee Last Name!') && emptyvalidation(Emp_SSN, 'Empty Employee SSN!') && validateSSn(Emp_SSN,'SSN Must be 9 digit no') && emailvalidationConditional(Emp_Email,'Check Email') && valDropDownList(State,'Empty State') && validateZip(Emp_Zip, 'Zip should be 5 digit!') && emptyvalidation(Emp_Phno,'Empty Phone no') && validatePhone(Emp_Phno,'Check Phone No!'))
}



//================================================================================================
//function createUser_validation(U_Name,PAass,RePass, Address, City, State, Country,Zip,Phone,Email)
//{
//   return (emptyvalidation(U_Name, 'Empty User Name!') && emptyvalidation(PAass, 'Enter Password!') && emptyvalidation(RePass, 'Enter Re-Password!') && emptyvalidation(Address, 'Empty Address') && emptyvalidation(City, 'Empty City value!') && emptyvalidation(State, 'Empty State value!') && emptyvalidation(Country, 'Empty Country Value!') && emptyvalidation(Zip, 'Empty Zip Code!') && emptyvalidation(Phone, 'Empty Phone No!') && emailvalidation(Email, 'Invalid Email Id!') && emptyvalidation(Email, 'Empty Email Id!'))
//}


//validate Image Inputs
function ValidateInputs(ImgTitle,ImgDescription,ImgCamera,txtImgLens,ImgShotSettings,ImgBackColor,ImgFontColor,Camera,Lens)
{
    return(customvalidation(ImgTitle,'Image title may not be more than 50 characters',50,'Image Title cannot be blank',1) && customvalidation(ImgDescription,'Image description may not be more than 1000 characters',1000,'Image Description cannot be blank',1) && customvalidation(ImgBackColor,'',250,'Image forecolor cannot be blank',1)&& customvalidation(ImgFontColor,'',250,'Image backcolor cannot be blank',1) && CameraValidation(Camera,ImgCamera,'Please specify Camera') && CameraValidation(Lens,txtImgLens,'Please Specify Lens') && customvalidation(ImgShotSettings,'Image shot setting may not be more than 250 characters',250,'Image shot setting cannot be blank',0) )
}

//Validate User Info
  function UserValidation(Password,ConfirmPassword,Fname,Lname,Ssn,Permission,PhoneNo,State,Zip,Email)
  {
       
       return(emptyvalidation(Password,'Enter Password') && comparevalidation(Password,ConfirmPassword,'Password does not match! Try Again..') && emptyvalidation(Fname,'Enter First name') && emptyvalidation(Lname,'Enter Last name') && emptyvalidation(Ssn,'Enter SSN') && validateSSn(Ssn,'SSN Must be 9 digit no') && valDropDownList(Permission,'Select any Permission') && validatePhone(PhoneNo,'Phone no must be 10 digit no') && valDropDownList(State,'Select State') && validateZip(Zip,'Zip Code must be 5 digit no') && emailvalidationConditional(Email,'Check email'))
  }

  function UserUpdateValidation(Password,ConfirmPassword,Fname,Lname,Ssn,Permission,PhoneNo,State,Zip,Email)
  {
       
       return(comparevalidation(Password,ConfirmPassword,'Password does not match! Try Again..') && emptyvalidation(Fname,'Enter First name') && emptyvalidation(Lname,'Enter Last name') && emptyvalidation(Ssn,'Enter SSN') && validateSSn(Ssn,'SSN Must be 9 digit no') && valDropDownList(Permission,'Select any Permission') && validatePhone(PhoneNo,'Phone no must be 10 digit no') && valDropDownList(State,'Select State') && validateZip(Zip,'Zip Code must be 5 digit no') && emailvalidationConditional(Email,'Check email'))
  }  

   function AvailableValidation(UserID)
   {
      return (emptyvalidation(UserID,'Enter USerID'))
   }


function Upload_Validation(txtTitle,txtdescription,category)
{
  return(emptyvalidation(txtTitle, 'Image title cannot be blank!') && emptyvalidation(txtdescription, 'Image description cannot be blank!') && valDropDownList(category,'You must select a category'))
}
function alert1()
{
   //alert('abcd');
   alert(isInteger('1'));
}
    function CreateRestaurantValidation(RestaurantName,Fax,Phone,State,Zip)
    {
      return(emptyvalidation(RestaurantName,'Restaurant name cannot be blank') && validatePhone(Fax,'Fax must be 10 digit no') && validatePhone(Phone,'Phone must be 10 digit no') && valDropDownList(State,'Select State') && validateZip(Zip,'Zip Code must be 5 digit no'))
    }
   
function ImageDetailValidation(FirstName,LastName,ddlCountry,ddlStateCanada,ddlStateUS,City,Phone,Email,FilePath,Rules,Captcha)
{
   
  //alert(document.getElementById(FilePath).value);
  if(document.getElementById(ddlCountry).selectedIndex==0)
    {
       alert('All fields are mandatory.');
       return false;
    }
  if(document.getElementById(ddlCountry).selectedIndex==1)
    {
       return(emptyvalidation(FirstName,'All fields are mandatory.') && emptyvalidation(LastName,'All fields are mandatory.') && valDropDownList(ddlStateCanada,'All fields are mandatory.') && emptyvalidation(City,'All fields are mandatory.') && emptyvalidation(Phone,'All fields are mandatory.') && validatePhone(Phone,'Phone no must be 10 digit no.') && emptyvalidation(Email,'All fields are mandatory.') && emailvalidationConditional(Email,'Check Email') && hdnvalidation(FilePath,'Please upload file.') && CheckboxValidation(Rules,'Agree rules & regulations')&& emptyvalidation(Captcha,'All fields are mandatory.'))
    }
  if(document.getElementById(ddlCountry).selectedIndex==2)
    {
       return(emptyvalidation(FirstName,'All fields are mandatory.') && emptyvalidation(LastName,'All fields are mandatory.') && valDropDownList(ddlStateUS,'All fields are mandatory.') && emptyvalidation(City,'All fields are mandatory.') && emptyvalidation(Phone,'All fields are mandatory.') && validatePhone(Phone,'Phone no must be 10 digit no') && emptyvalidation(Email,'All fields are mandatory.') && emailvalidationConditional(Email,'Check Email') && hdnvalidation(FilePath,'Please upload file.') && CheckboxValidation(Rules,'Agree rules & regulations')&& emptyvalidation(Captcha,'All fields are mandatory.'))
    }
}  

function DirectPaymentValidation(CardNo,ExpirationMonth,Year,CVVCode)
{
    return ( emptyvalidation(CardNo,'Please enter Credit Card number') && validateCreditCard(CardNo,'Credit Card number must be numeric') && valDropDownList(ExpirationMonth,'Please select month') && valDropDownList(Year,'Please select year') && emptyvalidation(CVVCode,'Please enter CVV2 number') && IsNumeric(CVVCode));
}
 
   
//function validatePhone(obj,alertbox)
//{
//var o = document.getElementById(obj);
//var validNum =(/^[0-5]\d{2}-\d{8}$/);
//if (validNum.test(o.value) == false)
// {
// alert(alertbox);
//return false;
// }
//else
//  {
//  return true;
//  }
//}
function validatePhone(obj,alertbox)
{
var o = document.getElementById(obj);
var validNum =(/^[0-9]\d{9}$/);
if(o.value=="")
{
   return true;  
}
else
{
if (validNum.test(o.value) == false)
 {
 o.focus();
 alert(alertbox);
return false;
 }
else
  {
  return true;
  }
 }
} 

function validateMobile(obj,alertbox)
{
var o = document.getElementById(obj);
var validNum =(/^[0-9]\d{9}$/);
if (validNum.test(o.value) == false)
 {
 alert(alertbox);
return false;
 }
else
  {
  return true;
  }
}

function valDropDownList(target, alertbox)
 {
var selected = document.getElementById(target);
//alert(selected);
//alert(selected.value);
if (selected.value ==0) 
{
selected.focus();
alert(alertbox);
return false;
}
 else
 { 
 return true;
 }
} 

 //Validate Credit Card
function validateCreditCard(obj,alertbox)
{
var o = document.getElementById(obj);
var validNum =(/^[0-9]\d{15}$/);
if (validNum.test(o.value) == false)
 {
 alert(alertbox);
return false;
 }
else
  {
  return true;
  }
}






function validateZip(obj,alertbox)
{ 
var o = document.getElementById(obj);
var TextValue =o.value;
var TextLength=parseInt(TextValue.length);

//var exp= (/^[0-9]\d{''TextLength''}$/);
//alert(exp);


var validNum =(/^[0-9]\d{4}$/);
var validNum2 =(/^[0-9]\d{5}$/);
//alert(o.value);
if(o.value=="")
{
   return true;  
}
else
{
    if(TextLength>=5 && TextLength<=6)
    {
        //alert(TextLength);
        if(TextLength==5)
        {
            if (validNum.test(o.value) == false)
             {
             alert(alertbox);
            return false;
             } 
            else
             {
              return true;
             }
         }
        if(TextLength==6)
        {
            if (validNum2.test(o.value) == false)
             {
             alert(alertbox);
            return false;
             } 
            else
             {
              return true;
             }
        }
    }
    else
    {
       alert('Please enter number between 5 to 6 digits');
       o.focus();
       return false;
    }
 }
 
}








function validateTax(obj,alertbox)
{
var o = document.getElementById(obj);
var validNum =(/^[0-9]\d{14}$/);
if(o.value=="")
{
   return true;  
}
else
{
if (validNum.test(o.value) == false)
 {
 o.focus();
 alert(alertbox);
return false;
 }
else
  {
  return true;
  }
 }
} 



function validateSSn(obj,alertbox)
{
var o = document.getElementById(obj);
var validNum =(/^[0-9]\d{8}$/);
if (validNum.test(o.value) == false)
 {
 alert(alertbox);
return false;
 }
else
  {
  return true;
  }
}

function IsMatchFloat(target,alertbox)
{
var mystring=document.getElementById(target);
//    mystring = str;
    if (mystring.match(/^\d+$|^\d+\.\d{2}$/ ) ) 
    {
     
        return true;
    }
    else
    {
       if (alertbox!="")
        {
            alert(alertbox);
        }
        return false;
    }
}

function formatNum(target,alertbox) 
{
var con = document.getElementById(target);
var s=con.value;
//alert(target);
//alert(s);
var OK = /^\d{1,9}(\.\d\d?)?$/.test(s);
if (OK) 
{
s = s.replace(/(\.\d)$/, "$10").replace(/^(\d+)$/, "$1.00")
return true;
} 
else 
{
//alert(s);
//      if (alertbox!="")
//        {
            alert(alertbox);
            return false;
//        }
        
}

}

///^(0|[1-9]\d{0,3})(\.\d\d?)?$/




function isInteger(digit)
{
    var i;
    
    for (i = 0; i < digit.length; i++)
    {
        var c = digit.charAt(i);

        if (!isDigit(c))
            return false;
    }

    return true;
}

function isDigit (c)
{
    return ((c >= "0") && (c <= "9"));
}

function validateInt(target, alertbox)
{
    var o = document.getElementById(target);
    var v = o.value;
    
    var where_is=v.indexOf('.');
        
    if(where_is > -1)
    {
        var first = v.split(".");
        
        if (!isInteger(first[0])) 
        { 
            alert(alertbox);
            setfocus(target);
            return false;
        }
        else
        {
            if (!isInteger(first[1])) 
            { 
                alert(alertbox);
                setfocus(target);
                return false;
            }
            else
            {
                if(first[1].length > 2)
                {
                    alert('Decimal part cann\'t be more than 2 digits!');
                    setfocus(target);
                    return false;
                }
                else
                    return true;
            }
        }
   }
   else
   {
        if (!isInteger(v)) 
        { 
            alert(alertbox);
            setfocus(target);
            return false;
        }
        else
            return true;
   }
}


 function validatePhoneEmpty(obj,alertbox)
{
var o = document.getElementById(obj);
var validNum =(/^[0-9]\d{9}$/);
if (validNum.test(o.value) == false)
 {
 alert(alertbox);
return false;
 }
else
  {
  return true;
  }
 
}

//// Sets Dirty Flag
function setDirtyFlag()
  {
  
    objDF = document.getElementById('dirtyflag');
    //alert(objDF);
    objDF.value = '1';
      
  }
  
  
 //// Check Dirty Flag
 function checkDirtyFlag()
 {
 
    objDF = document.getElementById('dirtyflag');
    //alert(objDF);
    if(objDF.value == '1')
    {
        res=confirm('There is unsaved data in the screen. Do you really want to continue? ');
    }
    //alert(res);
    
    if(res == true)
     return true;
    else
     return false;
 
 
 }
  
 function getRadioSelectedValue(radioList)
 {
 alert(radiolist);
var options = radioList.getElementsByTagName('input');

for(i=0;i<options.length;i++){
var opt = options[i];
if(opt.checked){
a=opt.value
alert( a);
//return opt.value
}
}
}

function CheckShipping(id1,id2)
{
  
  var count=0;
  var radio1=document.getElementById(id1);  
  var radio2=document.getElementById(id2);  
  //var radio3=document.getElementById(id3);  
  if(radio1.checked)
  {
    count++;
    return true;    
  }
  if(radio2.checked)
  {
    count++;
     return true; 
  }
//  if(radio3.checked)
//  {
//    count++;
//     return true; 
//  }
  if(count==0)
  alert('Please select any shipping option');
  return false;
}

//CheckBox
 var TargetBaseControl = null;
        
       window.onload = function()
       {
          try
          {
             //get target base control.
             TargetBaseControl = 
               document.getElementById('<%= this.grdProduct.ClientID %>');
          }
          catch(err)
          {
             TargetBaseControl = null;
          }
       }
    
    function TestCheckBox()
   {  
              
      if(TargetBaseControl == null) return false;
        
      //get target child control.
      var TargetChildControl = "chkSelect";
            
      //get all the control of the type INPUT in the base control.
      var Inputs = TargetBaseControl.getElementsByTagName("input"); 
      var q=0;      
      for(var n = 0; n < Inputs.length; ++n)
        
         {
           
           
         if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0 && Inputs[n].checked)
           {      
                    
                   
                     q++;
                   
                   
             
                 }           
              }             
//             
              if(q==0)
              {
              alert('Select at least one Product!');               
              return false;
              }
              
          
   }
   
   //-------------------------

     
     
     
     
     
     
     
 //------------------------------------------    
     
     function CheckboxValidation(obj,Message)
     {
       //alert(obj);
       var id= document.getElementById(obj);
       if(id.checked==true)
       {
        return true;
       }
       else
       {
       alert(Message);
       return false;
       }
       
     }

     function FileUploadValidation(obj)
     {
        //alert(obj);
        var Target= document.getElementById(obj);
        //alert(Target);
        var FileName=Target.value;
        var ext = FileName.substring(FileName.lastIndexOf('.') + 1);        
        if(FileName=='')
        {
        alert('Please upload file');
        return false;
        }
        else
        {
        //alert(FileName);
        //alert(FileName.lastIndexOf('.')!=-1);
          if(FileName.lastIndexOf('.')!=-1)
          { 
              if(ext.toUpperCase() == 'JPG' || ext.toUpperCase() == 'GIF' || ext.toUpperCase() == 'JPEG')
                {
                return true;
                } 
                else
                {
                alert("Only .jpg,.gif can be uploaded");
                Target.focus();
                return false;
                }
           }
           else
           {
                alert('Please provide a proper filename');
                return false;
           }

        }
     }
     
     function IncorrectCaptcha()
    {
     alert('Incorrect Captcha ! Please try again...');
    }
    
     function  ShowMessage()
    {
        alert('Sorry but your file has too much cuteness. Images must be less than 500 KB in size please.');
    }
    
    
    
 function ConfirmDelete()
 {
    res=confirm('Are you sure you want to delete the selected images ? All data will be lost. Please click on OK to delete the selected images or CANCEL to return to the main. ');
    if(res==true)
    return true;
    else
    return false;
 } 
 function ConfirmPaid()
 {
    res=confirm('This operation will update the payment status for the selected records. Are you sure you want to continue?. Please click on OK to Update the selected Affiliate  or CANCEL to return to the main. ');
    if(res==true)
    return true;
    else
    return false;
 } 
 
 function ConfirmDeleteAffiliate()
 {
    res=confirm('Are you sure you want to delete the selected affiliates ? All data will be lost. Please click on OK to delete the selected affiliates or CANCEL to return to the main. ');
    if(res==true)
    return true;
    else
    return false;
 }          
  
  
                     function isURL ( txtId ){ 
  
                  var string = document.getElementById(txtId).value;     
  
//                  if ( string.search(/^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$/) != -1 ){ 
//                            //alert('Valid URL'); 
//                        return true; 
//                  } 
  
  
                  if ( string.search(/^[http:/\/]+[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$/) != -1 ){ 
                            //alert('valid URL'); 
                        return true; 
                  } 
  
                  alert('Not a valid URL'); 
                  document.getElementById(txtId).select(); 
                  document.getElementById(txtId).focus();         
                  return false; 
  
            } 
  
  
     function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   //alert( document.getElementById(strString).value);
   if(document.getElementById(strString)!=null)
   {
       var Number=(document.getElementById(strString)).value;
       var strValidChars = "0123456789";
       var strChar;
       var blnResult = true;

       //if (strString.length == 0) return false;

       //  test strString consists of valid characters listed above
       for (i = 0; i < Number.length && blnResult == true; i++)
          {
          strChar = Number.charAt(i);
          if (strValidChars.indexOf(strChar) == -1)
             {
             blnResult = false;
             alert('Enter only numbers');
             break;
             }
          }
       return blnResult;
   }
   else
   {
       return true;
   }
  }

   function SuccessMessage()
   {
    alert('Thank you, your application has been submitted. A Wiggle Wag representative will contact you shortly.');
   }
    
    
  function CheckLenght(obj)
  {
     //alert(document.getElementById(obj.id).value);
     var TextValue=document.getElementById(obj).value;
     var TextLenght=TextValue.length;
     //alert(TextLenght);
     if(TextLenght>500)
     {
         alert('Enter comments within 500 characters');
         //obj.id.focus();          
         return false;
         obj.focus();
     }
     else
     {
        return true;
     }
  }
  
    function checkRadioButton(GroupName,Message)
          {
               //alert('hi');
               var Flag=false;
               var Radio=document.getElementsByName(GroupName);
               for (var i = 0; i < Radio.length; i++) 
               {
		        if (Radio.item(i).checked)
		         {
			        Flag = true;
			        //return Flag;
		            }
	            }
	            if(Flag==false)
	            {
	              alert(Message);
	            }
	           return Flag; 

          }
          
        
          