//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 == "Search for groups, people, discussions")
	{
		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 = "Search for groups, people, discussions";
	}
}


/* Global Search - START */

function searchchk()
{
	if(document.getElementById('searchtxt').value == 'Search for groups, people, discussions')
	{
		document.getElementById('searchtxt').value = '';
	}
}

function chksearch()
{
	if(document.getElementById('searchtxt').value == '' || document.getElementById('searchtxt').value == 'Search for groups, people, discussions')
	{
		document.getElementById('searchtxt').value = 'Search for groups, people, discussions';
	}
}
       
function search(bpath)
{
	var sid = document.getElementById('searchtxt').value;
	if(sid == "Search for groups, people, discussions")
	{
		sid = "";
	}	
	document.frm.action = bpath + "global-search?search=" + sid;
	document.frm.submit();
}


/* 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 = '';
	}
}

function chksearch_grs()
{
	if(document.getElementById('searchtxtgrs').value == '' || document.getElementById('searchtxtgrs').value == 'Search this group')
	{
		document.getElementById('searchtxtgrs').value = 'Search this group';
	}
}
       
function search_grs(bpath)
{
	var sid = document.getElementById('searchtxtgrs').value;
	document.frm.action = bpath + "group_search?search=" + sid;
	document.frm.submit();
}


/* 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;
		
		//== 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;

		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 emeeting duration.";
		}
		else if(document.getElementById('hrs').value == "hr")
		{
			errors[errors.length] = "Please enter the proper emeeting duration.";
		}
		else if(document.getElementById('mins').value == "min")
		{
			errors[errors.length] = "Please enter the proper emeeting duration.";
		}
		else if(document.getElementById('hrs').value == 0 && document.getElementById('mins').value == 0)
		{
			errors[errors.length] = "Please enter the proper emeeting duration.";
		}
// ==================================================================================================
		if (!ck_name.test(rname)) 
		{
			errors[errors.length] = "Room name must be less than 60 characters.";
		}
		else
		{
			if(rname.search(" ") != "-1")
			{
				errors[errors.length] = "Spaces are not allowed in RoomName.";
			}
		}

		if (!ck_name.test(agenda)) 
		{
			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;
			//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 =====================================================
function manageInsert(val, burl) 
{
	var errors = [];

	if(document.getElementById("scrname").value=="" || document.getElementById("scagenda").value=="" || document.getElementById("scinvityname").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=="")
		{
			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;
 		
		//== 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 emeeting duration.";
		}
		else if(document.getElementById('schr').value == "hr")
		{
			errors[errors.length] = "Please enter the proper emeeting duration.";
		}
		else if(document.getElementById('scmin').value == "min")
		{
			errors[errors.length] = "Please enter the proper emeeting duration.";
		}
		else if(document.getElementById('schr').value == 0 && document.getElementById('scmin').value == 0)
		{
			errors[errors.length] = "Please enter the proper emeeting duration.";
		}
		// ================================================================================================

		if (!ck_name.test(rname)) 
		{
			errors[errors.length] = "Room name must be less than 60 characters.";
		}
		else
		{
			if(rname.search(" ") != "-1")
			{
				errors[errors.length] = "Spaces are not allowed in RoomName.";
			}
		}

		if (!ck_name.test(agenda)) 
		{
			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 url = burl + "/php_includes/insert_meeting.php?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;
			//alert(url);
			http.open("GET",url,true);
			http.onreadystatechange = handleHttpResponse_insert;
			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 handleHttpResponse_insert()
{
	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 meeting has been scheduled, but no mail has been sent to all invitees.");
			}
			else if(ctr[0] > 0)
			{
				window.location.reload(true);
				alert("Your meeting has been scheduled and mail has been sent to all invitees.");
			}
			else
			{
				alert("Some internal error has been occured!");
			}
		}
	} 
}
//================================================= 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 featured_Update(type, nid, burl, gid)
{	
	var url = burl + "/php_includes/update_featured.php?nid="+nid+"&type="+type+"&gid="+gid+"&burl="+burl;
	//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] == "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";
				}
			}
			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")
		{      
		        checkhomepage(gid, burl);
			//window.location.href = burl + "/node/" + gid;
			//alert(window.location.href);
		}
		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-privilages";
		}
		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";
		}
		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 == "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";
		}
	}
}

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";
	}
	else if(id == "visb_on_boomity")
	{
		var val = "off";
	}
	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 ======================================================================


//=================================================== User Privilages - START ======================================================================

function setUserPrivilages(chkid, pr_type, uid, gid, user_type, seatpur, burl)
{
	var cb_val;	
	if(document.getElementById(chkid).checked)
	{
		cb_val = 1;
	}
	else
	{
		cb_val = 0;
	}
	
	var url = burl +  "/php_includes/set_user_privilages.php?cb_val="+cb_val+"&pr_type="+pr_type+"&uid="+uid+"&gid="+gid+"&utype="+user_type+"&seatpur="+seatpur;
	//alert(url);
	http.open("GET",url,true);
	http.onreadystatechange = handleHttpResponse_setUPrv;
	http.send(null);
}

function handleHttpResponse_setUPrv()
{
	if(http.readyState < 4)
	{}
	if(http.readyState == 4)
	{
		if(http.status==200)
		{
			var results = http.responseText;
			var res = results.split("<><>");
			if(res[0] == "group")
			{
				alert(res[1]);
			}
			else if(res[0] == "prtools")
			{
				if(res[1] == "Premium tools access allowed successfully.")
				{
					document.getElementById('rem_seat').innerHTML = (parseInt(document.getElementById('rem_seat').innerHTML) - parseInt(1));
				}
				else if(res[1] == "Premium tools access removed successfully.")
				{
					document.getElementById('rem_seat').innerHTML = (parseInt(document.getElementById('rem_seat').innerHTML) + parseInt(1));
				}
				alert(res[1]);
			}			
			return false;
		}
	}
}

//=================================================== User Privilages - 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;
		}
	}
}

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 = "";
			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[2] != "")
			{
				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).checked == true)
		{
			ids_var += "," + document.getElementById('chklist_'+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++)
		{
			document.getElementById('chklist2_'+i).checked = true;
		}
	}
	else if(document.getElementById('chkmain2').value == "checked")
	{
		document.getElementById('chkmain2').value = "unchecked";
		for(i=1;i<=paging;i++)
		{
			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;
		}
	}
	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_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 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++)
		{
			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++)
		{
			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++)
		{
			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++)
		{
			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);
	}
}

//=================================================== 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)
{
	if(document.getElementById("embedId").value == "")
	{
		alert("Please enter an embed code first!!");
		//document.getElementById("chkId").checked = false;
	}
	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;		
		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;
		        //alert(results);
			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 ======================================================================================================
