
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 emptyvalidation(target, alertbox)
{
    var targetobj=document.getElementById(target);
//    alert(target);
//    alert(targetobj);
    if (targetobj.value==null || targetobj.value=="")
    {
        if (alertbox!="")
        {
            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.length > 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 a value from dropdown')
return false;
}
return true;
}

//DropDownList Validation for ""
function DropDownValidation(ddl)
{
var ddlobj=document.getElementById(ddl);
if (ddlobj.value == "")
{
alert('Plese select a value from dropdown')
return false;
}
return true;
}

//DropDownList Validation for "HelpFulScore"
function DropDownValidationHlp(ddl)
{
var ddlobj=document.getElementById(ddl);
//alert(ddlobj.value);
//return false;
if (ddlobj.value == "-1")
{
alert('Plese select another option from dropdown!')
return false;
}
else
{
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(digit)
{
    var i;
    
    for (i = 0; i < digit.length; i++)
    {
        var c = digit.charAt(i);

        if (!isDigit(c))
            return false;
    }

    return true;
}

 function isIntegerChkRange(target,alertbox)
{
//alert(target);
//var objtarget=document.getElementById(target);

var objtargetValue=target.value;
 var where_is=objtargetValue.indexOf('.');
 
//alert(where_is);
if(where_is==-1)
{
    var i;
    
    for (i = 0; i < objtargetValue.length; i++)
    {
        var c = objtargetValue.charAt(i);

        if (!isDigit(c))
        {
        alert(alertbox);
           return false;
         }
    }
//   alert(objtargetValue);
    
    if(objtargetValue>=0 && objtargetValue<=10)
    {
//    alert('aa');
        return true;
    }
    else
    {
        alert('Enter value from (0-10)');
         return false;
    }
    return true;
 }
    else
    {
    alert(alertbox);
     return false;
    }
}

function isDigit (c)
{
    return ((c >= "0") && (c <= "9"));
}

function validateIntForGrid(target, alertbox)
{
// alert('123456');
//  alert(target.id);
    var o = document.getElementById(target.id);
    var v = o.value;
//    alert(v);
    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 validateInt(target, alertbox)
{
//  alert(target.id);
    var o = document.getElementById(target);
    var v = o.value;
//    alert(v);
    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 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 checkCheckBoxes(checkbox, alertbox)
 {
     var checkboxobj=document.getElementById(checkbox);
	if (checkboxobj.checked == false)	
	{
			alert (alertbox);
			
		return false;	
	}
		else	
	{	
		return true;
		
	}
	
}



function createuser_validation(username,firstname,lastname, email, confirmemail,pass, re_pass,checkbox,ddl)
{
   return (emptyvalidation(username, 'User Name cannot be empty!') && emptyvalidation(firstname, 'First Name cannot be empty!') &&  emptyvalidation(lastname, 'Last Name cannot be empty!') && emptyvalidation(email, 'E-Mail cannot be empty!') && emailvalidation(email, 'Invalid Email Id!') && comparevalidation(email, confirmemail, 'Email Mismatch!') && emptyvalidation(pass,'Password cannot be empty!') && comparevalidation(pass, re_pass, 'Password Mismatch!') && checkCheckBoxes(checkbox,'You must accept the site terms and conditions') && DropDownValidation(ddl));
}

function passwordchange_validation(oldpass,newpass,confirmpass)
{
   return (emptyvalidation(oldpass, 'Current Password cannot be empty!') && emptyvalidation(newpass, 'New Password cannot be empty!') &&  emptyvalidation(confirmpass, 'Confirm Password cannot be empty!') && comparevalidation(newpass, confirmpass, 'Password Mismatch!'));
}

function updateuser_validation(username,firstname,lastname, email, ddl)
{
   return (emptyvalidation(username, 'User Name cannot be empty!') && emptyvalidation(firstname, 'First Name cannot be empty!') &&  emptyvalidation(lastname, 'Last Name cannot be empty!') && emptyvalidation(email, 'E-Mail cannot be empty!') && emailvalidation(email, 'Invalid Email Id!') && valDropDownList(ddl, 'Please Select Country!') );
}

function createmessage_validation(subject,msg)
{
   return (emptyvalidation(subject, 'Subject cannot be empty!') && emptyvalidation(msg, 'You must enter a message.') );
}



//===========================================================================
//function createuser_validation(pass, re_pass,name,address, city, state, country, zip, phone, email)
//{
//   return (emptyvalidation(pass,'Password cannot be empty!') && comparevalidation(pass, re_pass, 'Password Mismatch!') && emptyvalidation(name, 'Name cannot be empty!') &&  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!') && validateZip(zip, 'Zip should be 5 digit!') && emptyvalidation(phone, 'Phone cannot be empty!') && validatePhone(phone, 'Invalid Phone no!') && 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 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,ImgShotSettings,ImgFontColor,ImgBackColor,Camera,Lens,CheckCritique,txtCritique)
//{
//    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(ImgCamera,'Camera name may not be more than 100 characters',100,'Camera name cannot be blank',0) && customvalidation(txtImgLens,'Lens name may not be more than 100 characters',100,'Lens name cannot be blank',0) && customvalidation(ImgShotSettings,'Image shot setting may not be more than 250 characters',250,'Image shot setting cannot be blank',0) && customvalidation(ImgBackColor,'',250,'Image backcolor cannot be blank',1) && customvalidation(ImgFontColor,'',250,'Image backcolor cannot be blank',1) && valDropDownList(Camera,'You must select a Camera') && valDropDownList(Lens,'You must select a Lens') && chkCritique(CheckCritique,txtCritique))
//}

function ValidateInputs(ImgTitle,ddlCategory,ImgDescription,ImgShotSettings,ImgFontColor,ImgBackColor,Camera,Lens,CheckCritique,txtCritique)
{
    return(customvalidation(ImgTitle,'Image title may not be more than 50 characters',50,'Image Title cannot be blank',1) && valDropDownList(ddlCategory,'Please select a category!') && customvalidation(ImgDescription,'Image description may not be more than 1000 characters',1000,'Image Description cannot be blank',1) && customvalidation(ImgShotSettings,'Image shot setting may not be more than 250 characters',250,'Image shot setting cannot be blank',0) && customvalidation(ImgBackColor,'',250,'Image backcolor cannot be blank',1) && customvalidation(ImgFontColor,'',250,'Image backcolor cannot be blank',1) && valDropDownList(Camera,'You must select a Camera') && valDropDownList(Lens,'You must select a Lens') && chkCritique(CheckCritique,txtCritique))
}

function chkCritique(CheckCritique,txtCritique)
{

var critiqueChk=document.getElementById(CheckCritique);

if(critiqueChk.checked==true)
{
    var txtValCritique=(document.getElementById(txtCritique)).value;
    if(txtValCritique=='')
    {
        alert('Please Enter Text for Critique Request');
     return false;
   
    }
    else
    {
    return true;
    }
}
else
{
return true;
}
}

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 BlogEntry_Validation(txtTitle,txtdescription)
//{
//  return(emptyvalidation(txtTitle, 'Blog title cannot be blank!') && emptyvalidation(txtdescription, 'Blog description cannot be blank!'))
//}
//function BlogUpdate_Validation(txtTitle,txtdescription)
//{
//  return(emptyvalidation(txtTitle, 'Blog title cannot be blank!') && emptyvalidation(txtdescription, 'Blog description cannot be blank!'))
//}

function BlogEntry_Validation(txtTitle)
{
  return(emptyvalidation(txtTitle, 'Blog title cannot be blank!'))
}



function validatePhone(obj,alertbox)
{
var o = document.getElementById(obj);
var validNum =(/^[0-9]\d{10}$/);
if (validNum.test(o.value) == false)
 {
 alert(alertbox);
return false;
 }
else
  {
  return true;
  }
}

function validateMobile(obj,alertbox)
{
var o = document.getElementById(obj);
var validNum =(/^[0-9]\d{10}$/);
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 ==-1) 
{
alert(alertbox);
return false;
}
 else
 { 
 return true;
 }
} 


function validateZip(obj,alertbox)
{
var o = document.getElementById(obj);
var validNum =(/^[0-9]\d{4}$/);
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;
//        }
        
}

}

function getObject(obj)
{
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function toCount(entrance,exit,text,characters) 
{

//alert(characters);
  var entranceObj=document.getElementById(entrance);
//  alert(entranceObj);
  var exitObj=document.getElementById(exit);
  var length=characters - entranceObj.value.length;
  if(length <= 0) {
    length=0;
    text='<span class="disable"> '+text+' </span>';
    entranceObj.value=entranceObj.value.substr(0,characters);
  }
  exitObj.innerHTML = text.replace("{CHAR}",length);
}





