   /**
	* Check Duplicacy
	*/		

function isDuplicate(str){
	var len = str.length;
	var i =0;
	var duplicate = true;
	var fchar = str.charAt(0);
	for(i=0; i < len; i++){
		if(fchar != str.charAt(i)){
			duplicate = false;
			break;
		}
	}
	return duplicate;
}



   /**
	* Check Future Date
	*/		
	
	function isFutureDate(dd,mm,yy){
		var time = new Date();   
		var d = time.getDate();
		var m = time.getMonth()+1;
		var y = time.getYear();   
		var future = false;
	
		if(yy == y){
			if(mm == m){
				if(dd > d){
					future = true;
				}
			}else if(mm > m){
				future = true;
			}
		}else if(yy > y){
			future = true;
		}
		
		return future;
	}
	
   /**
	* Check Blank fields
	*/			
	function isBlankField(str){
                var mVal = str;                
		var isBlank = true;
                for(i=0; i < mVal.length; i++){
                    if(mVal.charAt(i) != ' '){
                       isBlank = false;
                       break;
                    }
                }
		return isBlank;
	}

	///////////////////////////////////////////////////
	// The function validates the date given to it 
	//	returns False if The date is Not Valid    
	function isValidDate(dt, mn, yr){
			//Number validation aded by shalin
			if(!isValidNumber(dt) || !isValidNumber(mn) || !isValidNumber(yr)){
				return false;
			}
			// If user has not entered date, it's invalid
			if ( dt == 0 || mn == 0 || yr == "0000" ){
				return false;
			}
			// else ..
			var yr_1 = yr/4;
			var d_max = 28;
			m31= new Array (1, 3, 5, 7, 8, 10, 12);
			var flag_m=0;
			var i=0;
			
			// If the person is born in February check 
			if ( mn == 2)
			{
				if ( yr_1 == Math.round(yr_1))    d_max=29;
								
			}
			else
			{
				// Check to see if the month is of 31 days 
				for ( i =0; i<7; i++) {
				if (mn == m31[i]) flag_m = 1;
				}
				if ( flag_m ) {d_max=31 } else {d_max=30}
			}
			if ( dt > d_max ) return false;	
			return true;
			
	}
//////////////
        function isValidDecimalNumber(numStr){
            for(var i=0;i<numStr.length;i++){
        	 var flag=0;
                	if(!isValidDigit(parseInt(numStr.charAt(i))) && numStr.charAt(i)!='.'){
                        	flag=1;
                            break;
                        }
            }
            if(flag == 1)
                return (false);		
            else
                return (true);		
        }
	
//////////////
        function isValidNumber(numStr){
            for(var i=0;i<numStr.length;i++){
        	 var flag=0;
                	if(!isValidDigit(parseInt(numStr.charAt(i)))){
                        	flag=1;
                                break;
                        }
            }
            if(flag == 1)
                return (false);		
            else
                return (true);		
        }
//////////////
        function isValidDigit(digit){
            switch(digit){
                case 0 : return (true);
                case 1 : return (true);
                case 2 : return (true);
                case 3 : return (true);
                case 4 : return (true);
                case 5 : return (true);
                case 6 : return (true);
                case 7 : return (true);
                case 8 : return (true);
                case 9 : return (true);
                default : return (false);								
            }
        }
		
    /*
     *
     *
     ************************************/
     function checkWebAddress(webUrl){
        var firstDot = webUrl.indexOf(".");
        var lastDot = webUrl.lastIndexOf(".");
        
        if(firstDot == -1 || firstDot == 0 || lastDot == webUrl.length-1){
            return false;
        }

		var prevdot = firstDot;
		for (var i=(firstDot+1);i < (webUrl.length-1);i++) {
			var curchar =webUrl.charAt(i);
			if ( (curchar == '.') && (i == prevdot+1) ) {
				return false;
			}		
			if ( curchar == '.' ) {
				prevdot = i;
			}
		}
        return true;
     }
	/////////////////////////////////////////////////
	// 	returns False if the eMail is not Valid
		// The rule of checking of eMail is as follows
		// 1. No space should be present
		// 2. Exactly one @ shold be present
		// 3. At least one dot should be present
		// 4. dot can not be preseant at the beg or end
		
	function isValidEmailAddress (inEmail) {
	
		var okEmail;
		var locAt = inEmail.indexOf("@"); 
		var emailsize=inEmail.length;
		var locPeriod = inEmail.lastIndexOf(".");
		var firstdot=inEmail.indexOf(".");
	
		if ( ( firstdot == -1) || (firstdot == locAt-1) || (firstdot == locAt+1) || (firstdot == 0)) {
	 		return false;
		}
 	
	  	var prevdot = firstdot;
		for (var i=(firstdot+1);i < (inEmail.length -1);i++) {
			var curchar =inEmail.charAt(i);
			if ( (curchar == ".") && (i == prevdot+1) ) {
				return false;
			}
		
			if ( curchar == "." ) {
				prevdot = i;
			}
		}
	
		okEmail = ((locAt != -1) && (locAt != 0) && (locAt != (inEmail.length - 1)) &&
    	         (inEmail.indexOf("@", (locAt + 1)) == -1) &&
        	     ( (locPeriod == (inEmail.length - 3)) || 
				 (locPeriod == (inEmail.length - 4))) && 
	             (locPeriod > locAt) 
		); 

		return okEmail; 				
	}


        //////////////////////////////////////
        // Verify that the given string makes up a http URL
        // if 'http://' is not given it will add this to make it a valid url

        function httpURLify(s){
            //check the string to see if it srarts with http:// if not ad it
            // if user wants to edit arb URL but has not given the url, Warn.
            if ( s == "" ){
                alert("Please enter a valid web address(url)");
	        return false;
            }
            else {
                // it should start with http:// else ad this at the begining.
                if ( s.indexOf("http://") != 0 ) s = "http://" + s;

	        // now check if url is of the form http://a.b.somthing.tld if y add a '/'
                if( s.substring(7).indexOf("/") == -1 ) s = s + "/"; 
                // return this string now
                return s;
            }	
        }



        //////////////////////////////////////////
        // Make the input (text) field values of a form
        // SQL compliant.
        // i.e., Replace any single (') with ('' ) char
        ///////////////////////////////////////////////
        function sqlEscape(frm){
                var ipts = frm.elements.tags('INPUT');
                for (i=0; i < ipts.length; i++){
                        var vlu = ipts[i].value;
                        // It may be that string alreay has double of these
                        // TODO: try to find elagent solution later
                        vlu = vlu.replace("''", "'");
                        vlu = vlu.replace("''", "'");
                        vlu = vlu.replace("''", "'");
                        if ( vlu.indexOf("'") != -1){
                                frm.elements.tags('INPUT')[i].value = vlu.replace("'", "''");
                        }
                }
        }

        function getCountryCode(index){
            //Based on Prontocarpet country List
            codes = new Array("000","355","213","54","61","43","32","55","359","1","56","86","57","506","385","42","45","593","20","358","33","49","30","852","36","91","62","353","972","39","81","962","254","82","961","60","52","00","212","31","64","47","92","51","63","48","351","00","40","7","966","65","27","34","46","41","886","66","90","1","7","971","44","58","381");
            return codes[index];
        }

    //Auto select current Date
    function setCurrentDate(obj){
        var date = new Date();
        var day = date.getDate();
        var month = date.getMonth();
        var year = date.getFullYear();

        day = day -1;
        year = year - 2004;

        eval("document.dispatchForm.dDay.options["+day+"].selected = true");
        eval("document.dispatchForm.dMonth.options["+month+"].selected = true");
        eval("document.dispatchForm.dYear.options["+year+"].selected = true");
    }

    //Get current Date String
    function setCurrentDate(obj){
        var date = new Date();
        var day = date.getDate();
        var month = date.getMonth();
        var year = date.getFullYear();

	var dateStr = date+"/"+month+"/"+year;
	return dateStr;
    }

