
function getQueryVariable(variable) {
		var query = window.location.search.substring(1);
		var vars = query.split("&");

		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
				return pair[1];
			}
		}
	}
	var xurl = getQueryVariable("read");
	var msg = getQueryVariable("msg");
	
	
function chkAllsubscriberSearchfrm(){
	var cnt;

	cnt = document.forms[0].elements.length;
	if(document.forms[0].cbChkAll.checked){
		for(i=0;i<cnt;i++){

			if(document.forms[0].elements[i].type == "checkbox" && document.forms[0].elements[i].name== "del[]"){
				document.forms[0].elements[i].checked = true;
			}
			
		}
	}
	else{
		for(i=0;i<cnt;i++){

			if(document.forms[0].elements[i].type == "checkbox"){
				document.forms[0].elements[i].checked = false;
			}
		}
	}
}


function toggleActions(str) {

	if ( document.message_center.moveto.value == "Delete" ) { 
		confirmDelete( document.message_center.action, str)
	} else if ( document.message_center.moveto.value == "Archive" ) {
		confirmArchive(document.message_center.action, str)
	}

}




//START WELCOME COOKIE
function setCookie(c_name, value, expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(affiliateid)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
} 

function checkCookie()
{
	welcomecookie=getCookie('welcomecookie');
	if (welcomecookie!=null && welcomecookie!="")
	{
		//alert('Welcome again '+welcomecookie+'!');
		
	}
	else
	{
		setCookie('welcomecookie', welcomecookie, 30);
		showPopup('popup');
	}
}
//END WELCOME COOKIE

function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
        // otherwise, update 'characters left' counter
    else 
        countfield.value = maxlimit - field.value.length;
}

function textCounter2(field, id, maxlimit) {
	var obj = document.getElementById(id);
	if (obj)
	{
		if (field.value.length > maxlimit) // if too long...trim it!
		{
			field.value = field.value.substring(0, maxlimit);
			// otherwise, update 'characters left' counter
			obj.innerHTML = "0";
		}else {
			if (maxlimit - field.value.length < 20)
			{
				obj.innerHTML = "<span class='textCount'>" + (maxlimit - field.value.length) + "</span>";
			} else {
				obj.innerHTML = (maxlimit - field.value.length);
			}
		}
	}
}


function confirmDelete(form,$str)
{  
	var flag=0;
	var tempvar=document.getElementsByName('del[]');
		for(i=0;i < (tempvar.length);i++)
		{
			if(tempvar[i].checked == true && tempvar[i].type == "checkbox" )
			{
				flag=1;
				break;
		   }
  	   }
 if(flag==1)
  {
 	if(confirm("Are you sure you want to delete selected Record(s)?"))
	{
		var attach="";
		if(form.indexOf('?')!=-1)
		attach='&remove=yes&step=delete';
		else
		attach='?remove=yes&step=delete';
		document.forms[0].action=form+attach;
		document.forms[0].submit();
	}
	return false;
  }
  else 
	{
		alert("Please select records to delete.");
		return false;
	}
}

function confirmArchive(form,$str)
{  
	var flag=0;
	var tempvar=document.getElementsByName('del[]');
		for(i=0;i < (tempvar.length);i++)
		{
			if(tempvar[i].checked == true && tempvar[i].type == "checkbox" )
			{
				flag=1;
				break;
		   }
  	   }
 if(flag==1)
  {
 	if(confirm("Are you sure you want to archive selected Record(s)?"))
	{
		var attach="";
		if(form.indexOf('?')!=-1)
		attach='?step=archive';
		else
		attach='?step=archive';
		document.forms[0].action=form+attach;
		document.forms[0].submit();
	}
	return false;
  }
  else 
	{
		alert("Please select records to archive.");
		return false;
	}
}



/*
/////////////////////////////////////////////////////////////////////////////////////
// BRS 
	- PHP VARS FOR JAVASCRIPT
/////////////////////////////////////////////////////////////////////////////////////
*/
	var userid = "##userid##";
	var affiliateid = "##affiliateid##";
	var socialnetworkenabled = "##social_network_enabled##";
	var customcontentenabled = "##custom_content##";

/*
/////////////////////////////////////////////////////////////////////////////////////
// BRS 
	- GENERIC CHECKBOX CHECK UNCHECK ALL
/////////////////////////////////////////////////////////////////////////////////////
*/
function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++)
	{
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
		{
			theForm[z].checked = theElement.checked;
		}
    }
}

/*
/////////////////////////////////////////////////////////////////////////////////////
// BRS 
	- TO LIST CHECKBOX CHECK UNCHECK ALL
/////////////////////////////////////////////////////////////////////////////////////
*/
function checkUncheckAllToList(theElement) {
	var theForm = theElement.form, z = 0;
	var prefix = theElement.id;
	if (prefix == 'all') {
		prefix = '';
	}

	for(var z=0; z<theForm.length;z++)
	{
		if(theForm[z].type == 'checkbox' && theForm[z].name.indexOf(prefix) == 0)
		{
			theForm[z].checked = theElement.checked;
		}
    }
}


/*
/////////////////////////////////////////////////////////////////////////////////////
// BRS 
	- USED TO VALIDATE THAT YOU HAVE SELECTED A NETWORK OR SET OF GROUPS TO
	SHARE MESSAGE WITH
/////////////////////////////////////////////////////////////////////////////////////
*/
function checkBoxCount( checkBoxName )
{
	//alert (tempvar[i].id);
	var flag=0;
	var tempvar=document.getElementsByTagName("input");
	var toStr = '';
//	var tempvar=document.getElementsByName( checkBoxName );
	var i;
		for(i=0;i < (tempvar.length);i++)
		{
			if(tempvar[i].type == "checkbox" && tempvar[i].checked == true)
			{
				if (tempvar[i].id.indexOf('email_list[') == 0)
				{
					toStr += document.getElementById("e_" + tempvar[i].value).innerHTML+ '; ';
				} else if (tempvar[i].id.indexOf('network_list[') == 0) {
					toStr += document.getElementById("n_" + tempvar[i].value).innerHTML+ '; ';
				}
			}
		}

		if (toStr.length == 0) {
			alert("You have not made any selections.");
			return false;
		}
		
		toStr = toStr.substring(0, toStr.length - 2);
		document.add_custom_message.todisplay.value = toStr;
		hidePopup('popup');
		return true;
		
}


/*
/////////////////////////////////////////////////////////////////////////////////////
// BRS 
	- VALIDATE THAT A CUSTOME MESSAGE HAS A SUBJECT AND BODY
/////////////////////////////////////////////////////////////////////////////////////
*/
function validateMessage(mode)
{
	// Save the mode for when the form is submitted
	document.add_custom_message.mode.value = mode;

	if (document.add_custom_message.subject.value == '' ) {
		alert ("The subject can not be blank");
	}
	else {
	/*
		if (mode == "Save & Share") {
		if (mode == "Send") {
			showPopup('popup');
		}
		else {
		*/
			document.add_custom_message.submit();
		//}
	}
}

/*
/////////////////////////////////////////////////////////////////////////////////////
// BRS 
	- VALIDATE THAT A POST TO A TOPIC IS NOT NULL
/////////////////////////////////////////////////////////////////////////////////////
*/
function validateTopicPost()
{
	//if ( document.forms["topicPostForm_" + topicId].post.value == "" ) {
	if ( topicPostForm.post.value == "" ) {
		alert ('There is no content to save!');
	} 
	else {
		//return;
		//return this.post_topicId.value != \'\') ? true : false;
		//return
		//document.forms["topicPostForm_" + topicId].submit();
		topicPostForm.submit();
	}
		
}

/*
/////////////////////////////////////////////////////////////////////////////////////
GAK 
	- FUNCTIONS FOR TOPIC DISPLAY
/////////////////////////////////////////////////////////////////////////////////////
*/
function toggleTopicPost(topicId)
{
	var obj = document.getElementById("topicPost_" + topicId);

	// Toggle between showing and hiding post form
	if (obj.style.display == "block")
	{
		hide("topicPost_" + topicId);
		return;
	}

	obj.style.display = "block";
// BRS - NOT WORKING
//	focusPost(topicId);
}

function focusPost(topicId)
{
	var obj = document.getElementById("topicPost_" + topicId);
	var textarea = document.getElementById("post_" + topicId);
	if (obj && obj.style.display != "none" && textarea)
		textarea.focus();
}

function hide(id)
{
	var obj = document.getElementById(id);
	obj.style.display = "none";
}

/*
/////////////////////////////////////////////////////////////////////////////////////
BRS - COPIED FROM ABOVE/GAK
	- WILL NEED TO COMBINE BOTH
	- FUNCTIONS FOR SETTINGS DISPLAY
/////////////////////////////////////////////////////////////////////////////////////
*/
function toggleGDiv(divId)
{
	var obj = document.getElementById(divId);
	
	// Toggle between showing and hiding post form
	if (obj.style.display == "block")
	{
		hide(divId);
		return;
	}
	else {
		
	}
	obj.style.display = "block";
	focusDiv(divId);

}

function toggleDiv(divId)
{
	var obj = document.getElementById(divId);

	// Toggle between showing and hiding post form
	if (obj.style.display == "block")
	{
		hide(divId);
		document.getElementById('imgArrow_' + divId).src='images/arrow_close_sm.gif';
		return;
	}
	else {
		document.getElementById('imgArrow_' + divId).src='images/arrow_open_sm.gif';
	}
	obj.style.display = "block";
	focusDiv(divId);

}

function focusDiv(divId)
{
	var obj = document.getElementById(divId);
	var textarea = document.getElementById("close_" + divId);
	if (obj && obj.style.display != "none" && textarea)
		textarea.focus();
}

function hide(id)
{
	var obj = document.getElementById(id);
	obj.style.display = "none";
}

function show(id)
{
	var obj = document.getElementById(id);
	obj.style.display = "block";
	obj.focus();
}

/*
////////////////////////////////////////////////////////////////////////////////////////////
BRS
	-POPUP GRAYOUT BACKDROP
///////////////////////////////////////////////////////////////////////////////////////////
*/

function addEvent(obj ,evt, fnc)
{
if (obj.addEventListener)
  obj.addEventListener(evt,fnc,false);
else if (obj.attachEvent)
  obj.attachEvent('on'+evt,fnc);
else
  return false;
return true;
}

function removeEvent(obj ,evt, fnc)
{
if (obj.removeEventListener)
  obj.removeEventListener(evt,fnc,false);
else if (obj.detachEvent)
  obj.detachEvent('on'+evt,fnc);
else
  return false;
return true;
}

function appendElement(node,tag,id,htm)
{
var ne = document.createElement(tag);
if(id) ne.id = id;
if(htm) ne.innerHTML = htm;
node.appendChild(ne);
}

function showPopup(p)
{
greyout(true);
document.getElementById(p).style.display = 'block';
}

function hidePopup(p)
{
greyout(false);
document.getElementById(p).style.display = 'none';
}

//----------

function greyout(d,z)
{
var obj = document.getElementById('greyout');
if(!obj)
{
	appendElement(document.body,'div','greyout');
	obj = document.getElementById('greyout');
	obj.style.position = 'absolute';
	obj.style.top = '0px';
	obj.style.left = '0px';
	obj.style.background = '#111';
	obj.style.opacity = '.5';
	obj.style.filter = 'alpha(opacity=50)';
}
if(d)
{
	if(!z){ z = 50 }
	obj.style.zIndex = z;
	//obj.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
	obj.style.height = Math.max(document.body.scrollHeight,document.documentElement.clientHeight)+'px';
	obj.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
	obj.style.display = 'block';
	addEvent(window,'resize',greyoutResize);
}
else
{
	obj.style.display = 'none';
	removeEvent(window,'resize',greyoutResize);
	}
}

function greyoutResize()
{
	var obj = document.getElementById('greyout');
	//obj.style.height = document.body.clientHeight+'px';
	obj.style.height = document.documentElement.clientHeight;
	//obj.style.height = '1000px';
	//obj.style.height = document.documentElement.clientHeight;
	//obj.style.height = window.innerHeight;
	//obj.style.height = window.innerHeight+'px';;
	obj.style.width  = document.body.clientWidth+'px';
	
	//obj.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
	obj.style.height = Math.max(document.body.scrollHeight,document.documentElement.clientHeight)+'px';
	obj.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
	
	
}



/*
////////////////////////////////////////////////////////////////////////////////////////////
BRS
	-ALERTS
///////////////////////////////////////////////////////////////////////////////////////////
*/
/*
function toggleAlerts(id)
{
	var obj = document.getElementById(id);
	if (obj && (obj.alert_email.checked || obj.alert_desktop.checked))
	{
		obj.alert_none.checked = false;
	}
	if (obj && (obj.alert_email.checked == false && obj.alert_desktop.checked == false))
	{
		obj.alert_none.checked = true;
	}
}

function uncheckAlerts(id)
{
	var obj = document.getElementById(id);
	if (obj && obj.alert_none.checked)
	{
		obj.alert_email.checked = false;
		obj.alert_desktop.checked = false;
	}
	if (obj && (obj.alert_email.checked == false && obj.alert_desktop.checked == false))
	{
		obj.alert_none.checked = true;
	}
	
}
*/

/*
BRS
*/



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;
}

var xmlHttp

function sdnStart(str1,str2)
{

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  }

var newBaseURL = location.href.substring(0,location.href.lastIndexOf('/')+1);
var url=newBaseURL+"sn_get_email_list.php?userid="+userid+"&replytomsg="+replytomsg+"&reply="+reply
//var url="http://p1dev.ixs1.net/sn_get_email_list.php"
//url=url+"?q="+str1
url=url+"?userid="+str1
//url=url+"&affiliateId="+str2
//url=url+"&sid="+Math.random()
url=url+"&sid="+str2
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
//alert(url)

}

function stateChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		//document.getElementById("popupbody").innerHTML=xmlHttp.responseText + document.getElementById("popupbody").innerHTML;
		document.getElementById("popupbody").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 load()
{
	document.add_custom_message.select_email_id.focus();
}

function checkEmail()
{
	if (document.signup_form.email.value == '')
	{
		//alert("Please enter an email address.");
		//document.write("Please enter an email address.");
		document.getElementById("popupbody").innerText = "Email Error";
		return false;

	}

	document.getElementById("popupbody").innerText = "";
	toggleLayer("signUpForm")
	toggleLayer("leftContent")
	return true;
}

function toggleLayer( whichLayer )
{
	var elem, vis;
	if (document.getElementById) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
		vis = elem.style;  // if the style.display value is blank we try to figure it out here

	if (vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
		vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

