var security;
function closeportalwindow()
{
    closeModalWindow('addCommunityPortal');
	if(security != "1")
	{	
		var content = document.getElementById('portalcontent');
		content.style.display = "block";
		var message = document.getElementById('portalmessage');
		message.style.display = "none";
	}
}
var toggleSelect = "unchecked";
function selectAllMessages()
{
	var cont = document.getElementsByTagName("input");
	
	if (toggleSelect == "unchecked")
		{
		for (var i=0; i<cont.length; i++)
			{
			if (cont[i].type == "checkbox")
				{
				cont[i].checked = "true";
				}
			}
		toggleSelect = "checked";
		}
	else
		{
		for (var i=0; i<cont.length; i++)
			{
			if (cont[i].type == "checkbox")
				{
				cont[i].checked = "";
				}
			}
		toggleSelect = "unchecked";
		}
	
	
}
function inviteOthers()
{

	var security = getSelectedRadioValue('shareOptionsAdd');
	//showFeedback('inviteOthersActionContainer');     
	if (security == 5)
	{
		var iframedoc = document.getElementById('uploadfileIFRAMEInv').contentDocument;
		if (iframedoc == null){
		    iframedoc = document.getElementById('uploadfileIFRAMEInv').contentWindow.document;
		}
		
		var fname = iframedoc.getElementById('file').value;

        //stop user from uploading a file with 'invalid' characters
        if (!isValidFileName(fname) && hasWhiteSpace(fname))
	    {
    	    alert('Your CSV filename cannot contain symbols or spaces. Please rename your file and upload it again.');
		    return ;
	    }

        showFeedback('inviteOthersActionContainer');     
		if (fname != '')
		{
			var uploadguid = iframedoc.getElementById('guid').value;
    		iframedoc.getElementById("fileErr").innerHTML = "";
			document.getElementById('uploadfileIFRAMEInv').contentWindow.submitform();
		}	
	}
	else
	{
	    showFeedback('inviteOthersActionContainer');     
		
		var Email = getControlValue('txtEmail');
		var groupIDs = getGroupIDs("ulGroups");
		if (groupIDs[0] == null)
		{
			groupIDs[0] = 0;
		}
		var friendsIDs = getFriendsIDs("ulFriends");
		if(friendsIDs[0] == null)
		{
			friendsIDs[0] = 0;
		}
		engPortal.inviteOthers(Email, security, groupIDs, friendsIDs, callback_inviteOthers);
	}
	
    
}

function callback_inviteOthers(res)
{
  checkResponse(res.value);
  var results  = res.value.Tables[0];
  if (results.Rows[0].result == "True")
   {
		var controls = res.value.Tables[1];
		
		switch(results.Rows[0].errMessage)
		{
			case "valid":
				feedbackValid('Saving','Saved');
				window.setTimeout('hideinviteOthers();', 7000);
				break;
				
			case "NonRegisteredUsers":
			    alert("One (or more) of the email addresses provided is not\nyet registered on Obami, and therefore can not be invited.\nIf they sign up to Obami in future, they will receive\nan invitation to join your community portal.");
                feedbackValid('Saving','Saved');
				window.setTimeout('hideinviteOthers();', 7000);			    
			    break;
		}
	}
	else
	{
		var controls = res.value.Tables[1];
		switch (results.Rows[0].errMessage)
		{
			case "invalid":
				feedbackInvalid('inviteOthersActionContainer');
				window.setTimeout(function(){processValidationResponse(controls);}, 2001);
				break;
		}

	}
}
function hideinviteOthers()
{
	cleanupFeedback('inviteOthersActionContainer');
	closePortalModalWindow('inviteOthers');
	window.location = location.href;

}
function addPortal(){  
    showFeedback('addPortalActionContainer');	
    updateFeedbackMessage('Uploading_Image');
	saveimgFile('Add');
}

function ChangeFullScreenModeOff() {
 if ($('radYesFullScreen') != null) { $('radYesFullScreen').checked = false;}
 if ($('radNoFullScreen') != null) { $('radNoFullScreen').checked = true;}    
}

function ChangeFullScreenModeOn() {

 if ($('radYesFullScreen') != null) { $('radYesFullScreen').checked = true;}
 if ($('radNoFullScreen') != null) { $('radNoFullScreen').checked = false;}
}

function SetAddUploadImageToDone(filenames) {
   updateFeedbackMessage('Image_Uploaded');
   var fdata = filenames.split(":");
   var files = new Array();
      
     if (fdata.length == 1) {
         var tmp = fdata[0].split("|");
         if (tmp[0] == 'badge') {
            files[0] = tmp[1]; 
            files[1] = '';        
         }
         else if (tmp[0] == 'header') {
            files[0]='';
            files[1] = tmp[1];
         }
         else if (tmp[0] == '') {
            files[0]='';
            files[1] = '';
         }
     }
     else if (fdata.length == 2) {
         var tmp1 = fdata[0].split("|");
         var tmp2 = fdata[1].split("|");
            files[0] = tmp1[1]; 
            files[1] = tmp2[1];   
     }
     else {
        files[0] = '';
        files[1] = '';     
     }   
   
	security = getSelectedRadioValue('shareOptionsAdd');
	//stop user from uploading a file with 'invalid' characters, if theyre importing a csv
	if (security == 5) 
	{     
        var iframedoc = document.getElementById('uploadfileIFRAME').contentWindow.document;
        var fname = iframedoc.getElementById('file').value;
        
	    if (!isValidFileName(fname) && hasWhiteSpace(fname))
	    {
	        alert('Your CSV filename cannot contain symbols or spaces. Please rename your file and upload it again.');
		    return ;
	    }
	    
    }
	
	var title = getControlValue('txtCommunityPortalTitle');
	if(security != "1" && security != "0")
	{
		var content = document.getElementById('portalcontent');
		if(content.style.display == "block")
		{
			content.style.display = "none";
			var message = document.getElementById('portalmessage');
			message.style.display = "block";
			setSpanValue('portalname1',title);
			setSpanValue('portalname2',title);
		}
	}
	
	var category = getDropDownSelected('ddCategory');
	var subcategory = getDropDownSelected('ddSubCategory');
	var tags = getControlValue('txtTags');
	
	var groupIDs = getGroupIDs("ulGroups");
	if (groupIDs[0] == null)
	{
		groupIDs[0] = 0;
	}
	var friendsIDs = getFriendsIDs("ulFriends");
	if(friendsIDs[0] == null)
	{
		friendsIDs[0] = 0;
	}
	var invitation = getSelectedRadioValue('radinvitation');
	var Moderators = 1;
	var modPubFriendsIDs = new Array();
	modPubFriendsIDs[0] = 0;
	var modGrpFriendsIDs = new Array(); 
	modGrpFriendsIDs[0] = 0;
	var approve = getSelectedRadioValue('radapprove');
        
    var ViewSource = $('cbAddPortalShowSource').checked;

    var fullViewMode = 1;
    if ($('radYesFullScreen') != null) {
     if ($('radYesFullScreen').checked) {
        fullViewMode = 1;
     }
     else {
        fullViewMode = 0;
     }
    }
    else if ($('radNoFullScreen') != null) {
     if ($('radNoFullScreen').checked) {
        fullViewMode = 0;
     }
     else {
        fullViewMode = 1;
     }    
    }
    else {
        fullViewMode = 1;
    }
    
    engPortal.addNewPortal('txtCommunityPortalTitle', title, category, subcategory, tags, security, groupIDs, friendsIDs, invitation, Moderators, modPubFriendsIDs, modGrpFriendsIDs, approve, imguploadguid, files[0],  files[1], ViewSource,fullViewMode, callback_addPortal);
}

function callback_addPortal(res){
checkResponse(res.value);
 var results  = res.value.Tables[0];
 if (results.Rows.length > 0)
     {
        if (results.Rows[0].result == "True") {
	        var controls = res.value.Tables[1];
	        //for(var i=0; i<controls.Rows.length;i++)
	        //{
	        //	setControlErrorMessage(controls.Rows[i].controlID,'');
	        //}
    	
	        switch(results.Rows[0].errMessage)
	        {
		        case "valid": 
			        var security = getSelectedRadioValue('shareOptionsAdd');
        			
    			    if (security == 0 || security == 1) {
				            feedbackValid('Saving','Saved');
				            window.setTimeout('hideAddPortal()', 14000);	    			
    			    }
    			    else {
			            if (security == 5)
			            {
			        	    saveFile();	
			            }
			            feedbackValid('Saving','Saved');
			            window.setTimeout('ShowAddPortalCloseButton()', 5000);			        		        
    			    }
        			

			        break;
    			
	        }
	     }
     }
 else
    {
	    var controls = res.value.Tables[1];
	    switch (controls.Rows[0].errMessage)
		    {
			    case "invalid":
				    feedbackInvalid('addPortalActionContainer');
				    window.setTimeout(function(){processValidationResponse(controls)}, 2001);
				    break;
				case "Please seperate your tags keywords with commas.":
				    feedbackInvalid('addPortalActionContainer');
				    window.setTimeout(function(){processValidationResponse(controls)}, 2001);
				    break;				
		    }

    }
}
function hideAddPortal()
{    
	cleanupFeedback('addPortalActionContainer');
	closeportalwindow();
	$('ShowAddPortalCloseButton').style.display='none';
	window.location = "/myCommunityPortals/index.aspx?ddlMemberOption=ManagePortalSharing";
}

function ShowAddPortalCloseButton() {
    removeFeedback('addPortalActionContainer');
    $('ShowAddPortalCloseButton').style.display='block';
}

function showPrivateOptions(){

	setControlDisplay('addPortalGroups', 'none');
	setControlDisplay('addportalFriends', 'none');
	setControlDisplay('addportalCsv', 'none');
	setControlDisplay('addEmails', 'none');
}

function showShareOptions(){
	setControlDisplay('addPortalGroups', 'none');
	setControlDisplay('addportalFriends', 'none');
	setControlDisplay('addportalCsv', 'none');
	Effect.SlideDown('addEmails');	
}
function showPublicOptions(){

	setControlDisplay('addPortalGroups', 'none');
	setControlDisplay('addportalFriends', 'none');
	setControlDisplay('addportalCsv', 'none');
	setControlDisplay('addEmails', 'none');
}

function showGroupsOptions(){

	Effect.SlideDown('addPortalGroups');
	setControlDisplay('addportalFriends', 'none');
	setControlDisplay('addportalCsv', 'none');
	setControlDisplay('addEmails', 'none');

}
function showCsvOptions(){

	Effect.SlideDown('addportalCsv');
	setControlDisplay('addportalFriends', 'none');
	setControlDisplay('addPortalGroups', 'none');
	setControlDisplay('addEmails', 'none');
}

function showdonotshare(){
setControlDisplay('addmodFriends', 'none');
}

function showdoshare(){
  var security = getSelectedRadioValue('shareOptionsAdd');
  
  switch(security)
  {
  
	case '0':
	Effect.SlideDown('addmodFriends');
	break;
	case '1':
	//setControlDisplay('addModFriends', 'none')
	break
	
	case '2':
	var groupIDs = getGroupIDs("ulGroups");
	if (groupIDs[0] != void 0)
		{
			engPortal.getUsersForGroup(groupIDs, callback_groupMembers);
			Effect.SlideDown('addmodFriendslist');
		}
	break;
	
	case '4':
	var friendsIDs = getFriendsIDs("ulFriends");
	if(friendsIDs[0] != void 0)
		{
			var friendsUsername = getFriendsUsername("ulFriends");		
			var ul = document.getElementById("ulmodFriendList");	
				
			for (var i = 0; i<friendsIDs.length; i++)
							{
							var chk = document.createElement("input");
							chk.type = "checkbox";
							chk.value = friendsIDs[i];
							chk.id = "cm_"+ friendsIDs[i];
							 							
							var lbl = document.createElement("label");
							lbl.innerHTML = friendsUsername[i];
							lbl.id = "lm_"+ friendsUsername[i];
							
						var li = document.createElement("li");
											
							li.appendChild(chk);
							li.appendChild(lbl);
														
							ul.appendChild(li);
							}
		
		Effect.SlideDown('addmodFriendslist');			
		}
	break;
	
	case '5':
	
	
	
	
	break;
  }
  
}
function callback_groupMembers(res){
if (res.error!=null){alert(res.error)};
checkResponse(res.value);
	
	var dt = res.value;
		
				var ul = document.getElementById("ulmodFriendList");	
				if (dt.Rows.length != 0)
					{
						for (var i = 0; i<dt.Rows.length; i++)
							{
							var chk = document.createElement("input");
							chk.type = "checkbox";
							chk.value = dt.Rows[i].User_ID;
							chk.id = "cm_"+ dt.Rows[i].User_ID;
							 							
							var lbl = document.createElement("label");
							lbl.innerHTML = dt.Rows[i].Username;
							lbl.id = "lm_"+ dt.Rows[i].User_ID;
							
						    var li = document.createElement("li");
											
							li.appendChild(chk);
							li.appendChild(lbl);
														
							ul.appendChild(li);
							}
					
					}
			
}

function hideGroupPanel(){
	if (document.getElementById('ulGroups').style.display != "none")
		{
			Effect.SlideUp('addPortalGroups');
		}
	if(document.getElementById('ulFriends').style.display != "none")
		{
			Effect.SlideUp('addEventFriends');
		}
	
}

function getGroupIDs(controlID){
	var chks = document.getElementById(controlID).getElementsByTagName("input");
	
	var idList = new Array();
	var counter = 0;
	for (var i=0; i<chks.length; i++)
		{
		if (chks[i].type == "checkbox")
			{
			if (chks[i].checked)
				{
				
				idList[counter] = chks[i].value;
				counter = counter + 1;
				}
			}
		}
	
	return idList;			
}

function getFriendsIDs(controlID){
	var chks = document.getElementById(controlID).getElementsByTagName("input");
	var idList = new Array();
	var counter = 0;
	for (var i=0; i<chks.length; i++)
		{
		if (chks[i].type == "checkbox")
			{
						
				idList[counter] = chks[i].value;
				counter = counter + 1;
				
			}
		}
	return idList;
}
function getFriendsUsername(controlID){
	var chks = document.getElementById(controlID).getElementsByTagName("input");
	var idList = new Array();
	var counter = 0;
	for (var i=0; i<chks.length; i++)
		{
		if (chks[i].type == "checkbox")
			{
						
				idList[counter] = chks[i].name;
				counter = counter + 1;
				
			}
		}
	return idList;
}


function clearGroupIDs(controlID){
	var chks = document.getElementById("ulGroups").getElementsByTagName("input");
	
	var idList = new Array();
	var counter = 0;
	for (var i=0; i<chks.length; i++)
		{
		if (chks[i].type == "checkbox")
			{
			if (chks[i].checked)
				{
				
				chks[i].checked = false;
				}
			}
		}
	
	return idList;			
}

function showFriendsOptions(){
		//setControlDisplay('pubAddEmail', 'none');
		
		if (document.getElementById('ulGroups').style.display != "none")
		{
			setControlDisplay('addPortalGroups', 'none');
		//	Effect.SlideUp('addPortalGroups');
		}
		setControlDisplay('addportalCsv', 'none');
		setControlDisplay('addEmails', 'none');
		var ul = document.getElementById("ulFriends"); 
		Effect.toggle('addportalFriends','blind');
		
}
function callback_AutoCompleteFriends(res){

checkResponse(res.value);

	if (res.value != null)
		{
		var ds = res.value;
		var listControlID = "autoCompleteListtxtFriends";
		var listControlWrapper = "txtFriendsListWrapper";
		document.getElementById(listControlID).innerHTML = "";
		
		var ul = document.createElement("ul");
		ul.id = "autoList";
		
		if (ds != null && typeof(ds) == "object" && ds.Rows.length != 0)
			{
			
			for (var i=0; i<ds.Rows.length; i++)
				{
				var li = document.createElement("li");
				var a = document.createElement("a");

				a.href = "javascript:completeFriends('" + ds.Rows[i].UserID + "','" + ds.Rows[i].Username + " (" + ds.Rows[i].firstname + " " + ds.Rows[i].lastname.replace("'", "") + ")" + "');void(0);";
				a.innerHTML = ds.Rows[i].Username+ " ("+ds.Rows[i].firstname + " " + ds.Rows[i].lastname+")";
				
				li.appendChild(a);
				ul.appendChild(li)
				}
		
				
			document.getElementById(listControlID).appendChild(ul);
			document.getElementById(listControlWrapper).style.display = "block";
			document.getElementById(listControlID).style.display = "block";
		
			}
		else
			{
			document.getElementById(listControlWrapper).style.display = "none";
			document.getElementById(listControlID).style.display = "none";
			}
		
		}
}
function completeFriends(accID, username)
{
	Effect.Fade('txtFriendsListWrapper');
	var ul = document.getElementById("ulFriendsList");	
	var chks = document.getElementById("ulFriendsList").getElementsByTagName("input");
	var counter = 0;
	if(chks.length != 0)
	{
		for(var i=0;i<chks.length;i++)
		{
				if(accID == chks[i].value)
				{
					counter = 1;
				}
		}			
			
		if(counter == 0)
		{
			var chk = document.createElement("input");
			chk.type = "checkbox";
			chk.value = accID;
			chk.id = "c_"+accID;
			chk.name = username;
			chk.style.display = "none"; 
			var lbl = document.createElement("label");
			lbl.innerHTML = username;
			lbl.id = "l_"+accID;
			var img = document.createElement("img");
			img.id = "i_"+accID;
			img.alt ="Remove";
			img.src="/images/icons/delete.gif";
			var aImg = document.createElement("a");
			aImg.href ="javascript:deleteFriend(" + accID + ");";
			aImg.id = "a_"+accID;
			aImg.appendChild(img);
			var li = document.createElement("li");
			li.id="l_"+accID;
			li.appendChild(chk);
			li.appendChild(lbl);
			li.appendChild(aImg);			
			ul.appendChild(li);
		}
		else
		{
			alert('You have already selected to share the event with this person.');
		}
		
	}
	else
	{
		var chk = document.createElement("input");
		chk.type = "checkbox";
		chk.value = accID;
		chk.id = "c_"+accID;
		chk.name = username
		chk.style.display = "none"; 
		var lbl = document.createElement("label");
		lbl.innerHTML = username;
		lbl.id = "l_"+accID;
		var img = document.createElement("img");
		img.id = "i_"+accID;
		img.alt ="Remove";
		img.src="/images/icons/delete.gif";
		var aImg = document.createElement("a");
		aImg.href ="javascript:deleteFriend(" + accID + ");";
		aImg.id = "a_"+ accID;
		aImg.appendChild(img);
		var li = document.createElement("li");
		li.id="l_"+accID;
		li.appendChild(chk);
		li.appendChild(lbl);
		li.appendChild(aImg);			
		ul.appendChild(li);
	}
	document.getElementById("txtFriends").value = "";
}

function callback_AutoCompletemodFriends(res){

checkResponse(res.value);

	if (res.value != null)
		{
		var ds = res.value;
		var listControlID = "autoCompleteListmodtxtFriends";
		var listControlWrapper = "txtmodFriendsListWrapper";
		document.getElementById(listControlID).innerHTML = "";
		
		var ul = document.createElement("ul");
		ul.id = "autoList";
		
		if (ds != null && typeof(ds) == "object" && ds.Rows.length != 0)
			{
			
			for (var i=0; i<ds.Rows.length; i++)
				{
				var li = document.createElement("li");
				var a = document.createElement("a");
			
				a.href = "javascript:completemodFriends('" + ds.Rows[i].UserID + "','" + ds.Rows[i].Username + " ("+ds.Rows[i].firstname + " " + ds.Rows[i].lastname+")"+ "');void(0);";
				a.innerHTML = ds.Rows[i].Username+ " ("+ds.Rows[i].firstname + " " + ds.Rows[i].lastname+")";
				
				li.appendChild(a);
				ul.appendChild(li)
				}
		
				
			document.getElementById(listControlID).appendChild(ul);
			document.getElementById(listControlWrapper).style.display = "block";
			document.getElementById(listControlID).style.display = "block";
		
			}
		else
			{
			document.getElementById(listControlWrapper).style.display = "none";
			document.getElementById(listControlID).style.display = "none";
			}
		
		}
}
function completemodFriends(accID, username)
{
	Effect.Fade('txtmodFriendsListWrapper');
	var ul = document.getElementById("ulmodFriendsList");	
	var chks = document.getElementById("ulmodFriendsList").getElementsByTagName("input");
	var counter = 0;
	if(chks.length != 0)
	{
		for(var i=0;i<chks.length;i++)
		{
				if(accID == chks[i].value)
				{
					counter = 1;
				}
		}			
			
		if(counter == 0)
		{
			var chk = document.createElement("input");
			chk.type = "checkbox";
			chk.value = accID;
			chk.id = "c_"+accID;
			chk.style.display = "none"; 
			var lbl = document.createElement("label");
			lbl.innerHTML = username;
			lbl.id = "l_"+accID;
			var img = document.createElement("img");
			img.id = "i_"+accID;
			img.alt ="Remove";
			img.src="/images/icons/delete.gif";
			var aImg = document.createElement("a");
			aImg.href ="javascript:deletemodFriend(" + accID + ");";
			aImg.id = "a_"+accID;
			aImg.appendChild(img);
			var li = document.createElement("li");
			li.id="l_"+accID;
			li.appendChild(chk);
			li.appendChild(lbl);
			li.appendChild(aImg);			
			ul.appendChild(li);
		}
		else
		{
			alert('You have already selected to share the event with this person.');
		}
		
	}
	else
	{
		var chk = document.createElement("input");
		chk.type = "checkbox";
		chk.value = accID;
		chk.id = "c_"+accID;
		chk.style.display = "none"; 
		var lbl = document.createElement("label");
		lbl.innerHTML = username;
		lbl.id = "l_"+accID;
		var img = document.createElement("img");
		img.id = "i_"+accID;
		img.alt ="Remove";
		img.src="/images/icons/delete.gif";
		var aImg = document.createElement("a");
		aImg.href ="javascript:deletemodFriend(" + accID + ");";
		aImg.id = "a_"+ accID;
		aImg.appendChild(img);
		var li = document.createElement("li");
		li.id="l_"+accID;
		li.appendChild(chk);
		li.appendChild(lbl);
		li.appendChild(aImg);			
		ul.appendChild(li);
	}
	document.getElementById("txtmodFriends").value = "";
}
function deletemodFriend(accID)
{
	var ul = document.getElementById("ulmodFriendsList");
	var chks = document.getElementById("ulmodFriendsList").getElementsByTagName("input");
	var lis = document.getElementById("ulmodFriendsList").getElementsByTagName("li");
	for(var i=0;i<chks.length;i++)
		{
				if(accID == chks[i].value)
				{
					var li = document.getElementById(lis[i].id);
					ul.removeChild(li);
				}
		}	
	
	
}
function deleteFriend(accID)
{
	var ul = document.getElementById("ulFriendsList");
	var chks = document.getElementById("ulFriendsList").getElementsByTagName("input");
	var lis = document.getElementById("ulFriendsList").getElementsByTagName("li");
	for(var i=0;i<chks.length;i++)
		{
				if(accID == chks[i].value)
				{
					var li = document.getElementById(lis[i].id);
					ul.removeChild(li);
				}
		}	
	
	
}

function getFriendsCheckedIDs(controlID){
	var chks = document.getElementById("ulFriends").getElementsByTagName("input");
	var idList = new Array();
	var counter = 0;
	for(var i=0; i<chks.length; i++)
		{
			if(chks[i].type == "checkbox")
				{
					if(chks[i].checked)
					{
						idList[counter] = chks[i].value;
						counter = counter + 1;
					}
				}
		}
		return idList;
}

function publishCommunityPortal(){
	showFeedback('publishCommunityPortalActionContainer');
	engPortal.publishCommunityPortal(callback_publishCommunityPortal);
}

function callback_publishCommunityPortal(res)
{
	checkResponse(res.value);
		var results  = res.value.Tables[0];
		if (results.Rows[0].result == "True")
		{
			var controls = res.value.Tables[1];

			switch(results.Rows[0].errMessage)
				{
					case "valid":
			
						feedbackValid('Publishing','Published');
						window.setTimeout('hidepublishCommunityPortal();', 7000);
						break
				}
		}
		else
		{
			var controls = res.value.Tables[1];
			switch (results.Rows[0].errMessage)
				{
					case "invalid":
						feedbackInvalid('publishCommunityPortalActionContainer');
						window.setTimeout(function(){processValidationResponse(controls)}, 2001);
						break
				}

		}

}

function hidepublishCommunityPortal()
{		
		cleanupFeedback('publishCommunityPortalActionContainer');
		closePortalModalWindow('publishCommunityPortal');
		window.location = window.location;
}
function publishCommunityPortalChanges(){

		var PortalUpdateSummary = getControlValue('textPortalUpdateSummary');
		var Notify = getSelectedRadioValue('radNotify');
		var SendSMS;
		var SendEmail;
		if (document.getElementById('editchkSMS').checked)
			SendSMS = 1
		else
			SendSMS = 0
		if (document.getElementById('editchkEmail').checked)
			SendEmail = 1
		else
			SendEmail = 0
		showFeedback('publishCommunityPortalChangesActionContainer');
		engPortal.publishCommunityPortalChanges(PortalUpdateSummary,Notify,SendSMS,SendEmail, callback_publishCommunityPortalChanges);
}

function callback_publishCommunityPortalChanges(res)
{
	checkResponse(res.value);
		var results  = res.value.Tables[0];
		if (results.Rows[0].result == "True")
		{
			var controls = res.value.Tables[1];

			switch(results.Rows[0].errMessage)
				{
					case "valid":
			
						feedbackValid('Publishing','Published');
						window.setTimeout('hidepublishCommunityPortalChanges();', 7000);
						break
				}
		}
		else
		{
			var controls = res.value.Tables[1];
			switch (results.Rows[0].errMessage)
				{
					case "invalid":
						feedbackInvalid('publishCommunityPortalChangesActionContainer');
						window.setTimeout(function(){processValidationResponse(controls)}, 2001);
						break
				}

		}

}

function hidepublishCommunityPortalChanges()
{		
		cleanupFeedback('publishCommunityPortalChangesActionContainer');
		closePortalModalWindow('publishCommunityPortalChanges');
		//window.location = "/myCommunityPortals/index.aspx";
		window.location = window.location;
}


function  ChangeRadOption() {

 var radyes = $('radyes');
 
 if (radyes.checked) {
	var ele = $('layPortalSum');
	ele.style.display = "block";
 }
 else {
	var ele = $('layPortalSum');
	ele.style.display = "none"; 
 }
}

function showRemoveUser(itemID,userName)
{
	 setSpanValue('removeUserID', itemID);
	 setSpanValue('removeUsername', userName);
	 openModalWindow('deleteCommunityPortalUser')
	  
}


function deleteUser()
{
	var UserId = getSpanValue('removeUserID');
	showFeedback('deleteCommunityPortalUserActionContainer');
	engPortal.deletePortalUser(UserId, callback_deleteUser);
}

function callback_deleteUser(res)
{
	checkResponse(res.value);
		var results  = res.value.Tables[0];
		if (results.Rows[0].result == "True")
		{
			var controls = res.value.Tables[1];

			switch(results.Rows[0].errMessage)
				{
					case "valid":
			
						feedbackValid('Deleting','Deleted');
						window.setTimeout('hidedeleteUser();', 7000);
						break
				}
		}
		else
		{
			var controls = res.value.Tables[1];
			switch (results.Rows[0].errMessage)
				{
					case "invalid":
						feedbackInvalid('deleteCommunityPortalUserActionContainer');
						window.setTimeout(function(){processValidationResponse(controls)}, 2001);
						break
				}

		}

}

function hidedeleteUser()
{		
		cleanupFeedback('deleteCommunityPortalUserActionContainer');
		closePortalModalWindow('deleteCommunityPortalPage');
		window.location = "/myCommunityPortals/index.aspx?ID=0";
}

function deletePortal()
{
	var PortalId = getSpanValue('removePortalID');
	if ($('deleteCommunityPortalFromHomeActionContainer') != null)
	{
		showFeedback('deleteCommunityPortalFromHomeActionContainer');
		engPortal.deletePortal(PortalId, callback_removePortal);
	}
	else {
		showFeedback('deleteCommunityPortalActionContainer');
		engPortal.deletePortal(PortalId, callback_deletePortal);
	}
	
}

function deletePortalForReal() {
    var PortalId = getSpanValue('removePortalID');
    showFeedback('deleteCommunityPortalFromHomeActionContainer');
    engPortal.deletePortalForReal(PortalId, callback_removePortal);
}


function callback_deletePortal(res)
{
	checkResponse(res.value);
		var results  = res.value.Tables[0];
		if (results.Rows[0].result == "True")
		{
			var controls = res.value.Tables[1];

			switch(results.Rows[0].errMessage)
				{
					case "valid":
			
						feedbackValid('Deleting','Deleted');
						window.setTimeout('hidedeletePortal();', 7000);
						break
				}
		}
		else
		{
			var controls = res.value.Tables[1];
			switch (results.Rows[0].errMessage)
				{
					case "invalid":
						feedbackInvalid('deleteCommunityPortalActionContainer');
						window.setTimeout(function(){processValidationResponse(controls)}, 2001);
						break
				}

		}

}

function hidedeletePortal()
{		
		cleanupFeedback('deleteCommunityPortalActionContainer');
		closePortalModalWindow('deleteCommunityPortal');
		window.location = "/index.aspx";
}

function getSubCategorylist(){
	
var Category = getDropDownSelected('ddCategory');

switch(Category)
{
	case "Schools":
			var subCategory = document.getElementById('ddSubCategory');
			subCategory.length = 0;
			var optn0 = document.createElement("OPTION");
			optn0.text = "";
			optn0.value = "";
			subCategory.options.add(optn0);
			var optn1 = document.createElement("OPTION");
			optn1.text = "Internal";
			optn1.value = "Internal";
			subCategory.options.add(optn1);
			var optn2 = document.createElement("OPTION");
			optn2.text = "External";
			optn2.value = "External";
			subCategory.options.add(optn2);
			var optn3 = document.createElement("OPTION");
			optn3.text = "Other";
			optn3.value = "Other";
			subCategory.options.add(optn3);
			break;
	case "Academics":
			var subCategory = document.getElementById('ddSubCategory');
			subCategory.length = 0;
			var optn0 = document.createElement("OPTION");
			optn0.text = "";
			optn0.value = "";
			subCategory.options.add(optn0);
			var optn1 = document.createElement("OPTION");
			optn1.text = "Accounting";
			optn1.value = "Accounting";
			subCategory.options.add(optn1);
			var optn2 = document.createElement("OPTION");
			optn2.text = "Additional Mathematics";
			optn2.value = "Additional Mathematics";
			subCategory.options.add(optn2);
			var optn3 = document.createElement("OPTION");
			optn3.text = "Afrikaans Eerste Taal";
			optn3.value = "Afrikaans Eerste Taal";
			subCategory.options.add(optn3);
			var optn4 = document.createElement("OPTION");
			optn4.text = "Afrikaans Tweede Taal";
			optn4.value = "Afrikaans Tweede Taal";
			subCategory.options.add(optn4);
			var optn5 = document.createElement("OPTION");
			optn5.text = "Art";
			optn5.value = "Art";
			subCategory.options.add(optn5);
			var optn60 = document.createElement("OPTION");
			optn60.text = "Arts and Culture";
			optn60.value = "Arts and Culture";
			subCategory.options.add(optn60);
			var optn61 = document.createElement("OPTION");
			optn61.text = "Advanced Mathematics";
			optn61.value = "Advanced Mathematics";						
			subCategory.options.add(optn61);
			var optn6 = document.createElement("OPTION");
			optn6.text = "Biblical Studies";
			optn6.value = "Biblical Studies";
			subCategory.options.add(optn6);
			var optn7 = document.createElement("OPTION");
			optn7.text = "Biology";
			optn7.value = "Biology";
			subCategory.options.add(optn7);
			var optn8 = document.createElement("OPTION");
			optn8.text = "Business Economics";
			optn8.value = "Business Economics";
			subCategory.options.add(optn8);
			var optn62 = document.createElement("OPTION");
			optn62.text = "Business Studies";
			optn62.value = "Business Studies";
			subCategory.options.add(optn62);
			var optn54 = document.createElement("OPTION");
			optn54.text = "Chapel";
			optn54.value = "Chapel";
			subCategory.options.add(optn54);				
			var optn86 = document.createElement("OPTION");
			optn86.text = "Cognitive Education";
			optn86.value = "Cognitive Education";
			subCategory.options.add(optn86);			                   
			var optn63 = document.createElement("OPTION");
			optn63.text = "Computer Applications Technology";
			optn63.value = "Computer Applications Technology";
			subCategory.options.add(optn63);								
			var optn9 = document.createElement("OPTION");
			optn9.text = "Computer Studies";
			optn9.value = "Computer Studies";
			subCategory.options.add(optn9);
			var optn64 = document.createElement("OPTION");
			optn64.text = "Computers";
			optn64.value = "Computers";
			subCategory.options.add(optn64);			
			var optn10 = document.createElement("OPTION");
			optn10.text = "Computyping";
			optn10.value = "Computyping";
			subCategory.options.add(optn10);
			var optn87 = document.createElement("OPTION");
			optn87.text = "Consumer Studies";
			optn87.value = "Consumer Studies";
			subCategory.options.add(optn87);		
			var optn85 = document.createElement("OPTION");
			optn85.text = "Creativity";
			optn85.value = "Creativity";
			subCategory.options.add(optn85);			
			var optn55 = document.createElement("OPTION");
			optn55.text = "Dance";
			optn55.value = "Dance";
			subCategory.options.add(optn55);
			var optn11 = document.createElement("OPTION");
			optn11.text = "Design";
			optn11.value = "Design";
			subCategory.options.add(optn11);
			var optn64 = document.createElement("OPTION");
			optn64.text = "Design and Technology";
			optn64.value = "Design and Technology";
			subCategory.options.add(optn64);				
			var optn66 = document.createElement("OPTION");
			optn66.text = "Economic Management Sciences";
			optn66.value = "Economic Management Sciences";
			subCategory.options.add(optn66);				
			var optn12 = document.createElement("OPTION");
			optn12.text = "Economics";
			optn12.value = "Economics";
			subCategory.options.add(optn12);
			var optn83 = document.createElement("OPTION");
			optn83.text = "Engineering, Graphics and Design";
			optn83.value = "Engineering, Graphics and Design";
			subCategory.options.add(optn83);			
			var optn13 = document.createElement("OPTION");
			optn13.text = "English First Language";
			optn13.value = "English First Language";
			subCategory.options.add(optn13);
			var optn14 = document.createElement("OPTION");
			optn14.text = "English Second Language";
			optn14.value = "English Second Language";
			subCategory.options.add(optn14);
			var optn15 = document.createElement("OPTION");
			optn15.text = "French";
			optn15.value = "French";
			subCategory.options.add(optn15);
			var optn16 = document.createElement("OPTION");
			optn16.text = "Geography";
			optn16.value = "Geography";
			subCategory.options.add(optn16);
			var optn17 = document.createElement("OPTION");
			optn17.text = "German First Language";
			optn17.value = "German First Language";
			subCategory.options.add(optn17);
			var optn18 = document.createElement("OPTION");
			optn18.text = "German Third Language";
			optn18.value = "German Third Language";
			subCategory.options.add(optn18);
			var optn19 = document.createElement("OPTION");
			optn19.text = "Graphic Art";
			optn19.value = "Graphic Art";
			subCategory.options.add(optn19);			
			var optn20 = document.createElement("OPTION");
			optn20.text = "Hebrew";
			optn20.value = "Hebrew";
			subCategory.options.add(optn20);
			var optn21 = document.createElement("OPTION");
			optn21.text = "History";
			optn21.value = "History";
			subCategory.options.add(optn21);
			var optn22 = document.createElement("OPTION");
			optn22.text = "Home Economics";
			optn22.value = "Home Economics";
			subCategory.options.add(optn22);
			var optn23 = document.createElement("OPTION");
			optn23.text = "HotelKeeping & Catering";
			optn23.value = "HotelKeeping & Catering";
			subCategory.options.add(optn23);
			var optn67 = document.createElement("OPTION");
			optn67.text = "Human & Social Sciences";
			optn67.value = "Human & Social Sciences";
			subCategory.options.add(optn67);
			var optn68 = document.createElement("OPTION");
			optn68.text = "Information Technology";
			optn68.value = "Information Technology";
			subCategory.options.add(optn68);
			var optn69 = document.createElement("OPTION");
			optn69.text = "Information Skills";
			optn69.value = "Information Skills";
			subCategory.options.add(optn69);										
			var optn24 = document.createElement("OPTION");
			optn24.text = "IsiXhosa First Language";
			optn24.value = "IsiXhosa First Language";
			subCategory.options.add(optn24);
			var optn25 = document.createElement("OPTION");
			optn25.text = "IsiXhosa Second Language";
			optn25.value = "IsiXhosa Second Language";
			subCategory.options.add(optn25);
			var optn84 = document.createElement("OPTION");
			optn84.text = "IsiZulu First Additional Language";
			optn84.value = "IsiZulu First Additional Language";
			subCategory.options.add(optn84);				
			var optn26 = document.createElement("OPTION");
			optn26.text = "IsiZulu Second Language";
			optn26.value = "IsiZulu Second Language";
			subCategory.options.add(optn26);
			var optn27 = document.createElement("OPTION");
			optn27.text = "IsiZulu Third Language";
			optn27.value = "IsiZulu Third Language";
			subCategory.options.add(optn27);
			var optn28 = document.createElement("OPTION");
			optn28.text = "Italian";
			optn28.value = "Italian";
			subCategory.options.add(optn28);
			var optn29 = document.createElement("OPTION");
			optn29.text = "Jewish Studies";
			optn29.value = "Jewish Studies";
			subCategory.options.add(optn29);
			var optn31 = document.createElement("OPTION");
			optn31.text = "Latin";
			optn31.value = "Latin";
			subCategory.options.add(optn31);			
			var optn70 = document.createElement("OPTION");
			optn70.text = "Library";
			optn70.value = "Library";
			subCategory.options.add(optn70);
			var optn71 = document.createElement("OPTION");
			optn71.text = "Life Orientation";
			optn71.value = "Life Orientation";
			subCategory.options.add(optn71);
			var optn72 = document.createElement("OPTION");
			optn72.text = "Life Sciences";
			optn72.value = "Life Sciences";
			subCategory.options.add(optn72);			
			var optn56 = document.createElement("OPTION");
			optn56.text = "Life Skills";
			optn56.value = "Life Skills";
			subCategory.options.add(optn56);
			var optn57 = document.createElement("OPTION");
			optn57.text = "Literacy";
			optn57.value = "Literacy";
			subCategory.options.add(optn57);
			var optn73 = document.createElement("OPTION");
			optn73.text = "Mathematical Literacy";
			optn73.value = "Mathematical Literacy";
			subCategory.options.add(optn73);			
			var optn32 = document.createElement("OPTION");
			optn32.text = "Mathematics";
			optn32.value = "Mathematics";
			subCategory.options.add(optn32);
			var optn74 = document.createElement("OPTION");
			optn74.text = "Mathematics Paper 3";
			optn74.value = "Mathematics Paper 3";
			subCategory.options.add(optn74);	
			var optn82 = document.createElement("OPTION");
			optn82.text = "Media";
			optn82.value = "Media";
			subCategory.options.add(optn82);				
			var optn33 = document.createElement("OPTION");
			optn33.text = "Music";
			optn33.value = "Music";
			subCategory.options.add(optn33);
			var optn34 = document.createElement("OPTION");
			optn34.text = "Music Performance";
			optn34.value = "Music Performance";
			subCategory.options.add(optn34);
			var optn74 = document.createElement("OPTION");
			optn74.text = "Music (EEB)";
			optn74.value = "Music (EEB)";
			subCategory.options.add(optn74);
			var optn75 = document.createElement("OPTION");
			optn75.text = "Music (FET)";
			optn75.value = "Music (FET)";
			subCategory.options.add(optn75);
			var optn76 = document.createElement("OPTION");
			optn76.text = "Music (NSC)";
			optn76.value = "Music (NSC)";
			subCategory.options.add(optn76);			
			var optn58 = document.createElement("OPTION");
			optn58.text = "Natural Sciences";
			optn58.value = "Natural Sciences";
			subCategory.options.add(optn58);
			var optn59 = document.createElement("OPTION");
			optn59.text = "Numeracy";
			optn59.value = "Numeracy";
			subCategory.options.add(optn59);
			var optn35 = document.createElement("OPTION");
			optn35.text = "Painting";
			optn35.value = "Painting";
			subCategory.options.add(optn35);
			var optn36 = document.createElement("OPTION");
			optn36.text = "Physical Science";
			optn36.value = "Physical Science";
			subCategory.options.add(optn36);
			var optn77 = document.createElement("OPTION");
			optn77.text = "Physical Education";
			optn77.value = "Physical Education";
			subCategory.options.add(optn77);
			var optn37 = document.createElement("OPTION");
			optn37.text = "Portuguese";
			optn37.value = "Portuguese";
			subCategory.options.add(optn37);
			var optn78 = document.createElement("OPTION");
			optn78.text = "Science";
			optn78.value = "Science";
			subCategory.options.add(optn78);			
			var optn38 = document.createElement("OPTION");
			optn38.text = "Sculpture";
			optn38.value = "Sculpture";
			subCategory.options.add(optn38);
			var optn39 = document.createElement("OPTION");
			optn39.text = "Sepedi First Language";
			optn39.value = "Sepedi First Language";
			subCategory.options.add(optn39);
			var optn40 = document.createElement("OPTION");
			optn40.text = "Sepedi Second Language";
			optn40.value = "Sepedi Second Language";
			subCategory.options.add(optn40);
			var optn41 = document.createElement("OPTION");
			optn41.text = "Sesotho Second Language";
			optn41.value = "Sesotho Second Language";
			subCategory.options.add(optn41);
			var optn42 = document.createElement("OPTION");
			optn42.text = "Setswana First Language";
			optn42.value = "Setswana First Language";
			subCategory.options.add(optn42);
			var optn43 = document.createElement("OPTION");
			optn43.text = "Setswana Second Language";
			optn43.value = "Setswana Second Language";
			subCategory.options.add(optn43);
			var optn44 = document.createElement("OPTION");
			optn44.text = "Siswati First Language";
			optn44.value = "Siswati First Language";
			subCategory.options.add(optn44);
			var optn45 = document.createElement("OPTION");
			optn45.text = "Siswati Second Language";
			optn45.value = "Siswati Second Language";
			subCategory.options.add(optn45);
			var optn79 = document.createElement("OPTION");
			optn79.text = "Social Science";
			optn79.value = "Social Science";
			subCategory.options.add(optn79);			
			var optn46 = document.createElement("OPTION");
			optn46.text = "Spanish";
			optn46.value = "Spanish";
			subCategory.options.add(optn46);
			var optn47 = document.createElement("OPTION");
			optn47.text = "Speech & Drama";
			optn47.value = "Speech & Drama";
			subCategory.options.add(optn47);
			var optn48 = document.createElement("OPTION");
			optn48.text = "Technical & Drawing";
			optn48.value = "Technical & Drawing";
			subCategory.options.add(optn48);
			var optn49 = document.createElement("OPTION");
			optn49.text = "Technika Electronics";
			optn49.value = "Technika Electonics";
			subCategory.options.add(optn49);
			var optn80 = document.createElement("OPTION");
			optn80.text = "Technology";
			optn80.value = "Technology";
			subCategory.options.add(optn80);			
			var optn50 = document.createElement("OPTION");
			optn50.text = "Travel & Tourism";
			optn50.value = "Travel & Tourism";
			subCategory.options.add(optn50);
			var optn51 = document.createElement("OPTION");
			optn51.text = "Typing";
			optn51.value = "Typing";
			subCategory.options.add(optn51);
			var optn81 = document.createElement("OPTION");
			optn81.text = "Visual Arts";
			optn81.value = "Visual Arts";
			subCategory.options.add(optn81);			
			var optn52 = document.createElement("OPTION");
			optn52.text = "Woodwork";
			optn52.value = "Woodwork";
			subCategory.options.add(optn52);
			var optn53 = document.createElement("OPTION");
			optn53.text = "Other";
			optn53.value = "Other";
			subCategory.options.add(optn53);
			break;
	case "Cultural": 
			var subCategory = document.getElementById('ddSubCategory');
			subCategory.length = 0;
			var optn0 = document.createElement("OPTION");
			optn0.text = "";
			optn0.value = "";
			subCategory.options.add(optn0);
			var optn1 = document.createElement("OPTION");
			optn1.text = "Art";
			optn1.value = "Art";
			subCategory.options.add(optn1);
			var optn2 = document.createElement("OPTION");
			optn2.text = "Choir";
			optn2.value = "Choir";
			subCategory.options.add(optn2);
			var optn3 = document.createElement("OPTION");
			optn3.text = "Cultural Programme";
			optn3.value = "Cultural Programme";
			subCategory.options.add(optn3);
			var optn4 = document.createElement("OPTION");
			optn4.text = "Dance";
			optn4.value = "Dance";
			subCategory.options.add(optn4);
			var optn5 = document.createElement("OPTION");
			optn5.text = "Debating";
			optn5.value = "Debating";
			subCategory.options.add(optn5);
			var optn6 = document.createElement("OPTION");
			optn6.text = "Drama";
			optn6.value = "Drama";			
			subCategory.options.add(optn6);
			var optn65 = document.createElement("OPTION");
			optn65.text = "Dramatic Arts";
			optn65.value = "Dramatic Arts";			
			subCategory.options.add(optn65);			
			var optn7 = document.createElement("OPTION");
			optn7.text = "First Aid";
			optn7.value = "First Aid";
			subCategory.options.add(optn7);
			var optn8 = document.createElement("OPTION");
			optn8.text = "Music";
			optn8.value = "Music";
			subCategory.options.add(optn8);
			var optn9 = document.createElement("OPTION");
			optn9.text = "Photography Club";
			optn9.value = "Photography Club";
			subCategory.options.add(optn9);
			var optn10 = document.createElement("OPTION");
			optn10.text = "Pottery";
			optn10.value = "Pottery";
			subCategory.options.add(optn10);
			var optn11 = document.createElement("OPTION");
			optn11.text = "Public Speaking";
			optn11.value = "Public Speaking";
			subCategory.options.add(optn11);
			var optn12 = document.createElement("OPTION");
			optn12.text = "Students' Christian Association";
			optn12.value = "Students' Christian Association";
			subCategory.options.add(optn12);
			var optn13 = document.createElement("OPTION");
			optn13.text = "Other";
			optn13.value = "Other";
			subCategory.options.add(optn13);
			break;
	case "Sport":
			var subCategory = document.getElementById('ddSubCategory');
			subCategory.length = 0;
			var optn0 = document.createElement("OPTION");
			optn0.text = "";
			optn0.value = "";
			subCategory.options.add(optn0);
			var optn1 = document.createElement("OPTION");
			optn1.text = "Athletics";
			optn1.value = "Athletics";
			subCategory.options.add(optn1);
			var optn2 = document.createElement("OPTION");
			optn2.text = "Badminton";
			optn2.value = "Badminton";
			subCategory.options.add(optn2);
			var optn3 = document.createElement("OPTION");
			optn3.text = "Baseball";
			optn3.value = "Baseball";
			subCategory.options.add(optn3);
			var optn4 = document.createElement("OPTION");
			optn4.text = "Basketball";
			optn4.value = "Basketball";
			subCategory.options.add(optn4);
			var optn5 = document.createElement("OPTION");
			optn5.text = "BMX";
			optn5.value = "BMX";
			subCategory.options.add(optn5);
			var optn6 = document.createElement("OPTION");
			optn6.text = "Canoeing";
			optn6.value = "Canoeing";
			subCategory.options.add(optn6);
			var optn7 = document.createElement("OPTION");
			optn7.text = "Climbing";
			optn7.value = "Climbing";
			subCategory.options.add(optn7);
			var optn8 = document.createElement("OPTION");
			optn8.text = "Cricket";
			optn8.value = "Cricket";
			subCategory.options.add(optn8);
			var optn9 = document.createElement("OPTION");
			optn9.text = "Cycling";
			optn9.value = "Cycling";
			subCategory.options.add(optn9);
			var optn10 = document.createElement("OPTION");
			optn10.text = "Dance";
			optn10.value = "Dance";
			subCategory.options.add(optn10);
			var optn11 = document.createElement("OPTION");
			optn11.text = "Diving";
			optn11.value = "Diving";
			subCategory.options.add(optn11);
			var optn12 = document.createElement("OPTION");
			optn12.text = "Equestrain";
			optn12.value = "Equestrain";
			subCategory.options.add(optn12);
			var optn13 = document.createElement("OPTION");
			optn13.text = "Fishing";
			optn13.value = "Fishing";
			subCategory.options.add(optn13);
			var optn14 = document.createElement("OPTION");
			optn14.text = "Golf";
			optn14.value = "Golf";
			subCategory.options.add(optn14);
			var optn15 = document.createElement("OPTION");
			optn15.text = "Gymnastics";
			optn15.value = "Gymanstics";
			subCategory.options.add(optn15);
			var optn16 = document.createElement("OPTION");
			optn16.text = "Hiking";
			optn16.value = "Hiking";
			subCategory.options.add(optn16);
			var optn17 = document.createElement("OPTION");
			optn17.text = "Hockey";
			optn17.value = "Hockey";
			subCategory.options.add(optn17);
			var optn18 = document.createElement("OPTION");
			optn18.text = "Judo";
			optn18.value = "Judo";
			subCategory.options.add(optn18);
			var optn19 = document.createElement("OPTION");
			optn19.text = "Karate";
			optn19.value = "Karate";
			subCategory.options.add(optn19);
			var optn20 = document.createElement("OPTION");
			optn20.text = "Kayaking";
			optn20.value = "Kayaking";
			subCategory.options.add(optn20);
			var optn21 = document.createElement("OPTION");
			optn21.text = "Kite Surfing";
			optn21.value = "Kite Surfing";
			subCategory.options.add(optn21);
			var optn22 = document.createElement("OPTION");
			optn22.text = "Mixed Discipline";
			optn22.value = "Mixed Discipline";
			subCategory.options.add(optn22);
			var optn23 = document.createElement("OPTION");
			optn23.text = "Motorcycling";
			optn23.value = "Motorcycling";
			subCategory.options.add(optn23);
			var optn24 = document.createElement("OPTION");
			optn24.text = "Mountain Biking";
			optn24.value = "Mountain Biking";
			subCategory.options.add(optn24);
			var optn25 = document.createElement("OPTION");
			optn25.text = "Mountaineering";
			optn25.value = "Mountaineering";
			subCategory.options.add(optn25);
			var optn26 = document.createElement("OPTION");
			optn26.text = "Netball";
			optn26.value = "Netball";
			subCategory.options.add(optn26);
			var optn27 = document.createElement("OPTION");
			optn27.text = "Parachuting";
			optn27.value = "Parachuting";
			subCategory.options.add(optn27);
			var optn28 = document.createElement("OPTION");
			optn28.text = "Pilates";
			optn28.value = "Pilates";
			subCategory.options.add(optn28);
			var optn29 = document.createElement("OPTION");
			optn29.text = "Rollerblading";
			optn29.value = "Rollerblading";
			subCategory.options.add(optn29);
			var optn30 = document.createElement("OPTION");
			optn30.text = "Rowing";
			optn30.value = "Rowing";
			subCategory.options.add(optn30);
			var optn31 = document.createElement("OPTION");
			optn31.text = "Rugby";
			optn31.value = "Rugby";
			subCategory.options.add(optn31);
			var optn32 = document.createElement("OPTION");
			optn32.text = "Sailing";
			optn32.value = "Sailing";
			subCategory.options.add(optn32);
			var optn33 = document.createElement("OPTION");
			optn33.text = "Shooting";
			optn33.value = "Shooting";
			subCategory.options.add(optn33);
			var optn34 = document.createElement("OPTION");
			optn34.text = "Skateboarding";
			optn34.value = "Skateboarding";
			subCategory.options.add(optn34);
			var optn35 = document.createElement("OPTION");
			optn35.text = "Skiing";
			optn35.value = "Skiing";
			subCategory.options.add(optn35);
			var optn36 = document.createElement("OPTION");
			optn36.text = "Snooker";
			optn36.value = "Snooker";
			subCategory.options.add(optn36);
			var optn37 = document.createElement("OPTION");
			optn37.text = "Snowboarding";
			optn37.value = "Snowboarding";
			subCategory.options.add(optn37);
			var optn38 = document.createElement("OPTION");
			optn38.text = "Soccer";
			optn38.value = "Soccer";
			subCategory.options.add(optn38);
			var optn39 = document.createElement("OPTION");
			optn39.text = "Squash";
			optn39.value = "Squash";
			subCategory.options.add(optn39);
			var optn40 = document.createElement("OPTION");
			optn40.text = "Surfing";
			optn40.value = "Surfing";
			subCategory.options.add(optn40);
			var optn41 = document.createElement("OPTION");
			optn41.text = "Swimming";
			optn41.value = "Swimming";
			subCategory.options.add(optn41);
			var optn42 = document.createElement("OPTION");
			optn42.text = "Synchronised Swimming";
			optn42.value = "Synchronised Swimming";
			subCategory.options.add(optn42);
			var optn43 = document.createElement("OPTION");
			optn43.text = "Tennis";
			optn43.value = "Tennis";
			subCategory.options.add(optn43);
			var optn44 = document.createElement("OPTION");
			optn44.text = "Wake boarding";
			optn44.value = "Wake boarding";
			subCategory.options.add(optn44);
			var optn45 = document.createElement("OPTION");
			optn45.text = "Waterpolo";
			optn45.value = "Waterpolo";
			subCategory.options.add(optn45);
			var optn46 = document.createElement("OPTION");
			optn46.text = "Water Skiing";
			optn46.value = "Water Skiing";
			subCategory.options.add(optn46);
			var optn47 = document.createElement("OPTION");
			optn47.text = "Widsurfing";
			optn47.value = "Widsurfing";
			subCategory.options.add(optn47);
			var optn48 = document.createElement("OPTION");
			optn48.text = "Yoga";
			optn48.value = "Yoga";
			subCategory.options.add(optn48);
			var optn49 = document.createElement("OPTION");
			optn49.text = "Other";
			optn49.value = "Other";
			subCategory.options.add(optn49);
			break;
	case "Groups":
			var subCategory = document.getElementById('ddSubCategory');
			subCategory.length = 0;
			var optn0 = document.createElement("OPTION");
			optn0.text = "";
			optn0.value = "";
			subCategory.options.add(optn0);
			var optn1 = document.createElement("OPTION");
			optn1.text = "Year";
			optn1.value = "Year";
			subCategory.options.add(optn1);
			var optn2 = document.createElement("OPTION");
			optn2.text = "Class";
			optn2.value = "Class";
			subCategory.options.add(optn2);
			var optn3 = document.createElement("OPTION");
			optn3.text = "House";
			optn3.value = "House";
			subCategory.options.add(optn3);
			var optn4 = document.createElement("OPTION");
			optn4.text = "Parents";
			optn4.value = "Parents";
			subCategory.options.add(optn4);
			var optn5 = document.createElement("OPTION");
			optn5.text = "Teachers";
			optn5.value = "Teachers";
			subCategory.options.add(optn5);
			var optn6 = document.createElement("OPTION");
			optn6.text = "Pupils";
			optn6.value = "Pupils";
			subCategory.options.add(optn6);
			var optn7 = document.createElement("OPTION");
			optn7.text = "Other";
			optn7.value = "Other";
			subCategory.options.add(optn7);
			break;
	case "Other":
			var subCategory = document.getElementById('ddSubCategory');
			subCategory.length = 0;
			var optn0 = document.createElement("OPTION");
			optn0.text = "";
			optn0.value = "";
			subCategory.options.add(optn0);
			var optn1 = document.createElement("OPTION");
			optn1.text = "Animals";
			optn1.value = "Animals";
			subCategory.options.add(optn1);
			var optn2 = document.createElement("OPTION");
			optn2.text = "Beauty & Fashion";
			optn2.value = "Beauty & Fashion";
			subCategory.options.add(optn2);
			var optn3 = document.createElement("OPTION");
			optn3.text = "Business";
			optn3.value = "Business";
			subCategory.options.add(optn3);
			var optn4 = document.createElement("OPTION");
			optn4.text = "Entertainment";
			optn4.value = "Entertainment";
			subCategory.options.add(optn4);
			var optn5 = document.createElement("OPTION");
			optn5.text = "Family";
			optn5.value = "Family";
			subCategory.options.add(optn5);
			var optn6 = document.createElement("OPTION");
			optn6.text = "Food & Drink";
			optn6.value = "Food & Drink";
			subCategory.options.add(optn6);
			var optn7 = document.createElement("OPTION");
			optn7.text = "Health & Fitness";
			optn7.value = "Heatlh & Fitness";
			subCategory.options.add(optn7);
			var optn8 = document.createElement("OPTION");
			optn8.text = "Home & Garden";
			optn8.value = "Home & Garden";
			subCategory.options.add(optn8);
			var optn9 = document.createElement("OPTION");
			optn9.text = "Just for Fun";
			optn9.value = "Jusr for Fun";
			subCategory.options.add(optn9);
			var optn10 = document.createElement("OPTION");
			optn10.text = "Medical";
			optn10.value = "Medical";
			subCategory.options.add(optn10);
			var optn11 = document.createElement("OPTION");
			optn11.text = "Money";
			optn11.value = "Money";
			subCategory.options.add(optn11);
			var optn12 = document.createElement("OPTION");
			optn12.text = "News & Politics";
			optn12.value = "News & Politics";
			subCategory.options.add(optn12);
			var optn13 = document.createElement("OPTION");
			optn13.text = "Relationships";
			optn13.value = "Relationships";
			subCategory.options.add(optn13);
			var optn14 = document.createElement("OPTION");
			optn14.text = "Religion";
			optn14.value = "Religion";
			subCategory.options.add(optn14);
			var optn15 = document.createElement("OPTION");
			optn15.text = "Technology";
			optn15.value = "Technology";
			subCategory.options.add(optn15);
			var optn16 = document.createElement("OPTION");
			optn16.text = "Travel";
			optn16.value = "Travel";
			subCategory.options.add(optn16);
			var optn17 = document.createElement("OPTION");
			optn17.text = "Other";
			optn17.value = "Other";
			subCategory.options.add(optn17);
			break;
}

}

var title;
var category ;
var subcategory;
var tags;

function searchPortal()
{
		title = $('txtTitle').value;
		category = $('ddCategory').value;
		subcategory = $('ddSubCategory').value;
		tags = $('txtTags').value;
		engPortal.NavigateSearchWithDetails(title,category,subcategory,tags,callback_searchPortal)
}

function callback_searchPortal(res)
{  
    
	var pDiv = $('SearchResults');
	if (pDiv) {
		pDiv.innerHTML = res.value;
		
		if ($('txtTitle') != null) {
			document.getElementById('txtTitle').value = title;
		}
		
		
		if ($('ddCategory') != null) {
			var ddCategory = document.getElementById('ddCategory');
			ddCategory.className = "modalOK";
			for(var i = 0; i < ddCategory.options.length; i++) {
				if (ddCategory.options[i].value == category) {
					ddCategory.selectedIndex =  i;
				}
			}
		}
		else {
		}
		
		
		
		if ($('ddSubCategory') != null) {
			getSubCategorylist();
			var ddSubCategory = document.getElementById('ddSubCategory');
			ddSubCategory.className = "modalOK";
			for(var i = 0; i < ddSubCategory.options.length; i++) {
				if (ddSubCategory.options[i].value == subcategory) {
					ddSubCategory.selectedIndex =  i;
				}
			}
		}
		else {
		}
		
		if (document.getElementById('txtTags') != null) {
			document.getElementById('txtTags').value = tags;
		}
		
      //  window.location = 'BrowseCommunityPortal.aspx?Page=1';
	}
}

var spanportalid;
function joinPortal(portalid)
{
	spanportalid = portalid;
	showFeedback("joinPortalNotificationActionContainer_" + portalid);
	engPortal.joinPortal(portalid, callback_joinPortal);

}
function callback_joinPortal(res)
{
	checkResponse(res.value);
		var results  = res.value.Tables[0];
		if (results.Rows[0].result == "True")
		{
			var controls = res.value.Tables[1];

			switch(results.Rows[0].errMessage)
				{
					case "valid":
				            feedbackValid('Joining','Joined');
				            window.setTimeout('hideJoinPortal();', 3000);
				            break;
				}
		}
		else
		{
			var controls = res.value.Tables[1];
			switch (results.Rows[0].errMessage)
				{
					case "invalid":
						feedbackInvalid('joinPortalNotificationActionContainer_' + spanportalid);				
						break;
						
					case "AccessDenied":
						feedbackInvalid('joinPortalNotificationActionContainer_' + spanportalid);				
						break;						
				}

		}
}

function hideJoinPortal() {
	var path = '/myCommunityPortals/index.aspx?PortalID=' + spanportalid
	window.location = path;
}

function showRemovePortal(portalID,userID)
{
	 var dt = engPortal.getPortalOwner(portalID);	 
	  
	 if (dt != null) {		  
	    if(dt.value.Rows.length > 0) {
	        if (dt.value.Rows[0].User_ID == userID) {

	            if ($('ifPortalOwner') != null) {
	                $('ifPortalOwner').style.display = '';
	            }

	            if ($('IfNotPortalOwner') != null) {
	                $('IfNotPortalOwner').style.display = 'none';
	            }

	        }
	        else {
	            if ($('ifPortalOwner') != null) {
	                $('ifPortalOwner').style.display = 'none';
	            }

	            if ($('IfNotPortalOwner') != null) {
	                $('IfNotPortalOwner').style.display = '';
	            }
	        }	
        }
	 }
 
	 var dt2 = engPortal.getPortalDetailsByID(portalID);
	 if (dt2 != null) {
		 setSpanValue('removePortalTitle', dt2.value.Rows[0].Portal_Title);
	 }
	 setSpanValue('removePortalID', portalID);

	 openModalWindow('deleteCommunityPortalFromHome')	 
}


function removePortalFromHomepage()
{
	var PortalID = getSpanValue('removePortalID');
	showFeedback('deleteCommunityPortalFromHomeActionContainer');
	engPortal.RemovePortalFromHomepage(PortalID, callback_removePortal);
}

function addPortalToHomePage(portalid) {
	spanportalid = portalid;
	showFeedback("joinPortalNotificationActionContainer_" + portalid);
    engPortal.AddPortalToHomepage(portalid, callback_joinPortal);
}

function callback_removePortal(res)
{
	checkResponse(res.value);
		var results  = res.value.Tables[0];
		if (results.Rows[0].result == "True")
		{
			var controls = res.value.Tables[1];

			switch(results.Rows[0].errMessage)
				{
					case "valid":
			
						feedbackValid('Removing','Removed');
						window.setTimeout('hideremovePortal();', 7000);
						break
				}
		}
		else
		{
			var controls = res.value.Tables[1];
			switch (results.Rows[0].errMessage)
				{
					case "invalid":
						feedbackInvalid('deleteCommunityPortalFromHomeActionContainer');
						window.setTimeout(function(){processValidationResponse(controls)}, 2001);
						break
				}

		}

}

function hideremovePortal()
{		
		cleanupFeedback('deleteCommunityPortalFromActionContainer');
		closeModalWindow('deleteCommunityPortalFromHome');
		window.location = "/index.aspx";
}

function RemoveBatch(){
	var cont = document.getElementById("Div1").getElementsByTagName("input");
	var counter = 0;
	
	for (var i=0; i<cont.length; i++)
		{
		if (cont[i].type == "checkbox")
			{
			if (cont[i].checked)
				{
				
				counter = 1;
				break;
				}
			}

		}
	
	
	if(counter == 0)
	{
		setControlDisplay('selectbatch','block');
		setControlDisplay('deletebatch','none');
		
		
	}
	else
	{
		setControlDisplay('deletebatch','block');
		setControlDisplay('selectbatch','none');
		
	}
	
openPortalModalWindow('removeBatch');
	
}
function removeBatch(){
	var controls = new Array();
	var cont = document.getElementById("Div1").getElementsByTagName("input");
	var counter = 0;
	
	for (var i=0; i<cont.length; i++)
		{
		if (cont[i].type == "checkbox")
			{
			if (cont[i].checked)
				{
				controls[counter] = cont[i].value;
				counter = counter + 1;
				}
			}

		}
	showFeedback('removeBatchActionContainer');
	engPortal.deleteSelectedMembers(controls, callback_removeBatch);
	
}
function callback_removeBatch(res)
{
	if (res.error!=null){alert(res.error)};
	if (res.value)
		{
		feedbackValid('Deleting','Deleted');
		window.setTimeout("hideBatch();", 4000);		
		}
	else
		{
		feedbackInvalid('removeBatchActionContainer');
		}	
	
}
function hideBatch(){
	cleanupFeedback('removeBatchActionContainer');
	openPortalModalWindow('removeBatch');
	window.location = location.href;
}

function exportMembersToCsv()
{
    var filter = getDropDownSelected('ddlExportMembersFilter');
    var portalId = $('PortalID').value;
    
    $('exportMembersDownload').update("");
    
    $('btnExportMembers').style.display = 'none';
    Effect.Appear('exportMembersVerifying', { 'duration' : '1.0' } );
    
    engPortal.ExportPortalMembersToCSV(portalId, filter, callback_exportMembersToCsv2);
}

function callback_exportMembersToCsv2(res)
{
    if (res.error) { alert(res.error); return; }
    
    if (res.value == "0")
    {
        
    }
    else
    {
        $('exportMembersVerifying').style.display = 'none';
        $('exportMembersDone').style.display = 'block';
        
        var FileLink = new Element('a', { 'href' : res.value, 'target' : '_blank' }).update('Click to download');
        $('exportMembersDownload').insert(FileLink);
        window.setTimeout('showExportButton()', 3000);
    }
}



function showExportButton()
{
    $('exportMembersDone').style.display = 'none';
    Effect.Appear('btnExportMembers', { 'duration' : '1.0' } );
}


function callback_AutoCompletePortalAdmins(res) {

    checkResponse(res.value);

    if (res.value != null) {
        var ds = res.value;
        var listControlID = "autoCompleteListtxtPortalAdmins";
        var listControlWrapper = "txtPortalAdminsListWrapper";
        document.getElementById(listControlID).innerHTML = "";

        var ul = document.createElement("ul");
        ul.id = "autoList";

        if (ds != null && typeof (ds) == "object" && ds.Rows.length != 0) {

            for (var i = 0; i < ds.Rows.length; i++) {
                var li = document.createElement("li");
                var a = document.createElement("a");

                a.href = "javascript:completePortalAdmins('" + ds.Rows[i].UserID + "','" + ds.Rows[i].Username + " (" + ds.Rows[i].firstname + " " + ds.Rows[i].lastname + ")" + "');void(0);";
                a.innerHTML = ds.Rows[i].Username + " (" + ds.Rows[i].firstname + " " + ds.Rows[i].lastname + ")";

                li.appendChild(a);
                ul.appendChild(li)
            }


            document.getElementById(listControlID).appendChild(ul);
            document.getElementById(listControlWrapper).style.display = "block";
            document.getElementById(listControlID).style.display = "block";

        }
        else {
            document.getElementById(listControlWrapper).style.display = "none";
            document.getElementById(listControlID).style.display = "none";
        }

    }
}

function loadExistingPortalAdmins() {
    engPortal.GetPortalAdmins(callback_getPortalAdmins);
}

function callback_getPortalAdmins(res) {
      checkResponse(res.value);

      if (res.value != null) {
          var dr = res.value.Rows;
          for (a = 0; a < dr.length; a++) {
              completePortalAdmins(dr[a].UserID, dr[a].Username + " (" + dr[a].Firstname + " " + dr[a].lastname + ")");
          }
      }
}

function completePortalAdmins(accID, username) {
    Effect.Fade('txtPortalAdminsListWrapper');
    var ul = document.getElementById("ulPortalAdminsList");
    var chks = document.getElementById("ulPortalAdminsList").getElementsByTagName("input");
    var counter = 0;
    if (chks.length != 0) {
        for (var i = 0; i < chks.length; i++) {
            if (accID == chks[i].value) {
                counter = 1;
            }
        }

        if (counter == 0) {
            var chk = document.createElement("input");
            chk.type = "checkbox";
            chk.value = accID;
            chk.id = "c_" + accID;
            chk.style.display = "none";
            var lbl = document.createElement("label");
            lbl.innerHTML = username;
            lbl.id = "l_" + accID;
            var img = document.createElement("img");
            img.id = "i_" + accID;
            img.alt = "Remove";
            img.src = "/images/icons/delete.gif";
            var aImg = document.createElement("a");
            aImg.href = "javascript:deletePortalAdmins(" + accID + ");";
            aImg.id = "a_" + accID;
            aImg.appendChild(img);
            var li = document.createElement("li");
            li.id = "l_" + accID;
            li.appendChild(chk);
            li.appendChild(lbl);
            li.appendChild(aImg);
            ul.appendChild(li);
        }
        else {
            alert('You have already selected to share the event with this person.');
        }

    }
    else {
        var chk = document.createElement("input");
        chk.type = "checkbox";
        chk.value = accID;
        chk.id = "c_" + accID;
        chk.style.display = "none";
        var lbl = document.createElement("label");
        lbl.innerHTML = username;
        lbl.id = "l_" + accID;
        var img = document.createElement("img");
        img.id = "i_" + accID;
        img.alt = "Remove";
        img.src = "/images/icons/delete.gif";
        var aImg = document.createElement("a");
        aImg.href = "javascript:deletePortalAdmins(" + accID + ");";
        aImg.id = "a_" + accID;
        aImg.appendChild(img);
        var li = document.createElement("li");
        li.id = "l_" + accID;
        li.appendChild(chk);
        li.appendChild(lbl);
        li.appendChild(aImg);
        ul.appendChild(li);
    }
    document.getElementById("txtPortalAdmins").value = "";
}

function deletePortalAdmins(accID) {
    var ul = document.getElementById("ulPortalAdminsList");
    var chks = document.getElementById("ulPortalAdminsList").getElementsByTagName("input");
    var lis = document.getElementById("ulPortalAdminsList").getElementsByTagName("li");
    for (var i = 0; i < chks.length; i++) {
        if (accID == chks[i].value) {
            var li = document.getElementById(lis[i].id);
            ul.removeChild(li);
        }
    }


}

function addPortalAdmin() {
    var admins = getFriendsIDs('ulPortalAdminsList');
    showFeedback('portalAdminActionContainer');
    engPortal.UpdatePortalAdmins(admins.toString(), callback_addPortalAdmin);
}

function callback_addPortalAdmin(res) {
    checkResponse(res.value);
    var results = res.value.Tables[0];
    if (results.Rows[0].result == "True") {
        var controls = res.value.Tables[1];

        switch (results.Rows[0].errMessage) {
            case "valid":
                feedbackValid('Saving', 'Saved');
                window.setTimeout('hideaAddPortalAdmin();', 7000);
                break;
        }
    }
    else {
        var controls = res.value.Tables[1];
        switch (results.Rows[0].errMessage) {
            case "invalid":
                feedbackInvalid('portalAdminActionContainer');
                window.setTimeout(function () { processValidationResponse(controls); }, 2001);
                break;
        }

    }
}

function hideaAddPortalAdmin() {
    
    cleanupFeedback('portalAdminActionContainer');
    closePortalModalWindow('addPortalAdministrators');
    window.location = location.href;

}
