
function addNewInfo(parentDivId,childDivId) 
{
	var inserHtml = $("#"+childDivId).html();
	
	var className = $("#"+childDivId).attr("class");
	var num = $("."+className).length;
	
	var splitId = childDivId.split("_");
	var rootId = splitId[0];
	num++;
	
	inserHtml = inserHtml.replace(/_1/g, '_'+num);

	var newId = rootId + '_' + num;
	var radioName = className + '_' + num;
	var deleteButton = '<img src="' + BASEPATH + 'images/inbox_delete.gif" class="closer" align="right" border="0" onclick="removeDiv(' + "'" + newId + "'" + ')">';
	
	$("#"+parentDivId).append('<div id="' + newId + '" class="' + className + '" style="display:none">' + deleteButton + inserHtml + '</div>');
	$("#" + newId).clearForm().slideDown("slow");
}


function bookmark(){
  var title = 'ShesConnected Your Homepage';
  var url = BASEPATH;
 
  if (window.external && window.external.AddFavorite)
	window.external.AddFavorite(url,title); // IE4 and later
  else if (window.sidebar && window.sidebar.addPanel)
   window.sidebar.addPanel(title,url,''); // Gecko/firefox  
} 


function changeArticles(obj,parent) {
	$("#"+parent + '_recent').hide('slow');
	$("#"+parent + '_popular').hide('slow');
	$("#"+parent + '_favorite').hide('favorite');
	$("#"+parent+'_' + obj.value).slideToggle('slow');
}

function cheskDuplicket(field, table, column)
{
	value = $("#" + field).val();
	
	$.ajax({
	  type: "POST",
	  url: BASEPATH + "Ajax/checkDuplicate/id/table/"+ table +"/column/"+ column +"/value/"+ value ,
	  success: function(msg){
		if(msg == '1')
		{
			$("#" + field).addClass("accepted");
			$("#" + field).parent(".ctrlHolder").removeClass("error");
			$("#" + field+"_duplicate").hide();
			

		}
		else
		{	
			$("#" + field).addClass("accepted");
			$("#" + field).parent(".ctrlHolder").removeClass("error");
			$("#" + field+"_duplicate").hide();	
			$("#" + field).parent(".ctrlHolder").addClass("error");
			$("#" + field).after("&nbsp;<b id='"+field +"_duplicate'><font color='red'>Already used! Try another.</font></b><br />");
		}
	  }
	});

}

function deleteResource(url, id) {
  if (confirm("Are you sure you want to remove this?")) {
	$('#' + id).show();
	$.ajax({
	  type: "GET",
	  url: url,
	  success: function(msg) {
		$('#' + id).css('background', '#eee');
		$('#' + id).fadeOut('normal');
	}});
  }
}

function deleteContentPiece(url, id) {
  if (confirm("Are you sure you want to delete this?")) {
	$('#' + id).show();
	$.ajax({
	  type: "GET",
	  url: url,
	  success: function(msg) {
		if (msg=='success') {
		  $('#' + id).fadeOut('normal');
		} 
		  
	}});
  }
}

function featureForGroup(url, id) {
  $('#' + id).show();
  $.ajax({
	type: "GET",
	url: url,
	success: function(msg) {
	  $('#' + id).hide();
  }});
}

//#----------AJAX CONTROLS SECTION------------
function memberAdminRemove(url, id) {
  $.ajax({
	type: "GET",
	url: url,
	success: function(msg) {
	 if (msg=='success') 
	 { 
	 $('#' + id).fadeOut();
	 //$('#' + id).hide(); 
	 }
	 
	 if (msg!='success') { alert(msg); }
  }});
}

function memberAdminToggleAdmin(url, id, id2) {
  $.ajax({
	type: "GET",
	url: url,
	success: function(msg) {
	 if (msg=='nowadmin') 
	 { 
		$('#'+ id).fadeOut('slow',function() { $('#'+ id).html("Revoke Admin Rights").fadeIn(); });
		$('#'+ id + 'black').fadeOut('slow',function() { $('#'+ id + 'black').html("admin").fadeIn(); });
	 }
	 
	 if (msg=='nownotadmin') 
	 { 
	   $('#'+ id).fadeOut('slow',function() { $('#'+ id).html("Make Admin").fadeIn(); });
	   $('#'+ id + 'black').fadeOut('slow',function() { $('#'+ id + 'black').html("member").fadeIn(); });       
	 }
  }});
}

function joinRequestAccept(url, id) {
  $.ajax({
	type: "GET",
	url: url,
	success: function(msg) {
	 if (msg=='accepted') 
	 { 
	 $('#' + id).html("You have accepted this user's request");
	 }
	 
	 if (msg!='accepted') { alert("Ooops... This request has already been processed!"); }
  }});
}

function joinRequestDeny(url, id) {
  $.ajax({
	type: "GET",
	url: url,
	success: function(msg) {
	 if (msg=='denied') 
	 { 
	 $('#' + id).html("You have denied this user's request");
	 }
	 
	 if (msg!='denied') { alert("Ooops... This request has already been processed!"); }
  }});
}


function incrementalSearch(url,txt) {
  $.ajax({
	type: "GET",
	url: url+'/query/'+txt,
	success: function(msg) {
		alert(msg);
  }});    
}
//#----------AJAX CONTROLS SECTION END-------------



// flash detecting scripts - 
// Flash Player Version Detection - Rev 1.6
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 6;
// Minor version of Flash required
var requiredRevision = 0;
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			// alert("flashVer="+flashVer);
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

			// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
	return src.replace(/\?/, ext+'?'); 
  else
	return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
	var str = '';
	if (isIE && isWin && !isOpera)
	{
		str += '<object ';
		for (var i in objAttrs)
			str += i + '="' + objAttrs[i] + '" ';
		for (var i in params)
			str += '><param name="' + i + '" value="' + params[i] + '" /> ';
		str += '></object>';
	} else {
		str += '<embed ';
		for (var i in embedAttrs)
			str += i + '="' + embedAttrs[i] + '" ';
		str += '> </embed>';
	}

	document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
	AC_GetArgs
	(  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
	 , "application/x-shockwave-flash"
	);
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
	var currArg = args[i].toLowerCase();    

	switch (currArg){	
	  case "classid":
		break;
	  case "pluginspage":
		ret.embedAttrs[args[i]] = args[i+1];
		break;
	  case "src":
	  case "movie":	
		args[i+1] = AC_AddExtension(args[i+1], ext);
		ret.embedAttrs["src"] = args[i+1];
		ret.params[srcParamName] = args[i+1];
		break;
	  case "onafterupdate":
	  case "onbeforeupdate":
	  case "onblur":
	  case "oncellchange":
	  case "onclick":
	  case "ondblClick":
	  case "ondrag":
	  case "ondragend":
	  case "ondragenter":
	  case "ondragleave":
	  case "ondragover":
	  case "ondrop":
	  case "onfinish":
	  case "onfocus":
	  case "onhelp":
	  case "onmousedown":
	  case "onmouseup":
	  case "onmouseover":
	  case "onmousemove":
	  case "onmouseout":
	  case "onkeypress":
	  case "onkeydown":
	  case "onkeyup":
	  case "onload":
	  case "onlosecapture":
	  case "onpropertychange":
	  case "onreadystatechange":
	  case "onrowsdelete":
	  case "onrowenter":
	  case "onrowexit":
	  case "onrowsinserted":
	  case "onstart":
	  case "onscroll":
	  case "onbeforeeditfocus":
	  case "onactivate":
	  case "onbeforedeactivate":
	  case "ondeactivate":
	  case "type":
	  case "codebase":
		ret.objAttrs[args[i]] = args[i+1];
		break;
	  case "id":
	  case "width":
	  case "height":
	  case "align":
	  case "vspace": 
	  case "hspace":
	  case "class":
	  case "title":
	  case "accesskey":
	  case "name":
	  case "tabindex":
		ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
		break;
	  default:
		ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
	}
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

//Adobe version  of flash embedder
function smart_embed (flash_path, image_path, content_width, content_height)
{
// Version check based upon the values entered above in "Globals"
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

// Check to see if the version meets the requirements for playback
if (hasReqestedVersion) {
	// if we've detected an acceptable version
	// embed the Flash Content SWF when all tests are passed
			document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+content_width+'" height="'+content_height+'" title="Top Ad">');
			document.write('<param name="movie" value="'+flash_path+'" />');
			document.write('<param name="quality" value="high" />');
			document.write('<param name="wmode" value="opaque" />');
			document.write('<embed src="'+flash_path+'" quality="high" wmode="opaque" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+content_width+'" height="'+content_height+'"></embed>');
			document.write('</object>');
} else	{
			document.write('<img src="'+image_path+'" width="'+content_width+'" height="'+content_height+'" border=0 class="noflash_image">');
		}
}

// Flash embedder function
function smart_embed2 (flash_path, image_path, content_width, content_height)
{

	var MM_contentVersion = 6;
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if ( plugin ) {
			var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			for (var i = 0; i < words.length; ++i)
			{
			if (isNaN(parseInt(words[i])))
			continue;
			var MM_PluginVersion = words[i];
			}
		var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
	}
	
	
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) 
		{
			document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
			document.write('on error resume next \n');
			document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
			document.write('</SCR' + 'IPT\> \n');
		}
	if ( MM_FlashCanPlay ) 
		{
			document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+content_width+'" height="'+content_height+'" title="Top Ad">');
			document.write('<param name="movie" value="'+flash_path+'" />');
			document.write('<param name="quality" value="high" />');
			document.write('<embed src="'+flash_path+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+content_width+'" height="'+content_height+'"></embed>');
			document.write('</object>');
		} 
	else
		{
			document.write('<img src="'+image_path+'" width="'+content_width+'" height="'+content_height+'" border=0 class="noflash_image">');
		}
}


// Counting File inputs for Picture and videos
var picFiles=0; 
var vidFiles=0;


//Show/hide the Permition box according to radio button selection
function permit(btn,divname)	
	{
	if(btn.value=="contact")
		{
			document.getElementById(divname+"Group").style.display="none";		
			document.getElementById(divname+"Contact").style.display="block";
		}
		else if(btn.value=="group")
		{
			document.getElementById(divname+"Contact").style.display="none";	
			document.getElementById(divname+"Group").style.display="block";	
		}
		else
		{
			document.getElementById(divname+"Group").style.display="none";	
			document.getElementById(divname+"Contact").style.display="none";
		}
	}
	
function addTag(tag)
	{
		if($("#tags").val() == "")
		{
			$("#tags").val(tag);	
		}
		else
		{
			$("#tags").val($("#tags").val() + ", " + tag);
		}
	}

//Delete a file input when clicked on 'X' image
function setDel(num,self)
	{
	$("#picture"+num).attr("value","");	
	$("#picture"+num).hide();
	$("#deleter"+num).hide();
	$("#temp_picture"+num).hide();
	}
	
//Add a file input for picture upload
//Add a delete image for current filr input.
function addPic(num)	
	{	
		imagepath = $("#picture"+num).val();
		
		newtext = '<img src="'+ BASEPATH +'images/tools/delete.png" id="deleter'+num+'" onclick="setDel(\''+num+'\')">';
		newtext += '<input name="picture'+(picFiles+1)+'" id="picture'+(picFiles+1)+'" size="25" type="file" onchange="addPic('+(picFiles+1)+',this)" />';
		newtext += '<input type="hidden" value="' + imagepath + '" name="filevalues[]">';
		if(imagepath == "")
		{
			return false;
		}
		else
		{
			$("#picture"+num).after(newtext);	
			picFiles++;
			$("#picCount").attr('value',picFiles);
		}
	}
	
//Add a file input for video upload	
function addVid(num)	
	{
		$("#video"+num).after('<input name="video[]" id="video'+(vidFiles+1)+'" size="65" type="file" onchange="addVid('+(vidFiles+1)+')" />');	
		vidFiles++;
	}	
	
function printDateBox(boxname, month, day, year)
	{
		today = new Date();
		//Writing month 
		if(month == '') month = today.getMonth() + 1;
		document.write("<select name='"+boxname+"_month' class='cat_month'>");
		document.write("<option value='0' "); if($month=='' || $month==0) document.write('selected'); document.write(">Select</option>");
		document.write("<option value='1' "); if(month == 1) document.write('selected'); document.write(">January</option>");
		document.write("<option value='2' "); if(month == 2) document.write('selected'); document.write(">February</option>");
		document.write("<option value='3' "); if(month == 3) document.write('selected'); document.write("> March </option>");
		document.write("<option value='4' "); if(month == 4) document.write('selected'); document.write("> April </option>");
		document.write("<option  value='5' "); if(month == 5) document.write('selected'); document.write("> May </option>");
		document.write("<option value='6' "); if(month == 6) document.write('selected'); document.write("> June </option>");
		document.write("<option value='7' "); if(month == 7) document.write('selected'); document.write("> July </option>");
		document.write("<option  value='8'"); if(month == 8) document.write('selected'); document.write("> August </option>");
		document.write("<option  value='9' "); if(month == 9) document.write('selected'); document.write("> September </option>");
		document.write("<option  value='10'"); if(month == 10) document.write('selected'); document.write("> October </option>");
		document.write("<option  value='11' "); if(month == 11) document.write('selected'); document.write("> November </option>");
		document.write("<option value='12' "); if(month == 12) document.write('selected'); document.write("> December </option> </select>&nbsp;");
		
		//writing day
		if(day == '') day = today.getDate();
		document.write("<select name='"+boxname+"_day' class='cat_date'>");  
		document.write("<option value='0' "); if($day=='' || $day==0) document.write('selected'); document.write(">Select</option>");
			for(i=1;i<32;i++)
			{
				document.write("<option "); 
				if(day == i) document.write('selected'); 
				document.write( ">" + i + "</option>");
			}
		document.write("</select>&nbsp;");
		
		//writing Year	
		
		thisYear = today.getYear() + 1900;

		if(year == '') year = thisYear;
		
		document.write("<select name='"+boxname+"_year' class='cat_year'>");  
				document.write("<option value='0' "); if($year=='' || $year==0) document.write('selected'); document.write(">Select</option>");
			for(i = (thisYear - 50); i < (thisYear + 50); i++)
			{
				document.write("<option "); 
				if(year == i) document.write('selected'); 
				document.write(" >" + i + "</option>"); 
			}
		document.write("</select>&nbsp;");
	}//printDateBox(boxname)

function printTimeBox(boxname, hour, am)
{
	today = new Date();
	
	//Printing hour
	if(hour == '') hour = today.getHours();
	if(hour > 12)  hour = (hour - 12);

	document.write("<select name='"+boxname+"_hour' class='cat_date'>");  
	for(i = 1; i < 13; i++)
	{
		document.write("<option "); 
		if(hour == i) document.write('selected'); 
		document.write(" >" + i + "</option>"); 
	}
	document.write("</select>&nbsp; : &nbsp;");
	
	//printing minuit
	document.write("<select name='"+boxname+"_min' class='cat_date'>");  
	document.write("<option>00</option>");
	document.write("<option>05</option>");
	for(i = 2; i < 13; i++)
	{
		document.write("<option "); 
		document.write(" >" + i*5 + "</option>");
	}
	document.write("</select>&nbsp;");
	
	//printing am 
	document.write('&nbsp;&nbsp;<select name="' + boxname + '_am" class="cat_date">><option value="am"');
	if(am == 'am')document.write('selected="selected"');
	document.write('>A.M.</option><option  value="pm"');
	if(am == 'pm')document.write('selected="selected"');
	document.write('>P.M.</option></select>');
}
	
/* Created By Tarek Mahmud Apu */	
function addElement(type,id,size,divname) 
{
	var d = document.createElement("div");
	var apu = document.createElement("input");
	apu.setAttribute("type", type);
	apu.setAttribute("class", "temp");
	apu.setAttribute("name",id+"[]");
	apu.setAttribute("id", id+"[]");
	apu.setAttribute("size",size);
	apu.setAttribute("maxlength",100);
	d.appendChild(apu);
	document.getElementById(divname).appendChild(d);
}

function addShareElement(type,id,id1,size,divname,maxsize,className) 
{
	var d = document.createElement("div");
	className = (className == null) ?''  : className ;
	var apu = document.createElement("input");
	apu.setAttribute("type", type);
	apu.setAttribute("class", className);
	apu.setAttribute("name",id1+"[]");
	apu.setAttribute("id", id1+"[]");
	apu.setAttribute("size",size);
	apu.setAttribute("maxlength",maxsize);
	d.appendChild(apu);
	document.getElementById(divname).appendChild(d);
	
/*	Node space = document.createElement("text");
	textNode.setTextContent(' &nbsp; ');
	d.appendChild(apu);*/
	
	var apu = document.createElement("input");
	apu.setAttribute("type", type);
	apu.setAttribute("class", className);
	apu.setAttribute("name",id+"[]");
	apu.setAttribute("id", id+"[]");
	apu.setAttribute("size",size);
	apu.setAttribute("maxlength",maxsize);
	d.appendChild(apu);
	document.getElementById(divname).appendChild(d);
}



/*function addNewInfo(parentDivId,childDivId) 
{
	var inserHtml = $("#"+childDivId).html();
	var checkedValue = $("#"+childDivId +" .permission input[@checked]").val();
	
	var className = $("#"+childDivId).attr("class");
	var num = $("."+className).length;
	
	var splitId = childDivId.split("_");
	var rootId = splitId[0];
	num++;
	var newId = rootId + '_' + num;
	var radioName = className + '_' + num;
	var deleteButton = '<img src="' + BASEPATH + 'images/inbox_delete.gif" class="closer" align="right" border="0" onclick="removeDiv(' + "'" + newId + "'" + ')">';
	
	$("#"+parentDivId).append('<div id="' + newId + '" class="' + className + '" style="display:none">' + deleteButton + inserHtml + '</div>');

	$("#"+newId + " .permission input").attr("name",radioName);
	$("#"+childDivId + " .permission input[@value='" + checkedValue + "']").attr("checked","checked");
	$("#" + newId).slideDown("slow");
}*/
//$("input[@checked='checked']").attr("checked","checked");

//$("#id option[@selected='selected']").attr("value");
function removeDiv(element)
{	
	$("#" + element).slideUp("slow",function(){
		$("#" + element).html("");
	});
}

/* Created by khabir*/
function momma_photo(name)
{
	document.getElementById('default_avt').src=name; 
	document.getElementById('avatar').value=name;	
	return true;
}

//Checks if Video and picture rights has checked
function checkRights(frm)
{
	if(frm.picture0.value !="")
	{
		if(!frm.pics_right.checked)
		{
			alert("Please check the photo rights check box.");
			return false;
		}
		
	}

	if(frm.video.value !="")
	{
		if(!frm.vids_right.checked)
		{
			alert("Please check the video rights check box.");
			return false;
		}
		
	}	
	
	 return true;
}

//Add an item as favorite of user
function addToFavorite(ref_id, ref_type)
{
	$.ajax({
	  type: "POST",
	  url: BASEPATH + "Ajax/addToFavorite/"+ ref_id +"/"+ ref_type ,
	  success: function(msg){
		//blockMoment("<h3>" + msg + "</h3>", 2);
		show('favourite_added');
	  }
	});
}

function joinGroupByhash(hash,status)
{
	$.ajax({
	  type: "POST",
	  url: BASEPATH + "groups/joinByInvite/"+hash+"/"+status,
	  success: function(msg){
		blockMoment("<h3>" + msg + "</h3>", 2);
	  }
	});
}



function makeAdmin(groupId,userId)
{
	$.ajax({
	  type: "POST",
	  url: BASEPATH + "groups/makeAdmin/"+ groupId +"/"+ userId,
	  success: function(msg){
	   
		if(msg == 'Yes')
		{
			 blockMoment("<h3>Member converted to admin</h3>", 2);
		}
		else
		{
			blockMoment("<h3>Sorry! Try later</h3>", 2);
		}
		
	  }
	});
}


//Get 2 listbox make them associate
function makeSublist(parent,child,isSubselectOptional,childVal)
{
	$("body").append("<select style='display:none' id='"+parent+child+"'></select>");
	$('#'+parent+child).html($("#"+child+" option"));
	
		var parentValue = $('#'+parent).attr('value');
		$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
	
	childVal = (typeof childVal == "undefined")? "" : childVal ;
	$("#"+child+' option[value="'+ childVal +'"]').attr('selected','selected');
	
	$('#'+parent).change(
		function()
		{
			var parentValue = $('#'+parent).attr('value');
			$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
			if(isSubselectOptional) $('#'+child).prepend("<option value='none'> -- Select -- </option>");
			$('#'+child).focus();
		}
	);
}

//appear block ui for some seconds
// .../js/jquery.blockUI.js MUST import to use this function
function blockMoment(message, second)
{
	/*$.blockUI(message); 
	setTimeout("$.unblockUI()",second*1000);
	*/
	//alert(message);
	//$.facebox( "hello" );
	$.facebox(message);
}
		
function checkValue(name, rule, message)
{
	if(rule == 'required')
	{
		if($("#" + name).attr('type') == "text" || $("#" + name).attr('type') == "password")
		{
			theValue = $("#" + name).val();
		}
		else
		{
			try {
				theValue = tinyMCE.getContent(name);
			} catch(err) {
				// muri khao
			}
		}
		if(theValue == "")
		{
			$("#" + name).parent(".ctrlHolder").addClass("error");
			$("#" + name).parent(".ctrlHolder").append("<div id='error"+ name + "'><font color='red'>" + message + "</font></div>");

			$("#" + name).focus();
			return false;
		}
		else
		{
			$("#" + name).parent(".ctrlHolder").removeClass("error");
			$("div").remove("#error"+ name );
			return true;
		}
	}	
	else
	{
		return true;
	}
}

function changeView(id)
{// alert('yes'+id);
	var MyStyle =  $('#' + id).css("display");
	if(MyStyle == "none" )
	{ 
		if($.browser.msie)
		{
			$('#' + id).css("display","block");
		}
		else
		{
			$('#' + id).css("display","table-row");
		}
	}
	else
	{
		$('#' + id).css("display","none");
	}
}

function checkURL(field)
{
	var url = $("#" + field).val();
	$.ajax({
	  type: "POST",
	  url: BASEPATH + "Ajax/visit",
	  data: 'url='+url,
	  success: function(msg){
		if(msg == '1')
		{
			$("#" + field).addClass("accepted");
			$("#" + field).parent(".ctrlHolder").removeClass("error");
			$("#" + field+"_duplicate").hide();
		}
		else
		{
			$("#" + field).parent(".ctrlHolder").addClass("error");
			if(! $("#" + field+"_duplicate").html())
				$("#" + field).after("<b id='"+field +"_duplicate'><font color='red'>Web site not found!</font></b>");
		}
	  }
	  });
}

function limitChars(textid, limit)
{
	var text = $('#'+textid).val();	
	var textlength = text.length;
	if(textlength > limit)
	{
		//alert('You cannot write more then '+limit+' characters!');
		$('#charlimitinfo').html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else
	{
		$('#charlimitinfo').html('You have '+ (limit - textlength) +' characters left.');
		return true;
	}
}

function NEWlimitChars(textid, limit)
{
	var text = $('#'+textid).val();	
	var textlength = text.length;
	if(textlength > limit)
	{
		//alert('You cannot write more then '+limit+' characters!');
		//$('#charlimitinfo').html('You cannot write more then '+limit+' characters!');
		$('#newCharLimit').html('0');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else
	{
		$('#newCharLimit').html((limit - textlength));
		return true;
	}
}

function replaceSpaces(string) {
 return string.split(' ').join('_');
}

function replaceSpecialStr(string) {
return string.replace(/[^a-zA-Z0-9\-\_]+/g,'_');


}

function filterUrl(txt) {
var invalids = "!@#$%^&*()-~,'<.>/?;:\|=+";
for(i=0; i<invalids.length; i++) {
	if(txt.indexOf(invalids.charAt(i)) >= 0 ) {
		while (txt.indexOf(invalids.charAt(i)) >= 0)
			{
				for(j=0; j<invalids.length; j++) {
					txt = txt.split(invalids.charAt(j)).join('');
				}
			}
		$('#alphanumproblem').show();           
		return txt;        
	}
	
}
	   
return txt;
}

function filterUrlCustom(txt,error_id) {
var invalids = "!@#$%^&*()-~,'<.>/?;:\|+=";
for(i=0; i<invalids.length; i++) {
	if(txt.indexOf(invalids.charAt(i)) >= 0 ) {
		while (txt.indexOf(invalids.charAt(i)) >= 0)
			{
				for(j=0; j<invalids.length; j++) {
					txt = txt.split(invalids.charAt(j)).join('');
				}
			}
		$("#"+error_id).show();           
		return txt;        
	}
	
}
	   
return txt;
}

function popupateFieldFromField(fromField, toField)
{
 if (document.getElementById(toField).value == '')
 {
	document.getElementById(toField).value = document.getElementById(fromField).value;    
 }   
}

function SelectAllOptions(the_form, the_select, val)
{
 var selectObject = document.forms[the_form].elements[the_select];
 var selectCount = selectObject.length;
if(val == "none")
{
	for (var i = 0; i < selectCount; i++) 
	{
	 selectObject.options[i].selected = true;
	} // end for
	
}
 
 return true;
}

function deleteComment(comment_id)
{
	if(window.confirm("Do you really want to delete this comment?"))
	{
	$('#comment_' + comment_id).hide("slow");
	$.ajax({
		type: "POST",
		url: BASEPATH + "comments/deleteComment",
		data: "id=" + comment_id ,
		success: function(msg)
		{
			if(msg != "1") 
			{
				alert("Comment not deleted! Please try later.");
				$('#comment_' + comment_id).show("slow");
			}
		}
	});
	}
}





jQuery.fn.center = function() {
		// Always return each...
		return this.each(function() {
				var t = jQuery(this);

				// Set position to other than 'static' so element shrink-wraps and width/height is calculated properly
				t.css({position: 'fixed'});

				// Why are there no jQuery.fn.outerWidth/Height:s?
				var w = t.width(),
						h = t.height(),
						lrPadding = parseInt(t.css('paddingLeft'), 10) + parseInt(t.css('paddingRight'), 10),
						lrBorder = parseInt(t.css('borderLeftWidth'), 10) + parseInt(t.css('borderRightWidth'), 10),
						tbPadding = parseInt(t.css('paddingTop'), 10) + parseInt(t.css('paddingBottom'), 10),
						tbBorder = parseInt(t.css('borderTopWidth'), 10) + parseInt(t.css('borderBottomWidth'), 10),
						leftMargin = (w + lrPadding + lrBorder) / 2;
						topMargin = (h + tbPadding + tbBorder) / 2;

				t.css({
						position: 'fixed',
						left: '50%',
						top: '50%',
						marginLeft: '-' +leftMargin +'px',
						marginTop: '-' +topMargin +'px',
						zIndex: '99'
				});

				/* Use this code if you care about IE<7, this requires the dimensions plug-in tho */
				// Calculate left and top pos values
				//var leftPos = (jQuery(window).width() - jQuery(this).outerWidth()) / 2 + jQuery(window).scrollLeft(), 
				//    topPos = (jQuery(window).height() - jQuery(this).outerHeight()) / 2 + jQuery(window).scrollTop();

				// Make sure element is not out of bounds
				var leftPos = (leftPos < 0) ? 0 : leftPos;
				var topPos = (topPos < 0) ? 0 : topPos;

				jQuery(this).css({left: leftPos +'px', top: topPos +'px', zIndex: '1000'});
				/* close ie stuff */
		});
};

// If dimensions plug-in isn't available
// Why is there no jQuery.fn.outerWidth bundled with jQuery?
if(!jQuery.fn.outerWidth) {
		jQuery.fn.outerWidth = function() {
				var t = jQuery(this[0]),
						w = t.width(),
						lrPadding = parseInt(t.css('paddingLeft'), 10) + parseInt(t.css('paddingRight'), 10),
						lrBorder = parseInt(t.css('borderLeftWidth'), 10) + parseInt(t.css('borderRightWidth'), 10);

				return w + lrPadding + lrBorder;
		};
}
if(!jQuery.fn.outerHeight) {
		jQuery.fn.outerHeight = function() {
				return this.each(function() {
						var t = jQuery(this[0]),
								h = t.height(),
								tbPadding = parseInt(t.css('paddingTop'), 10) + parseInt(t.css('paddingBottom'), 10),
								tbBorder = parseInt(t.css('borderTopWidth'), 10) + parseInt(t.css('borderBottomWidth'), 10);

						return h + tbPadding + tbBorder;
				});
		};
}

function showArticle(category,selectedNum) {
  $('#featured-articles li.selected').removeClass('selected');
  $('#article-tab-'+selectedNum).addClass('selected');
  $.ajax({
		type: "POST",
		url: BASEPATH + "articles/getFeaturedArticlesByInterest/" +category,
		success: function(msg){
		$('#featured-articles-content').html(msg);
		}
	  });
  return false;
}


function TestString (s, badChars) {
	if (IsStringValid(s, badChars)) {
	return 1;
	} else {
	  return 0;
	}
}

// IsStringValid returns true/false
// String s is valid if it does not
// contain any invalidChars
function IsStringValid(s, invalidChars) {
	for (i = 0; i < invalidChars.length; i++) {
	  if (s.indexOf(invalidChars.charAt(i)) > -1) {
		return false;
		}
	}
  return true;
}
	  
function pwChange(pw, rpw) {
if (pw == rpw) {
	if (pw != null) {
		var badChars = '#$~!\'\"\\';
		if (TestString(pw, badChars ) == 1) {
			alert("Password change succesful!");
			/*
				 $.ajax({
				   type: "POST",
				   url: "<?php  echo site_url().'auth/chpw'; ?>",
				   data: [{name: "pas", value: pw}],
				   success: function(msg)  {
				   alert("Password change succesful!");
				   hideFields();
				   }
				 });
				 */
			return true;
		} else {
		alert("Oops - Password must not contain any special characters");
		return false;
		}

	} else {
	  alert('Oops - You cannot have a blank password');
	hideFields();
	}

} else {
  alert("Oops - password does not match repeat password. Please try again.");
  return false;
}

}






//Header section

$(document).ready(function() {

		//var mainMenus = new Array('profile-link','mind-body-main', 'privacy-settings-link', 'msg-center-link', 'connections-link', 'groups-link', 'photos-link', 'journal-link', 'calendar-link', 'todo-link', 'articles-link');
		var mainMenus = new Array('profile-link');

		$.each(mainMenus, function(i, n){
			/*$('#' + n).attr('class', '');*/
			$('#' + n +' > a').click(function(){
				var nextClass = ($('#' + n).attr('class') == 'selected') ? '' : 'selected';
				$('#' + n).attr('class', nextClass);
			});
		});
		

		
		
});

//Main Page widget calendar reload
function reloadCalendar(yr,mo) {
		$.ajax({
		type: "GET",
		url: BASEPATH + "events/regenerateCalendar/"+yr+"/mo/"+mo,
		success: function(msg)
		{
		  $('#calendar_box').html(msg);
		}
	});
}

//Main Page widget calendar cell action
function widgetCellAction(id) {
	$('.highlight').css('background-color','#FFFFFF');
	$('.highlight').css('color','#0095E5');
	$('.highlight').css('font-weight','normal');
	
	for (i=0;i<32;i++) {
		for (j=0;j<13;j++) {
			$('#cell_' + i + '_' + j).css('background-color','#FFFFFF');
			$('#cell_' + i + '_' + j).css('color','#0095E5');
			$('#cell_' + i + '_' + j).css('font-weight','normal');	
			$('#cell_' + i + '_' + j).css('width','12px');	
			$('#cell_' + i + '_' + j).css('padding','0px');	
		}
	}
	
	$('#' + id).css('background-color','#0095E5');
	$('#' + id).css('color','#FFFFFF');
	$('#' + id).css('font-weight','bold');
	$('#' + id).css('padding-left','2px');
	$('#' + id).css('padding-right','2px');
	
	yr = $('#hidden_year').val();
	year = yr.substring(yr.length,yr.length-4);
	$.ajax({
		type: "GET",
		url: BASEPATH + "events/generateEventsOfDate/"+id+"_"+year,
		success: function(msg)
		{
			if (msg != '') {
				$("#event_box").html(msg);
				
			} else {
				$("#event_box").html('There are no events starting on that date');
			}
			//alert(msg);
			//$('#calendar_box').html(msg);
		}
	});	
	
}



function load_social_site(site) { 
	var screen_height = parseInt(screen.height*0.65);
	$("#entire_page").load(BASEPATH+"social_proxy/proxy/"+site+"/height/"+screen_height);
}

function busy_meter_insert(type) {
	var status = $("#busy_meter").val();
	
	if(status!= -1) { // if value is not -1
	var message = new Array();
	message[0] = "Just relaxing";
	message[1] = "A little bit busy";
	message[2] = "Busy but not crazy busy";
	message[3] = "So busy I don't remember what day it is";
	
	$.ajax({ type: "POST",
				 url: BASEPATH + "newsFeeds/busy_meter_insert",
				 data: [{name: "status", value: status}, 
						{name: "type", value: type}],
				 success: function(data)  {
					if (data==1) {
						$("#busy_meter_message").html('');
						$("#busy_meter_message").html(message[status]);
					} else {
						$("#busy_meter_message").html('');
						$("#busy_meter_message").html('<span style=\'color: red;\'>Error: please try again</span>');
					}
				 }
	});
  } // end of if value is not -1
}
