	//For Selecting/ deselecting check boxed
	function selectDeselect(field, isCheck) {
		var boxes = document.getElementsByName(field);
		var boxes_checked = anyChecked();

		if(isCheck){
			if(document.getElementsByName(isCheck)[0].checked) setChecks(true);
			else setChecks(false);
		}else{
			if(!boxes_checked) setChecks(true);
			else setChecks(false);
		}

		function setChecks( setting ) {
			for( var i=0; i < boxes.length; i++ ) {
				boxes[ i ].checked = setting;
			}
		}

		function anyChecked() {
			for( var i=0; i < boxes.length; i++ ) {
				if( boxes[i].checked == true) {
					return (true);
				}
			}
			return (false);
		}
	}

	//To check wheather user have selected box or not
	function anyChecked(field) {
		 var boxes = document.getElementsByName(field);
		for( var i=0; i < boxes.length; i++ ) {
			if( boxes[i].checked == true) {
				return (true);
			}
		}
		return (false);
	}


	//For checking Null values
	function isNull(aStr)
	{
		var index;
		for (index=0; index < aStr.length; index++)
			if (aStr.charAt(index) != ' ')
				return false;
		return true;
	}

	////for checking numeric values
	function IsNumeric(sText)
    {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;


   for (j = 0; j < sText.length && IsNumber == true; j++)
      {
      Char = sText.charAt(j);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

   }


  function cleanString(str)
  {
     str=encodeURIComponent(str);
	 return str;
  }

   function showString(str)
  {
     str=decodeURIComponent(str);
	 return str;
  }


  function inArray (arr,value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
    var s, j=0;
    for (s=0; s < arr.length; s++) {
        // Matches identical (===), not just similar (==).
		 if (arr[s] == value)
			 {
                j=1;
             }
    }
    return j;
};


function trim(str)
{
    s = str.replace(/^(\s)*/, '');
    s = s.replace(/(\s)*$/, '');
    return s;
}

	//For checking invalid E-Mail address

	function isEmail(aStr){
		var reEmail=/^[0-9a-zA-Z_\.-]+\@[0-9a-zA-Z_\.-]+\.[0-9a-zA-Z_\.-]+$/;
		if(!reEmail.test(aStr))
		{
			return false;
		}
		return true;
	}

   //For checking field exist in form or not
	function testIsValidObject(objToTest) {
		if (objToTest == null || objToTest == undefined) {
		return false;
		}
		return true;
		}


	//Removing the newline character
	function countChars(str){
		var reg = new RegExp("[\f\n\r\v]*","g");
		str = str.replace(reg,"");
		return str.length;
	}

    ///Replace ,br> with \r\n
	function br2nl(text)
	{
		text=text.replace(/<br>/gi, '\r\n');
		return text;
	}


 ///Valid date
	function checkDate(dt){
	var reg = new RegExp("[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}$");
	if(reg.test(dt))
	{
		var datepart = dt.split("/");
		for(i=0;i<datepart.length;i++)
			datepart[i] = parseInt(parseFloat(datepart[i]));
		if(datepart[1] > 31 || datepart[0] > 12)
			return false;
		else if((datepart[0] == 4 || datepart[0] == 6 || datepart[0] == 9 || datepart[0] == 11) && datepart[1] == 31)
			return false;
		else if(datepart[0] == 2)
		{
			if(datepart[1] > 29)
				return false;
			if(!LeapYear(datepart[2]) && datepart[1] == 29)
				return false;
		}
		return true;
	}
	return false;
}

function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	}
	else {
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}


///Time Validation/////
function checktime(thetime) {
var a,b,c,f,err=0;
a=thetime;
if (a.length != 5) err=1;
b = a.substring(0, 2);
c = a.substring(2, 3);
f = a.substring(3, 5);
if (/\D/g.test(b)) err=1; //not a number
if (/\D/g.test(f)) err=1;
if (b<0 || b>23) err=1;
if (f<0 || f>59) err=1;
if (c != ':') err=1;
if (err==1) {
return 0;
}
else
{
	return 1;
}
}
/////Format Currency
function formatCurrency(num,prefix) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + prefix + num + '.' + cents);
}

function todayDate(field)
{
d = new Date();
field.value = (d.getMonth()+1) + '/' + d.getDate() + '/' + d.getFullYear();
// Format date
formatDate(field);
}

// FORMATS THE DATE FIELDS
function formatDate(objname)
{
strDate = objname.value;

if (strDate != '')
{
d = new Date();
var intElementNr;
var strDateArray;
var strSeparatorArray = new Array("-"," ","/",".");

for (intElementNr = 0; intElementNr < strSeparatorArray.length;
intElementNr++)
{
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1)
{
strDateArray =
strDate.split(strSeparatorArray[intElementNr]);
// Full date
if (strDateArray.length == 3)
{
strMonth = strDateArray[0];
strDay = strDateArray[1];
strYear = strDateArray[2];
}
// Missing year
if (strDateArray.length == 2)
{
strMonth = strDateArray[0];
strDay = strDateArray[1];
strYear = d.getFullYear();
}
}
}


if (parseInt(strDay,10) > 31 || parseInt(strMonth,10) > 12)
{
alert("Invalid Date");
objname.focus();
objname.value = '';
}
else
{
if(strDay.length == 1)
{
strDay = '0' + strDay;
}
if(strMonth.length == 1)
{
strMonth = '0' + strMonth;
}
if(strYear.length == 2)
{
strYear = '20' + strYear;
}

objname.value = strMonth + '/' + strDay + '/' + strYear;
}
}
}


/**
 * START OF CODE
 * Magic time parsing, based on Simon Willison's Magic date parser
 * @see http://simon.incutio.com/archive/2003/10/06/betterDateInput
 * @author Stoyan Stefanov &lt;stoyan@phpied.com&gt;
 */


/**
 * This is the place to customize the result format,
 * once the date is figured out
 *
 * @param Date d A date object
 * @return string A time string in the preferred format
 */
function getReadable(d) {

    return padAZero(d.getHours())
           + ':'
           + padAZero(d.getMinutes());
}
/**
 * Helper function to pad a leading zero to an integer
 * if the integer consists of one number only.
 * This function s not related to the algo, it's for
 * getReadable()'s purposes only.
 *
 * @param int s An integer value
 * @return string The input padded with a zero if it's one number int
 * @see getReadable()
 */
function padAZero(s) {

    s = s.toString();
    if (s.length == 1) {
        return '0' + s;
    } else {
        return s;
    }
}


/**
 * Array of objects, each has:
 * <ul><li>'re' - a regular expression</li>
 * <li>'handler' - a function for creating a date from something
 *     that matches the regular expression</li>
 * <li>'example' - an array of examples that show matching examples</li>
 * Handlers may throw errors if string is unparseable.
 * Examples are used for automated testing, so they should be updated
 *   once a regexp is added/modified.

 * Noon and midnight cases added by Matt Winchester
 * 12am/12pm bug fixed by Matt Winchester
 */
var timeParsePatterns = [
    // Now
    {   re: /^now/i,
        example: new Array('now'),
        handler: function() {

            return new Date();
        }
    },
    // Noon
    {   re: /^noon/i,
        example: new Array('noon'),
        handler: function() {
            var d = new Date();
			d.setHours(12);
			d.setMinutes(0);
			d.setSeconds(0);
			return d;
        }
    },
    // Midnight
    {   re: /^midnight/i,
        example: new Array('midnight'),
        handler: function() {

            var d = new Date();
			d.setHours(23);
			d.setMinutes(59);
			d.setSeconds(59);
			return d;
        }
    },
    // p.m.
    {   re: /(\d{1,2}):(\d{1,2}):(\d{1,2})(?:p| p)/,
        example: new Array('9:55:00 pm','12:55:00 p.m.','9:55:00 p','11:5:10pm','9:5:1p'),
        handler: function(bits) {

            var d = new Date();
            var h = parseInt(bits[1], 10);
            if (h < 12) {h += 12;}
            d.setHours(h);
            d.setMinutes(parseInt(bits[2], 10));
            d.setSeconds(parseInt(bits[3], 10));
            return d;
        }
    },
    // p.m., no seconds
    {   re: /(\d{1,2}):(\d{1,2})(?:p| p)/,
        example: new Array('9:55 pm','12:55 p.m.','9:55 p','11:5pm','9:5p'),
        handler: function(bits) {

            var d = new Date();
            var h = parseInt(bits[1], 10);
            if (h < 12) {h += 12;}
            d.setHours(h);
            d.setMinutes(parseInt(bits[2], 10));
            d.setSeconds(0);
            return d;
        }
    },
    // p.m., hour only
    {   re: /(\d{1,2})(?:p| p)/,
        example: new Array('9 pm','12 p.m.','9 p','11pm','9p'),
        handler: function(bits) {

            var d = new Date();
            var h = parseInt(bits[1], 10);
            if (h < 12) {h += 12;}
            d.setHours(h);
            d.setMinutes(0);
            d.setSeconds(0);
            return d;
        }
    },
    // hh:mm:ss
    {   re: /(\d{1,2}):(\d{1,2}):(\d{1,2})(\D*)/,
        example: new Array('9:55:00','19:55:00','19:5:10','9:5:1','9:55:00 a.m.','11:55:00a'),
        handler: function(bits) {

            var d = new Date();
			if(parseInt(bits[1], 10) == 12 && bits[3] && String(bits[3]).indexOf('a') != -1){
				 d.setHours(0);
			}
			else{
				 d.setHours(parseInt(bits[1], 10));
			}
            d.setMinutes(parseInt(bits[2], 10));
            d.setSeconds(parseInt(bits[3], 10));
            return d;
        }
    },
    // hh:mm
    {   re: /(\d{1,2}):(\d{1,2})(\D*)/,
        example: new Array('9:55','19:55','19:5','9:55 a.m.','11:55a'),
        handler: function(bits) {

            var d = new Date();
			if(parseInt(bits[1], 10) == 12 && bits[3] && String(bits[3]).indexOf('a') != -1){
				 d.setHours(0);
			}
			else{
				 d.setHours(parseInt(bits[1], 10));
			}
            d.setMinutes(parseInt(bits[2], 10));
            d.setSeconds(0);
            return d;
        }
    },
    // hhmmss
    {   re: /(\d{1,6})(\D*)/,
        example: new Array('9','9a','9am','19','1950','195510','0955'),
        handler: function(bits) {

            var d = new Date();
            var h = bits[1].substring(0,2);
            var m = parseInt(bits[1].substring(2,4), 10);
            var s = parseInt(bits[1].substring(4,6), 10);
            if (isNaN(m)) {m = 0;}
            if (isNaN(s)) {s = 0;}
			if(h == 12 && bits[2] && String(bits[2]).indexOf('a') != -1){
				 d.setHours(0);
			}
			else{
				  d.setHours(parseInt(h, 10));
			}
			d.setMinutes(parseInt(m, 10));
            d.setSeconds(parseInt(s, 10));
            return d;
        }
    },


];

/**
 * Method that loops through all regexp's examples and lists them.
 * Optionally, the method can also run tests with the examples.
 *
 * @param boolean run_test TRUE is tests should be run on the examples, FALSE if only to show examples
 * @return object An XML 'ul' node
 */
function getExamples(run_tests) {

    var xml = document.createElement('ul');
    xml.setAttribute('id', 'time-parser-examples');
    for (var i = 0; i < timeParsePatterns.length; i++) {
        try {
            var example = timeParsePatterns[i].example;
            for (var j = 0; j < example.length; j++) {
                var list_item = document.createElement('li');
                if (!run_tests) {
                    var list_item_value = document.createTextNode(example[j]);
                } else {
                    var parsed = parseTimeString(example[j]);
                    var result = getReadable(parsed) + ' -> ' + parsed.toTimeString();
                    var list_item_value = document.createTextNode(example[j] + ' -> ' + result)
                }
                list_item.appendChild(list_item_value);
                xml.appendChild(list_item);
            }
        } catch(e){}
    }
    return xml;
}

/**
 * Parses a string to figure out the time it represents
 *
 * @param string s String to parse
 * @return Date a valid Date object
 * @throws Error

 * Case insensitivity added by Matt Winchester
 */
function parseTimeString(s) {

    s = String(s).toLowerCase();
	for (var i = 0; i < timeParsePatterns.length; i++) {
        var re = timeParsePatterns[i].re;
        var handler = timeParsePatterns[i].handler;
        var bits = re.exec(s);
        if (bits) {
            return handler(bits);
        }
    }
    throw new Error("Invalid time string");
}

function formatTime(input) {

    var messagespan = input.id + '-messages';
    try {
        var d = parseTimeString(input.value);
        input.value = getReadable(d);
        input.className = '';
        try {
            // Human readable time
            el = document.getElementById(messagespan);
            el.firstChild.nodeValue = d.toTimeString();
            el.className = 'normal';
        }
        catch (e) {
            // the message div is not in the document
        }
    }
    catch (e) {
        input.className = 'error';
        try {
            el = document.getElementById(messagespan);
            var message = e.message;
            // Fix for IE6 bug
            if (message.indexOf('is null or not an object') > -1) {
                message = 'Invalid time string';
            }
            el.firstChild.nodeValue = message;
            el.className = 'error';
        } catch (e){} // no message div
    }
}
/** END OF CODE
 * Magic time parsing, based on Simon Willison's Magic date parser
 * @see http://simon.incutio.com/archive/2003/10/06/betterDateInput
 * @author Stoyan Stefanov &lt;stoyan@phpied.com&gt;
 */