
/**
FUNTION SELECTALL CHECK BOXES
**/
function SelectAll(frm) {
 //alert(frm.selectall.checked);
   if(frm.selectall.checked == true) {
   
     for(i=0;i<frm.elements.length;i++) {
       if((frm.elements[i].type == "checkbox") && (frm.elements[i].name != "selectall")) {
         frm.elements[i].checked = true;
       } // if statement
     } // for loop
   }
   else if(frm.selectall.checked == false) {
    
      for(i=0;i<frm.elements.length;i++) {
         if((frm.elements[i].type == "checkbox") && (frm.elements[i].name != "selectall")) {
           frm.elements[i].checked = false;
         } // if statement
      } // for loop
   } // if - else - if condition

} // closing the function SelectAll()

/**
 FUNCTION SELECTVALIDATION(element,message)  **/
function SelectValidation(Element,Message)
{
    if(Element.value == "0")
    {
        alert("Please Select "+Message+"");
        Element.focus();
        return 0;
    }
}

function SelectValidationFree(Element,Message)
{
    if(Element.value.innerText == "Free")
    {
        alert("Member type should not be Free");
        Element.focus();
        return 0;
    }
}
/**
 FUNCTION EMAILVALIDATION(element)  **/
function EmailValidation(Element)
{
    Flag  = 1;
    count = 0;
    var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@.-";
    if(Element.value.length > 0)
    {
        for (var i=0;i<Element.value.length;i++)
        {
            temp=Element.value.substring(i,i+1);
            if (alp.indexOf(temp)==-1)
            {
                Flag = 0;
            }
        } // closing the for loop
    }
    else
    {
        Flag = 0;
    }

    for(var i=0;i<=Element.value.length;i++)
    {
        if(Element.value.charAt(0)=='@')
        {
            Flag = 0;
            break;
        }
        if(Element.value.charAt(Element.value.length-1)=='@')
        {
            Flag = 0;
            break;
        }
        if(Element.value.charAt(i)=='@')
        {
            count=count+1;
            if(count>1)
            {
                Flag = 0;
                break;
            }
            if((Element.value.charAt(i-1)=='.') || (Element.value.charAt(i+1)=='.'))
            {
                Flag = 0;
                break;
            }
        }
        if(Element.value.indexOf('@')==-1)
        {
            Flag = 0;    
            break;
        }
        if(Element.value.charAt(0)=='.')
        {
            Flag = 0;
            break;
        }
        if(Element.value.indexOf('.')==-1)
        {
            Flag = 0;    
            break;
        }
    } //closing the for loop
    if(Element.value.charAt(Element.value.length-1) == '.')
        Flag = 0;
    if(Flag != 1)
    {
        alert("Please Enter Valid EMail Address");
        Element.focus();
        return 0;
    }
}


function EmailValidationConfirm(Element)
{
    Flag  = 1;
    count = 0;
    var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@.-";
    if(Element.value.length > 0)
    {
        for (var i=0;i<Element.value.length;i++)
        {
            temp=Element.value.substring(i,i+1);
            if (alp.indexOf(temp)==-1)
            {
                Flag = 0;
            }
        } // closing the for loop
    }
    else
    {
        Flag = 0;
    }

    for(var i=0;i<=Element.value.length;i++)
    {
        if(Element.value.charAt(0)=='@')
        {
            Flag = 0;
            break;
        }
        if(Element.value.charAt(Element.value.length-1)=='@')
        {
            Flag = 0;
            break;
        }
        if(Element.value.charAt(i)=='@')
        {
            count=count+1;
            if(count>1)
            {
                Flag = 0;
                break;
            }
            if((Element.value.charAt(i-1)=='.') || (Element.value.charAt(i+1)=='.'))
            {
                Flag = 0;
                break;
            }
        }
        if(Element.value.indexOf('@')==-1)
        {
            Flag = 0;    
            break;
        }
        if(Element.value.charAt(0)=='.')
        {
            Flag = 0;
            break;
        }
        if(Element.value.indexOf('.')==-1)
        {
            Flag = 0;    
            break;
        }
    } //closing the for loop
    if(Element.value.charAt(Element.value.length-1) == '.')
        Flag = 0;
    if(Flag != 1)
    {
        alert("Please Enter Confirm EMail Address");
        Element.focus();
        return 0;
    }
}

/**
 FUNCTION GENVALIDATION(element,message1,size,spl)  **/
function GenValidation(Element,MessageLen0,MessageLen4,spl)			
{
    if(MessageLen0.length != 0)
    {
        if(isBlank(Element.value) || Element.value.length == 0)
        {
            alert("Please Enter the "+ MessageLen0);
            Element.focus();
            return 0;
        }
    }
    if(MessageLen4.length!=0) 
    {
	    if(Element.value.length >= MessageLen4) 
	    {   
//            if(validateSize(Element,MessageLen0,MessageLen4,'') == 0)
//                return 0;
	        alert( MessageLen0 + " Should be less than " + MessageLen4 + " characters" );
	        Element.focus();
	        return 0;
	    }
    }
    if(spl.length != 0)
    {
        if(spl == "name")
        {
            if(validateName(Element,MessageLen0) == 0)
            return 0;
        }
        else if(spl == "phone")
        {
            if(validatePhone(Element,MessageLen0) == 0)
            return 0;
        }        
        else if(spl == "pwd")
        {
            if(CheckPass(Element) == 0)
            return 0;
        }
        else if(spl == "mail")
        {
            if(EmailValidation(Element) == 0)
            return 0;
        }
        else if(spl == "date")
        {
            if(validateDate(Element,MessageLen0) == 0)
            return 0;
        }
        else if(spl == "num")
        {
            if(NumbersOnly(Element,MessageLen0) == 0)
            return 0;
        }
        else if(spl == "float")
        {
            if(Floating(Element,MessageLen0) == 0)
            return 0;
        }     
    }
} // closing the function GenValidation()

function validateSize(Element,Message,size,spl)
{
    if(Element.value.length >= size) 
    {   
	    //alert( Message + " Should be less than " + size + " characters" );
	    alert( Message + " Should be less than " + size + " digits" );
	    Element.focus();
	    return 0;
    }
    if(spl.length != 0)
    {
        if(spl == "num")
        {
            if(NumbersOnly(Element,Message) == 0)
            return 0;
        }
        else if(spl == "float")
        {
            if(Floating(Element,MessageLen0) == 0)
            return 0;
        }           
    }
}
function validateName(Val,txt)
{
    var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. ";
    for (var i=0;i<Val.value.length;i++)
    {
        temp=Val.value.substring(i,i+1);
        if (alp.indexOf(temp)==-1)
        {
            alert("No special characters in " + txt + " \nValid entries are [a-z][A-Z][0-9][space][.]");
            Val.focus();
            return 0;
        }
    } // closing the for loop
} // closing the function validateName()

function validateDate(Val,txt)
{
    var checkStr = Val.value;
    if (checkStr.match(/\d{1,2}\/\d{1,2}\/\d{2,4}/))
    {
        var dayfield=Val.value.split("/")[0]
        var monthfield=Val.value.split("/")[1]
        var yearfield=Val.value.split("/")[2]
        var dayobj = new Date(yearfield, monthfield-1, dayfield)
        if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
        {
            alert('Invalid Day/Month/Year range detected. Please Correct.')
            return 0;
        }
        else
            return 1;
    }
    else
    {
        alert("The Date Of Birth format should be: dd/mm/yyyy");
        //document.EntryForm.Dob.focus();
        return 0;
    }
} // closing the function validateDate()

function validatePhone(Element,txt)
{
    if(Element.value.length > 15) 
    {   
	    alert( txt + " Should be less than 15 digits" );
	    Element.focus();
	    return 0;
    }
    else
    {
        var alp = "0123456789-+ ";
        for (var i=0;i<Element.value.length;i++)
        {
            temp=Element.value.substring(i,i+1);
            if (alp.indexOf(temp)==-1)
            {
                alert("No special characters in " + txt + "\nValid entries are [0-9][space, -, + ]");
                Element.focus();
                return 0;
            }
        } // closing the for loop
    }
} // closing the function validatePhone()

/**
 FUNCTION NUMBERSONLY(element)  **/
function NumbersOnly(Val,txt)
{
    var alp = "0123456789.";
    for (var i=0;i<Val.value.length;i++)
    {
        temp=Val.value.substring(i,i+1);
        if (alp.indexOf(temp)==-1)
        {
            alert("Valid entries are [0-9] in "+txt+"");
            Val.focus();
            return 0;
        }
    } // closing the for loop   
} // closing the function NumbersOnly()

function Floating(Val,txt)
{
    if(isNaN(Val.value))
    {
        alert("Please enter only Numbers in "+ txt);
        Val.focus();
        return 0;
    }    
} // closing the function Floating()

//Function Password Verification for Alphanumeric Values
function CheckPass(password)
{
    if(password.value.length < 6) 
    {   
        alert( "Password Should be more than 5 characters" );
        password.focus();
        return 0;
    }
    else
    {
        var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.";
        for (var i=0;i<password.value.length;i++)
        {
            temp=password.value.substring(i,i+1);
            if (alp.indexOf(temp)==-1)
            {
                alert("No special characters in Password \nValid entries are [a-z][A-Z][0-9][.]");
                password.focus();
                return 0;
            }
        }
	}
}

/**
 FUNCTION PASSVALIDATION(element1,element2)  **/
function PassValidation(Element1,Element2)
{
    if(Element1.value != Element2.value)
    {
        alert("Confirm Password doesn't match");
        Element2.focus();
        return 0;
    }
} // closing the function PassValidation()

function PassValidation1(Element1,Element2)
{
    if(Element1.value != Element2.value)
    {
        alert("Confirm E-Mail Id doesn't match");
        Element2.focus();
        return 0;
    }
}
/**
 FUNCTION FOR CHECKING THE FIELD CONTAINS BLANK VALUES ISBLANK(Element.value)  **/
//To check if trim(value) is blank
function isBlank(txt)
{
    if( txt.length == getCountOf(' ', txt) )
    {
        return true;
    }
    else
    {
        return false;
    }
}

//This can be used for any character validation.
//For example in a valid date the count of - or / should not be more than 2
//Likewise in a valid numer there should be only one .
function getCountOf(vChr, txt)
{
    var i = 0;
    var iCount = 0;
    for( i=0; i < txt.length; i++ )
    {
        if( txt.charAt(i) == vChr )
        {
            iCount++;
        }
    }
    return iCount;
}

function sizeCompage(Element1,Element2,Msg1,Msg2)
{
    var e1=parseInt(Element1.value);
    var e2=parseInt(Element2.value);
    if(e1 > e2) 
    {
	    alert( Msg1 + " Should be less than " + Msg2 );
	    Element1.focus();
	    return 0;
    }
}
/**
 Function for validation of Locality drop dwon list in sellerPost.aspx **/
function SelectValidationLocality(Element)
{
    if(Element.value=="0")
    {
        var ans=confirm("Please Select Locality if present to obtain better search results");
        if(ans=="0")
            return 1;
        else
        {
            Element.focus();
            return 0;
        }
    }
}//Closing of the function drop down list of locality

//*****  STRING TRIM FUNCTION**********//////
function trim(str)
{
var i=0,p = str.length-1;
while(str.charAt(i)==' ')i++;
while(str.charAt(p)==' ') p--;
if(i>p) return '';
return str.substring(i,p+1);
}
//*****  END OF STRING TRIM FUNCTION******************//////

/**
 FUNCTION onkeyup="javascript:changeToUpper(this.form,this)  **/
function changeToUpper(objFrm,objTxt)
{	
	var objFrmName=objFrm.name;
	var objTxtName=objTxt.name;
	document.forms(objFrmName).elements(objTxtName).value=document.forms(objFrmName).elements(objTxtName).value.toUpperCase(); 
}
function validateCharacterOnly(Val,txt)
{
    var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
    for (var i=0;i<Val.value.length;i++)
    {
        temp=Val.value.substring(i,i+1);
        if (alp.indexOf(temp)==-1)
        {
            alert("No special characters in " + txt + " \nValid entries are [a-z][A-Z][space]");
            Val.focus();
            return 0;
        }
    } // closing the for loop
} // closing the function AgeValidation()
function AgeValidation(Val,txt)
{

    if(isNaN(Val.value))
    {
        alert("Please enter only Numbers in "+ txt);
        Val.focus();
        return 0;
    }
    
} // closing the function Floating()
function AgeSize(Element,Message,size,spl)
{
    if(Element.value > size) 
    {   
	    alert( Message + " Should be less than " + size);
	    Element.focus();
	    return 0;
    }
    if(spl.length != 0)
    {
        if(spl == "num")
        {
            if(NumbersOnly(Element,Message) == 0)
            return 0;
        }
        else if(spl == "float")
        {
            if(Floating(Element,MessageLen0) == 0)
            return 0;
        }           
    }
}

