//Browser Support Code
function getHTTPObject()
{
	var xmlhttp;
	if(window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
  		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	 	if(!xmlhttp)
	 	{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
   	}
	return xmlhttp;
}
var http = getHTTPObject(); // Creating HTTP Object

/* showTab
 *
 * returns true on failure, so that the html link will activate in lieu of the javascript switch.
 */
function showTab(tab, tabContentID, tabGroupID) {
    // get elements from id params
    var tabGroup = document.getElementById(tabGroupID);
    var tabContent = document.getElementById(tabContentID);
    if(!tab || !tabGroup || !tabContent) return true;
    
    // find all divs inside the tab group.  loop them and reset their className
    groupDivs = tabGroup.getElementsByTagName('div');
    if(groupDivs.length) {
        for(i=0; i<groupDivs.length; i++) {
            if(groupDivs[i].className == 'tabContentOn') {
                groupDivs[i].className = 'tabContent';
            }
        }
    }
    // set the active tab content element to be active (visible)
    tabContent.className = 'tabContentOn';
    
    // find the <li> for the clicked tab
    var tabLI = tab.parentNode;
    while(tabLI.nodeName != 'LI') {
        tabLI = tabLI.parentNode;
        if(tabLI.nodeName == 'BODY') return true;
    }
    if(tabLI.className == 'on') {
        return true;
    }

    // find the <ul> containing tabs
    var tabUL = tabLI.parentNode;
    while(tabUL.nodeName != 'UL') {
        tabUL = tabUL.parentNode;
        if(tabUL.nodeName == 'BODY') return true;
    }
    // loop all <li> elements inside the <ul> and reset them
    var tabs = tabUL.getElementsByTagName('LI');
    if(tabs.length) {
        for(i=0; i<tabs.length; i++) {
            tabs[i].className = '';
        }
    }
    // set the active tab to be active
    tabLI.className = 'on';
    
    return false;
}

/* inputClear
 *
 * put this in the focus and blur callback attributes of form elements to show default text when empty.
 */
function inputClear(inputEl, defaultValue, focus) {
    focus = (typeof(focus) == 'undefined') ? true : focus;
    var curValue = inputEl.value;
    
    if(focus) {
        if(curValue == defaultValue)
            inputEl.value = '';
    }
    else {
        if(curValue == '')
            inputEl.value = defaultValue;
    }
}

/* srhOnFocus
 *
 * When the search box gets focus.
 */
function srhOnFocus()
{
	if(document.getElementById('edit-keys').value == "Find Groups")
	{
		document.getElementById('edit-keys').value = "";
	}
}

/* srhOnBlur
 *
 * When the search box losts focus.
 */
function srhOnBlur()
{
	if(document.getElementById('edit-keys').value == "")
	{
		document.getElementById('edit-keys').value = "Find Groups";
	}
}


/* Global Search - START */

function searchchk()
{	
	if((document.getElementById('searchtxt').value == 'Find Groups') || (document.getElementById('searchtxt').value == 'Please enter search term'))
	{
		document.getElementById('searchtxt').value = '';
	}
}

function chksearch()
{
	if(document.getElementById('searchtxt').value == '' || document.getElementById('searchtxt').value == 'Find Groups' || document.getElementById('searchtxt').value == 'Please enter search term')
	{
		document.getElementById('searchtxt').style.color = "black";
		document.getElementById('searchtxt').value = 'Find Groups';
	}
}
       
function search(bpath, type)
{	
	var sid = document.getElementById('searchtxt').value;
	if(sid == "Find Groups" || sid == "Please enter search term" || sid == "")
	{
		sid = "";
		document.getElementById('searchtxt').style.color = "red";
		document.getElementById('searchtxt').value = "Please enter search term";		
	}
	else
	{
		/*document.frm.action = bpath + "global-search?search=" + sid; */
		document.frm.action = bpath + "find-groups?gtype=&searchtext_fg=" + sid;
		document.frm.submit();
	}
	
	if(type == "1")
	{
		return false;
	}
}

function adminpanelsearch()
{	
	var sid = document.getElementById('txtsearch').value;
	if(sid == "")
	{
		sid = "";
		document.getElementById('txtsearch').style.color = "red";
	}
	else
	{
		/*document.frm.action = bpath + "global-search?search=" + sid; */
		//document.frmadminpanel.action = "/admin/panel?search=" + sid;
		//document.frmadminpanel.submit();
		window.location = "/admin/panel?search=" + sid;
	}
}

function utilitysearch()
{	
	var sid = document.getElementById('txtsearch').value;
	if(sid == "")
	{
		sid = "";
		document.getElementById('txtsearch').style.color = "red";
	}
	else
	{
		/*document.frm.action = bpath + "global-search?search=" + sid; */
		//document.frmadminpanel.action = "/admin/panel?search=" + sid;
		//document.frmadminpanel.submit();
		window.location = "/admin/content/boomity-api-utility?search=" + sid;
	}
}

function onenter(evt) {
  if(evt.keyCode == 13){
	adminpanelsearch();
  }
}

function onenterutility(evt) {
  if(evt.keyCode == 13){
	utilitysearch();
  }
}


function generateKey(gid){
	var bpath = Drupal.settings.basePath;

	$.ajax({
		type: "POST",
		url: bpath+'php_includes/generate_api_key.php',
		data: "gid="+gid,
		success: function(msg){
			if(msg != "error"){
				var substr = msg.split('|||');
				
				$('#'+gid+'_key').html(substr[0]);
				$('#'+gid+'_secret').html(substr[1]);
				
				alert("API Key and API secret generated.");
			}
			else{
				alert("Error generating api key an api secret.");
			}
		}
	});
}
/* Global Search - END */


/* FIND GROUPS - START */

function searchchk_fg()
{
	if(document.getElementById('searchtext_fg').value == 'Find Groups')
	{
		document.getElementById('searchtext_fg').value = '';
	}
}

function chksearch_fg()
{
	if(document.getElementById('searchtext_fg').value == '' || document.getElementById('searchtext_fg').value == 'Find Groups')
	{
		document.getElementById('searchtext_fg').value = 'Find Groups';
	}
}
                  
function search_fg(bpath, gtype)
{
	var sid = document.getElementById('searchtext_fg').value;
	document.frm_fg.action = bpath + "find-groups?gtype=" + gtype+"&searchtext_fg=" + sid;
	document.frm_fg.submit();
}

function findgroups_gd(bpath, gtype)
{
	window.location.href = bpath + "find-groups?gtype=" + gtype;
}

/* FIND GROUPS - END */

/* FIND Community - START */

function searchchk_community()
{
	if(document.getElementById('searchtext_comm').value == 'Search for community')
	{
		document.getElementById('searchtext_comm').value = '';
	}
}

function chksearch_community()
{
	if(document.getElementById('searchtext_comm').value == '' || document.getElementById('searchtext_comm').value == 'Find Community')
	{
		document.getElementById('searchtext_comm').value = 'Search for community';
	}
}

function search_community(bpath)
{
	var sid = document.getElementById('searchtext_comm').value;
	document.frm_comm.action = bpath + "join-community?search=" + sid;
	document.frm_comm.submit();
} 


/* FIND Community - END */

/* SEARCh THIS GROUP - START */

function searchchk_grs()
{
	if(document.getElementById('searchtxtgrs').value == 'Search this group' || document.getElementById('searchtxtgrs').value == 'Please enter search term')
	{
		document.getElementById('searchtxtgrs').value = '';
	}
}

function chksearch_grs()
{
	if(document.getElementById('searchtxtgrs').value == '' || document.getElementById('searchtxtgrs').value == 'Search this group'|| document.getElementById('searchtxtgrs').value == 'Please enter search term')
	{
		document.getElementById('searchtxtgrs').value = 'Search this group';
	}
}
       
function search_grs(bpath, type)
{
	var sid = document.getElementById('searchtxtgrs').value;
	if(sid == "Search this group" || sid == "Please enter search term" || sid == "")
	{
		sid = "";
		document.getElementById('searchtxtgrs').style.color = "red";
		document.getElementById('searchtxtgrs').value = "Please enter search term";
	}
	else
	{
		document.frm.action = bpath + "group_search?search=" + sid;
		document.frm.submit();
	}
	
	if(type == "1")
	{
		return false;
	}
}


/* SEARCh THIS GROUP - END */


/* FIND MEMBERS - START */

function searchchk_mem()
{
	if(document.getElementById('searchtext_mem').value == 'Find Members')
	{
		document.getElementById('searchtext_mem').value = '';
	}
}

function chksearch_mem()
{
	if(document.getElementById('searchtext_mem').value == '' || document.getElementById('searchtext_mem').value == 'Find Members')
	{
		document.getElementById('searchtext_mem').value = 'Find Members';
	}
}
                  
function search_mem(bpath, grnamealias)
{
	var sid = document.getElementById('searchtext_mem').value;	
	document.frm_mem.action = bpath + "group/" + grnamealias+ "/members?searchtext_mem=" + sid;
	document.frm_mem.submit();
}

/* FIND MEMBERS - END */

/* FIND MEDIA - START */

function searchchk_media()
{
	if(document.getElementById('searchtext_media').value == 'Find media')
	{
		document.getElementById('searchtext_media').value = '';
	}
}

function chksearch_media()
{
	if(document.getElementById('searchtext_media').value == '' || document.getElementById('searchtext_media').value == 'Find media')
	{
		document.getElementById('searchtext_media').value = 'Find media';
	}
}
                  
function search_media(bpath, argu)
{
	var sid = document.getElementById('searchtext_media').value;
	if(sid == "Find media")
	{
		sid = "";
	}
	document.frm_media.action = bpath + "group/" + argu + "/media/viewall?search=" + sid;
	document.frm_media.submit();
}

/* FIND MEDIA - END */



/*  FUNCTIONS to UPDATE the Manage Meetings Block ==================================================================================== */
var ck_name = /^[A-Za-z0-9 ]{1,60}$/;
var ck_email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
var ck_username = /^[A-Za-z0-9_]{1,20}$/;
var ck_password =  /^[A-Za-z0-9!@#$%^&*()_]{6,20}$/;


function managePopup(id, srno, burl) 
{
	var errors = [];
	if(document.getElementById("rname").value=="" || document.getElementById("agenda").value=="" || document.getElementById("invityname").value=="" || document.getElementById("mkey").value=="" || document.getElementById("hkey").value=="" || document.getElementById("calID").value=="")
	{
		//alert("values can not be left blank");
		//return false;
		if(document.getElementById("rname").value=="")
		{
			errors[errors.length] = "Room Name can not be left blank.";
		}
		if(document.getElementById("agenda").value=="")
		{
			errors[errors.length] = "Agenda can not be left blank.";
		}
		if(document.getElementById("invityname").value=="")
		{
			errors[errors.length] = "Invitees field can not be left blank.";
		}
		if(document.getElementById("calID").value=="")
		{
			errors[errors.length] = "Meeting Time can not be left blank.";
		}
		
		if (errors.length > 0) 
		{
			reportErrors(errors);
			return false;
		}

	}
	else
	{

		var srno = document.getElementById('hidsrno').value;
		var uid = document.getElementById('uid').value;
		var gid = document.getElementById('hidgrpID').value
		var rname = document.getElementById('rname').value;
		var agenda = document.getElementById('agenda').value;
		var inv_name = document.getElementById('invityname').value;
		var other_inv = document.getElementById('other_inv').value;
		var inv_id = document.getElementById('invity').value;
		var mkey = document.getElementById('mkey').value;
		var hkey = document.getElementById('hkey').value;
		var mtime = document.getElementById('calID').value;  
		var timezone = document.getElementById('edittimezoneId').value;
    var return_url = document.getElementById('return_url').value;
    var dimdim_ip_addr = document.getElementById('dimdim_ip_addr').value;
		
		//== Date Validation ============================================================================
		var currentTime = new Date();
		var month = currentTime.getMonth('M') + 1
		var day = currentTime.getDate()
		var year = currentTime.getFullYear()
		var hrs = currentTime.getHours()
		var min = currentTime.getMinutes()
		var sec = currentTime.getSeconds()
		var newday;
		var newmonth;

		if(day < 10)
		{
			newday = "0" + day;	
		}
		else
		{
			newday = day;
		}
		if(month < 10)
		{
			newmonth = "0" + month;
		}
		else
		{
			newmonth = month;
		}
		//var newdate = year + "-" + newmonth + "-" + newday + " " + hrs + ":" + min + ":" + sec;
		var newdate = year + "-" + newmonth + "-" + newday + " " + hrs + ":" + min + ":" + sec;

		//if(mtime < newdate)
		//{
			//COMMENTED AS OF NOW - START
			//errors[errors.length] = "Meeting time should be greater than current date .";
			//COMMENTED AS OF NOW - END
		//}
		//========== Time Validation ========================================================================

		if(document.getElementById('hrs').value == "hr" && document.getElementById('mins').value == "min")
		{
			errors[errors.length] = "Please enter the proper online meeting duration.";
		}
		else if(document.getElementById('hrs').value == "hr")
		{
			errors[errors.length] = "Please enter the proper online meeting duration.";
		}
		else if(document.getElementById('mins').value == "min")
		{
			errors[errors.length] = "Please enter the proper online meeting duration.";
		}
		else if(document.getElementById('hrs').value == 0 && document.getElementById('mins').value == 0)
		{
			errors[errors.length] = "Please enter the proper online meeting duration.";
		}
// ==================================================================================================
		//if (!ck_name.test(rname)) 
		if (rname.length > 60) 
		{
			errors[errors.length] = "Room name must be less than 60 characters.";
		}
		else
		{
			if(false && rname.search(" ") != "-1")
			{
				errors[errors.length] = "Spaces are not allowed in RoomName.";
			}
		}

		//if (!ck_name.test(agenda)) 
		if (agenda.length > 60) 
		{
			errors[errors.length] = "Agenda must be less than 60 characters.";
		}
		/*else
		{
			if(agenda.search(" ") != "-1")
			{
				errors[errors.length] = "Spaces are not allowed in Agenda.";
			}
		}*/

		if (!ck_name.test(mkey)) 
		{
			errors[errors.length] = "Meeting key does not contain special characters.";
		}
		else
		{
			if(mkey.search(" ") != "-1")
			{
				errors[errors.length] = "Spaces are not allowed in Meeting Key.";
			}
		}
				 
		if (!ck_name.test(hkey)) 
		{
			errors[errors.length] = "Host key does not contain special characters.";
		}
		else
		{
			if(hkey.search(" ") != "-1")
			{
				errors[errors.length] = "Spaces are not allowed in Host Key.";
			}
		}

		if(other_inv != "")
		{
			var chkstatus = 0;
			var other_inv1 = other_inv.split(",");
			for(k=0;k<other_inv1.length;k++)
			{
				var ot_inv = trim(other_inv1[k]);
				if (!ck_email.test(ot_inv))
				{
					chkstatus = 1;
				}
				else
				{
					chkstatus = 0;
				}
			}
			if(chkstatus == 1)
			{
				errors[errors.length] = "Please enter a valid Email Addres.";
			}
		}

		var scinvval = document.getElementById("invity").value;
		var scinvval2 = scinvval.split(",");
		for(k=0;k<scinvval2.length;k++)
		{
			if (!ck_email.test(scinvval2[k])) 
			{
				errors[errors.length] = "You must enter a valid email address.";
			}
		}

		if (errors.length > 0)
		{
			reportErrors(errors);
			return false;
		}
		else
		{
			document.getElementById("hidTime1").value = document.getElementById('hrs').value + ":" + document.getElementById('mins').value + ":" + "00";
			var mduration = document.getElementById("hidTime1").value;
			var url = burl + "/php_includes/update_meeting.php?srno="+srno+"&uid="+uid+"&rname="+rname+"&agenda="+agenda+"&inv_name="+inv_name+"&inv_id="+inv_id+"&mkey="+mkey+"&hkey="+hkey+"&mtime="+mtime+"&mduration="+mduration+"&burl="+burl+"&timezone="+timezone+"&other_inv="+other_inv+"&return_url="+return_url+"&dimdim_ip_addr="+dimdim_ip_addr;
			//alert(url);			
			http.open("GET",url,true);
			http.onreadystatechange = handleHttpResponse_mang;
			http.send(null); 
		}
	}
}

function handleHttpResponse_mang()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4) 
	{
		if(http.status==200) 
      	{	
			var results = http.responseText;
			var ctr = results.split("==")
			if(ctr[0] == 0)
			{
				window.location.reload(true);
				alert("Your's meeting has been updated, but no mail has been sent to all invitees.");
			}
			else if(ctr[0] > 0)
			{
				window.location.reload(true);
				alert("Your's meeting has been updated and mail has been sent to all invitees.");
			}
			else
			{
				alert("Some internal error has been occured!");
			}
		}
	}
}


// =================================== functions for INSERT DATA into database =====================================================
var global_burl;
var global_uid;
function manageInsert(isNow, val, burl) 
{
	//alert($('#take_survey').attr('checked'));
	global_burl = burl;
	var errors = [];
	if(document.getElementById("scrname").value=="" || document.getElementById("scagenda").value=="" || (document.getElementById("scinvityname").value=="" && document.getElementById('scother_inv').value == '') || document.getElementById("scmkey").value=="" || document.getElementById("schkey").value=="" || document.getElementById('calID1').value=="")	
	{
		if(document.getElementById("scrname").value=="")
		{
			errors[errors.length] = "Room Name can not be left blank.";
		}
		if(document.getElementById("scagenda").value=="")
		{
			errors[errors.length] = "Agenda can not be left blank.";
		}
		if(document.getElementById("scinvityname").value=="" && document.getElementById('scother_inv').value == '')
		{
			errors[errors.length] = "Invitees field can not be left blank.";
		}
		if(document.getElementById("calID1").value=="")
		{
			errors[errors.length] = "Meeting Time can not be left blank.";
		}
		
		
		if (errors.length > 0) 
		{
			reportErrors(errors);
			return false;
		}		
		
	}
	else
	{
		var uid = document.getElementById('uid').value;
		var gid = document.getElementById('hidgrpID').value
		var rname = document.getElementById('scrname').value;
		var agenda = document.getElementById('scagenda').value;
		var inv_name = document.getElementById('scinvityname').value;
		var other_inv = document.getElementById('scother_inv').value;
		var inv_id = document.getElementById('scinvity').value;
		var mkey = document.getElementById('scmkey').value;
		var hkey = document.getElementById('schkey').value;
		var mtime = document.getElementById('calID1').value;
		var timezone = document.getElementById('timezoneId').value;
		var return_url = document.getElementById('return_url').value;
		var dimdim_ip_addr = document.getElementById('dimdim_ip_addr').value;
		//var openmeeting_ip_addr = document.getElementById('openmeeting_ip_addr').value; 
     	
		global_uid = uid;
		//== Date Validation ============================================================================

		var currentTime = new Date();
		var month = currentTime.getMonth('M') + 1
		var day = currentTime.getDate()
		var year = currentTime.getFullYear()
		var hrs = currentTime.getHours()
		var mint = currentTime.getMinutes()
		var sec = currentTime.getSeconds()
		var newday;
		var newmonth;

		if(day < 10)
		{
			newday = "0" + day;	
		}
		else
		{
			newday = day;
		}
		if(month < 10)
		{
			newmonth = "0" + month;
		}
		else
		{
			newmonth = month;
		}
		//var newdate = year + "-" + newmonth + "-" + newday + " " + hrs + ":" + mint + ":" + sec;
		var newdate = year + "-" + newmonth + "-" + newday + " " + hrs + ":" + mint + ":" + sec;
	
		//alert(mtime+" ==== "+newdate);			//if(mtime <= newdate)
		//{
			//COMMENTED AS OF NOW - START
			//errors[errors.length] = "Meeting time should be greater than current date .";
			//COMMENTED AS OF NOW - END
		//}
		//========== Time Validation =======================================================================

		if(document.getElementById('schr').value == "hr" && document.getElementById('scmin').value == "min")
		{
			errors[errors.length] = "Please enter the proper online meeting duration.";
		}
		else if(document.getElementById('schr').value == "hr")
		{
			errors[errors.length] = "Please enter the proper online meeting duration.";
		}
		else if(document.getElementById('scmin').value == "min")
		{
			errors[errors.length] = "Please enter the proper online meeting duration.";
		}
		else if(document.getElementById('schr').value == 0 && document.getElementById('scmin').value == 0)
		{
			errors[errors.length] = "Please enter the proper online meeting duration.";
		}
		// ================================================================================================

		//if (!ck_name.test(rname))
		if (rname.length > 60) 
		{
			errors[errors.length] = "Room name must be less than 60 characters.";
		}
		else
		{
			if(false && rname.search(" ") != "-1")
			{
				errors[errors.length] = "Spaces are not allowed in RoomName.";
			}
		}

		//if (!ck_name.test(agenda))
		if (agenda.length > 60) 
		{
			errors[errors.length] = "Agenda must be less than 60 characters.";
		}
		/*else
		{
			removeSpaces(agenda);
			
		}*/

		if (!ck_name.test(mkey)) 
		{
			errors[errors.length] = "Meeting key does not contain special characters.";
		}
		else
		{
			if(mkey.search(" ") != "-1")
			{
				errors[errors.length] = "Spaces are not allowed in Meeting Key.";
			}
		}
	 
		if (!ck_name.test(hkey))
		{
			errors[errors.length] = "Host key does not contain special characters.";
		}
		else
		{
			if(hkey.search(" ") != "-1")
			{
				errors[errors.length] = "Spaces are not allowed in Host Key.";
			}
		}

		if(other_inv != "")
		{
			var chkstatus = 0;
			var other_inv1 = other_inv.split(",");
			for(k=0;k<other_inv1.length;k++)
			{
				var ot_inv = trim(other_inv1[k]);
				if (!ck_email.test(ot_inv))
				{
					//errors[errors.length] = "Please enter a valid Email Addres.";
					chkstatus = 1;
				}
				else
				{
					chkstatus = 0;
				}
			}
			if(chkstatus == 1)
			{
				errors[errors.length] = "Please enter a valid Email Addres.";
			}
		}

		

		if (errors.length > 0) 
		{
			reportErrors(errors);
			return false;
		}
		else
		{ 
			document.getElementById("hidTime").value = document.getElementById('schr').value + ":" + document.getElementById('scmin').value + ":" + "00";
			var mduration = document.getElementById("hidTime").value;
			var startnow = 0
			if(isNow){
				startnow = 1;
				$('#loader').css('opacity', 1);
			}
			var is_check = 0;
			var is_check_survey = 0;
			
			if($('#use_conference').attr('checked')){
				is_check = 1;	
			}
			
			if($('#take_survey').attr('checked')){
				is_check_survey = 1;	
			}
			
			/*
			$(':checkbox:checked').each(function(i){
				is_check = 1;
				});
			*/
		
			//var url = burl + "/php_includes/insert_meeting.php?startnow="+startnow+"&uid="+uid+"&gid="+gid+"&rname="+rname+"&agenda="+agenda+"&inv_name="+inv_name+"&inv_id="+inv_id+"&mkey="+mkey+"&hkey="+hkey+"&mtime="+mtime+"&mduration="+mduration+"&burl="+burl+"&timezone="+timezone+"&other_inv="+other_inv+"&return_url="+return_url+"&dimdim_ip_addr="+dimdim_ip_addr;
			var url = burl + "/php_includes/insert_meeting.php?is_check_survey="+is_check_survey+"&use_conference="+is_check+"&startnow="+startnow+"&uid="+uid+"&gid="+gid+"&rname="+rname+"&agenda="+agenda+"&inv_name="+inv_name+"&inv_id="+inv_id+"&mkey="+mkey+"&hkey="+hkey+"&mtime="+mtime+"&mduration="+mduration+"&burl="+burl+"&timezone="+timezone+"&other_inv="+other_inv+"&return_url="+return_url;
			
			//alert(url);
			//return false;
			http.open("GET",url,false);
			http.onreadystatechange = handleHttpResponse_insert;
			http.send(null); 
		}
	}
}

function manageInsert_event(isNow, val, burl, isevent) 
{
	if(isevent == null){
		isevent = 0;
	}
	
	global_burl = burl;
	var errors = [];
	var uid = document.getElementById('uid').value;
	var gid = document.getElementById('gid').value
	var rname = document.getElementById('scrname').value;
	var agenda = document.getElementById('scagenda').value;
	var inv_name = document.getElementById('scinvityname').value;
	var other_inv = document.getElementById('scother_inv').value;
	var inv_id = document.getElementById('scinvity').value;
	var mkey = document.getElementById('scmkey').value;
	var hkey = document.getElementById('schkey').value;
	//var mtime = document.getElementById('calID1').value;
	var mtime_str = document.getElementById('edit-field-event-date-0-value-datepicker-popup-0').value + " " + document.getElementById('edit-field-event-date-0-value-timeEntry-popup-1').value;
	
	//date and time
	MyDate=mtime_str;
	MD_Y=MyDate.substring(6,10);
	MD_M=MyDate.substring(0,2); // Jan-Dec=01-12
	MD_D=MyDate.substring(3,5);
	MD_H=MyDate.substring(11,13);
	MD_N=MyDate.substring(14,16);
	MD_S=0;
	//MD_M=MD_M-1; // Jan-Dec=00-11
	if (MyDate.indexOf('PM') > -1) { MD_H=MD_H*1+12; }
	//DObj=new Date(MD_Y, MD_M, MD_D, MD_H, MD_N, MD_S);
	var mtime = MD_M + '-' + MD_D + '-' + MD_Y + ' ' + MD_H + ':' + MD_N + ':' + '00';
	//end date and time
	
	var timezone = document.getElementById('timezoneId').value;
	var return_url = document.getElementById('return_url').value;
	//var dimdim_ip_addr = document.getElementById('dimdim_ip_addr').value;
	var openmeeting_ip_addr = document.getElementById('openmeeting_ip_addr').value; 
	global_uid = uid;
	//== Date Validation ============================================================================

	var currentTime = new Date();
	var month = currentTime.getMonth('M') + 1
	var day = currentTime.getDate()
	var year = currentTime.getFullYear()
	var hrs = currentTime.getHours()
	var mint = currentTime.getMinutes()
	var sec = currentTime.getSeconds()
	var newday;
	var newmonth;

	if(day < 10)
	{
		newday = "0" + day;	
	}
	else
	{
		newday = day;
	}
	if(month < 10)
	{
		newmonth = "0" + month;
	}
	else
	{
		newmonth = month;
	}
	//var newdate = year + "-" + newmonth + "-" + newday + " " + hrs + ":" + mint + ":" + sec;
	var newdate = year + "-" + newmonth + "-" + newday + " " + hrs + ":" + mint + ":" + sec;

	//alert(mtime+" ==== "+newdate);			//if(mtime <= newdate)
	//{
		//COMMENTED AS OF NOW - START
		//errors[errors.length] = "Meeting time should be greater than current date .";
		//COMMENTED AS OF NOW - END
	//}
	//========== Time Validation =======================================================================

	if(document.getElementById('schr').value == "hr" && document.getElementById('scmin').value == "min")
	{
		errors[errors.length] = "Please enter the proper online meeting duration.";
	}
	else if(document.getElementById('schr').value == "hr")
	{
		errors[errors.length] = "Please enter the proper online meeting duration.";
	}
	else if(document.getElementById('scmin').value == "min")
	{
		errors[errors.length] = "Please enter the proper online meeting duration.";
	}
	else if(document.getElementById('schr').value == 0 && document.getElementById('scmin').value == 0)
	{
		errors[errors.length] = "Please enter the proper online meeting duration.";
	}
	// ================================================================================================
	
	//validate rname length
	//if (!ck_name.test(rname))
	if (rname.length > 60) 
	{
		errors[errors.length] = "Room name must be less than 60 characters.";
	}
	else
	{
		if(false && rname.search(" ") != "-1")
		{
			errors[errors.length] = "Spaces are not allowed in RoomName.";
		}
	}

	//if (!ck_name.test(agenda))
	if (agenda.length > 60)
	{
		errors[errors.length] = "Agenda must be less than 60 characters.";
	}
	/*else
	{
		removeSpaces(agenda);
		
	}*/

	if (!ck_name.test(mkey)) 
	{
		errors[errors.length] = "Meeting key does not contain special characters.";
	}
	else
	{
		if(mkey.search(" ") != "-1")
		{
			errors[errors.length] = "Spaces are not allowed in Meeting Key.";
		}
	}
 
	if (!ck_name.test(hkey))
	{
		errors[errors.length] = "Host key does not contain special characters.";
	}
	else
	{
		if(hkey.search(" ") != "-1")
		{
			errors[errors.length] = "Spaces are not allowed in Host Key.";
		}
	}

	if(other_inv != "")
	{
		var chkstatus = 0;
		var other_inv1 = other_inv.split(",");
		for(k=0;k<other_inv1.length;k++)
		{
			var ot_inv = trim(other_inv1[k]);
			if (!ck_email.test(ot_inv))
			{
				//errors[errors.length] = "Please enter a valid Email Addres.";
				chkstatus = 1;
			}
			else
			{
				chkstatus = 0;
			}
		}
		if(chkstatus == 1)
		{
			errors[errors.length] = "Please enter a valid Email Addres.";
		}
	}

	

	if (errors.length > 0) 
	{
		reportErrors(errors);
		return false;
	}
	else
	{ 
		document.getElementById("hidTime").value = document.getElementById('schr').value + ":" + document.getElementById('scmin').value + ":" + "00";
		var mduration = document.getElementById("hidTime").value;
		var startnow = 0
		if(isNow){
			startnow = 1;
			$('#loader').css('opacity', 1);
		}
		
		var is_check = (document.getElementById("use_conference").checked ? 1 : 0);
		var is_check_survey = (document.getElementById("take_survey").checked ? 1 : 0);
		
		/*
		$(':checkbox:checked').each(function(i){
			is_check = 1;
			});
		*/
		
		//var url = burl + "/php_includes/insert_meeting.php?startnow="+startnow+"&uid="+uid+"&gid="+gid+"&rname="+rname+"&agenda="+agenda+"&inv_name="+inv_name+"&inv_id="+inv_id+"&mkey="+mkey+"&hkey="+hkey+"&mtime="+mtime+"&mduration="+mduration+"&burl="+burl+"&timezone="+timezone+"&other_inv="+other_inv+"&return_url="+return_url+"&dimdim_ip_addr="+dimdim_ip_addr;
		var url = burl + "/php_includes/insert_meeting.php?is_check_survey="+is_check_survey+"&use_conference="+is_check+"&startnow="+startnow+"&uid="+uid+"&gid="+gid+"&rname="+rname+"&agenda="+agenda+"&inv_name="+inv_name+"&inv_id="+inv_id+"&mkey="+mkey+"&hkey="+hkey+"&mtime="+mtime+"&mduration="+mduration+"&burl="+burl+"&timezone="+timezone+"&other_inv="+other_inv+"&return_url="+return_url+"&isevent="+isevent;
		
		//alert(url);
		//return false;
		http.open("GET",url,true);
		http.onreadystatechange = handleHttpResponse_insert_event;
		http.send(null); 
	}
}

function reportErrors(errors)
{
	 var msg = "Please Enter Valid Data...\n";
	 for (var i = 0; i<errors.length; i++) 
	 {
	  	var numError = i + 1;
	  	msg += "\n" + numError + ". " + errors[i];
	 }
	 alert(msg);
}

// ==============================================================================================

function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
} 

function handleHttpResponse_insert_event()
{
	//alert("event");
	//setTimeout("funcwait()",10000);
	pausecomp(2000);
	if(http.readyState < 4)
	{  }
	if(http.readyState == 4) 
	{
		if(http.status==200) 
	      {
			var results = http.responseText;
			var ctr = results.split("==");
			//alert(ctr[0]);
			//alert(ctr[2]);
			//alert(results);
			
			if(ctr[0] == 0)
			{
					alert("Your meeting has been scheduled, but no mail has been sent to all invitees.");
					
					//window.location.reload(true);
					if(trim(ctr[4]) == "1"){
						window.location = global_burl + "/node/add/om-survey/" + ctr[2];	
					}
					else{
						window.location.reload(true);
					}
			}
			else if(ctr[0] > 0)
			{
				alert("Your meeting has been scheduled and mail has been sent to all invitees.");
				
				//window.location.reload(true);
				if(trim(ctr[4]) == "1"){
					window.location = global_burl + "/node/add/om-survey/" + ctr[2];	
				}
				else{
					window.location.reload(true);
				}
			}
			else
			{
				alert("Some internal error has been occured!");
			}
			
		}
	} 
}

function handleHttpResponse_insert()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4) 
	{
		if(http.status==200) 
	      {	
			var results = http.responseText;
			
			var ctr = results.split("==");
			//alert(ctr[0]);
			//alert(ctr[2]);
			//alert(results);
			if(global_stval == "StartM")
			{
				//startMeeting(1, global_burl, global_uid);
				startMeetingNow(global_burl, ctr[2], ctr[3]);
			}
			else if(global_stval == "ScheduleM") 
			{
			
				if(ctr[0] == 0)
				{
						alert("Your meeting has been scheduled, but no mail has been sent to all invitees.");
						//window.location.reload(true);
						if(trim(ctr[4]) == "1"){
							window.location = global_burl + "/node/add/om-survey/" + ctr[2];	
						}
						else{
							window.location.reload(true);
						}
						
						
				}
				else if(ctr[0] > 0)
				{
					alert("Your meeting has been scheduled and mail has been sent to all invitees.");
					//window.location.reload(true);
					
					if(trim(ctr[4]) == "1"){
						window.location = global_burl + "/node/add/om-survey/" + ctr[2];	
					}
					else{
						window.location.reload(true);
					}
				}
				else
				{
					alert("Some internal error has been occured!");
				}
			}
		}
	} 
}
function startMeetingNow(burl, mid, md5mid)
{
	var uid = document.getElementById('uid').value;
		var name = '';//document.getElementById('hidrname').value
		var room = document.getElementById('scrname').value;
		var agenda = document.getElementById('scagenda').value;
		agenda = removeSpaces(agenda);
		var inv_name = document.getElementById('scinvityname').value;
		var other_inv = document.getElementById('scother_inv').value;
		var invitee = document.getElementById('scinvity').value;
		if(other_inv != '')
		  invitee += invitee;  
		var pass1 = document.getElementById('scmkey').value;
		var pass2 = pass1;
		
	
	var mids=md5mid;
	
	window.location=burl+"/start-meeting?uid="+uid+"&name="+name+"&room="+room+"&agenda='"+agenda+"'&pass1="+pass1+"&pass2="+pass2+"&invitee="+invitee+"&mid="+mid+"&mids="+mids;
	//alert(burl+"/start-meeting?uid="+uid+"&name="+name+"&room="+room+"&agenda='"+agenda+"'&pass1="+pass1+"&pass2="+pass2+"&invitee="+invitee+"&mid="+mid+"&mids="+mids);
}
//================================================= CREATE COMMUNITY - START ==================================================

function create_comm() 
{
	if(document.getElementById("commName").value=="" || document.getElementById("commDesc").value=="" || document.getElementById("sel_aff_grp").value=="" || document.getElementById("commMsg").value=="")
	{
		alert("values can not be left blank");
		return false;
	}
	
}

function validate_commName(burl)
{
	if(document.getElementById("commName").value!="")
	{
		var commname = document.getElementById("commName").value
		var url = "php_includes/community_validation.php?comm_name="+commname;		
		http.open("GET",url,true);
		http.onreadystatechange = handleHttpResponse_comm_validation;
		http.send(null);
	}
	else
	{
		alert("Please enter Community Name");
		document.getElementById("commName").focus();
		return false;
	}	

}

function handleHttpResponse_comm_validation()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4) 
	{		
		if(http.status==200) 
		{      
			var results = http.responseText;					
			if(results == "success")
			{
				alert("This community already exists. Please try again with some other name.");
				document.getElementById("commName").focus();
				return false;
			}
			
			return false;
		}
	}
} 

function update_comm() 
{
	if(document.getElementById("commName").value=="" || document.getElementById("commDesc").value=="" || document.getElementById("sel_aff_grp").value=="" || document.getElementById("commMsg").value=="")
	{
		alert("values can not be left blank");
		return false;
	}	
}



//=================================================  CREATE COMMUNITY - END  ==================================================



//==================================================== FEATURED UPDATE START ===================================================

function save_widgets(burl, wid, wname, wemcode, wstat, type)
{

        var winame = document.getElementById(wname).value;
        var wiemcode = document.getElementById(wemcode).value;
        var wistat;


        if(document.getElementById(wstat).checked)
	{
		wistat = 1;
	}
	else
	{
		wistat = 0;
	}

        if(winame == '')
          {
              alert('Widget Name Cannot be Empty');
              $("#"+wname).focus();
          }
        else if(wiemcode == '')
          {
              alert('Widget Embed Code Cannot be Empty');
              $("#"+wemcode).focus();
          }
        else
            {

               var str = wiemcode;
               wiemcode = str.replace(/&/gi,"4mP3rs4nd");
               var str2 = wiemcode;
               wiemcode = str2.replace(/#/gi,"sh2r4p");

               var url = burl + "/php_includes/update_widgets.php?wid="+wid+"&ename="+winame+"&emcode="+wiemcode+"&stat="+wistat+"&burl="+burl+"&type="+type;
               http.open("GET",url,true);
               http.onreadystatechange = handleHttpResponse_featured;
               http.send(null);
            }
  
}


function featured_Update(type, nid, burl, gid)
{
	var url = burl + "/php_includes/update_featured.php?nid="+nid+"&type="+type+"&gid="+gid+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_featured;
	http.send(null); 
}

function publish_Update(chkid, type, burl, nid)
{
        var cbval;


        if(document.getElementById(chkid).checked)
	{
		cbval = 1;
	}
	else
	{
		cbval = 0;
	}

       
	var url = burl + "/php_includes/update_blog_publish.php?nid="+nid+"&cbval="+cbval+"&type="+type;
	//alert(url);
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_featured;
	http.send(null);
}

function handleHttpResponse_featured()
{
	if(http.readyState < 4)
      {}
	if(http.readyState == 4) 
      {
		if(http.status==200) 
            {
			var results = http.responseText;			
			var ctr = results.split("==")
			
			if(ctr[0] == "success")
			{
				if(ctr[2] == "widgets")
				{
                                     if(ctr[4] == "update")
                                       {
					alert(ctr[1]+" has been updated.");
					window.location = ctr[3]+"/manage-widgets";
                                       }
                                      else if(ctr[4] == "insert")
                                       {
					alert(ctr[1]+" has been added.");
					window.location = ctr[3]+"/manage-widgets";
                                       }

				}

                                if(ctr[2] == "event")
				{
					alert("This event has been set as featured event.");
					window.location = ctr[3]+"/manage-events";
				}
				if(ctr[2] == "media")
				{
					alert("This media has been set as featured media.");
					window.location = ctr[3]+"/manage-media";
				}
				if(ctr[2] == "blog")
				{
					alert("This blog has been set as featured blog.");
					window.location = ctr[3]+"/manage-blogs";
				}

                                if(ctr[2] == "blog1")
				{
					alert("This blog has been published.");
					window.location = ctr[3]+"/manage-blogs";
				}

                                if(ctr[2] == "blog0")
				{
					alert("This blog has been drafted.");
					window.location = ctr[3]+"/manage-blogs";
				}
			}
			else
			{
				alert("Internal Error!! Please try again...");
			}
			
			return false;
		}
	}
} 

function unfeatured_media_event(type, burl, gid)
{
	var url = burl + "/php_includes/update_unfeatured.php?type="+type+"&gid="+gid+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_unfeatured;
	http.send(null); 
}
function handleHttpResponse_unfeatured()
{
	if(http.readyState < 4)
      {}
	if(http.readyState == 4) 
      {
		if(http.status==200) 
            {
			var results = http.responseText;
			var res = results.split("<><>");			
			if(res[0] == "success")
			{
				if(res[1] == "media")
				{
					alert("Your "+res[1]+" has been unfeatured!!");
					window.location = res[2]+"/manage-media";
				}
				else if(res[1] == "event")
				{
					alert("Your "+res[1]+" has been unfeatured!!");
					window.location = res[2]+"/manage-events";
				}
			}
			else
			{
				alert("Internal Error!! Please try again...");
			}
			
			return false;
		}
	}
} 



function manage_event(act)
{
	var val = document.getElementById("search_event").value;
	
	if(act == "focus")
	{
		if(val == "Search for event")
			document.getElementById("search_event").value = "";
	}
	else if(act == "blur")
	{
		if(val == "")
			document.getElementById("search_event").value = "Search for event";
	}
}

function manage_media(act)
{
	var val = document.getElementById("search_media").value;
	
	if(act == "focus")
	{
		if(val == "Search for media")
			document.getElementById("search_media").value = "";
	}
	else if(act == "blur")
	{
		if(val == "")
			document.getElementById("search_media").value = "Search for media";
	}
}

function manage_blog(act)
{
	var val = document.getElementById("search_blog").value;
	
	if(act == "focus")
	{
		if(val == "Search for blog")
			document.getElementById("search_blog").value = "";
	}
	else if(act == "blur")
	{
		if(val == "")
			document.getElementById("search_blog").value = "Search for blog";
	}
}

function manage_mem(act)
{
	var val = document.getElementById("search_mem").value;
	
	if(act == "focus")
	{
		if(val == "Search for members")
			document.getElementById("search_mem").value = "";
	}
	else if(act == "blur")
	{
		if(val == "")
			document.getElementById("search_mem").value = "Search for members";
	}
}

function mng_evt_search(bpath)
{
	var sid = document.getElementById('search_event').value;
	if(sid == "Search for event")
	{
		sid = "";
	}
	document.frm_mng_evt.action = bpath + "manage-events?searchtext=" + sid;
	document.frm_mng_evt.submit();
}

function mng_mda_search(bpath)
{
	var sid = document.getElementById('search_media').value;
	if(sid == "Search for media")
	{
		sid = "";
	}
	document.frm_mng_mda.action = bpath + "manage-media?searchtext=" + sid;
	document.frm_mng_mda.submit();
}

function mng_blog_search(bpath)
{
	var sid = document.getElementById('search_blog').value;
	if(sid == "Search for blog")
	{
		sid = "";
	}
	document.frm_mng_blog.action = bpath + "manage-blogs?searchtext=" + sid;
	document.frm_mng_blog.submit();
}

function mng_mem_search(bpath)
{
	var sid = document.getElementById('search_mem').value;
	if(sid == "Search for members")
	{
		sid = "";
	}
	document.frm_mng_mem.action = bpath + "manage-members?searchtext=" + sid;
	document.frm_mng_mem.submit();
}

function goto_featured_event(bpath)
{
	var ft_cnt = document.getElementById('hid_featured_cnt').value;
	var rppage = document.getElementById('hid_rows_per_page').value;
	var srh_evt = document.getElementById('search_event').value;
	if(srh_evt == "Search for event")
	{
		srh_evt = "";
	}
	
	var pageno;	
	if(ft_cnt%rppage == 0)
	{
		pageno = parseInt(ft_cnt/rppage);
	}
	else if(ft_cnt%rppage != 0)
	{
		pageno = (parseInt(ft_cnt/rppage) + 1);
	}
	window.location = bpath + "manage-events?pageno=" + pageno + "&searchtext=" + srh_evt;
}

function goto_featured_media(bpath)
{
	var ft_cnt = document.getElementById('hid_featured_cnt').value;
	var rppage = document.getElementById('hid_rows_per_page').value;
	var srh_mda = document.getElementById('search_media').value;
	if(srh_mda == "Search for media")
	{
		srh_mda = "";
	}
	
	var pageno;
	if(ft_cnt%rppage == 0)
	{
		pageno = parseInt(ft_cnt/rppage);
	}
	else if(ft_cnt%rppage != 0)
	{
		pageno = (parseInt(ft_cnt/rppage) + 1);
	}
	window.location = bpath + "manage-media?pageno=" + pageno + "&searchtext=" + srh_mda;
}



//==================================================== FEATURED UPDATE END =====================================================


//=================================================Group Admin Menu - START =====================================================================
function group_admin_menu(burl, uid, gid, oemm_users_list, oemm_users_gen_list, oemm_users_name_list, gr_ttl, gr_desc, grp_name_alias, home_status, ishometabnid)
{	
	var selval = document.getElementById("group_admin_menu").value;	
	//alert(selval);
	if(selval != "")
	{	
		document.getElementById("ajaxloader1").style.display = "";
		document.getElementById("ajaxloader2").style.display = "";			

		if(selval == "Control Panel Page")
		{
			window.location.href = burl + "/group-control-panel";
		}	
		else if(selval == "Manage Group Profile")
		{
			window.location.href = burl + "/node/" + gid + "/edit";
		}
		else if(selval == "Group Badge")
		{ 
			window.location.href = burl + "/group/"+grp_name_alias+"/group-badge";		    
			//checkhomepage(gid, burl);
		}
		else if(selval == "Turn-Off Advertising")
		{
			window.location.href = burl + "/manage-advertising";
		}
		else if(selval == "Order Premium Tools")
		{
			window.location.href = burl + "/order-premium-tools";
		}
		else if(selval == "Manage User Privileges")
		{
			window.location.href = burl + "/manage-user-privileges";
		}
		else if(selval == "Manage Widgets")
		{
			window.location.href = burl + "/manage-widgets";
		}
		else if(selval == "Home Tab")
		{
			//window.location.href = burl + "/group-home-tab";
			if(home_status == 1)
			{
				window.location.href = burl + "/node/" + ishometabnid + "/edit";
			}
			else if(home_status == 0)
			{
				window.location.href = burl + "/node/add/grouphometab";
			}
		}		
		else if(selval == "Manage Communities")
		{
			window.location.href = burl + "/manage-communities";
		}
		else if(selval == "Welcome Email")
		{
			window.location.href = burl + "/node/add/welcome-email";
		}
		else if(selval == "Weekly Digest Email")
		{
			window.location.href = burl + "/weekly-digest-email";
		}
		else if(selval == "Share/Invite")
		{
			window.location.href = burl + "/invitepage/group/" + gid;
		}
		else if(selval == "Manage Blog")
		{
			window.location.href = burl + "/manage-blogs";
		}
		else if(selval == "Manage Events")
		{
			window.location.href = burl + "/manage-events";
		}
		else if(selval == "Manage Media")
		{
			window.location.href = burl + "/manage-media";
		}
		else if(selval == "Discussions")
		{
			window.location.href = burl + "/group/" + grp_name_alias + "/forums";
		}
		else if(selval == "Manage eMeetings")
		{
			//window.location.href = burl + "/my-emeetings";
			window.location.href = burl + "/online-meetings";
		}
		else if(selval == "Email Marketing")
		{
			/*
			var url = burl + "/php_includes/group_admin_menu.php?selval="+selval+"&uid="+uid+"&gid="+gid+"&oemm_users_list="+oemm_users_list+"&oemm_users_gen_list="+oemm_users_gen_list+"&oemm_users_name_list="+oemm_users_name_list+"&gr_ttl="+gr_ttl+"&gr_desc="+gr_desc;
			//alert(url);
			http.open("GET",url,true);
			http.onreadystatechange = handleHttpResponse_gam;
			http.send(null);
			*/
			
			window.location.href = burl + "/em/contacts";
		}
		else if(selval == "Project Management")
		{
			window.location.href = burl + "/projects";
		}
      else if(selval == "Document Management")
		{
			window.location.href = burl + "/group/"+grp_name_alias+"/documents";
		}
		else if(selval == "Manage Members")
		{
			window.location.href = burl + "/manage-members";
			//alert(window.location.href);
		}
		else if(selval == "Signup Q&A")
		{
			window.location.href = burl + "/signup-qa";
		}			
		else if(selval == "Group Reporting")
		{
			window.location.href = burl + "/group-reporting";
		}
		else if(selval == "Web Analytics")
        {
            window.location.href = burl + "/group-analytics";
        }
	}
}

function handleHttpResponse_gam()
{	
	if(http.readyState < 4)
    {}
	if(http.readyState == 4)
    {
		if(http.status==200)
        {
			var results = http.responseText;
			res = results.split("<><>");
			
			document.getElementById("username").value = res[1];
			document.getElementById("password").value = res[2];
			
			if(res[0] == "useradded" || res[0] == "usernotadded")
			{				
				document.getElementById("oe_login_form").submit();
			}
			return false;
		}
	}
}
//=================================================Group Admin Menu - END =======================================================================

//=================================================== User Profile - START ======================================================================

function chk_status(id, nid, burl) 
{
	//alert(id+" === "+nid);
	if(id == "visb_to_gr_mem")
	{
		//var val = "Make Private";
		var val = "Private";
	}
	else if(id == "visb_on_boomity")
	{
		//var val = "off";
		var val = "Public";
	}
	if(val != "")
	{
		//var nidval = document.getElementById("hid_nid").value
		var url = burl + "/php_includes/update_profile.php?nidval="+nid+"&val="+val;
		//alert(url);
		http.open("GET",url,true);
		http.onreadystatechange = handleHttpResponse_profile;
		http.send(null);
	} 	
}

function handleHttpResponse_profile()
{
	//alert(http.readyState + " == " + http.status);
	if(http.readyState < 4)
	{}
	if(http.readyState == 4) 
	{
		if(http.status==200) 
	      {
			//alert(http.status);
			var results = http.responseText;			
			//alert(results);
			
			if(results == "success")
			{
				alert("Your's Profile Visibility has been modified.");
			}
			
			return false;
		}
	}
}

//=================================================== User Profile - END ======================================================================



//================================================= Decline Request - START ==================================================================
function decline_request()
{
	document.getElementById('hid_action').value = "decline";
	document.getElementById('frm_request').submit();
}
//================================================= Decline Request - END ==================================================================

//================================================= Accept Request - START ==================================================================
function accept_request()
{
	document.getElementById('hid_action').value = "accept";
	document.getElementById('frm_request').submit();
}
//================================================= Accept Request - END ==================================================================


//=================================================== Community Section - START ===========================================================

function chgCommGrVal(burl)
{
	var sel_comm = document.getElementById('sel_comm').value;
	var url = burl +  "/php_includes/chgcommgrval.php?ck="+sel_comm+"&burl="+burl;
	//alert(url);
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_chgcommgrval;
	http.send(null);	
}

function handleHttpResponse_chgcommgrval()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			document.getElementById('sel_comm_gr_id').innerHTML = results;
			return false;
		}
	}
}

function gotocommgr(burl)
{
	var sel_comm_gr = document.getElementById('sel_comm_gr').value;	
	window.location = burl + "/node/" + sel_comm_gr;		
}

//=================================================== Community Section - END ==============================================================

//=================================================== PROJECT MANAGEMENT - START ===========================================================

function chk_proj_status(id, bpath) 
{
	window.location.href = bpath + "/projects?type=p&id=" + id;
}

function chk_task_status(tstatusid, bpath) 
{
	var projval = document.getElementById('tasksel').value;
	if(document.getElementById('task_mine').checked)
	{
		var ttype = document.getElementById('task_mine').value;
	}
	if(document.getElementById('task_ev').checked)
	{
		var ttype = document.getElementById('task_ev').value;
	}
	//alert("ttype=== "+ttype);
	window.location.href = bpath + "/projects?type=t&projval=" + projval+"&ttype=" + ttype+"&tstatusid=" + tstatusid;
}

function chk_task_type(ttype, bpath)
{
	var projval = document.getElementById('tasksel').value;
	if(document.getElementById('open').checked)
	{
		var tstatusid = document.getElementById('open').value;		
	}
	if(document.getElementById('close').checked)
	{
		var tstatusid = document.getElementById('close').value;
	}
	//alert("tstatusid=== "+tstatusid);
	window.location.href = bpath + "/projects?type=t&projval=" + projval+"&ttype=" + ttype+"&tstatusid=" + tstatusid;
}

function funaddTask(bpath)
{ 
	//alert("hello"+ document.getElementById('tasksel').value);
	if(document.getElementById('tasksel').value == "all")
	{
		alert("Please select a Project first!!!!");
		return false;
	}
	else
	{
		var pid = document.getElementById('tasksel').value;
		window.location.href = bpath + "/set-add-task-ses?pid=" + pid;
	}
}

//=================================================== PROJECT MANAGEMENT - END ===========================================================


//=================================================== EMAIL MARKETING - START ===========================================================

function addcontacts(burl)
{
	window.location = burl + "/em/add/contacts";
}

function add_contacts(burl, gid)
{
	var ac_fname = document.getElementById('ac_fname').value;
	var ac_lname = document.getElementById('ac_lname').value;
	var ureg_email = document.getElementById('ac_email').value;
	
	if(ac_fname.length > 55)
	{
		alert("First Name can not be greater than 55 charcacters");
		document.getElementById('ac_fname').focus();
		return false;
	}
	else if(ac_lname.length > 55)
	{
		alert("Last Name can not be greater than 55 charcacters");
		document.getElementById('ac_lname').focus();
		return false;
	}
	else
	{	
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	
		if(pattern.test(ureg_email) == false)
		{
			alert("Please enter valid Email.");
			document.getElementById('ac_email').focus();
			return false;
		}
	}
	
	var url = burl +  "/php_includes/add_contacts.php?fname="+ac_fname+"&lname="+ac_lname+"&email="+ureg_email+"&gid="+gid+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_add_contacts;
	http.send(null);
}

function handleHttpResponse_add_contacts()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");
			if(res[1] == "email exists")
			{
				alert("Email already exists. Please try again with another one.");
				document.getElementById('ac_email').focus();
				return false;
			}
			else if(res[1] == "not inserted")
			{
				alert("Internal error occured!!. Please try again.");
				document.getElementById('ac_email').focus();
				return false;
			}
			else if(res[1] == "successfully inserted")
			{
				alert("Contact added successfully.");
				window.location = res[0] + "/em/contacts";
			}
			return false;
		}
	}
}

function edit_contact(ctr)
{
	document.getElementById("hid_edit").value = document.getElementById("hid_edit_" + ctr).value;	
	document.getElementById("frm_mem_edit").submit();
}

function edit_contacts(burl, memid)
{
	var ac_fname_edit = document.getElementById('ac_fname_edit').value;
	var ac_lname_edit = document.getElementById('ac_lname_edit').value;
	var ureg_email_edit = document.getElementById('ac_email_edit').value;
	
	if(ac_fname_edit.length > 55)
	{
		alert("First Name can not be greater than 55 charcacters");
		document.getElementById('ac_fname_edit').focus();
		return false;
	}
	else if(ac_lname_edit.length > 55)
	{
		alert("Last Name can not be greater than 55 charcacters");
		document.getElementById('ac_lname_edit').focus();
		return false;
	}
	else
	{	
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	
		if(pattern.test(ureg_email_edit) == false)
		{
			alert("Please enter valid Email.");
			document.getElementById('ac_email_edit').focus();
			return false;
		}
	}
	
	var url = burl +  "/php_includes/edit_contacts.php?fname="+ac_fname_edit+"&lname="+ac_lname_edit+"&email="+ureg_email_edit+"&memid="+memid+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_edit_contacts;
	http.send(null);
}

function handleHttpResponse_edit_contacts()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");
			if(res[1] == "not updated")
			{
				alert("Internal error occured!!. Please try again.");
				document.getElementById('ac_fname_edit').focus();
				return false;
			}
			else if(res[1] == "successfully updated")
			{
				alert("Contact updated successfully.");
				window.location = res[0] + "/em/contacts";
			}
			return false;
		}
	}
}

function delete_contact(ctr)
{
	document.getElementById("hid_delete").value = document.getElementById("hid_delete_" + ctr).value;
	document.getElementById("frm_mem_delete").submit();
}

function delete_contacts(burl, memid)
{
	var url = burl +  "/php_includes/delete_contacts.php?memid="+memid+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_delete_contacts;
	http.send(null);
}

function handleHttpResponse_delete_contacts()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");
			if(res[1] == "not deleted")
			{
				alert("Internal error occured!!. Please try again.");
				window.location = res[0] + "/em/contacts";
			}
			else if(res[1] == "successfully deleted")
			{
				alert("Member has been deleted from your contact list successfully.");
				window.location = res[0] + "/em/contacts";
			}
			return false;
		}
	}
}

function cancel_contacts(burl)
{
	window.location = burl + "/em/contacts";
}

function search_em(e, burl)
{
	if(e.keyCode == "13")
	{
		var sid = document.getElementById('srhem').value;	
		if(sid == "search by email")
		{
			sid = "";
		}	
		document.frm.action = burl + "/em/contacts?srhem=" + sid;
		document.frm.submit();
	}
}

function search_em_fobl(action)
{
	if(action == "focus")
	{
		if(document.getElementById('srhem').value == 'search by email')
		{
			document.getElementById('srhem').value = '';
		}
	}
	if(action == "blur")
	{
		if(document.getElementById('srhem').value == '' || document.getElementById('srhem').value == 'search by email')
		{
			document.getElementById('srhem').value = 'search by email';
		}
	}
}

function search_em2(burl)
{
	var sid = document.getElementById('srhem').value;
	if(sid == "search by email")
	{
		sid = "";
	}
	document.frm.action = burl + "/em/contacts?srhem=" + sid;
	document.frm.submit();	
}

function checkall(paging)
{
	if(document.getElementById('chkmain').value == "unchecked")
	{
		document.getElementById('chkmain').value = "checked";
		for(i=1;i<=paging;i++)
		{
			document.getElementById('chklist_'+i).checked = true;
		}
	}
	else if(document.getElementById('chkmain').value == "checked")
	{
		document.getElementById('chkmain').value = "unchecked";
		for(i=1;i<=paging;i++)
		{
			document.getElementById('chklist_'+i).checked = false;
		}
	}
}

function setmemstatus(paging, burl)
{
	var ids = "";
	var action = document.getElementById('sel_mem_status').value;
	for(i=1;i<=paging;i++)
	{		
		if(document.getElementById('chklist_'+i))
		{
			if(document.getElementById('chklist_'+i).checked == true)
			{
				ids += "," + document.getElementById('chklist_'+i).value;
			}
		}
		else
		{
			break;
		}
	}
	
	if(ids == "")
	{
		alert("Please select check box(es) to activate or deactivate the member(s).");
		return false;
	}
	else
	{
		var url = burl +  "/php_includes/set_mem_status.php?ids="+ids+"&action="+action+"&burl="+burl;		
		http.open("GET",url,true);
		http.onreadystatechange = handleHttpResponse_setmemstatus;
		http.send(null);
	}
}

function handleHttpResponse_setmemstatus()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");
			if(res[1] == "not updated")
			{
				alert("Internal error occured!!. Please try again.");
				window.location = res[0] + "/em/contacts";
			}
			else if(res[1] == "successfully updated")
			{
				alert("Status has been successfully updated.");
				window.location = res[0] + "/em/contacts";
			}
			return false;
		}
	}
}

function importcontacts(burl)
{
	window.location = burl + "/em/import/contacts";
}

function import_contacts(burl, gid)
{
	var invitee_ids = document.getElementById('invitee_ids').value;
	if(invitee_ids == "")
	{
		alert("Please insert atleast a single Email id to import.");
		document.getElementById('invitee_ids').focus();
		return false;
	}
	else
	{
		invitee_ids_arr = invitee_ids.split(",");
	
		var flag = 1;
		for(i=0;i<invitee_ids_arr.length;i++)
		{
			var inv_ids = trim(invitee_ids_arr[i]);
			if(inv_ids != "")
			{
				var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		
				if(pattern.test(inv_ids) == false)
				{
					flag = 0;
					break;
				}
			}
		}
	
		if(flag == 0)
		{
			alert("Please enter valid Email id(s).");
			document.getElementById('invitee_ids').focus();
			return false;
		}
		else if(flag == 1)
		{
			/*
			var url = burl +  "/php_includes/import_contacts.php?invitee_ids="+invitee_ids+"&gid="+gid+"&burl="+burl;
			http.open("GET",url,true);
			http.onreadystatechange = handleHttpResponse_impcontacts;
			http.send(null);
			return false;
			*/
			var name_email_list = "";
			if($('#name_email_list') != null)
				name_email_list = $('#name_email_list').val();
			
			var url = burl +  "/php_includes/import_contacts.php";
			var params = "invitee_ids="+invitee_ids+"&gid="+gid+"&burl="+burl+"&name_email_list="+name_email_list;
			
			//alert(params);
			//return false;
		
			http.open("POST", url, true);
			
			//Send the proper header information along with the request
			http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length", params.length);
			http.setRequestHeader("Connection", "close");
			
			http.onreadystatechange = handleHttpResponse_impcontacts;
			http.send(params);

			return false;
		}
	}
}

function handleHttpResponse_impcontacts()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;			
			var res = results.split("<><>");
			var msg = "";
			//alert(results)
			if(res[1] != "")
			{
				msg = "\nFollowing email id(s) has(ve) been successfully added in your contact list:\n"+res[1];
			}
			if(res[0] != "")
			{
				msg = "\nFollowing email id(s) has(ve) already been added in your contact list earlier:\n"+res[0];
			}
			if(res[4] != "")
			{
				msg = "\n"+res[4];
			}
			if(res[2] != "")
			{
				msg = "";
				if(res[4] != "")
				{
					msg = "\n"+res[4];
				}
				msg += "\nInternal error occurred while adding following email id(s) into your contact list:\n"+res[2];
			}
			
			
			alert(msg);
			window.location = res[3] + "/em/contacts";
			return false;
		}
	}
}

function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function fetch_res_not_on_list(burl, gid, email, pageno, paging, list_sesid)
{
	var url = burl +  "/php_includes/fetch_res_not_on_list.php?email="+email+"&gid="+gid+"&pageno="+pageno+"&paging="+paging+"&list_sesid="+list_sesid+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_fetchresnotonlist;
	http.send(null);	
}

function handleHttpResponse_fetchresnotonlist()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");		
			document.getElementById('res_not_on_list').innerHTML = res[0];
			document.getElementById('hid_res_not_on_list_ttl_rows').value = res[1];
			
			if(res[0] == "No Members Available")
			{
				document.getElementById('add_to_list_id').style.display = "none";
				document.getElementById('srhemnotonlist').style.display = "none";
				document.getElementById('srhemnotonlistimg').style.display = "none";				
			}
			return false;
		}
	}
}

function checkall_list(paging)
{
	if(document.getElementById('chkmain').value == "unchecked")
	{
		document.getElementById('chkmain').value = "checked";
		for(i=1;i<=paging;i++)
		{
			document.getElementById('chklist_'+i).checked = true;
		}
	}
	else if(document.getElementById('chkmain').value == "checked")
	{
		document.getElementById('chkmain').value = "unchecked";
		for(i=1;i<=paging;i++)
		{
			document.getElementById('chklist_'+i).checked = false;
		}
	}
}

function add_to_list(burl, list_sesid, gid, email, pageno, paging)
{
	var hrnoltr = document.getElementById('hid_res_not_on_list_ttl_rows').value;
	var ids_var = "";	
	for(i=1;i<=hrnoltr;i++)
	{
		if(document.getElementById('chklist_'+i) != null){
			if(document.getElementById('chklist_'+i).checked == true)
			{
				ids_var += "," + document.getElementById('chklist_'+i).value;
			}
		}else if(document.getElementById('chklistedit2_'+i) != null){
			if(document.getElementById('chklistedit2_'+i).checked == true)
			{
				ids_var += "," + document.getElementById('chklistedit2_'+i).value;
			}
		}
	}
	ids_var = ids_var.substring(1, (ids_var.length));	
	if(ids_var == "")
	{
		alert("Please select any member.");
		return false;		
	}
	else if(ids_var != "")
	{
		var url = burl +  "/php_includes/add_to_list.php?list_sesid="+list_sesid+"&ids_var="+ids_var+"&gid="+gid+"&email="+email+"&pageno="+pageno+"&paging="+paging+"&burl="+burl;	
		http.open("GET",url,true);
		http.onreadystatechange = handleHttpResponse_addtolist;
		http.send(null);
	}
}

function handleHttpResponse_addtolist()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");
			if(res[0] == "internal error")
			{
				alert("Internal error occured!! Please try again.");
				return false;
			}
			else if(res[0] == "successfully added")
			{
				alert("Member(s) has(ve) been added successfully in your list.");				
				document.getElementById('remove_from_list_id').style.display = "";
				document.getElementById('srhemonlist').style.display = "";
				document.getElementById('srhemonlistimg').style.display = "";
				
				document.getElementById('srhemonlist').value = 'search by email';
				document.getElementById('srhemnotonlist').value = 'search by email';
				
				add_to_list_move(res[1], res[2], res[4], res[5], res[3], res[6]);
			}
			
			return false;
		}
	}
}

function add_to_list_move(list_sesid, gid, pageno, paging, email, burl)
{
	var url = burl +  "/php_includes/add_to_list_move.php?list_sesid="+list_sesid+"&gid="+gid+"&pageno="+pageno+"&paging="+paging+"&email="+email+"&burl="+burl;	
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_addtolistmove;
	http.send(null);
}

function handleHttpResponse_addtolistmove()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");		
			document.getElementById('res_on_list').innerHTML = res[0];
			document.getElementById('hid_res_on_list_ttl_rows').value = res[1];
			
			//fetch_res_not_on_list(res[2], res[3], res[4], res[5], res[6], res[7]);
			fetch_res_not_on_list(res[2], res[3], "", res[5], res[6], res[7]);
			
			return false;
		}
	}
}

function checkall_list2(paging)
{
	if(document.getElementById('chkmain2').value == "unchecked")
	{
		document.getElementById('chkmain2').value = "checked";
		for(i=1;i<=paging;i++)
		{
			if(document.getElementById('chklist2_'+i) != null)
				document.getElementById('chklist2_'+i).checked = true;
		}
	}
	else if(document.getElementById('chkmain2').value == "checked")
	{
		document.getElementById('chkmain2').value = "unchecked";
		for(i=1;i<=paging;i++)
		{
			if(document.getElementById('chklist2_'+i) != null)
				document.getElementById('chklist2_'+i).checked = false;
		}
	}
}

function remove_from_list(burl, list_sesid, gid, email, pageno, paging)
{
	var hrnoltr = document.getElementById('hid_res_on_list_ttl_rows').value;
	var ids_var = "";
	
	for(i=1;i<=hrnoltr;i++)
	{
		if(document.getElementById('chklist2_'+i).checked == true)
		{
			ids_var += "," + document.getElementById('chklist2_'+i).value;
		}
	}
	
	//alert(list_sesid+ "  " + ids_var);
	ids_var = ids_var.substring(1, (ids_var.length));	
	if(ids_var == "")
	{
		alert("Please select any member.");
		return false;		
	}
	else if(ids_var != "")
	{
		var url = burl +  "/php_includes/remove_from_list.php?list_sesid="+list_sesid+"&ids_var="+ids_var+"&gid="+gid+"&email="+email+"&pageno="+pageno+"&paging="+paging+"&burl="+burl;
		http.open("GET",url,true);
		http.onreadystatechange = handleHttpResponse_removefromlist;
		http.send(null);
	}
}

function handleHttpResponse_removefromlist()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;			
			var res = results.split("<><>");
			if(res[0] == "internal error")
			{
				alert("Internal error occured!! Please try again.");
				return false;
			}
			else if(res[0] == "successfully removed")
			{
				alert("Member(s) has(ve) been removed successfully from your list.");
				
				document.getElementById('srhemonlist').value = 'search by email';
				document.getElementById('srhemnotonlist').value = 'search by email';				
				
				remove_from_list_move(res[1], res[2], res[4], res[5], res[3], res[6]);
			}
			
			return false;
		}
	}
}

function remove_from_list_move(list_sesid, gid, pageno, paging, email, burl)
{
	var url = burl +  "/php_includes/remove_from_list_move.php?list_sesid="+list_sesid+"&gid="+gid+"&pageno="+pageno+"&paging="+paging+"&email="+email+"&burl="+burl;	
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_removefromlistmove;
	http.send(null);
}

function handleHttpResponse_removefromlistmove()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");		
			document.getElementById('res_on_list').innerHTML = res[0];
			document.getElementById('hid_res_on_list_ttl_rows').value = res[1];
			
			if(res[0] == "No Members Available")
			{
				document.getElementById('remove_from_list_id').style.display = "none";
				document.getElementById('srhemonlist').style.display = "none";
				document.getElementById('srhemonlistimg').style.display = "none";
			}
			
			fetch_res_not_on_list(res[2], res[3], res[4], res[5], res[6], res[7]);
			
			return false;
		}
	}
}

function save_list(burl, list_sesid, gid)
{
	var listname = document.getElementById('al_name').value;
	var listdesc = document.getElementById('al_desc').value;
	if(listname == "")
	{
		alert("List name can not be left blank.");
		document.getElementById('al_name').focus();
		return false;
	}
	if(listdesc == "")
	{
		alert("List description can not be left blank.");
		document.getElementById('al_desc').focus();
		return false;
	}
	
	var url = burl +  "/php_includes/save_list.php?listname="+listname+"&listdesc="+listdesc+"&list_sesid="+list_sesid+"&gid="+gid+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_savelist;
	http.send(null);
}

function handleHttpResponse_savelist()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			//alert(results);
			var res = results.split("<><>");
			if(res[0] == "Name Match")
			{
				alert("List name already exists. Please change it.");
				document.getElementById('al_name').focus();
				return false;
			}
			else if(res[0] == "No Members Available")
			{
				alert("Please add atlest a single member to create your list.");
				document.getElementById('al_name').focus();
				return false;
			}			
			else if(res[0] == "internal error")
			{
				alert("internal error occured!! Please try again.");
				document.getElementById('al_name').focus();
				return false;
			}
			else if(res[0] == "list created successfully")
			{
				alert("List has been created successfully.");
				window.location = res[1] + "/em/lists";
			}			
			
			return false;
		}
	}
}

function addlists(burl)
{
	window.location = burl + "/em/add/list";
}

function delete_list_link(ctr)
{
	document.getElementById("hid_deletelist").value = document.getElementById("hid_deletelist_" + ctr).value;
	document.getElementById("frm_deletelist").submit();
}

function deletelist(burl, listid)
{
	var url = burl +  "/php_includes/delete_list.php?listid="+listid+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_deletelist;
	http.send(null);
}

function handleHttpResponse_deletelist()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");
			if(res[1] == "not deleted")
			{
				alert("Internal error occured!!. Please try again.");
				window.location = res[0] + "/em/lists";
			}
			else if(res[1] == "successfully deleted")
			{
				alert("List has been deleted successfully.");
				window.location = res[0] + "/em/lists";
			}
			return false;
		}
	}
}

function cancel_list(burl)
{
	window.location = burl + "/em/lists";
}

function exportcontacts(burl)
{
	window.location = burl + "/em/export/contacts";
}

function exportct(burl, gid)
{
	var ta_export = document.getElementById("ta_export").value;
	if(ta_export == "")
	{
		alert("There is no email id to export.");
		document.getElementById("ta_export").focus();
		return false;
	}
	else if(ta_export != "")
	{
		ta_export_arr = ta_export.split(",");
		var flag = 1;
		for(i=0;i<ta_export_arr.length;i++)
		{			
			var ta_export_id = trim(ta_export_arr[i]);
			if(ta_export_id != "")
			{
				var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
			
				if(pattern.test(ta_export_id) == false)
				{
					flag = 0;
					break;
				}
			}
		}
			
		if(flag == 0)
		{
			alert("Please enter valid Email id(s).");
			document.getElementById('ta_export').focus();
			return false;
		}
		else if(flag == 1)
		{
			window.location = burl + "/em/export/emcontacts";
		}		
	}
}

function search_em_fobl_notonlist(action)
{
	if(action == "focus")
	{
		if(document.getElementById('srhemnotonlist').value == 'search by email')
		{
			document.getElementById('srhemnotonlist').value = '';
		}
	}
	if(action == "blur")
	{
		if(document.getElementById('srhemnotonlist').value == '' || document.getElementById('srhemnotonlist').value == 'search by email')
		{
			document.getElementById('srhemnotonlist').value = 'search by email';
		}
	}
}

function search_em_notonlist(e, burl, gid, pageno, paging, list_sesid)
{
	if(e.keyCode == "13")
	{
		var sid = document.getElementById('srhemnotonlist').value;	
		if(sid == "search by email")
		{
			sid = "";
		}		
		fetch_res_not_on_list(burl, gid, sid, pageno, paging, list_sesid);
	}
}

function search_em2_notonlist(e, burl, gid, pageno, paging, list_sesid)
{
	var sid = document.getElementById('srhemnotonlist').value;	
	if(sid == "search by email")
	{
		sid = "";
	}		
	fetch_res_not_on_list(burl, gid, sid, pageno, paging, list_sesid);
}

function search_em_fobl_onlist(action)
{
	if(action == "focus")
	{
		if(document.getElementById('srhemonlist').value == 'search by email')
		{
			document.getElementById('srhemonlist').value = '';
		}
	}
	if(action == "blur")
	{
		if(document.getElementById('srhemonlist').value == '' || document.getElementById('srhemonlist').value == 'search by email')
		{
			document.getElementById('srhemonlist').value = 'search by email';
		}
	}
}

function search_em_onlist(e, list_sesid, gid, pageno, paging, burl)
{
	if(e.keyCode == "13")
	{
		var sid = document.getElementById('srhemonlist').value;	
		if(sid == "search by email")
		{
			sid = "";
		}
		add_to_list_move(list_sesid, gid, pageno, paging, sid, burl);
	}
}

function search_em2_onlist(e, list_sesid, gid, pageno, paging, burl)
{
	var sid = document.getElementById('srhemonlist').value;	
	if(sid == "search by email")
	{
		sid = "";
	}
	add_to_list_move(list_sesid, gid, pageno, paging, sid, burl);
}

function edit_list_link(ctr)
{
	document.getElementById("hid_editlist").value = document.getElementById("hid_editlist_" + ctr).value;	
	document.frm_editlist.submit();
}

function fetch_res_on_list(burl, gid, email, pageno, paging, listid, loadtype)
{
	var url = burl +  "/php_includes/fetch_res_on_list.php?email="+email+"&gid="+gid+"&pageno="+pageno+"&paging="+paging+"&listid="+listid+"&burl="+burl+"&loadtype="+loadtype;	
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_fetchresonlist;
	http.send(null);	
}

function handleHttpResponse_fetchresonlist()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;			
			var res = results.split("<><>");		
			document.getElementById('res_on_list').innerHTML = res[0];
			document.getElementById('hid_res_on_list_ttl_rows').value = res[1];
			
			if(res[0] == "No Members Available")
			{
				document.getElementById('remove_from_list_id').style.display = "none";
				document.getElementById('srhemonlist').style.display = "none";
				document.getElementById('srhemonlistimg').style.display = "none";				
			}
			
			if(res[8] == "normalload")
			{
				fetch_res_not_on_list_edit(res[2], res[3], res[4], res[5], res[6], res[7]);
			}
			
			return false;
		}
	}
}

function fetch_res_not_on_list_edit(burl, gid, email, pageno, paging, listid)
{
	var url = burl +  "/php_includes/fetch_res_not_on_list_edit.php?email="+email+"&gid="+gid+"&pageno="+pageno+"&paging="+paging+"&listid="+listid+"&burl="+burl;	
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_fetchresnotonlist;
	http.send(null);	
}

function handleHttpResponse_fetchresnotonlist()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;			
			var res = results.split("<><>");		
			document.getElementById('res_not_on_list').innerHTML = res[0];
			document.getElementById('hid_res_not_on_list_ttl_rows').value = res[1];
			
			/*if(res[0] == "No Members Available")
			{
				document.getElementById('add_to_list_id').style.display = "none";
				document.getElementById('srhemnotonlist').style.display = "none";
				document.getElementById('srhemnotonlistimg').style.display = "none";				
			}*/
			return false;
		}
	}
}

function checkall_list_edit(paging)
{
	if(document.getElementById('chkmain_edit').value == "unchecked")
	{
		document.getElementById('chkmain_edit').value = "checked";
		for(i=1;i<=paging;i++)
		{
			if(document.getElementById('chklistedit_'+i) != null)
				document.getElementById('chklistedit_'+i).checked = true;
		}
	}
	else if(document.getElementById('chkmain_edit').value == "checked")
	{
		document.getElementById('chkmain_edit').value = "unchecked";
		for(i=1;i<=paging;i++)
		{
			if(document.getElementById('chklistedit_'+i) != null)
				document.getElementById('chklistedit_'+i).checked = false;
		}
	}
}

function checkall_list_edit2(paging)
{
	if(document.getElementById('chkmain_edit2').value == "unchecked")
	{
		document.getElementById('chkmain_edit2').value = "checked";
		for(i=1;i<=paging;i++)
		{
			if(document.getElementById('chklistedit2_'+i) != null)
				document.getElementById('chklistedit2_'+i).checked = true;
		}
	}
	else if(document.getElementById('chkmain_edit2').value == "checked")
	{
		document.getElementById('chkmain_edit2').value = "unchecked";
		for(i=1;i<=paging;i++)
		{
			if(document.getElementById('chklistedit2_'+i) != null)
				document.getElementById('chklistedit2_'+i).checked = false;
		}
	}
}

function remove_from_list_edit(burl, listid, gid, email, pageno, paging)
{
	var hrnoltr = document.getElementById('hid_res_on_list_ttl_rows').value;
	var ids_var = "";
	
	for(i=1;i<=hrnoltr;i++)
	{
		if(document.getElementById('chklistedit_'+i).checked == true)
		{
			ids_var += "," + document.getElementById('chklistedit_'+i).value;
		}
	}
	
	ids_var = ids_var.substring(1, (ids_var.length));	
	if(ids_var == "")
	{
		alert("Please select any member.");
		return false;		
	}
	else if(ids_var != "")
	{
		var url = burl +  "/php_includes/remove_from_list_edit.php?listid="+listid+"&ids_var="+ids_var+"&gid="+gid+"&email="+email+"&pageno="+pageno+"&paging="+paging+"&burl="+burl;
		http.open("GET",url,true);
		http.onreadystatechange = handleHttpResponse_removefromlistedit;
		http.send(null);
	}
}

function handleHttpResponse_removefromlistedit()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;			
			var res = results.split("<><>");
			if(res[0] == "internal error")
			{
				alert("Internal error occured!! Please try again.");
				return false;
			}
			else if(res[0] == "successfully removed")
			{
				alert("Member(s) has(ve) been removed successfully from your list.");
				
				document.getElementById('srhemonlist').value = 'search by email';
				document.getElementById('srhemnotonlist').value = 'search by email';				
				
				remove_from_list_move_edit(res[1], res[2], res[4], res[5], res[3], res[6]);
			}
			
			return false;
		}
	}
}

function remove_from_list_move_edit(listid, gid, pageno, paging, email, burl)
{
	var url = burl +  "/php_includes/remove_from_list_move_edit.php?listid="+listid+"&gid="+gid+"&pageno="+pageno+"&paging="+paging+"&email="+email+"&burl="+burl;	
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_removefromlistmoveedit;
	http.send(null);
}

function handleHttpResponse_removefromlistmoveedit()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");		
			document.getElementById('res_on_list').innerHTML = res[0];
			document.getElementById('hid_res_on_list_ttl_rows').value = res[1];
			
			if(res[0] == "No Members Available")
			{
				document.getElementById('remove_from_list_id').style.display = "none";
				document.getElementById('srhemonlist').style.display = "none";
				document.getElementById('srhemonlistimg').style.display = "none";
			}
			
			fetch_res_not_on_list_edit(res[2], res[3], res[4], res[5], res[6], res[7]);
			
			return false;
		}
	}
}

function add_to_list_move_edit(listid, gid, pageno, paging, email, burl)
{
	var url = burl +  "/php_includes/add_to_list_move_edit.php?listid="+listid+"&gid="+gid+"&pageno="+pageno+"&paging="+paging+"&email="+email+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_addtolistmove;
	http.send(null);
}

function handleHttpResponse_addtolistmove()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;			
			var res = results.split("<><>");		
			document.getElementById('res_on_list').innerHTML = res[0];
			document.getElementById('hid_res_on_list_ttl_rows').value = res[1];
			
			//fetch_res_not_on_list(res[2], res[3], res[4], res[5], res[6], res[7]);
			fetch_res_not_on_list_edit(res[2], res[3], "", res[5], res[6], res[7]);
			
			return false;
		}
	}
}

function add_to_list_edit(burl, listid, gid, email, pageno, paging)
{
	var hrnoltr = document.getElementById('hid_res_not_on_list_ttl_rows').value;
	var ids_var = "";	
	for(i=1;i<=hrnoltr;i++)
	{
		if(document.getElementById('chklistedit2_'+i).checked == true)
		{
			ids_var += "," + document.getElementById('chklistedit2_'+i).value;
		}
	}
	ids_var = ids_var.substring(1, (ids_var.length));	
	if(ids_var == "")
	{
		alert("Please select any member.");
		return false;		
	}
	else if(ids_var != "")
	{
		var url = burl +  "/php_includes/add_to_list_edit.php?listid="+listid+"&ids_var="+ids_var+"&gid="+gid+"&email="+email+"&pageno="+pageno+"&paging="+paging+"&burl="+burl;		
		http.open("GET",url,true);
		http.onreadystatechange = handleHttpResponse_addtolistedit;
		http.send(null);
	}
}

function handleHttpResponse_addtolistedit()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");
			if(res[0] == "internal error")
			{
				alert("Internal error occured!! Please try again.");
				return false;
			}
			else if(res[0] == "successfully added")
			{
				alert("Member(s) has(ve) been added successfully in your list.");				
				document.getElementById('remove_from_list_id').style.display = "";
				document.getElementById('srhemonlist').style.display = "";
				document.getElementById('srhemonlistimg').style.display = "";
				
				document.getElementById('srhemonlist').value = 'search by email';
				document.getElementById('srhemnotonlist').value = 'search by email';
				
				add_to_list_move_edit(res[1], res[2], res[4], res[5], res[3], res[6]);
			}
			
			return false;
		}
	}
}

function edit_list(burl, listid, gid)
{
	var listname = document.getElementById('al_name_edit').value;
	var listdesc = document.getElementById('al_desc_edit').value;
	if(listname == "")
	{
		alert("List name can not be left blank.");
		document.getElementById('al_name_edit').focus();
		return false;
	}
	if(listdesc == "")
	{
		alert("List description can not be left blank.");
		document.getElementById('al_desc_edit').focus();
		return false;
	}
	
	var url = burl +  "/php_includes/edit_list.php?listname="+listname+"&listdesc="+listdesc+"&listid="+listid+"&gid="+gid+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_editlist;
	http.send(null);
}

function handleHttpResponse_editlist()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;		
			var res = results.split("<><>");
			if(res[0] == "Name Match")
			{
				alert("List name already exists. Please change it.");
				document.getElementById('al_name_edit').focus();
				return false;
			}
			else if(res[0] == "No Members Available")
			{
				alert("Please add atlest a single member to save your list.");
				document.getElementById('al_name_edit').focus();
				return false;
			}			
			else if(res[0] == "internal error")
			{
				alert("internal error occured!! Please try again.");
				document.getElementById('al_name_edit').focus();
				return false;
			}
			else if(res[0] == "list saved successfully")
			{
				alert("List has been saved successfully.");
				window.location = res[1] + "/em/lists";
			}			
			
			return false;
		}
	}
}

function search_em_onlist_edit(e, listid, gid, pageno, paging, burl)
{
	if(e.keyCode == "13")
	{
		var sid = document.getElementById('srhemonlist').value;	
		if(sid == "search by email")
		{
			sid = "";
		}
		add_to_list_move_edit(listid, gid, pageno, paging, sid, burl);
	}
}

function search_em2_onlist_edit(e, listid, gid, pageno, paging, burl)
{
	var sid = document.getElementById('srhemonlist').value;	
	if(sid == "search by email")
	{
		sid = "";
	}
	add_to_list_move_edit(listid, gid, pageno, paging, sid, burl);
}

//=================================================== EMAIL MARKETING - END ===========================================================


//=================================================== REMOVE FROM GROUP - START ===========================================================

function remove_from_group(nid)
{
	var hid_gid2 = document.getElementById("hid_gid2_" + nid).value;
	var hid_burl = document.getElementById("hid_burl_" + nid).value;
	window.location = hid_burl + "/remove-group?id=" + hid_gid2;
}

function cancel_rmv_frm_grp(burl)
{
	window.location = burl + "/my-groups";
}

function remove_group(burl, gid, uid)
{
	var url = burl +  "/php_includes/remove_group.php?gid="+gid+"&uid="+uid+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_rmvgroup;
	http.send(null);
}

function handleHttpResponse_rmvgroup()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");
			if(res[1] == "error")
			{
				alert("Internal error occurred. Please try again.");
				window.location = res[0] + "/my-groups";				
			}
			else if(res[1] == "successfully removed")
			{
				alert("Group has been removed successfully.");
				window.location = res[0] + "/my-groups";
			}
			return false;
		}
	}
}

//=================================================== REMOVE FROM GROUP - END ===========================================================

// =================================== Functions for Manage WIDGETS - START =====================================================
function addslashes(str) 
{
	embed=str.replace(/\\/g,'\\\\');
	embed=embed.replace(/\'/g,'\\\'');
	embed=embed.replace(/\"/g,'\\"');
	embed=embed.replace(/\0/g,'\\0');
	return embed;
}
function onSave(burl, uid, gid)
{
	var collection = document.getElementById('myDiv').getElementsByTagName('textarea');
	
	var cnt_empty = 0;
	var embedid_str = "";
	var status_str = "";
	
	var tmp_str = "";
	var tmp_str2 = "";
	var status_str_tmp = "";
	
	var bstart = true;
	var bstart2 = true;
	
	var inx = -1;
	
	for (var x=0; x<collection.length; x++) {
	     if(trim(collection[x].value) == ""){
			cnt_empty += 1;		
	     }
	     else{
			//get chkid value
			inx = collection[x].id.indexOf("_");
			
			if(inx >= 0){
				tmp_str = collection[x].id.substring(inx + 1);
				//tmp_str2 = "chkId_" + tmp_str;
                                tmp_str2 = "chkId";
				
				//if(document.getElementById(tmp_str2).checked == true)
				//{
					status_str_tmp = "1";
				//}
				//else if(document.getElementById(tmp_str2).checked == false)
				//{
				//	status_str_tmp = "0";
				//}
				
				
				if(bstart2){
					status_str = status_str_tmp;
				}
				else{
					status_str += "|" + status_str_tmp;	
				}
				
				bstart2 = false;
			}
			else{
				if(document.getElementById("chkId").checked == true)
				{
					status_str_tmp = "1";
				}
				else if(document.getElementById("chkId").checked == false)
				{
					status_str_tmp = "0";
				}
				
				if(bstart2){
					status_str = status_str_tmp;
				}
				else{
					status_str += "|" + status_str_tmp;
				}
				
				bstart2 = false;
			}
			//end get chkid value
		
			if(bstart){
				embedid_str = collection[x].id;
			}
			else{
				embedid_str += "|" + collection[x].id;
			}
			
			bstart = false;
	     }
	}
	
	if(cnt_empty == collection.length)
	{
		alert("Please enter an embed code first!!");
	}
	else
	{
		if(document.getElementById("chkId").checked == true)
		{
			var status = 1;
		}
		else if(document.getElementById("chkId").checked == false)
		{
			var status = 0;
		}	
		//var embed = document.getElementById("embedId").value;
		//embed = addslashes(embed);
		//alert(embed);
		
		//document.getElementById("hid_status").value = status;
		
		//store string
		document.getElementById("hid_validatedok").value = "success";
		document.getElementById("hid_status_str").value = status_str;
		document.getElementById("hid_embedid_str").value = embedid_str;
		//end store string
		
		document.frmwidget.submit();
		
		/*
		embed = URLEncode(embed);
		
		var url = burl +  "/php_includes/insert_widget.php?gid="+gid+"&uid="+uid+"&burl="+burl+"&embed="+embed+"&status="+status;
		//alert(url);
		http.open("GET",url,true);
		http.onreadystatechange = handleHttpResponse_widget;
		http.send(null); 
		*/
	}
}


/*
function handleHttpResponse_widget()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			if(results == "success_insert1")
			{
				alert("Embed code has been saved and successfully published to Group.");
				document.getElementById("btn").value = "Update";
				document.getElementById("embedId").focus();
				//document.getElementById('embedId').disabled = true;
				//window.location.reload()
			}
			else if(results == "success_insert0")
			{
				alert("Embed code has been saved, but not published to Group.");
				document.getElementById("btn").value = "Update";
				document.getElementById("embedId").focus();
				//document.getElementById('embedId').disabled = false;
				//window.location.reload()
			}
			else if(results == "unsuccess")
			{
				alert("Internal Error !!!!!!!!!!1.");
			}
			return false;
		}
	}
}

function URLEncode(clearString)
{
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}
*/

// ==================================== Functions for Manage WIDGETS - END ======================================================

// =================================== Functions for GROUP HOME TAB - START =====================================================
function onUpdate(btnval, burl, uid, gid)
{
	if(btnval == "Preview")
	{
		
		//code = document.getElementById("txtId").value;
		var code = CKEDITOR.instances.txtId.getData();
		document.getElementById("hid_html_code").value = code;
		document.frmhome.action = burl + "/group-home-tab-preview";
		document.frmhome.submit();
	}
	else if(btnval == "Update")
	{
		if(document.getElementById("chkId").checked == true)
		{
			var status = 1;
		}
		else if(document.getElementById("chkId").checked == false)
		{
			var status = 0;
		}	
		//code = document.getElementById("txtId").value;
		var code = CKEDITOR.instances.txtId.getData();
		document.getElementById("hid_html_code").value = code;		
		document.getElementById("hid_status").value = status;		
		document.frmhome.submit();
	}

	/*if(document.getElementById('txtId').value == "")
	{
		alert("Please enter any HTML code first");	
	}*/
	/*else if(btnval == "back to HTML code")
	{
		document.getElementById('txtId').style.display = "";
		document.getElementById('txtId_prev').style.display = "none";
		document.getElementById("btnprev").value = "Preview";
	}
	if(btnval == "Preview")
	{
		
		code = document.getElementById("txtId").value;
		document.getElementById("hid_html_code").value = code;
		//document.frmhome.action = burl + "/group-home-tab-preview";
		//alert(document.frmhome.action);
		document.frmhome.submit();
	}
	else if(btnval == "Update")
	{
		if(document.getElementById("chkId").checked == true)
		{
			var status = 1;
		}
		else if(document.getElementById("chkId").checked == false)
		{
			var status = 0;
		}	
		code = document.getElementById("txtId").value;
		document.getElementById("hid_html_code").value = code;		
		document.getElementById("hid_status").value = status;		
		//document.frmhome.action = burl + "/group-home-tab-update";
		document.frmhome.submit();
	}*/
}
// =================================== Functions for GROUP HOME TAB - END =====================================================

// ==================================== Functions for PROMO CODES - START =====================================================
function promocode_deactivate(btnval, burl, uid, nid, ctr)
{
	//alert(btnval+" == "+nid+" =hello= "+ctr);
	var url = burl +  "/php_includes/promocode_deactivate.php?uid="+uid+"&nid="+nid+"&burl="+burl+"&btnval="+btnval+"&ctr="+ctr;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_promocode_deactivate;
	http.send(null);
}

function handleHttpResponse_promocode_deactivate()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("==");
			if(res[0] == "success")
			{				
				//document.getElementById('confmsg').innerHTML = "Promo code has been successfully updated!!";
				//window.location = res[2] + "/promo-codes-list";
				if(res[3] == "deactive")
				{
					alert("Promo code has been Deactivated successfully.");
					document.getElementById("btn_"+res[4]).value = "Activate";
				}
				else if(res[3] == "active")
				{
					alert("Promo code has been Activated successfully.");
					document.getElementById("btn_"+res[4]).value = "Deactivate";			
				}
			}
			else if(res[0] == "unsuccess")
			{
				alert("Internal Error found.");
				//document.getElementById('confmsg').innerHTML = "Internal Error found.";
				window.location = res[2] + "/promo-codes-list";
			}
			return false; 
		}
	}
}

// ==================================== Functions for PROMO CODES - END =======================================================

// ==================================== Function for RUN YOUR OWN ADS - START =======================================================

function chkRunAdsFields()
{
	var taval = document.getElementById("ta_adcode").value;
	if(taval == "")
	{
		alert("Please enter any code");
		document.getElementById("ta_adcode").focus();
		return false;
	}
	else
	{
		var chk_turnoffyes = document.getElementById("chk_turnoffyes").checked;
		if(chk_turnoffyes == true)
		{
			document.getElementById("hid_cbval").value = "yes";
		}
		else if(chk_turnoffyes == false)
		{
			document.getElementById("hid_cbval").value = "no";
		}
	}
}

// ==================================== Function for RUN YOUR OWN ADS - END =======================================================

function checkhomepage(gid, burl)
{
       
	var url = burl +  "/php_includes/checkhomepage.php?gid="+gid+"&burl="+burl;
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_checkhomepage;
	http.send(null);                 
}

function handleHttpResponse_checkhomepage()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4) 
	{
		if(http.status==200) 
      	{	
			var results = http.responseText;		        
			var ctr = results.split("<><>");
			
			if(ctr[0] == 0)
			{
				window.location.href = ctr[1] + "/node/" + ctr[2];
			}
			else if(ctr[0] > 0)
			{
				window.location.href = ctr[1] + "/" + ctr[4] + "/?pt=o";
			}
			else
			{
				alert("Some internal error has been occured!");
			}
		}
	}
}

// GROUP HOME TAB - START ====================================================================================================

function onUpdate_grouphometab(btnval, burl, uid, gid)
{
	if(btnval == "Preview")
	{
		document.getElementById("node-form").action = burl + "/group-home-tab-preview";
		document.getElementById("node-form").submit();
	}
}
// GROUP HOME TAB - END ======================================================================================================



//============================================= START FREE TRIAL NOW - START ============================================
$(document).ready(function() {
	$("#oldest_first_btn").click(function() {
		var bpath = Drupal.settings.basePath;

		var hid_groupid = $("#hid_groupid").val();
		var hid_allgroupadmin = $("#hid_allgroupadmin").val();
		var hid_topicurl = $("#hid_topicurl").val();
		var hid_burl = $("#hid_burl").val();
		var hid_grpname = $("#hid_grpname").val();

		$.ajax({
			type: "GET",
			url: bpath+'php_includes/set_session_comment_order.php?commorder=asc&groupid='+hid_groupid+'&allgroupadmin='+hid_allgroupadmin+'&topicurl='+hid_topicurl+'&burl='+hid_burl+'&groupnameval='+hid_grpname,
			data: "",
			success: function(msg){
				$("#dynamic_content").html(msg);
			}
		});
	});
	
	$("#newest_first_btn").click(function() {
		var bpath = Drupal.settings.basePath;
		
		var hid_groupid = $("#hid_groupid").val();
		var hid_allgroupadmin = $("#hid_allgroupadmin").val();
		var hid_topicurl = $("#hid_topicurl").val();
		var hid_burl = $("#hid_burl").val();
		var hid_grpname = $("#hid_grpname").val();
		
		$.ajax({
			type: "GET",
			url: bpath+'php_includes/set_session_comment_order.php?commorder=desc&groupid='+hid_groupid+'&allgroupadmin='+hid_allgroupadmin+'&topicurl='+hid_topicurl+'&burl='+hid_burl+'&groupnameval='+hid_grpname,
			data: "",
			success: function(msg){
				$("#dynamic_content").html(msg);
			}
		});
	});
	
	$("#start_free_trial_now").click(function() {
		var bpath = Drupal.settings.basePath;
		$.ajax({
			type: "POST",
			url: bpath+'start/free/trial/now',
			data: "",
			success: function(msg){
				
				if(msg == "success")
				{
					alert("Congratulation! your free trial subscription has been activated.");
					location.reload();
				}
				else
				{
					alert("Error occured! Please try again.");					
				}
			}
		});
	});
});
//============================================= START FREE TRIAL NOW - END ==============================================



//======================================= REMOVE MEMBER (MEMBERS NAV. TAB) - START ======================================
function getUid(selulist, burl)
{
	var reply = confirm("Are you sure you want to remove this member from this group");
	if(reply == true)
	{
		var hid_gid = document.getElementById("hid_gid").value;		
		var url = burl +  "/remove/members?selulist="+selulist+"&hid_gid="+hid_gid;
		http.open("GET",url,true);
		http.onreadystatechange = handleHttpResponse_removemem;
		http.send(null); 
	}
}

function handleHttpResponse_removemem()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4) 
	{
		if(http.status==200) 
      	{	
			var results = http.responseText;
		    alert(results);
			location.reload();
		}
	}
}
//======================================= REMOVE MEMBER (MEMBERS NAV. TAB) - END ======================================




//=========================== CHECK AND CLOSE PROPUP CALENDAR (ADMIN PANEL PAGE) - START ===============================
function chk_and_close_popupcal()
{
	var pagetype = "";
	var href_path1 = document.location.href;
	//var pos = href_path1.search("my-emeetings");
	var pos = href_path1.search("online-meetings");	
	if(pos != -1)
	{
		//var href_path = href_path1.split("my-emeetings");
		var href_path = href_path1.split("online-meetings");
		//pagetype = "my-emeetings";
		pagetype = "online-meetings";
	}
	else
	{
		var pos1 = href_path1.search("admin/panel");
		if(pos1 != -1)
		{
			var href_path = href_path1.split("admin/panel");
			pagetype = "admin/panel";
		}
	}
	
	var calBorder = document.getElementById("calBorder");
	
	if(pagetype == "admin/panel" && calBorder != null)
	{
		document.getElementById("calBorder").style.display = "none";
	}
}
//=========================== CHECK AND CLOSE PROPUP CALENDAR (ADMIN PANEL PAGE) - END ===============================

//=========================== js for group-blog section-----start ===============================
$(document).ready(function() {
	
	$("#edit-field-blog-tags-0-value").blur(function() {	
		var str = $('#edit-field-blog-tags-0-value').val();
		alert(str);
		if(str != "")
		{
			var pattern = "/[a-z A-Z]+\,[a-z A-Z]+/";
			var reg = new RegExp(pattern);
			if(reg.test(str))
			{
				alert("Please this format abc, abd ...!!");	
				$('#edit-field-blog-tags-0-value').val("");			
			} 
		}
		
		//$("#edit-field-blog-tags-0-value").focus();  
	});

	$("#blogsave").click(function() {
		$("#node-form").submit();
	});

    if($('#edit-field-email-group-option-value').is(':checked')) {
        $("#member_select").show();
        $("#edit-submit").val("Save and Email");
    }

    $('#edit-field-email-group-option-value').click(function(e){
     if($(this).is(":checked")){
      $("#edit-submit").val("Save and Email");
      $("#member_select").show();
     }
     else {
      $("#edit-submit").val("Save");
      $("#member_select").hide();
     }
    });
});

//=========================== js for group-blog section-----End ===============================

//=========================== js for group-project section-----Start ===============================
$(document).ready(function()
{
	$("#mark_btn").click(function()
	{
		document.getElementById('edit-field-project-complete-0-value').value = 100;
		$("#edit-taxonomy-3 option[value='31']").attr('selected', 'selected');
		
	});

	$("#edit-taxonomy-3").change(function()
	{
		if(document.getElementById('edit-taxonomy-3').value == "31")
		{
			document.getElementById('edit-field-project-complete-0-value').value = "";
		}
	});

});
//=========================== js for group-project section-----Start ===============================

//=========================== js for group-task section-----Start ===============================
$(document).ready(function()
{
	$("#mark_btn").click(function()
	{
		document.getElementById('edit-field-task-complete-0-value').value = 100;
		$("#edit-taxonomy-4 option[value='35']").attr('selected', 'selected');
	});

	$("#edit-taxonomy-3").change(function()
	{
		if(document.getElementById('edit-taxonomy-3').value == "35")
		{
			document.getElementById('edit-field-project-complete-0-value').value = "";
		}
	});


    if($('#edit-field-task-email-option-value').is(':checked')) {
        $("#member_select").show();
        $("#edit-submit").val("Save and Email");
    }

    $('#edit-field-task-email-option-value').click(function(e){
     if($(this).is(":checked")){
      $("#edit-submit").val("Save and Email");
      $("#member_select").show();
     }
     else {
      $("#edit-submit").val("Save");
      $("#member_select").hide();
     }
    });
});
//=========================== js for group-task section-----End ===============================

function onunpublish(burl, id, gid)
{	
	window.location.href = burl + "/unpublish-hometab/" + id + "/" + gid;
}

function unpublish_masthead(burl, id, gid)
{	
	window.location.href = burl + "/unpublish-masthead/" + id + "/" + gid;
	
}

function changeCat(){
//alert($('#blog_category').val());
//alert($('#url').val());
if($('#blog_category').val() != '')
window.location = $('#blog_category').val();
}

