/*
'======================================================================
' AUTHOR: Tim Sewell
' OVERVIEW: 
' Javascript functions
'
' MODIFICATION DETAILS (LAST 2)
' LAST EDITED: Tim Sewell - 28/04/2004
' COMMENTS:
' 
'======================================================================
*/

/*======================================================================
								OPEN POPUP WINDOWS
======================================================================*/

function loadPageExtras()
{
}

function goNextPage(page,firstPage,lastPage)
{
	var currPage = nextPage.page.value;
	nextPage.page.value = Number(page);
	nextPage.firstPage.value = Number(firstPage);
	nextPage.lastPage.value = Number(lastPage);
	nextPage.submit();
}

function showViaLoadingPage(url,xWidth,xHeight)
{
	popupMainWindow1('loading.asp',xWidth,xHeight);
	setTimeout("mainWindow1.location.href='"+url+"';",550);

}


function reorderResults(frmName,frmField,orderBy)
{
	
	var frm = document.forms[frmName];
	var elem = document.forms[frmName].elements[frmField];
	elem.value = orderBy;
	frm.submit();
	
}

function showFormProcessing()
{	

	if (document.getElementById('formSubmitButtons'))
	{
		
		document.getElementById('formSubmitButtons').style.display = 'none';

		if (document.getElementById('formSubmitProcessing'))
		{
		document.getElementById('formSubmitProcessing').style.display = 'inline';
		}
	}
}


function reloadOpenerAndClose()
{
	if ( window.opener && !window.opener.closed )
	{
		if (window.opener.nextPage)
			window.opener.nextPage.submit();
		else
			window.opener.location.reload();
			
		window.opener.focus();
	}
	
	window.close();
}


function closeAndFocusOpener()
{
	
	if ( window.opener && !window.opener.closed )
	{
		window.opener.focus();
	}
	window.close();
}


function popupMainWindow(url,height,width) 
{
	var wHeight = screen.height
	var wWidth = screen.width

	var isHeight=Number(height);
	var isWidth=Number(width);
	var wTop = (wHeight - isHeight) / 2
	var wLeft = (wWidth - isWidth) / 2
	mainWindow  =   window.open(url,"mainWindow",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+isWidth+'px,height='+isHeight+'px,top='+wTop+',left='+wLeft);
	mainWindow.focus();
}

function popupMainWindow1(url,height,width) {
  var wHeight = screen.height
  var wWidth = screen.width
  
  var isHeight=Number(height);
  var isWidth=Number(width);
  var wTop = (wHeight - isHeight) / 2
  var wLeft = (wWidth - isWidth) / 2
  mainWindow1  =   window.open(url,"mainWindow1",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+isWidth+',height='+isHeight+',top='+wTop+',left='+wLeft);
  mainWindow1.focus();
}

function centerScreen(xWidth,xHeight)
{
	var wHeight = screen.height
	var wWidth = screen.width

	var uAgent = navigator.userAgent
	if(uAgent.indexOf("Windows NT 5.1")!=-1)
	{
		xHeight = xHeight+30;
	}
	window.resizeTo(xWidth,xHeight);
	var wHeight = screen.height-xHeight;
	var wWidth = screen.width-xWidth;
	window.moveTo(wWidth/2,wHeight/2);
}

/*======================================================================
								CHECK FOR DIGITS
======================================================================*/

function isDigits(str) {
	var i
	for (i = 0; i < str.length; i++) {
		mychar = str.charAt(i)
		if ((mychar < "0" || mychar > "9") && mychar !=".")
			return false;
	}
	return true;
}

function IsNumeric(strString)
  //  check for valid numeric strings	
  {
  var strValidChars = "0123456789.-";
  var strChar;
  var blnResult = true;

  if (strString.length == 0) return false;

  //  test strString consists of valid characters listed above
  for (i = 0; i < strString.length && blnResult == true; i++)
     {
     strChar = strString.charAt(i);
     if (strValidChars.indexOf(strChar) == -1)
        {
        blnResult = false;
        }
     }
  return blnResult;
  }

/*======================================================================
								CHECK FOR VALID EMAIL
======================================================================*/

function checkemail(s)
{
    var str = s;
    var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
    if (filter.test(str))
        testresults=true
    else
    {
        testresults=false
    }
    return (testresults)
}

function checkPassword(txtField) 
    {
	
	var error = 0;
	var errorChar = 1;
	var errorNum = 1;
	var validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWQYZ1234567890";
	var reNum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWQYZ"
	var reAlph = "1234567890"

	var password = txtField.value;

	// iterate through string and check against allowed character list
	for (x=0; x<password.length; x++)
	{
		c = password.charAt(x);
		if (validChars.indexOf(c) == -1)
		{
			error = 1;
			break;
		}
	}
	
	// check to make sure contains numbers and characters
	for (x=0; x<password.length; x++)
	{
		c = password.charAt(x);
		if (reNum.indexOf(c) != -1)
		{
			errorChar = 0;
			break;
		}
	}
	// check to make sure contains numbers and characters
	for (x=0; x<password.length; x++)
	{
		c = password.charAt(x);
		if (reAlph.indexOf(c) != -1)
		{
			errorNum = 0;
			break;
		}
	}

	// display appropriate message
	

	if ((error == 1) || (password.length < 6) || (errorChar == 1) || (errorNum == 1))
	{
		alert("The PASSWORD must be a minimum of 6 characters and contain a mixture of letters and numbers")
		txtField.focus();
		return false;
	}
	else
		return true;
}

function checkLimit(txtField, prompt, minchars, maxchars) 
{
	if (txtField.value == ''){alert("Please enter data for "+prompt);txtField.focus();return false;}
	else
	{
		if(txtField.value.length < minchars || txtField.value.length > maxchars)
		{
			alert(prompt+" length should be between "+minchars+" to "+maxchars+" characters.");
			txtField.focus();
			return false;
		}
		else return true;
	}
}

function leftTrim(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

function rightTrim(sString) 
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function trimAll(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function msgBox(strMessage)
{
	alert(strMessage);
}

function submitFormCouncilorDetails()
{
	frm = document.forms.f1;
	
	if (frm.partyid.value == '')
	{
		alert("Please select your party");
		frm.partyid.focus();
		return false;
	}
	
	if (frm.wardid.value == '')
	{
		alert("Please select your ward");
		return false;
	}
	
	showFormProcessing();
	frm.submit();
}

function submitFormCouncilorPages()
{
	frm = document.forms.f1;
	
	if (frm.name.value == '')
	{
		alert("Please type a name for the page");
		frm.partyid.focus();
		return false;
	}
	
	if (frm.content.value == '')
	{
		alert("Please provide content");
		return false;
	}
	
	showFormProcessing();
	frm.submit();
}

function submitFormCouncilorDetailsMod()
{
	frm = document.forms.f1;
		
	showFormProcessing();
	frm.submit();
}

function retrieveCouncilorDetails()
{
	frm = document.forms.f1;
	frm.action = "/myWycombe.asp?step=15";
		
	showFormProcessing();
	frm.submit();
}

//--------------------------------------------------------------------------
function submitFormParishDetails()
{
	frm = document.forms.f1;
	
 	if (frm.contactName.value == ''){alert("Please enter contact name");frm.contactName.focus();return false;}
 	if (frm.address1.value == ''){alert("Please enter first line of address");frm.address1.focus();return false;}
 	if (frm.postcode.value == ''){alert("Please enter postcode");frm.postcode.focus();return false;}
 	if (frm.tel.value == ''){alert("Please enter telephone");frm.tel.focus();return false;}
	
	showFormProcessing();
	frm.submit();
}

function submitFormParishPages()
{
	frm = document.forms.f1;
	
	if (frm.name.value == '')
	{
		alert("Please type a name for the page");
		frm.partyid.focus();
		return false;
	}
	
	if (frm.content.value == '')
	{
		alert("Please provide content");
		return false;
	}
	
	showFormProcessing();
	frm.submit();
}

function submitFormParishDetailsMod()
{
	frm = document.forms.f1;
		
	showFormProcessing();
	frm.submit();
}

function retrieveParishDetails()
{
	frm = document.forms.f1;
	frm.action = "/myWycombe.asp?step=115";
		
	showFormProcessing();
	frm.submit();
}
//--------------------------------------------------------------------------

function confirmDelete()
{
	var agree = confirm("Are you sure you want to DELETE this content?")
	if (agree)
		return true;
	else
		return false;

}

function deleteMyWycombeContent(contentID,step)
{
	if(confirmDelete() == true)
	{
		document.location.href = "/myWycombe.asp?step="+step+"&contentID="+contentID;
	}
}

function stopFlush()
{
	if (navigator.userAgent.indexOf('MSIE') < 0)
	{
		document.getElementById("awmflashVLI1").style.display = "none";
		document.getElementById("awmflashVLI2").style.display = "block";
	}
	else
		awmhidediv();
}

function startFlush()
{
	
	if (navigator.userAgent.indexOf('MSIE') < 0)
	{
		document.getElementById("awmflashVLI1").style.display = "block";
		document.getElementById("awmflashVLI2").style.display = "none";
	}
	else
		awmshowdiv();
}