function RemoteRequestObject()
{
var A = false;
try
{
	A = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
	try
	{
		A = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(err)
	{
		A = false;
	}
}
if(!A && typeof(XMLHttpRequest) != 'undefined')
	A = new XMLHttpRequest();
	
return A;
}

function fnCheckSpaces(txtObj)
{
	/*Local Variables intLen
		intLen -- To store the Length of the string
	*/

	var intLen
	intLen=txtObj.value.length
	// remove spaces bfore string
	for(var i=0;i<=intLen;i++)
	{
		if(txtObj.value.charAt(0)==" ")
		{
			txtObj.value=txtObj.value.replace(" ","")
		}
		else {
			break
		}
	}
	return txtObj
}

function fnInvitePeer()
{
	  var t=setTimeout("fnConformRefresh('errortext1')",10000);
	  if(document.frmInvitePeer.toemails.value=="")
	  {
		  document.getElementById('errortext1').style.display="";
		  document.getElementById('errortext1').innerHTML="<p>Enter Email-Id</p>";
		  document.frmInvitePeer.toemails.focus();
		  return false;
	  }
	  if(!fnEmail2(document.frmInvitePeer.toemails,'errortext1')){
		  return false;
	  }
}

var xmlHttpRemoveGM
function fnRemoveGM(gid,uid,uname)
{
	xmlHttpRemoveGM=GetXmlHttpObject()
	if (xmlHttpRemoveGM==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 } 
	var url = "/removepopup.php";
	url = url+"?gid="+gid+"&uid="+uid+"&uname="+uname+"&sessid="+Math.random();
	divwin=dhtmlwindow.open('divbox', 'div', 'DIVPOPUP', 'Loading...', 'width=450px,left=300px,top=150px,height=120px');
	xmlHttpRemoveGM.onreadystatechange=stateChangedRemoveGM;
	xmlHttpRemoveGM.open("GET",url,true);
	xmlHttpRemoveGM.send(null);
}

function fnCancel()
{
	dhtmlwindow.close(document.getElementById("divbox"));
}

function stateChangedRemoveGM() 
{ 
 if (xmlHttpRemoveGM.readyState==4 || xmlHttpRemoveGM.readyState=="complete")
 { 
	 document.getElementById("DIVPOPUP").innerHTML=xmlHttpRemoveGM.responseText;
	 divwin=dhtmlwindow.open('divbox', 'div', 'DIVPOPUP', 'Remove group membership?', 'width=450px,left=300px,top=150px,height=120px'); return false;
 } 
}



var xmlHttpGetPeerList
function fnGetPeerList(uid)
{
	xmlHttpGetPeerList=GetXmlHttpObject()
	if (xmlHttpGetPeerList==null)
	{
		 alert("Browser does not support HTTP Request")
		 return;
	} 
	//showBackground();
	LoadingImage();
	var url = "/groups/getpeerlist/"+uid;
	xmlHttpGetPeerList.onreadystatechange=stateChangedGetPeerList;
	xmlHttpGetPeerList.open("GET",url,true);
	xmlHttpGetPeerList.send(null);
}
function stateChangedGetPeerList() 
{ 
 if (xmlHttpGetPeerList.readyState==4 || xmlHttpGetPeerList.readyState=="complete")
 { 
	 document.getElementById("showdetails1").innerHTML=xmlHttpGetPeerList.responseText;
	 document.getElementById("loading").style.display="none";
	 document.getElementById("backgroundDiv").style.display="none";
	 if(xmlHttpGetPeerList.responseText!="<br><br>No peers available to display"){
	     if(fnCheckSpaces(document.getElementById("toemails")).value != ""){
			 document.getElementById("toemails").value=document.getElementById("toemails").value+","+document.getElementById("ptempemails").value;
		 }else{
			 document.getElementById("toemails").value=document.getElementById("ptempemails").value;
		 }
										
	}
 } 
}

function showBackground() {
    var waitDiv = document.getElementById('backgroundDiv');
	if (!document.all) {
      waitDiv.style.height = 600;
      waitDiv.style.width = 800;
    } else {
      waitDiv.style.height = document.body.clientHeight;
      waitDiv.style.width = document.body.clientWidth;
    }
    waitDiv.style.display = '';
    document.body.scrollTop = 0;
}

function fnRemoveEmails(chkval,pvalue)
{
	//alert(chkval);
	var tempemails = "";
	var ptempemails = "";
	if(pvalue == "GroupInvite"){
		//if(document.getElementById("showdetails1").innerHTML != ""){
			for(var i=0;i<document.getElementById("pcountval").value;i++){
				if(document.getElementById("pcheck"+i).checked == false){
					ptempemails = ptempemails;
				}else if(document.getElementById("pcheck"+i).checked == true){
					ptempemails = ptempemails+","+document.getElementById("pemail"+i).value;
				}
			}
			document.getElementById("ptempemails").value = ptempemails.substr(1);
		//}
	}
	if(document.getElementById("countval")){
		for(var i=0;i<document.getElementById("countval").value;i++){
			if(document.getElementById("check"+i).checked == false){
				tempemails = tempemails;
			}else if(document.getElementById("check"+i).checked == true){
				tempemails = tempemails+","+document.getElementById("email"+i).value;
			}
		}
		document.getElementById("tempemails").value = tempemails.substr(1);
	}
	if(ptempemails.substr(1) == ""){
		parent.document.getElementById("toemails").value = tempemails.substr(1);
	}else if((tempemails.substr(1) != "") && (ptempemails.substr(1) != "")){
		parent.document.getElementById("toemails").value = tempemails.substr(1)+","+ptempemails.substr(1);
	}else{
		parent.document.getElementById("toemails").value = ptempemails.substr(1);
	}
}


function LoadingImage()
{
	var scrolledX, scrolledY;
    if( self.pageYOffset ) {
	  scrolledX = self.pageXOffset;
	  scrolledY = self.pageYOffset;
    } else if( document.documentElement && document.documentElement.scrollTop ) {
	  scrolledX = document.documentElement.scrollLeft;
	  scrolledY = document.documentElement.scrollTop;
    } else if( document.body ) {
	  scrolledX = document.body.scrollLeft;
	  scrolledY = document.body.scrollTop;
    }
    var centerX, centerY;
    if( self.innerHeight ) {
	  centerX = self.innerWidth;
	  centerY = self.innerHeight;
    } else if( document.documentElement && document.documentElement.clientHeight ) {
	  centerX = document.documentElement.clientWidth;
	  centerY = document.documentElement.clientHeight;
    } else if( document.body ) {
	  centerX = document.body.clientWidth;
	  centerY = document.body.clientHeight;
    }
    var leftOffset = scrolledX + (centerX - 120) / 2;
    var topOffset = scrolledY + (centerY - 50) / 2;
    document.getElementById("loading").style.top = topOffset + "px";
    document.getElementById("loading").style.left = leftOffset + "px";
    document.getElementById("loading").style.display="";
}


function fnShowAttachments(mType,mincount,maxcount)
{
	if(mType == "Add"){
		var tempval = document.frmMessage.attachcount.value;
		if(tempval == "0"){tempval = mincount}else{tempval = parseInt(tempval) + parseInt(mincount)}
		document.getElementById("attachment"+tempval).style.display="";
		document.frmMessage.attachcount.value = tempval;
		if(tempval == maxcount){document.getElementById("attachfile").style.display="none";}
	}else if(mType == "Remove"){
		var tempval = document.frmMessage.attachcount.value;
		tempval = tempval - 1;
		document.frmMessage.attachcount.value = tempval;
		document.getElementById("attachedfile"+mincount).value = null;
		document.getElementById("attachment"+mincount).style.display="none";
		document.getElementById("attachfile").style.display="";
	}
}

function fnValidateRegister(step)
{
	  if(step == "step1")
	  {
		  if(document.frmRegister.full_name.value=="")
		  {
			  document.getElementById('errortext1').style.display="";
			  document.getElementById('errortext1').innerHTML="<p>Enter Full Name</p>";
			  document.frmRegister.full_name.focus();
			  return false;
		  }
		  if(document.frmRegister.alias_name.value=="")
		  {
			  document.getElementById('errortext1').style.display="";
			  document.getElementById('errortext1').innerHTML="<p>Enter Alias Name</p>";
			  document.frmRegister.alias_name.focus();
			  return false;
		  }
		  if(document.frmRegister.email.value=="")
		  {
			  document.getElementById('errortext1').style.display="";
			  document.getElementById('errortext1').innerHTML="<p>Enter Email</p>";
			  document.frmRegister.email.focus();
			  return false;
		  }
		  if(!fnEmail(document.frmRegister.email,'errortext1')){
			  return false;
		  }
		  if(document.frmRegister.pswd.value=="")
		  {
			  document.getElementById('errortext1').style.display="";
			  document.getElementById('errortext1').innerHTML="<p>Enter Password</p>";
			  document.frmRegister.pswd.focus();
			  return false;
		  }
		  if(document.frmRegister.validate_pswd.value=="")
		  {
			  document.getElementById('errortext1').style.display="";
			  document.getElementById('errortext1').innerHTML="<p>Validate your Password</p>";
			  document.frmRegister.validate_pswd.focus();
			  return false;
		  }
		  if(document.frmRegister.pswd.value != document.frmRegister.validate_pswd.value)
		  {
			  document.getElementById('errortext1').style.display="";
			  document.getElementById('errortext1').innerHTML="<p>Validate your Password</p>";
			  document.frmRegister.validate_pswd.value="";
			  document.frmRegister.validate_pswd.focus();
			  return false;
		  }
		  document.getElementById('errortext1').style.display="none";
		  show('step2'); 
		  hide('step1');
	  }else if(step == "step2"){
		  if(document.frmRegister.user_type.value=="")
		  {
			  document.getElementById('errortext2').style.display="";
			  document.getElementById('errortext2').innerHTML="<p>Select Type</p>";
			  document.frmRegister.user_type.focus();
			  return false;
		  }
		  if(document.frmRegister.job_title.value=="")
		  {
			  document.getElementById('errortext2').style.display="";
			  document.getElementById('errortext2').innerHTML="<p>Enter Job Title</p>";
			  document.frmRegister.job_title.focus();
			  return false;
		  }
		  if(document.frmRegister.area_of_expertise.value=="")
		  {
			  document.getElementById('errortext2').style.display="";
			  document.getElementById('errortext2').innerHTML="<p>Enter Area Of Expertise</p>";
			  document.frmRegister.area_of_expertise.focus();
			  return false;
		  }
		  document.getElementById('errortext2').style.display="none";
		  show('step3'); 
		  hide('step2');
	  }else if(step == "step3"){
		  if(document.frmRegister.company_name.value=="")
		  {
			  document.getElementById('errortext3').style.display="";
			  document.getElementById('errortext3').innerHTML="<p>Enter Company Name</p>";
			  document.frmRegister.company_name.focus();
			  return false;
		  }
		  if(document.frmRegister.company_vertical.value=="")
		  {
			  document.getElementById('errortext3').style.display="";
			  document.getElementById('errortext3').innerHTML="<p>Enter Company Vertical</p>";
			  document.frmRegister.company_vertical.focus();
			  return false;
		  }
		  if(document.frmRegister.company_size.value=="")
		  {
			  document.getElementById('errortext3').style.display="";
			  document.getElementById('errortext3').innerHTML="<p>Select Company Size</p>";
			  document.frmRegister.company_size.focus();
			  return false;
		  }
		  document.getElementById('errortext3').style.display="none";
		  show('step4'); 
		  hide('step3');
	  }else if(step == "step4"){
		  if(document.frmRegister.verification_code.value=="")
		  {
			  document.getElementById('errortext4').style.display="";
			  document.getElementById('errortext4').innerHTML="<p>Enter Verification Code</p>";
			  document.frmRegister.verification_code.focus();
			  return false;
		  }
		  if(document.frmRegister.accept.checked == false)
		  {
			  document.getElementById('errortext4').style.display="";
			  document.getElementById('errortext4').innerHTML="<p>Do You Read The Terms Of Use and Privacy Policy</p>";
			  return false;
		  }
	  }
	return true;
}
function refreshImage()
{
	var url = "/randomImage.php?p="+Math.random();
	document.getElementById("verImage").setAttribute('src', url);
}
function fnLogout()
{
   window.location.href="?c=control&m=logout";
}
function fnSignUp()
{
   window.location.href="?c=control&m=lp&page=register";
}
function fnValidateForgot()
{
	if(document.frmForgot.email.value=="")
    {
	    document.getElementById('errorforgot').style.display="";
	    document.getElementById('errorforgot').innerHTML="<p>Enter Email-Id</p>";
	    document.frmForgot.email.focus();
	    return false;
    }
	if(!fnEmail(document.frmForgot.email,'errorforgot')){
	    return false;
    }
	document.frmForgot.action="?c=control&m=sp&page=forgotpassword";
	document.frmForgot.submit();
	return true;
}
function fnShowServices(contactstatus)
{
	if(contactstatus == "Yes"){
		document.getElementById("service_name").disabled=false;
	}else if(contactstatus == "No"){
		document.getElementById("showdetails").style.display="none";
		document.getElementById("service_name").value="";
		document.getElementById("service_name").disabled=true;
		document.getElementById("showbook").style.display="none";
	}
}
function fnShowDetails(servicename)
{
	document.frmInvitePeer.emailaddress.value="";
	document.frmInvitePeer.password.value="";
	if(servicename != ""){
		document.getElementById("showbook").style.display="";
	}else{
		document.getElementById("showdetails").style.display="none";
		document.getElementById("showbook").style.display="none";
	}
	document.getElementById("sheadding").innerHTML = servicename+" Address Book Import";
}
function fnValidateImport()
{
	if(document.frmInvitePeer.emailaddress.value=="")
    {
		document.getElementById('errorimport').style.display="";
		document.getElementById('errorimport').innerHTML="<p>Enter Email-Id</p>";
		document.frmInvitePeer.emailaddress.focus();
		return false;
	}
	if(document.frmInvitePeer.password.value=="")
    {
		document.getElementById('errorimport').style.display="";
		document.getElementById('errorimport').innerHTML="<p>Enter Password</p>";
		document.frmInvitePeer.password.focus();
		return false;
	}
	var emailaddress = document.frmInvitePeer.emailaddress.value;
	var password     = document.frmInvitePeer.password.value;
	var service_name = document.frmInvitePeer.service_name.value;

	showUser(service_name,emailaddress,password);
	
	return true;
}

var xmlHttp
function showUser(sname,email,pwd)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 

var url="importer.php";
url=url+"?sname="+sname+"&email="+email+"&pwd="+pwd+"&sessid="+Math.random();
document.getElementById("showdetailstemp").style.display="";
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	document.getElementById("showdetailstemp").style.display="none";
	document.getElementById("showdetails").innerHTML=xmlHttp.responseText;
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function fnGroupValidate(ptype,gid)
{
	if(document.frmCreateGroup.group_name.value=="")
	{
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Enter Group Name</p>";
		 document.frmCreateGroup.group_name.focus();
		 return false;
	}
	if(document.frmCreateGroup.group_type.value=="")
	{
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Select Group Type</p>";
		 document.frmCreateGroup.group_type.focus();
		 return false;
	}
	if(document.frmCreateGroup.group_desc.value=="")
	{
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Enter Group Description</p>";
		 document.frmCreateGroup.group_desc.focus();
		 return false;
	}
	if(document.frmCreateGroup.group_originator_email.value=="")
	{
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Enter Group Originator Email</p>";
		 document.frmCreateGroup.group_originator_email.focus();
		 return false;
	}
	if(!fnEmail(document.frmCreateGroup.group_originator_email,'errortext')){
	     return false;
    }
	if(ptype == "CreateGroup"){
		document.frmCreateGroup.pType.value=ptype;
		document.frmCreateGroup.submit();
	}else if(ptype == "EditGroup"){
		document.frmCreateGroup.pType.value=ptype;
		document.frmCreateGroup.submit();
	}
	
	return true;
}

function fnPostEvent(gid)
{
	var emonth = document.frmPostEvent.emonth.value;
	var eday   = document.frmPostEvent.eday.value;
	var eyear  = document.frmPostEvent.eyear.value;
	if(document.frmPostEvent.event_title.value=="")
	{
		document.getElementById('errorevent').style.display="";
		document.getElementById('errorevent').innerHTML="<p><b>Enter Event Title</b></p>";
		document.frmPostEvent.event_title.focus();
		return false;
	}
	if(eday=="")
	{
		document.getElementById('errorevent').style.display="";
		document.getElementById('errorevent').innerHTML="<p><b>Select Event Day</b></p>";
		document.frmPostEvent.eday.focus();
		return false;
	}
	if(emonth=="")
	{
		document.getElementById('errorevent').style.display="";
		document.getElementById('errorevent').innerHTML="<p><b>Select Event Month</b></p>";
		document.frmPostEvent.emonth.focus();
		return false;
	}
	if(eyear=="")
	{
		document.getElementById('errorevent').style.display="";
		document.getElementById('errorevent').innerHTML="<p><b>Select Event Year</b></p>";
		document.frmPostEvent.eyear.focus();
		return false;
	}
	if((emonth=="04" || emonth=="06" || emonth=="09" || emonth=="11") && eday=="31"){
		document.getElementById('errorevent').style.display="";
		document.getElementById('errorevent').innerHTML="<p><b>Please select valid date</b></p>";
		document.frmPostEvent.emonth.focus();
		return false;
	}
	if(eyear%4=="0" && emonth=="02" && eday>29){
		document.getElementById('errorevent').style.display="";
		document.getElementById('errorevent').innerHTML="<p><b>Please select valid date</b></p>";
		document.frmPostEvent.emonth.focus();
		return false;
	}else if(eyear%4!="0" && emonth=="02" && eday>28){
		document.getElementById('errorevent').style.display="";
		document.getElementById('errorevent').innerHTML="<p><b>Please select valid date</b></p>";
		document.frmPostEvent.emonth.focus();
		return false;
	}
	if(document.frmPostEvent.ehours.value=="")
	{
		document.getElementById('errorevent').style.display="";
		document.getElementById('errorevent').innerHTML="<p><b>Select hours</b></p>";
		document.frmPostEvent.ehours.focus();
		return false;
	}
	if(document.frmPostEvent.eminutes.value=="")
	{
		document.getElementById('errorevent').style.display="";
		document.getElementById('errorevent').innerHTML="<p><b>Select minutes</b></p>";
		document.frmPostEvent.eminutes.focus();
		return false;
	}
	if(document.frmPostEvent.event_desc.value=="")
	{
		document.getElementById('errorevent').style.display="";
		document.getElementById('errorevent').innerHTML="<p><b>Enter Description</b></p>";
		document.frmPostEvent.event_desc.focus();
		return false;
	}
	document.frmPostEvent.action="/groups/postevent/"+gid;
	document.frmPostEvent.submit();
	
	return true;
}

function fnPostDocument(gid)
{
	var t=setTimeout("fnConformRefresh('errortext')",10000);
	if(document.frmPostDoc.file_name.value=="")
	{
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Select a document to post</p>";
		 document.frmPostDoc.file_name.focus();
		 return false;
	}
	if(document.frmPostDoc.file_desc.value=="")
	{
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Enter description</p>";
		 document.frmPostDoc.file_desc.focus();
		 return false;
	}
	document.frmPostDoc.action="/groups/postfile/"+gid;
	document.frmPostDoc.submit();
}


function fnPostLink(gid)
{
	if(document.frmPostLink.posted_link.value=="")
	{
		 document.getElementById('errorlink').style.display="";
		 document.getElementById('errorlink').innerHTML="<p><b>Enter Link</b></p>";
		 document.frmPostLink.posted_link.focus();
		 return false;
	}
	if(document.frmPostLink.link_comments.value=="")
	{
		 document.getElementById('errorlink').style.display="";
		 document.getElementById('errorlink').innerHTML="<p><b>Enter Link Comments</b></p>";
		 document.frmPostLink.link_comments.focus();
		 return false;
	}
	document.frmPostLink.action= "/groups/postlink/" + gid;
	document.frmPostLink.submit();
}

var xmlHttpSavePrivacy
function fnSavePrivacy(pname,uid)
{
	xmlHttpSavePrivacy=GetXmlHttpObject()
	if (xmlHttpSavePrivacy==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var pvalue = document.getElementById(pname).value;
	var url="?c=control&m=sp&page=saveprivacy&pvalue="+pvalue+"&pname="+pname+"&uid="+uid+"&sessid="+Math.random();
	xmlHttpSavePrivacy.onreadystatechange=stateChangedSavePrivacy;
	xmlHttpSavePrivacy.open("GET",url,true);
	xmlHttpSavePrivacy.send(null);
}

function stateChangedSavePrivacy() 
{ 
  if (xmlHttpSavePrivacy.readyState==4 || xmlHttpSavePrivacy.readyState=="complete")
  { 
	 document.getElementById("popup").style.display="none";
	 document.getElementById("errortext").innerHTML = "<p style='padding-left:175px;padding-bottom:15px;padding-top:18px;'><b>"+xmlHttpSavePrivacy.responseText+"</b></p><div style='text-align:right; background:#F6F8FA; border-bottom:#E3E3E3 solid 1px; border-top:#E3E3E3 solid 1px; padding:20px;'></div>";
	 document.getElementById("errortext").style.display="";
	 var t=setTimeout("fnConformRefresh()",500);
  } 
}

function fnConformRefresh()
{
	window.location.reload();
}


var xmlHttpJoinGroup
function fnJoinGroup(gid,gname)
{
	xmlHttpJoinGroup=GetXmlHttpObject()
	if (xmlHttpJoinGroup==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 } 
	var url = "/joinpopup.php";
	url = url+"?gid="+gid+"&gname="+gname+"&sessid="+Math.random();
	divwin=dhtmlwindow.open('divbox', 'div', 'DIVPOPUP', 'Loading...', 'width=450px,left=300px,top=150px,height=100px');
	xmlHttpJoinGroup.onreadystatechange=stateChangedJoinGroup;
	xmlHttpJoinGroup.open("GET",url,true);
	xmlHttpJoinGroup.send(null);
}

function stateChangedJoinGroup() 
{ 
 if (xmlHttpJoinGroup.readyState==4 || xmlHttpJoinGroup.readyState=="complete")
 { 
 	 
	 document.getElementById("DIVPOPUP").innerHTML=xmlHttpJoinGroup.responseText;
	 divwin=dhtmlwindow.open('divbox', 'div', 'DIVPOPUP', 'Add group membership?', 'width=450px,left=300px,top=150px,height=100px'); return false;
 } 
}

var xmlHttpLeaveGroup
function fnLeaveGroup(gid,gname)
{
	xmlHttpLeaveGroup=GetXmlHttpObject()
	if (xmlHttpLeaveGroup==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 } 
	var url = "/leavepopup.php";
	url = url+"?gid="+gid+"&gname="+gname+"&sessid="+Math.random();
	divwin=dhtmlwindow.open('divbox', 'div', 'DIVPOPUP', 'Loading...', 'width=450px,left=300px,top=150px,height=100px');
	xmlHttpLeaveGroup.onreadystatechange=stateChangedLeaveGroup;
	xmlHttpLeaveGroup.open("GET",url,true);
	xmlHttpLeaveGroup.send(null);
}

function fnConfirmRemoveGroup(gid,uid,gname)
{
	window.location.href="/groups/leavegroup/"+gid+"/"+uid;
}

function stateChangedLeaveGroup() 
{ 
 if (xmlHttpLeaveGroup.readyState==4 || xmlHttpLeaveGroup.readyState=="complete")
 { 
	 document.getElementById("DIVPOPUP").innerHTML=xmlHttpLeaveGroup.responseText;
	 divwin=dhtmlwindow.open('divbox', 'div', 'DIVPOPUP', 'Remove group membership?', 'width=450px,left=300px,top=150px,height=100px'); return false;
 } 
}

var xmlHttpPOPUP
function showPOPUP(divname,imgname, uid)
{ 
	xmlHttpPOPUP=GetXmlHttpObject()
	if (xmlHttpPOPUP==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="/popup.php";
	url=url+"?divname="+divname+"&imgname="+imgname+"&sessid="+Math.random()+"&uid="+uid;
	divwin=dhtmlwindow.open('divbox', 'div', 'DIVPOPUP', 'Loading...', 'width=450px,left=300px,top=200px,height=100px');
	xmlHttpPOPUP.onreadystatechange=stateChangedPOPUP;
	xmlHttpPOPUP.open("GET",url,true);
	xmlHttpPOPUP.send(null);
}

function stateChangedPOPUP() 
{ 
 if (xmlHttpPOPUP.readyState==4 || xmlHttpPOPUP.readyState=="complete")
 { 
	var result = xmlHttpPOPUP.responseText.split("$$$");
	document.getElementById("DIVPOPUP").innerHTML=result[1];
	divwin=dhtmlwindow.open('divbox', 'div', 'DIVPOPUP', 'Edit '+result[0]+' Privacy', 'width=450px,left=300px,top=200px,height=100px'); return false;
 } 
}

function fnChangeImage(val)
{
	if(val == "Only Me"){
		document.getElementById("sparklineimage").src="/images/sparkline_0.jpg";
	}else if(val == "Only Me and Peers"){
		document.getElementById("sparklineimage").src="/images/sparkline_2.jpg";
	}else if(val == "Everyone"){
		document.getElementById("sparklineimage").src="/images/sparkline_3.gif";
	}
}

function fnAddaddress(ival,acnt,mcnt)
{
	 var tempaccval = document.frmprofile.acount.value;
	if(tempaccval == ""){
		document.getElementById("Address"+acnt).style.display="";
		document.frmprofile.acount.value=acnt;
	}else{
		tempcnt = parseInt(tempaccval) + parseInt(ival);
		document.frmprofile.acount.value = tempcnt;
		document.getElementById("Address"+tempcnt).style.display="";
		if(tempcnt == mcnt){
			document.getElementById("Add").style.display="none";
		}
	}
}

function fnChangearea()
{
	 var expertareas = document.getElementById("area_of_expertise[]");
	 for(var i=1;i<expertareas.length;i++)
	 {
		 if(expertareas[i].selected == true)
		 {
			 if(expertareas[i].value == "Other")
			 {
				 document.getElementById('other').style.display="";
			 }else{
				 document.getElementById('other').style.display="none";
			 }
		 }
		 
	 }
}

function fnUploadPicture()
{
	var imgext;
	imgext=document.frmUploadPicture.user_image.value;
	imgext=imgext.substr(imgext.length-4);

if(imgext!=".jpg" && imgext!=".gif" && imgext!=".png" && imgext!=".JPG" && imgext!=".GIF" && imgext!=".PNG" || imgext==""){
//	if(imgext!=".jpg" && imgext!=".gif" && imgext!=".png" || imgext==""){
		document.getElementById('errortext2').style.display="";
		document.getElementById('errortext2').innerHTML="<p>Only JPEG or PNG or GIF files are allowed to upload</p>";
		document.frmUploadPicture.user_image.focus();
		return false;
	}
	if(document.frmUploadPicture.user_image_check.checked == false)
	{
		 document.getElementById('errortext2').style.display="";
		 document.getElementById('errortext2').innerHTML="<p>Please certify that picture does not violate the Terms of Use</p>";
		 document.frmUploadPicture.user_image_check.focus();
		 return false;
	}
	document.frmUploadPicture.action="/upload/";
	document.frmUploadPicture.submit();
}

function fnProfilePic(aType,pid)
{
	if(aType == "Cancel"){
		document.getElementById("EDIV"+pid).style.display="";
		document.getElementById("UDIV"+pid).style.display="none";
	}else if(aType == "Edit"){
		document.getElementById("EDIV"+pid).style.display="none";
		document.getElementById("UDIV"+pid).style.display="";
	}
}

function fnDeletePic(picid)
{
	if(confirm("Do you want to delete this image from your album?"))
	{
		window.location.href="/useralbum/delete/"+picid;
		return true;
	}else{
		return false;
	}
}

function fnEmail(txtEmail,DIVID)
{
	if (txtEmail.value!="")
	{
		var intLen=txtEmail.value.length
		var blnFlag=0
		if (txtEmail.value.charAt(0)=="@" || txtEmail.value.charAt(0)==".")
		{
			document.getElementById(DIVID).style.display="";
			document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
			txtEmail.focus()
			return false
		}
		if (txtEmail.value.charAt(intLen-1)=="@" || txtEmail.value.charAt(intLen-1)==".")
		{
			document.getElementById(DIVID).style.display="";
			document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
			txtEmail.focus()
			return false
		}
		for (var i=0;i<intLen;i++)
		{
			if (txtEmail.value.charAt(i)=="@")
			{
				blnFlag=blnFlag+1
			}
		}
		if (blnFlag>=0 && blnFlag<1 || blnFlag>1)
		{
			document.getElementById(DIVID).style.display="";
			document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
			txtEmail.focus()
			return false
		}
		strSplit=(txtEmail.value).split("@")
		intSptLen=strSplit[1].length
		var intCnt=0
		for(var j=0;j<intSptLen;j++)
		{
			if (strSplit[1].charAt(j)==".")
			{
				intCnt=intCnt+1
			}
		}
		if (intCnt<=0)
		{
			document.getElementById(DIVID).style.display="";
			document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
			txtEmail.focus()
			return false
		}
		return true
	}
}

function fnEmail1(txtEmail,DIVID)
{
	if (txtEmail.value!="")
	{
		var intLen=txtEmail.value.length
		var blnFlag=0
		if (txtEmail.value.charAt(0)=="@" || txtEmail.value.charAt(0)==".")
		{
			show('step1');hide('step2');hide('step3');hide('step4');
			document.getElementById(DIVID).style.display="";
			document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
			txtEmail.focus()
			return false
		}
		if (txtEmail.value.charAt(intLen-1)=="@" || txtEmail.value.charAt(intLen-1)==".")
		{
			show('step1');hide('step2');hide('step3');hide('step4');
			document.getElementById(DIVID).style.display="";
			document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
			txtEmail.focus()
			return false
		}
		for (var i=0;i<intLen;i++)
		{
			if (txtEmail.value.charAt(i)=="@")
			{
				blnFlag=blnFlag+1
			}
		}
		if (blnFlag>=0 && blnFlag<1 || blnFlag>1)
		{
			show('step1');hide('step2');hide('step3');hide('step4');
			document.getElementById(DIVID).style.display="";
			document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
			txtEmail.focus()
			return false
		}
		strSplit=(txtEmail.value).split("@")
		intSptLen=strSplit[1].length
		var intCnt=0
		for(var j=0;j<intSptLen;j++)
		{
			if (strSplit[1].charAt(j)==".")
			{
				intCnt=intCnt+1
			}
		}
		if (intCnt<=0)
		{
			show('step1');hide('step2');hide('step3');hide('step4');
			document.getElementById(DIVID).style.display="";
			document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
			txtEmail.focus()
			return false
		}
		return true
	}
}

function fnEmail2(txtEmail,DIVID)
{
	if (txtEmail.value!="")
	{
        var Emails = txtEmail.value.split(',');
		for(var i=0;i<Emails.length;i++){
			var intLen = Emails[i].length;
			var blnFlag=0
			if (Emails[i].charAt(0)=="@" || Emails[i].charAt(0)==".")
			{
				document.getElementById(DIVID).style.display="";
				document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
				txtEmail.focus()
				return false
			}
			if (Emails[i].charAt(intLen-1)=="@" || Emails[i].charAt(intLen-1)==".")
			{
				document.getElementById(DIVID).style.display="";
				document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
				txtEmail.focus()
				return false
			}
			for (var j=0;j<intLen;j++)
			{
				if (Emails[i].charAt(j)=="@")
				{
					blnFlag=blnFlag+1
				}
			}
			if (blnFlag>=0 && blnFlag<1 || blnFlag>1)
			{
				document.getElementById(DIVID).style.display="";
				document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
				txtEmail.focus()
				return false
			}
			strSplit=(Emails[i]).split("@")
			intSptLen=strSplit[1].length
			var intCnt=0
			for(var k=0;k<intSptLen;k++)
			{
				if (strSplit[1].charAt(k)==".")
				{
					intCnt=intCnt+1
				}
			}
			if (intCnt<=0)
			{
				document.getElementById(DIVID).style.display="";
				document.getElementById(DIVID).innerHTML="<p>Invalid E-Mail Address</p>";
				txtEmail.focus()
				return false
			}
		}
		return true
		
	}
}

/************************* FORUMS  START*********************************/
function fnCreateGroupForumCat(gid,cid,pType){
	document.getElementById('gid').value = gid;
	document.getElementById('pType').value = pType;
	document.getElementById('cid').value = cid;
	document.frmForums.action = '?c=control&m=lp&page=createforumcat';
	document.frmForums.submit();
}

function fnCreateForumCategory(gid,cid,pType){
	if(document.frmCreateCat.cat_name.value==""){
		 document.getElementById('errortext').style.display = "";
		 document.getElementById('errortext').innerHTML="<p>Enter category name</p>";
		 document.frmCreateCat.cat_name.focus();
		 return false;
	}
	document.getElementById('gid').value = gid;
	document.getElementById('cid').value = cid;
	document.getElementById('pType').value = pType;
	document.frmCreateCat.action = '/groups/createforumcat/' + gid + '/' + pType;
	document.frmCreateCat.submit();
}

function fnViewForumCategory(cid){
	document.getElementById('cid').value = cid;
	document.frmForums.action = '?c=control&m=lp&page=forumcat';
	document.frmForums.submit();
}

function fnCreateGroupForum(gid,cid,fid,pType){
	document.getElementById('gid').value = gid;
	document.getElementById('cid').value = cid;
	document.getElementById('fid').value = fid;
	document.getElementById('pType').value = pType;
	document.frmForums.action = '?c=control&m=lp&page=createforum';
	document.frmForums.submit();
}

function fnCreateForum(gid,cid,fid,pType){
	var t=setTimeout("fnConformRefresh('errortext')",10000);
	document.getElementById('gid').value = gid;
	document.getElementById('cid').value = cid;
	document.getElementById('fid').value = fid;
	document.getElementById('pType').value = pType;
	if(document.frmCreateForum.forum_name.value==""){
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Enter forum name</p>";
		 document.frmCreateForum.forum_name.focus();
		 return false;
	}
	if(document.frmCreateForum.forum_desc.value==""){
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Enter description</p>";
		 document.frmCreateForum.forum_desc.focus();
		 return false;
	}
	document.frmCreateForum.action = '?c=control&m=sp&page=CreateForum&sessid='+Math.random();
	document.frmCreateForum.submit();
}

function fnCreateForumTopics(cid,fid,tid,pType){
	document.getElementById('cid').value = cid;
	document.getElementById('fid').value = fid;
	document.getElementById('tid').value = tid;
	document.getElementById('pType').value = pType;
	document.frmForumTopics.action = '/groups/createforumtopics/' + gid + '/' + cid + '/' + pType;
	document.frmForumTopics.submit();
}

function fnCreateForumTopic(cid,fid,tid,pType){
	var t=setTimeout("fnConformRefresh('errortext')",10000);
	if(document.frmForumTopics.topic_title.value==""){
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Enter topic title</p>";
		 document.frmForumTopics.topic_title.focus();
		 return false;
	}
	if(document.frmForumTopics.topic_desc.value==""){
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Enter description</p>";
		 document.frmForumTopics.topic_desc.focus();
		 return false;
	}
	document.getElementById('cid').value = cid;
	document.getElementById('fid').value = fid;
	document.getElementById('tid').value = tid;
	document.getElementById('pType').value = pType;
	document.frmForumTopics.action = '/groups/createforumtopics/' + cid + '/' + fid + '/' + pType;
	document.frmForumTopics.submit();
}

function fnDeleteForumTopic(gid,fid,tid){
	if(confirm("Do you want to delete this topic?")){
		document.getElementById('fid').value = fid;
		document.getElementById('tid').value = tid;
		document.frmForumTopics.action = '/groups/deleteforumtopic/'+gid;
		document.frmForumTopics.submit();
	}
}

function fnPostReply(cid,fid,tid,fpid,pType){
	document.getElementById('cid').value = cid;
	document.getElementById('fid').value = fid;
	document.getElementById('tid').value = tid;
	document.getElementById('fpid').value = fpid;
	document.getElementById('pType').value = pType;
	document.frmForumTopics.action = '/groups/postreply/' + cid + '/' + fid + '/' + tid + '/' + pType;
	document.frmForumTopics.submit();
}

function fnCreatePostReply(cid,fid,tid,fpid,pType){
	var t=setTimeout("fnConformRefresh('errortext')",10000);
	if(document.frmPostReply.post_subject.value==""){
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Enter subject</p>";
		 document.frmPostReply.post_subject.focus();
		 return false;
	}
	if(document.frmPostReply.post_text.value==""){
		 document.getElementById('errortext').style.display="";
		 document.getElementById('errortext').innerHTML="<p>Enter description</p>";
		 document.frmPostReply.post_text.focus();
		 return false;
	}
	document.getElementById('cid').value = cid;
	document.getElementById('fid').value = fid;
	document.getElementById('tid').value = tid;
	document.getElementById('fpid').value = fpid;
	document.getElementById('pType').value = pType;
	document.frmPostReply.action = '?c=control&m=sp&page=PostReply';
	document.frmPostReply.submit();
}

function fnDeleteReply(cid,fid,tid,fpid){
	if(confirm("Do you want to delete this reply")){
		document.getElementById('cid').value = cid;
		document.getElementById('fid').value = fid;
		document.getElementById('tid').value = tid;
		document.getElementById('fpid').value = fpid;
		document.frmForumTopics.action = '/groups/deletereply/';
		document.frmForumTopics.submit();
	}
}

function fnDeleteForumCategory(gid,cid){
	if(confirm("Do you want to delete this category")){
		document.getElementById('gid').value = gid;
		document.getElementById('cid').value = cid;
		document.frmForums.action = '/groups/deleteforumcategory/';
		document.frmForums.submit();
	}
}

function fnDeleteForum(cid,fid){
	if(confirm("Do you want to delete this forum")){
		document.getElementById('cid').value = cid;
		document.getElementById('fid').value = fid;
		document.frmForums.action = '/groups/deleteforum/';
		document.frmForums.submit();
	}
}
/************************* FORUMS  START*********************************/
