

function isEmail (s) {
	var	i="@";	
	var c = s.indexOf(i);
	var d = s.indexOf(".");
	if (c > 0 && d > 1 ) {
	 	return true;
	}
	else return false;
}
function isNumber(s)

{   var i;
    var defaultEmptyOK=false;
	
    if (isEmpty(s)) 
       if (isNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isNumber.arguments[1] == true);
	   
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }

    return true;
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isIllegal(s,p)
{	   var c=s.indexOf(p);
	   return (c > 0)
}
/**/
function isLength(s,l)
{   return ((s.length == l))
}


// function for setting a cookie.
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

// function for deleting a cookie.
function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function validateUserInfo(myForm){
	if (validateSignUp(myForm)) {
	myForm.submit();
	}
	else { return (false);}
}

function confirmDelete(myForm){
	
	if (confirm("Are you sure you want to Delete this Item?")) {
		myForm.action.value="delete";
		myForm.submit();
	}
	else { return (false);}
}

	
function validateSignUp(myForm){
	// myForm.action.value="save";
	
	if (isEmpty(myForm.fullName.value)) {
		alert("Please enter your Full Name");
		myForm.fullName.focus();
		return (false);
	}
	if (!isEmail(myForm.emailAddress.value)){
		alert("Please enter an Email Address");
		myForm.emailAddress.focus();
		return (false);
	}
	/*
	if ((!myForm.agree.checked)){
		alert("Please confirm that you agree with the Customer Agreement");
	
		return (false);
	}*/
	if (myForm.passwd.value != myForm.passwd2.value){
		alert("Your Passwords do not match");
		return (false);
	}
	return true;
}

function validateMailForm(myForm){
if (!isEmail(myForm.emailAddress.value)){
		alert("Please enter a valid Email Address or you will not receive a response to your enquiry");
		myForm.emailAddress.focus();
		return (false);
	}
else {	
	myForm.submit();
	}
}

function submitAction(myForm,actionValue){
	
		myForm.action.value=actionValue;
		myForm.submit();

}

	function insertLink(myForm,cid){
		var target="";
		var xwin="";
		if (myForm.newwindow[0].checked) {
			target="target=new";
			xwin="xwin=1";
		}
		myValue="<a href='"+myForm.url.value+"' "+target+" >"+myForm.anchor.value+"</a>";
		insertDocCursor(opener.document.forms["content"+cid].textDetails, myValue,opener.document);
		window.close();
	}
	
	function insertULink(myForm,cid){
		var target="";
		var target="";
		var xwin="";
		if (myForm.newwindow[0].checked) {
			target="target=new";
			xwin="&xwin=1";
		}
		idx=myForm.pid.selectedIndex;
		//pid=myForm.pid[idx].value;
		pid=myForm.pid.options[idx].value;
		title=myForm.pid.options[idx].text;
		//title="test";
		//pid=15;
		
		myValue="<a href='/site/?pid="+pid+xwin+"' "+target+" >"+title+"</a>";
		
		insertDocCursor(opener.document.forms["content"+cid].textDetails, myValue,opener.document);
		window.close();
	}
	
	function insertDLink(myForm,cid){
		var target="";
	//	if (myForm.newwindow[0].checked) {
			target="target=new";
	//	}
	
		idx=myForm.rid.selectedIndex;
		//pid=myForm.pid[idx].value;
		rid=myForm.rid.options[idx].value;
		title=myForm.rid.options[idx].text;
		//title="test";
		//pid=15;
		
		myValue="<a href='/site/docviewer.php?rid="+rid+"' "+target+">"+title+"</a>";
		
		insertDocCursor(opener.document.forms["content"+cid].textDetails, myValue,opener.document);
		window.close();
	}
	
	function editAction(myForm,action,cid,pid){
	
	if (action == "save") {
		myForm.submit();
	}
	else if (action == "bold") {
			insertAtCursor(myForm.textDetails, "<b> </b>");
			//myForm.textDetails.value+="<b></b>";
	}
	else if (action == "italic") {
		insertAtCursor(myForm.textDetails, "<i> </i>");
		// myForm.textDetails.value+="<i></i>";
	}
	else if (action == "ulink") {

		openWindow("/admin/?ref=link_window&xwin=1&cid="+cid+"&action="+action,"link",600,200,100,200,"yes","no");
		
		//insertAtCursor(myForm.textDetails, "<a >");
		// myForm.textDetails.value+="<i></i>";
	}
	else if (action == "link") {
		openWindow("/admin/?ref=link_window&xwin=1&cid="+cid+"&action="+action,"link",600,200,100,200,"yes","no");
	}
	else if (action == "doc") {
		openWindow("/admin/?ref=link_window&xwin=1&action="+action+"&cid="+cid,"link",600,200,100,200,"yes","no");;
	}
	else if (action == "para") {
		insertAtCursor(myForm.textDetails, "<p> </p>");
		// myForm.textDetails.value+="<i></i>";
	}
	else if (action == "h1") {
		insertAtCursor(myForm.textDetails, "<h1> </h1>");
	}
		else if (action == "h2") {
		insertAtCursor(myForm.textDetails, "<h2> </h2>");
	}
		else if (action == "br") {
		insertAtCursor(myForm.textDetails, "<br>");
	}
}

function insertDocCursor(myField, myValue,myDocument) {
//IE support
if (myDocument.selection) {
myField.focus();
sel = myDocument.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}	
	

function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}



}	
	
function openWindow(windowURL,windowName,windowWidth,windowHeight,x,y,menu,scroll) {
	newWindow = window.open(windowURL,windowName,'width='+windowWidth+',height='+windowHeight+',left='+x+',top='+y+',toolbar=0,location=0,directories=0,status=0,menuBar='+menu+',scrollBars='+scroll+',resizable=1');
	newWindow.focus();
}	