﻿
/*******************************************************************************
FILE:           WValidation.js

Dependencies:   jquery-1.3.2.min.js
                RegExpValidate.js
                ValidatePKDate.js
                
AUTHOR:         Waqar Attari

DATE:           September 10, 2009

DESCRIPTION:    This file contains a library of validation functions
                using RegExpValidate.js & jquery-1.3.2.min.js. 
  

    FUNCTIONS:
    WgetHdn_SelectText  - Return value by replacing "LessThan into <" & "GreaterThan into >" becuase of HTML error "A potentially dangerous Request.Form value was detected from the client"
    WgetHdn_OthersText  - Return value by replacing "LessThan into <" & "GreaterThan into >" becuase of HTML error "A potentially dangerous Request.Form value was detected from the client"
    WgetCurrentDate     - Get No Parameter, Return date in dd-MMM-yyyy(14-Aug-1947)
    WIsEmptyValue       - Get TextboxID, ComboboxID(Return true if value selected -1)
    WIsOtherSelected    - Get ComboboxID(Return true if value selected according to hidden value in aspx page with name 'Hdn_OthersText' )   
    WvalidateEmail      - Get TextboxID
    WvalidateCNIC       - Get TextboxID
    WvalidateGPA        - Get TextboxID
    WvalidateGrade      - Get TextboxID    
    WvalidateYear       - Get TextboxID        
    WvalidateDate       - Get TextboxID Return TRUE if value is dd-MMM-yyyy(14-Aug-1947) format.
    WvalidateIsPastDate - Get TextboxID Return TRUE if value is dd-MMM-yyyy(14-Aug-1947) format & less then current date.
    WvalidateIsFutureDate - Get TextboxID Return TRUE if value is dd-MMM-yyyy(14-Aug-1947) format & greater then current date.
    WvalidateAlpha      - Get TextboxID (Alphabets Capital and Small allowed) 
    WvalidateInteger    - Get TextboxID
    WvalidateFromToDates            -   Get FromTextboxID & ToTextboxID Return FALSE if value is Invalid.
    WvalidateFromToDatesBYValues    -   Get FromDate & ToDate (dd-MMM-yyyy(14-Aug-1947))   Return FALSE if value is Invalid.
*******************************************************************************/

function WIsEmptyValue(id){

    var str = $('#' + id).get(0).value;
    var tagName = $('#' + id).get(0).tagName;

    if ( (validateNotEmpty(str) == false && tagName == "INPUT") || (str == '-1' && tagName == "SELECT")) {
        return true
    }else {
        return false;
    };
}//function IsEmptyValue(id){

function WvalidateEmail(id){
    return validateEmail($('#' + id).get(0).value);
}//function WvalidateEmail(id){


function WvalidateDate(id){
    return validatePKDate($('#' + id).get(0).value);
}//function WvalidateDate(id){


function WvalidateAlpha(id){
    return validateAlpha($('#' + id).get(0).value);
}//function WvalidateAlpha(id){



function WvalidateCNIC(id){
    return validateCNIC($('#' + id).get(0).value);
}//function WvalidateCNIC(id){

function WvalidateGPA(id){
    return validateGPA($('#' + id).get(0).value);
}//function WvalidateGPA(id){

function WvalidateGrade(id){
    return validateGrade($('#' + id).get(0).value);
}//function WvalidateGPA(id){

function WvalidateYear(id){
    return validateYear($('#' + id).get(0).value);
}//function WvalidateYear(id){




function WvalidateInteger(id){
    return validateInteger($('#' + id).get(0).value);
}//function WvalidateInteger(id){



function WIsOtherSelected(id){
  
   var str = GetComboSelectedText(id)
   var tagName = $('#' + id).get(0).tagName;


    if   (str.toLowerCase() == WgetHdn_OthersText().toLowerCase() && tagName == "SELECT") {
        return true
    }else {
        return false;
    };
    
}//function WIsOtherSelected(id){


function WvalidateIsPastDate(id){
  
    strdt1 = $('#' + id).get(0).value;
    CrntDate = WgetCurrentDate();
    
    return WvalidateFromToDatesBYValues(strdt1, CrntDate)
                      
}//function WvalidateIsPastDate(id){

function WvalidateIsFutureDate(id){
  
    strdt1 = $('#' + id).get(0).value;
    CrntDate = WgetCurrentDate();
    
    return WvalidateFromToDatesBYValues(CrntDate, strdt1)
                      
}//function WvalidateIsPastDate(id){


function WgetHdn_SelectText(){

    SelectTag = $('#Hdn_SelectText').get(0).value;
    
    SelectTag = SelectTag.replace('LessThan', '&lt;') 
    SelectTag = SelectTag.replace('GreaterThan', '&gt;')

    return SelectTag;
}//function WgetHdn_SelectText(){



function WgetHdn_OthersText(){

    OthersTag = $('#Hdn_OthersText').get(0).value;
    
    OthersTag = OthersTag.replace('LessThan', '<') 
    OthersTag = OthersTag.replace('GreaterThan', '>')

    return OthersTag;
}//function WgetHdn_OthersText(){



function WgetCurrentDate(){       
    var CrntDate = new Date( );
    
    // this is becuase some tiem MMM = minute and sometime MMM=month(jan)
    if ( !isNaN(parseInt(CrntDate.format("MMM"))) == true ) {
	    return  CrntDate.format("dd-mmm-yyyy");   
    }else{  
        return  CrntDate.format("dd-MMM-yyyy");       
    };
    
    
}//function WgetCurrentDate(){



function WvalidateFromToDates(FrmDtID,ToDtID){

    strdt1 = $('#' + FrmDtID).get(0).value;
    strdt2 = $('#' + ToDtID).get(0).value;
  		
	return  WvalidateFromToDatesBYValues(strdt1,strdt2);
}//function WvalidateFromToDates(FrmDtID,ToDtID){




function WvalidateFromToDatesBYValues(FrmDt,ToDt){

    strdt1 = FrmDt;
    strdt2 = ToDt;

    if ( validatePKDate(strdt1) == false || validatePKDate(strdt2) == false ){
        return false;
    }//if ( validatePKDate(strdt1) == false || validatePKDate(strdt2) == false ){
    
	if( trimAll(strdt1).length != 0 &&  trimAll(strdt2).length != 0){

			var dtFrom = new Date(ParseDate(strdt1));
			var dtTo = new Date(ParseDate(strdt2));
		
			if ( dtFrom < dtTo ) {
				return true;
			}//if ( dtFrom > dtTo ) {
	}//if( Trim(strdt1).length != 0 &&  Trim(strdt2).length != 0){
		
	return false;
}//function WvalidateFromToDates(FrmDtID,ToDtID){



function ParseDate(dtDate){
	var strDate = new String(dtDate);
	var result = '';
	
	for ( var i=0; i<strDate.length; i++){
		if ( strDate.charAt(i) == '-'){
			result = result + ' ';
		}else{
			result = result + strDate.charAt(i); 
		}//if ( strDate.charAt(i) == '-'){
	}//for ( var i=0; i<strDate.length; i++){
	
	return result;
}//function ParseDate(dtDate){






