<!--

///////////////////////////
// browser detect functions
///////////////////////////

// get browser type
var isNS4;
var isNS6;
var isIE4;
var isIE5;
var strPlatform;

isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;

Browser = navigator.appName
Net = Browser.indexOf("Netscape")
Micro = Browser.indexOf("Microsoft")
Netscape = false
IE = false

if(Net >= 0) {
	Netscape = true
	
	
}

if(Micro >= 0) {
	IE = true
}

if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

strPlatform = navigator.platform;



function ValidObject(Object) 
{
	if(Object == null)
	{
		return false;
	}
	
	if(typeof(Object) == "undefined") 
	{
		return false;
	}
	
	return true;
}

// function to return handle to form element
function GetObject(name, this_form)
{
	strHandle = '';

	if(ValidObject(eval("document." + this_form + ".elements['" + name + "']")))
	{
		//alert(\'name = \' + name + \'\n form name = \' + this_form);
		strHandle = eval("document." + this_form + ".elements['" + name + "']");
		//alert(\'handle = \' + strHandle);		
	}

	return strHandle;
}

// popup widow function
function Popup(url, width, height, options)
{
	if(!width) width = 400;
	if(!height) heigth = 600;
	if(!options) options = 'scrollbars=yes,status=no';

	myFloater = window.open('', 'Information', options + ',width=' + width + ',height=' + height);
    myFloater.location.href = url;
}

// function to write to a div or layer tag as appropriate to browser
function DoLayer(id, text)
{
// refer to field by method appropriate to the browser
	if (isIE4)
	{
		document.all[id].innerHTML = text;
	}
	else if (isNS4) 
	{
		id = id + '_layer';
		document.layers[id].document.open();
		document.layers[id].document.write(text);
		document.layers[id].document.close();
	}
	else if (isNS6 || isIE5)
	{
		document.getElementById(id).innerHTML = text;
	}
}

function Disable(name, form_name)
{
	handle = GetObject(name, form_name);
	handle.disabled = true;
}

function Enable(name, form_name)
{
	handle = GetObject(name, form_name);
	handle.disabled = false;
}

function EnableDisable(name, form_name)
{
	handle = document.getElementById('strPassword');
	if(handle.disabled == true)
	{		
		handle.disabled = false;
	}
	else
	{
		handle.disabled = true;
	}
}

function Clear(name, form_name)
{
	handle = GetObject(name, form_name);
	handle.value = '';
}

iRefreshLimit = 0;
if(ValidObject(document.SmsConsole) == true)
{
	iRefreshLimit = (document.SmsConsole.iRefresh.value * 10);
}

t = null;
refreshtime = 100 *  iRefreshLimit;
function RefreshMe()
{
	t = setTimeout("SmsConsole.submit()", refreshtime);
}

var xPos;
var yPos;

function XYpos(e) {

	if (IE == true) {
		xPos = event.screenX
		yPos = event.screenY
	}
	else{
		xPos = e.clientX;
		yPos = e.clientY;
	}
}

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    xPos = event.clientX + document.body.scrollLeft
    yPos = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    xPos = e.pageX
    yPos = e.pageY
  }  
  // catch possible negative values in NS4
  if (xPos < 0){xPos = 0}
  if (yPos < 0){yPos = 0}  
  return true
}


function changeActionDiv(content, visibleStatus, leftPos, topPos)
{
	handle = document.getElementById("actionDiv");
	handle.innerHTML = content;
	handle.style.visibility = visibleStatus;
	handle.style.top = topPos;
	handle.style.left = leftPos;
}


function hideActionDiv()
{
	handle = document.getElementById("actionDiv");
	handle.style.visibility = "hidden";
}

function debug_alert(strText)
{
	//window.alert(strText);
}

function disableFieldFromTickBox()
{
	form_name = document.getElementById('subscriberLogInForm');
	tickbox = document.getElementById('bPasswordUnknown');
	field = document.getElementById('strPassword');
	
	if(ValidObject(field) && ValidObject(tickbox))
	{
		if(tickbox.checked == true)
		{		
			field.disabled = true;
		}
		else
		{
			field.disabled = false;
		}
	}
	
}

/////////////////////////////////////////////////////////////////////////////////////////
// showSubscriberCompanyDetails()
//
// Parameters:
//	None.
//
// Returns:
//	Shows a dynamic javascript html menu.
//
// Revisions:
//	Created by Rob Terry, 30th January 2006
/////////////////////////////////////////////////////////////////////////////////////////
function showSubscriberCompanyDetails(strCreated, strModified, iActive)
{
	// Set a default blank content for the active flag.
	strActiveAlert = '';

	// If we have an inactive account.
	if(iActive == 0)
	{
		// Build up a text warning to show the subscriber that they won't receive anything if the subscription is inactive.
		strActiveAlert = '<tr><td><span class="defaultRed">This subscription is inactive. You will nto receive any emails from this company until your subscription is made active.</span></td></tr>';
	}

	// Build the HTML string to show the div.
	strHTML = '<table cellpadding="2" cellspacing="0" border="0" width="100%" border="0">' + 
				'<tr><td nowrap><span class="default"><strong>Created: </strong>' + strCreated + '</span></td></tr>' + 
				'<tr><td nowrap><span class="default"><strong>Modified: </strong>' + strModified + '</span></td></tr>' + strActiveAlert + '</table>';
	
	// Set the menu image location.
	strMenuImage = 'images/icons/details.gif';

	// Build the HTML content to display.
	strContent = buildSubscriberDivHTML(strMenuImage, 'Details', strHTML);

	// Let's grab the position of the click.
	yPos = yPos - 15;
	xPos = xPos - 15;

	// Pass back the action div content.
	return changeActionDiv(strContent, 'visible', xPos, yPos)
}

/////////////////////////////////////////////////////////////////////////////////////////
// showDeleteDiv()
//
// Parameters:
//	iSubscriber	-	This is the id of the subscriber we are removing.
//	iCompany	-	This is the company id.
//	iList		-	This is the list id.
//
// Returns:
//	Shows a dynamic javascript html menu.
//
// Revisions:
//	Created by Rob Terry, 30th January 2006
/////////////////////////////////////////////////////////////////////////////////////////
function showDeleteDiv(iSubscriber, iCompany, iList)
{
	// Build up each of the links correctly for each of the three options.
	strPreventLink = 'index.php?z=delete&amp;iCompany=' + iCompany + '&amp;iSubscriber=' + iSubscriber;

	strListLink = 'index.php?z=delete&amp;iCompany=' + iCompany + '&amp;iList=' + iList + '&amp;iSubscriber=' + iSubscriber;

	strReportAbuse = 'index.php?z=report&amp;iList=' + iList + '&amp;iCompany=' + iCompany + '&amp;iSubscriber=' + iSubscriber;

	// Build up a string of extra HTML code to display the link correctly.
	strExtra = 'class="boxLink" onMouseover="setStatus(0); return true;"';

	// Build the HTML to display the links
	strHTML	=	'<table cellpadding="0" cellspacing="3" border="0">' +
					'<tr>' + 
						'<td><span class="default"><a href="' + strListLink + '" ' + strExtra + '>Unsubscribe from list</a></span></td>' +
					'</tr>' +
					'<tr>' + 
						'<td><span class="default"><a href="' + strPreventLink + '" ' + strExtra + '>Prevent future contact</a></span></td>' +
					'</tr>' +
					'<tr>' + 
						'<td><span class="default"><a href="' + strReportAbuse + '" ' + strExtra + '>Report abuse</a></span></td>' +
					'</tr>' +
				'</table>';

	// Set the menu image location.
	strMenuImage = 'images/icons/delete.gif';	

	// Build the HTML content to display.
	strContent = buildSubscriberDivHTML(strMenuImage, 'Unsubscribe', strHTML);

	// Let's grab the position of the click.
	yPos = yPos - 15;
	xPos = xPos - 15;

	// Pass back the action div content.
	return changeActionDiv(strContent, 'visible', xPos, yPos)
}

/////////////////////////////////////////////////////////////////////////////////////////
// showConfirmDiv()
//
// Parameters:
//	iSubscriber	-	Subscriber id.
//	iCompany	-	Company id.
//	iList		-	List id.
//	iForm		-	Form id.
//
// Returns:
//	Shows a dynamic javascript html menu.
//
// Revisions:
//	Created by Nick Branson, 10 March 2006.
/////////////////////////////////////////////////////////////////////////////////////////
function showConfirmDiv(iSubscriber, iCompany, iList, iForm)
{
	// Build up each of the links correctly for each of the three options.
	strConfirm = 'index.php?z=confirm&amp;c=' + iCompany + '&amp;s=' + iSubscriber + '&amp;f=' + iForm + '&amp;l=' + iList + '&amp;a=1';

	strDelete = 'index.php?z=confirm&amp;c=' + iCompany + '&amp;s=' + iSubscriber + '&amp;f=' + iForm + '&amp;l=' + iList + '&amp;a=0';

	// Build up a string of extra HTML code to display the link correctly.
	strExtra = 'class="boxLink" onMouseover="setStatus(0); return true;"';

	// Build the HTML to display the links
	strHTML	=	'<table cellpadding="0" cellspacing="3" border="0">' +
					'<tr>' + 
						'<td><span class="default"><a href="' + strConfirm + '" ' + strExtra + '>Confirm Subscription</a></span></td>' +
					'</tr>' +
					'<tr>' + 
						'<td><span class="default"><a href="' + strDelete + '" ' + strExtra + '>Remove Subscription</a></span></td>' +
					'</tr>' +
				'</table>';

	// Set the menu image location.
	strMenuImage = 'images/icons/delete.gif';	

	// Build the HTML content to display.
	strContent = buildSubscriberDivHTML(strMenuImage, 'Unconfirmed', strHTML);

	// Let's grab the position of the click.
	yPos = yPos - 15;
	xPos = xPos - 15;

	// Pass back the action div content.
	return changeActionDiv(strContent, 'visible', xPos, yPos)
}

/////////////////////////////////////////////////////////////////////////////////////////
// showSubscriberCompanyDetails()
//
// Parameters:
//	strMenuImage		-	String location of the menu image.
//	strMenuImageAlt		-	String alt text for the image.
//	strMessageContent	-	String of HTML to display as actual content.
//
// Returns:
//	strHTML	-	String of HTML content for the javascript engine to display.
//
// Revisions:
//	Created by Rob Terry, 30th January 2006
/////////////////////////////////////////////////////////////////////////////////////////
function buildSubscriberDivHTML(strMenuImage, strMenuImageAlt, strMessageContent)
{
	strHTML = '<table cellpadding="5" cellspacing="0" width="200" border="0" class="blackBorder" bgcolor="white"><tr><td width="35" valign="top" align="left"><img id="menuImage" src="' + strMenuImage + '" alt="' + strMenuImageAlt + '" border="0"></td><td width="165" rowspan="2">' + strMessageContent + '</td></tr><tr><td width="35" valign="bottom" align="left"><a href="javascript:changeActionDiv(\'\', \'hidden\', (xPos - 188), (yPos - 60))" onMouseover="setStatus(0); return true;"><img src="images/icons/close_layer_white.gif" alt="close" border="0"></a></td></tr></table>';

	return strHTML;
}

/////////////////////////////////////////////////////////////////////////////////////////
// showEditHelp()
//
// Parameters:
//	None.
//
// Returns:
//	Shows content Div containing HTML to display a help icon and text.
//
// Revisions:
//	Created by Rob Terry, 9th February 2006
/////////////////////////////////////////////////////////////////////////////////////////
function showEditHelp()
{
	strMenuImage = 'images/icons/question.gif';
	strMenuImageAlt = 'Help';

	strMessageContent = 'This is a help menu icon.';

	strContent = buildSubscriberDivHTML(strMenuImage, strMenuImageAlt, strMessageContent);

	// Let's grab the position of the click.
	yPos = yPos - 15;
	xPos = xPos - 15;

	// Pass back the action div content.
	return changeActionDiv(strContent, 'visible', xPos, yPos)
}

/////////////////////////////////////////////////////////////////////////////////////////
// loadChangeEmailWindow()
//
// Parameters:
//	iSubscriber	-	This is the ID of the subscriber that we are changing the address for.
//	iCompany	-	This is the ID of the company that we are changing the address for.
//
// Returns:
//	strHTML	-	String of HTML content for the javascript engine to display.
//
// Revisions:
//	Created by Rob Terry, 30th January 2006
/////////////////////////////////////////////////////////////////////////////////////////
function loadChangeEmailWindow(iSubscriber, iCompany)
{
	// Build a string of the URL that we are setting up.
	strURL = "changeemail.php?iSub=" + iSubscriber + "&iCompany=" + iCompany;

	// Build a string of options to set the window with.
	strOptions = 'menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,location=no,width=440,height=190,top=200,left=200';

	// Open the window.
	window.open(strURL, 'change_email', strOptions);
}

/////////////////////////////////////////////////////////////////////////////////////////
// showListDetails()
//
// Parameters:
//	iCompany	-	Company id.
//	iSubscriber	-	Subscriber id.
//	iList		-	List id.
//	iConfirmed	-	This is the confirmed flag.
//	iVerified	-	This is the verified flag.
//	iSmsSignup	-	This is the SMS signup flag.
//	iImported	-	This is the flag that tells us if they're imported
//	strCreated	-	This is the string containing the created date.
//
// Returns:
//	Shows details div for the subscription.
//
// Revisions:
//	Created by Rob Terry, 16th February 2006
/////////////////////////////////////////////////////////////////////////////////////////
function showListDetails(iCompany, iSubscriber, iList, iConfirmed, iVerified, iSmsSignup, iImported, strCreated, strCompanyName)
{
	strConfirmed = '<span class="redMain"><a href="index.php?iSubscriber=' + iSubscriber + '&amp;iCompany=' + iCompany + '&amp;iList=' + iList + '&amp;iActivate=1" >Unconfirmed</a></span>';
	// onMouseover="setStatus(0); return true;"

	strVerified = '';
	strIPText = '';
	
	if(iConfirmed == 1)
	{
		strConfirmed = '<span class="redMain">Confirmed</span>';
	}

	if(iVerified == 0)
	{
		strVerified = '<br /><span class="defaultStrong">Awaiting verification</span>';
	}

	//window.alert("iImported: " + iImported + "\n" + "iSmsSignup: " + iSmsSignup + "\n");

	// If the iImported flag is set to 1 then we are dealing with some imported data.
	if(iImported == 1)
	{
		strIPText = 'Subscribed from outside Sign-Up.to. For further details please contact ' + strCompanyName;
	}
	// If they signed up using their mobile..... then
	else if(iSmsSignup == 1)
	{
		/// Build a string to say they signed up from their mobile.
		strIPText = 'Subscribed by sending a text message into one of the Sign-Up.to short codes.';
	}
	else
	{
		// So build some string to show that we have the IP and the means as to how the subscriber was added to the database.
		strIPText = 'You subscribed to this list from a Sign-Up.to form on ' + strCreated + '.';
	}


	strMessageContent = '<table width="180"><tr><td>' + 
							'<span class="defaultStrong">Details:<br><br></span>' + 
							'<span class="defaultStrong">Status: </span>' + strConfirmed +
							'<span class="default"><strong><br>Created:</strong> ' + strCreated + '</span>' +
							'<span class="default"><br><br>' + strIPText + '</span>' +
							strVerified +
						'</td></tr></table>';

	strMenuImage = 'images/icons/details.gif';
	strMenuImageAlt = 'Details';

	strContent = buildSubscriberDivHTML(strMenuImage, strMenuImageAlt, strMessageContent);

	// Let's grab the position of the click.
	yPos = yPos - 15;
	xPos = xPos - 15;

	// Pass back the action div content.
	return changeActionDiv(strContent, 'visible', xPos, yPos)
}

/////////////////////////////////////////////////////////////////////////////////////////
// setStatus()
//
// Parameters:
//	None.
//
// Returns:
//	Sets status bar text.
//
// Revisions:
//	Created by Rob Terry, 17th February 2006
/////////////////////////////////////////////////////////////////////////////////////////
function setStatus(bShow)
{
	// If we have set the bshow parameter to zero, then we don't want to shwo the links.
	if(bShow == 0) window.status = 'Sign-Up.to Subscriber Control Panel'; 
	return true;
}
//-->

