function isValidEmail(input){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(input);
}

function trimForm(form){
	for(var i = 0 ; i  < form.elements.length; i++){
		if(form.elements[i].type == 'text' || form.elements[i].type == 'textarea'){
			form.elements[i].value = trim(form.elements[i].value);
		}
	}
}

// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}

function limitTextArea(input, length){
	input.value = input.value.substring(0, length);
}

function hideObject(obj){
   if (window.ActiveXObject) { // IE
      obj.style.display = "none";
   } else if (window.XMLHttpRequest) { // Mozilla, Safari,...
      obj.style.display = "none";
   }
}

function showObject(obj){
   if (window.ActiveXObject) { // IE
      obj.style.display = "block";
   } else if (window.XMLHttpRequest) { // Mozilla, Safari,...
      obj.style.display = "table-row";
   }
}

function getRadioButtonValue(obj){
	if(obj.length == null)
		return obj.value;
	for(var i = 0; i < obj.length; i++){
		if(obj[i].checked)
			return obj[i].value;
	}
}

function isInteger(sInteger){
	var re = /^(-)?\d+$/;
	return re.test(sInteger);
}

function isDatetime(sDatetime) { 
	var re = /^\d{4}\-\d{2}\-\d{2}\s([0-1][0-9]|[2][0-3]):([0-5][0-9]):([0-5][0-9])$/;
	if (re.test(sDatetime)) { 
		var dtArr = sDatetime.split(" ");
		var dArr = dtArr[0].split("-");  //date part
		var d = new Date(dArr[1] + '-' + dArr[2] + '-' + dArr[0]); 
		return d.getMonth() + 1 == dArr[1] && d.getDate() == dArr[2] && d.getFullYear() == dArr[0];
	} 
	else { 
		return false; 
	} 
} 

function compareOptionText(a,b) {
  /*
   * return >0 if a>b
   *         0 if a=b
   *        <0 if a<b
   */
  // textual comparison
  return a.text.toUpperCase() != b.text.toUpperCase() ? a.text.toUpperCase() < b.text.toUpperCase() ? -1 : 1 : 0;
  // numerical comparison
//  return a.text - b.text;
}

function sortOptions(list) {
  var items = list.options.length;
  // create array and make copies of options in list
  var tmpArray = new Array(items);
  for ( i=0; i<items; i++ )
	tmpArray[i] = new Option(list.options[i].text,list.options[i].value);
  // sort options using given function
  tmpArray.sort(compareOptionText);
  // make copies of sorted options back to list
  for ( i=0; i<items; i++ )
	list.options[i] = new Option(tmpArray[i].text,tmpArray[i].value);
} 

function sortOptionsGroup(list) {
	var group_list = list.getElementsByTagName("optgroup");

	if(group_list == null)
		return;

	for(var i = 0 ; i < group_list.length; i++){
		var options = group_list[i].getElementsByTagName("option");
		var tmpArray = new Array(options.length);

		var j = 0;
		while(group_list[i].firstChild){
			if(group_list[i].firstChild.tagName == "OPTION"){
				tmpArray[j] = new Option(group_list[i].firstChild.text,group_list[i].firstChild.value);
				j++;
			}
			group_list[i].removeChild(group_list[i].firstChild);
		}

		tmpArray.sort(compareOptionText);

		for(var k = 0 ; k < tmpArray.length; k++){
			group_list[i].appendChild(tmpArray[k]);
		}
	}
}

function editorCustomCleanup(type, value) {

	if(type == "insert_to_editor") {
		var dom = document.createElement('span');
		dom.innerHTML = value;

		removeNode(dom, "title");
		removeNode(dom, "meta");
		removeNode(dom, "script");

		node_list = dom.getElementsByTagName("style");

		for(var i = 0; i < node_list.length; i++){
			var style_content = node_list[i].innerHTML;
			var lines = style_content.split("\n");
			style_content = "\n";
			for(var j = 0; j < lines.length; j++){
				if(lines[j].indexOf("<!--") == -1 && lines[j].indexOf("-->") == -1 && lines[j].indexOf("&amp;") == -1 && trim(lines[j]) != ""){
					style_content += lines[j] + "\n";
				}
			}

			 node_list[i].innerHTML = style_content;
		}

		value = dom.innerHTML;
	}
	return value;
}



function removeNode(dom, nodeName){
	node_list = dom.getElementsByTagName(nodeName);

	for(var i = 0; i < node_list.length; i++){
		node_list[i].parentNode.removeChild(node_list[i]);
	}
}
function check_member_login(){
	var flag=true;
	var errMessage="";	
	var frm = document.member_login_form;
	
	trimForm(frm);
	if(frm.member_login.value == ''){
		flag = false;
		errMessage += "User ID\n";

	}
	if(frm.member_password.value == ''){
		flag = false;
		errMessage += "Password\n";

	}
	
	if(flag==false){
		errMessage = "Please fill in the following information:\n" + errMessage;
		alert(errMessage);
	}
	
	return flag;
}
function check_reg_event(){
	var flag=true;
	var errMessage="";		
	var frm = document.event_registration_form;
	
	trimForm(frm);
	
	if(frm.contact_name.value == ''){
		flag = false;
		errMessage += "Name\n";
	}
	if(frm.contact_no.value == ''){
		flag = false;
		errMessage += "Contact no.\n";
	}
	if(frm.contact_email.value == ''||!isValidEmail(frm.contact_email.value)){
		flag = false;
		errMessage += "Email\n";
	}
	if(flag==false){
		errMessage = "Please fill in the following information:\n" + errMessage;
		alert(errMessage);
	}
	
	return flag;
}
function pop_userpage(id)
{
	window.open("popup.php?pid="+id, "pop_userpage", "status = 1, height = 450, width = 765, resizable = yes, scrollbars=yes, menubar = no, location = no, z-look= yes");

}
 function isDate(txtDate){  

   var objDate;  // date object initialized from the txtDate string  
   var mSeconds; // milliseconds from txtDate  
   
   // date length should be 10 characters - no more, no less  
   if (txtDate.length != 10) return false;  
   
   // extract day, month and year from the txtDate string  
   // expected format is mm/dd/yyyy  
   // subtraction will cast variables to integer implicitly  
   var day   = txtDate.substring(8,10)  - 0;  
   var month = txtDate.substring(5,7)  - 1; // because months in JS start with 0  
   var year  = txtDate.substring(0,4) - 0;  
   
   // third and sixth character should be /  
   if (txtDate.substring(4,5) != '-') return false;  
   if (txtDate.substring(7,8) != '-') return false;  
   
   // test year range  
   if (year < 999 || year > 3000) return false;  
   
   // convert txtDate to the milliseconds  
   mSeconds = (new Date(year, month, day)).getTime();  
   
   // set the date object from milliseconds  
   objDate = new Date();  
   objDate.setTime(mSeconds);  
   
   // if there exists difference then date isn't valid  
   if (objDate.getFullYear() != year)  return false;  
   if (objDate.getMonth()    != month) return false;  
   if (objDate.getDate()     != day)   return false;  
   
   // otherwise return true  
   return true;  
 }  
 function isValidPassword(txt, txt2){
	 if(txt==""||txt!=txt2){
		 return false;
	 }else{
		 return true;
	 }
 } 
 function isValidLogin(value){
	 var illegalChars = /\W/; 
	 return !illegalChars.test(value);
 }
 function htmlspecialchars_decode (string, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Mirek Slugen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Mateusz "loonquawl" Zalega
    // +      input by: ReverseSyntax
    // +      input by: Slawomir Kaniecki
    // +      input by: Scott Cariss
    // +      input by: Francois
    // +   bugfixed by: Onno Marsman
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Ratheous
    // +      input by: Mailfaker (http://www.weedem.fr/)
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: htmlspecialchars_decode("<p>this -&gt; &quot;</p>", 'ENT_NOQUOTES');
    // *     returns 1: '<p>this -> &quot;</p>'
    // *     example 2: htmlspecialchars_decode("&amp;quot;");
    // *     returns 2: '&quot;'

    var optTemp = 0, i = 0, noquotes= false;
    if (typeof quote_style === 'undefined') {
        quote_style = 2;
    }
    string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
    var OPTS = {
        'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE' : 1,
        'ENT_HTML_QUOTE_DOUBLE' : 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE' : 4
    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
        quote_style = [].concat(quote_style);
        for (i=0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            }
            else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }
        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
        // string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
    }
    if (!noquotes) {
        string = string.replace(/&quot;/g, '"');
    }
    // Put this in last place to avoid escape being double-decoded
    string = string.replace(/&amp;/g, '&');

    return string;
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


