// JavaScript Document
	function bottom_new_win(url) {

	  this.popwindow = window.open(
						"",
						"subWindow",
						"toolbar=no," +
						"location=no," +
						"directories=no," +
						"status=no," +
						"menubar=no," +
						"scrollbars=yes," +
						"resizable=yes," +
						"width=800," +
						"height=600," +
						"top=0," +
						"left=0," +
						"screenX=0," +
						"screenY=0"
						);

	 this.popwindow.document.location= url;

	}
	
	function openNewWindow(url) {
	height = screen.availHeight;
	width = screen.availWidth;

	this.popwindow = window.open(
		"",
		"mapviewer",
		"toolbar=no," +
		"location=no," +
		"directories=no," +
		"toolbar=no," +
		"menubar=no," +
		"status=yes," +
		"resizable=yes," +
		"scrollbars=yes," +
		"screenX=1," +
		"left=1," +
		"screenY=1," +
		"top=1," +
		"width=" + width + "," +
		"height=" + height
	);

	this.popwindow.document.location= url;
}

	// JavaScript Document
	function searchTips_new_win(url) {

	  this.popwindow = window.open(
						"",
						"subWindow",
						"toolbar=no," +
						"location=no," +
						"directories=no," +
						"status=no," +
						"menubar=no," +
						"scrollbars=yes," +
						"resizable=yes," +
						"width=812," +
						"height=600," +
						"top=0," +
						"left=0," +
						"screenX=0," +
						"screenY=0"
						);

	 this.popwindow.document.location= url;

	}


	// This form validates the two fields on the login page
	// to make sure they were not left empty.
	function validate(loginForm) {

		username = document.loginForm.username.value;
		password = document.loginForm.password.value;

		if (username == "") {
			alert("You must enter a username!");
			return false;
		}

		if (password == "") {
			alert("You must enter a password!");
			return false;
		}
	}

	// This form validates the two fields on the login page
	// to make sure they were not left empty.
	// This script is on contact.asp
	function validate_contact(form) {

		name = document.form.f_name.value;
		email = document.form.f_email.value;
		subject = document.form.subject.value;
		message = document.form.message.value;

		if (name == "") {
			alert("You must enter your name!");
			return false;
		}


		if (email == "") {
			alert("You must enter your email address!");
			return false;
		}


		if (subject == "") {
			alert("You must enter a subject!");
			return false;
		}

		if (message == "") {
			alert("You must enter a message!");
			return false;
		}
	}

	// This function changes the background color of the cells
	// when rolled over.
	// This script is on sitemap.asp
	// I have assigned variables to the background's
	// propety instead of fixed colors so as
	// the script could be used more versatiley
	var color;
	function switchBackground(obj) {
		obj.style.backgroundColor = color;
	}

	// This function switches the background color back
	// to its original color.
	var original;
	function backgroundRestore(obj) {
		obj.style.backgroundColor = original;
	}


	// This function changes the color
	// of the cells in the ledgend
	function ledgend_over(obj) {
		obj.style.backgroundColor = '#E6E6E6';
	}

	// This function switches the background color back
	// to its original color.
	function ledgend_out(obj) {
		obj.style.backgroundColor = '#BECDD8';
	}



	// This is the function that is used to
	// display the hidden drop down box that
	// appeares when you click on the ledgend tab
	// This script is on top.asp
	function ShowHide(a,b,c) {

		//var IfrRef = document.getElementById('DivShim');
		var a = document.getElementById(a);
		var b = document.getElementById(b);
		var c = document.getElementById(c);
		//var d = document.getElementById(d);

		// If the hidden div is visible
		if (a.style.display == 'block') {
			// Make it invisible
			a.style.display = 'none';
			b.style.display = 'none';
			c.style.display = 'none';
			//d.style.display = 'none';

		 	a.style.visibility = 'hidden';
			b.style.visibility = 'hidden';
			c.style.visibility = 'hidden';
			//d.style.visibility = 'hidden';


		} else {
			// Make it visible
			a.style.display = 'block';
			b.style.display = 'block';
			c.style.display = 'block';
			//d.style.display = 'block';

			a.style.visibility = 'visible';
			b.style.visibility = 'visible';
			c.style.visibility = 'visible';
			//d.style.visibility = 'visible';
				// This part of the script is only executed on
				// the Search_Header.asp page
				//if (ok == true) {
				//	IfrRef.style.width = obj[id].offsetWidth;
				//	IfrRef.style.height = obj[id].offsetHeight;
				//	IfrRef.style.top = obj[id].style.top;
				//	IfrRef.style.left = obj[id].style.left;
				//	IfrRef.style.zIndex = obj[id].style.zIndex - 1;
				//	IfrRef.style.display = "block";
				//}

		}
	}


	// This is only for the div that holds all the page content
	function HideDiv(a,b,c) {
		var a = document.getElementById(a);
		var b = document.getElementById(b);
		var c = document.getElementById(c);
		//var d = document.getElementById(d);


		if (a.style.display == 'block') {
			a.style.display = 'none';
			b.style.display = 'none';
			c.style.display = 'none';
			//d.style.display = 'none';

		 	a.style.visibility = 'hidden';
			b.style.visibility = 'visible';
			c.style.visibility = 'visible';
			//d.style.visibility = 'visible';
		}

	}
	

	
	// This is only for the div that holds all the page content
	function HideAll() {
		var divList = new Array("hidden","hide1","hide_admin1","hidden_admin","hide2","hide3");
				
		for (var i=0;i<divList.length;i++) {
			
			var a = document.getElementById(divList[i]);
			
			if (a.style.display == 'block') {
				
				a.style.display = 'none';					
				a.style.visibility = 'hidden';				
			}
			
		}
		
		//document.getElementById(elementid).style.visibility = "visible";
	}



		function ReloadList() {
		//Need to strip hash/search criteria from url when refreshing otherwise sorts may reverse
		var host, pathname;

		host = document.location.host;
		pathname = document.location.pathname;
		document.location.replace( "http://"+ host+ "/"+ pathname );

		//host = parent.frames[1].location.host
		//pathname = parent.frames[1].location.pathname
		//parent.frames[1].location.replace( "http://"+ host+ "/"+ pathname );
	}

	function logout_check() {

		var ok;
		ok = confirm("Are you sure you want to log out?");

		if (ok == true) {
			window.location.href = "logout_transfer.asp";
		}

	}


	function del_user_check(a) {

		var ok;		
		ok = confirm("Are you sure you want to delete this user?");

		if (ok == true) {
			window.location.href = "viewusers.asp?action=del&deluser=" + a;
		}

	}
	
	function del_pricecode_check(a) {

		var ok;		
		ok = confirm("Are you sure you want to delete this price code?");

		if (ok == true) {
			window.location.href = "viewpricecodes.asp?action=del&delpricecode=" + a;
		}

	}
	
	


	function validateEditLog() {

		wellname = document.editwell.newwellname.value;
		core = document.editwell.newcore.value;
		depthfrom = document.editwell.newdepthfrom.value;
		depthto = document.editwell.newdepthto.value;
		coreshift = document.editwell.newcoreshift.value;
		litho = document.editwell.newlitho.value;
		volume = document.editwell.newvolume.value;

		if (wellname == "") {
			alert("Please enter a Wellname!");
			return false;
		}

		if (core == "") {
			alert("Please enter a Core value!");
			return false;
		}

		if (depthfrom == "") {
			alert("Please enter a Depth From value!");
			return false;
		}

		if (depthto == "") {
			alert("Please enter a Depth To value!");
			return false;
		}

		if (coreshift == "") {
			alert("Please enter a Core log to shift value!");
			return false;
		}

		if (litho == "") {
			alert("Please enter a Lithostratigraphy value!");
			return false;
		}

		if (volume == "") {
			alert("Please enter a volume value!");
			return false;
		}


	}

	function validateAddPriceCodes() {
		priceCode = document.addPriceCode.pricecode.value;
		price = document.addPriceCode.price.value;
		
		if (priceCode == "") {
                        alert("Please select a price code!");
                        return false;
                }
		
                if (price.search(/^\d+(?:\.\d{0,2})?$/) == -1){
                	alert("price must  be a correct currency amount");
                        return false;
                }

                

	}

	 function validateEditPriceCodes() {
                price = document.editPriceCode.price.value;

                
                if (price.search(/^\d+(?:\.\d{0,2})?$/) == -1){
                        alert("price must  be a correct currency amount");
                        return false;
                }



        }


	function validateEditUser() {

		password = document.editUser.nccl_password.value;
		repassword = document.editUser.repassword.value;
		company = document.editUser.company.value;
		taxrate = document.editUser.taxrate.value;
		authcode = document.editUser.authcode.value;
		spendlimit = document.editUser.spendlimit.value;
		email = document.editUser.nccl_email.value;
		firstname = document.editUser.firstname.value;
		lastname = document.editUser.lastname.value;
		tel = document.editUser.tel.value;
		address = document.editUser.address.value;
		city = document.editUser.city.value;
		country = document.editUser.country.value;
		zip = document.editUser.zip.value;
		userrole = document.editUser.userrole.value;

		if (password != "") {
			if (repassword != password) {
				alert("The Re-enter Password and Password fields do not not match!");
				return false;
			}
		}

		if (company == "") {
			alert("Please enter a Company!");
			return false;
		}
		if (spendlimit.length > 0){
                        if (spendlimit.search(/^\d+(?:\.\d{0,2})?$/) == -1){
                                alert("spend limit must be a correct currency amount");
                                return false;
                        }
                }



		if ((authcode != "")) {

			if ((authcode.length < 12) || (authcode.length > 12))  {
				alert("The Authorisation Code must be 12 characters long!");
				return false;
			}
			
			checkAuth = /[\$\^\{\[\(\|\)\]\}\+\-\?\\&%£!@~.,<>"']+/;
			
			if ( (authcode.search(/[a-z]+/) == -1 ) || (authcode.search(/[A-Z]+/) == -1) || (authcode.search(/[0-9]+/) == -1) 
			|| (authcode.search(checkAuth) == -1) )  {
				alert("The Authorisation Code must contain at least one uppercase letter, one lowercase letter, one numeral and one symbol - apart from: # and *.");
				return false;
			}

			if (taxrate == "") {
				alert("Please enter a Tax Rate!");
				return false;
			}

			if (address == "") {
				alert("Please enter an Address!");
				return false;
			}

			if (city == "") {
				alert("Please enter a City!");
				return false;
			}

			if (country == "") {
				alert("Please enter a Country!");
				return false;
			}

			if (zip == "") {
				alert("Please enter a Zip Code!");
				return false;
			}

		}

		//if (spendlimit == "") {
			//alert("Please enter a Spend Limit!");
			//return false;
		//}

		if (email == "") {
			alert("Please enter an Email Address!");
			return false;
		}

		if (firstname == "") {
			alert("Please enter a First Name!");
			return false;
		}

		if (lastname == "") {
			alert("Please enter a Last Name!");
			return false;
		}

		if (tel == "") {
			alert("Please enter a Telephone Number!");
			return false;
		}


		if (userrole == "") {
			alert("Please enter a User Role!");
			return false;
		}

	}

	function validateAddUser() {

		username = document.editUser.nccl_username.value;
		password = document.editUser.nccl_password.value;
		repassword = document.editUser.repassword.value;
		company = document.editUser.company.value;
		taxrate = document.editUser.taxrate.value;
		authcode = document.editUser.authcode.value;
		spendlimit = document.editUser.spendlimit.value;
		email = document.editUser.nccl_email.value;
		firstname = document.editUser.firstname.value;
		lastname = document.editUser.lastname.value;
		tel = document.editUser.tel.value;
		address = document.editUser.address.value;
		city = document.editUser.city.value;
		country = document.editUser.country.value;
		zip = document.editUser.zip.value;
		userrole = document.editUser.userrole.value;
		spendlimit = document.editUser.spendlimit.value;		
		if (username == "") {
			alert("Please enter a Username!");
			return false;
		}
		if (username.search(/[ ]+/) != -1 ){
			alert("Username must not contain spaces!");
                        return false;
	
		}
		if (spendlimit.length > 0){
			if (spendlimit.search(/^\d+(?:\.\d{0,2})?$/) == -1){
				alert("spend limit must be a correct currency amount");
                        	return false;
			}
		}
		
		if (password != "") {
			if (repassword != password) {
				alert("The Re-enter Password and Password fields do not not match!");
				return false;
			}
		}
		
		if (repassword == "") {
			alert("Please enter a Password!");
			return false;
		}

		if (company == "") {
			alert("Please enter a Company!");
			return false;
		}


		if (authcode != "") {

			if ((authcode.length < 12) || (authcode.length > 12))  {
				alert("The Authorisation Code must be 12 characters long!");
				return false;
			}
			
			checkAuth = /[\$\^\{\[\(\|\)\]\}\+\-\?\\&%£!@~.,<>"']+/;

			if ( (authcode.search(/[a-z]+/) == -1 ) || (authcode.search(/[A-Z]+/) == -1) || (authcode.search(/[0-9]+/) == -1)
			|| (authcode.search(checkAuth) == -1) )  {
				alert("The Authorisation Code must contain at least one uppercase letter, one lowercase letter, one numeral and one symbol - apart from: # and *.");
				return false;
			}

			if (taxrate == "") {
				alert("Please enter a Tax Rate!");
				return false;
			}

			if (address == "") {
				alert("Please enter an Address!");
				return false;
			}

			if (city == "") {
				alert("Please enter a City!");
				return false;
			}

			if (country == "") {
				alert("Please enter a Country!");
				return false;
			}
			
			var pcodeRegxp = /([0-9A-Za-z])/;
			
			//var pcodeRegxp = /^([A-Za-z]{1,2})([0-9]{2,3})([A-Za-z]{2})$/;
			
			if (pcodeRegxp.test(zip) != true) {
				alert("The zip code you entered is not a valid zip code!");				
				return false;
			}

			if (zip == "") {
				alert("Please enter a Zip Code!");
				return false;
			}

		}

		//if (spendlimit == "") {
			//alert("Please enter a Spend Limit!");
			//return false;
		//}
		
		
		//var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
		//var regex = new RegExp(emailReg);
		//return regex.test(email);
		
		var emailRegxp = /^[a-z0-9][a-z0-9_\.-]{0,}[a-z0-9]@[a-z0-9][a-z0-9_\.-]{0,}[a-z0-9][\.][a-z0-9]{2,4}$/;
		
		if (emailRegxp.test(email) != true) {
			alert("The email address you entered is not a valid email address!");
			return false;
		}
					

		if (email == "") {
			alert("Please enter an Email Address!");
			return false;
		}

		if (firstname == "") {
			alert("Please enter a First Name!");
			return false;
		}

		if (lastname == "") {
			alert("Please enter a Last Name!");
			return false;
		}
		
		//var telnoRegxp = /^([0-9]{11})$/;
		var telnoRegxp = /([0-9])/;
		
		if (telnoRegxp.test(tel) != true) {
			alert("The telephone number you entered is not a valid telephone number!");			
			return false;
		}
		
		if (tel == "") {
			alert("Please enter a Telephone Number!");
			return false;
		}


		if (userrole == "") {
			alert("Please enter a User Role!");
			return false;
		}

	}
	function passwordForm(){
				var x_res = screen.width;
				var y_res = screen.height;
				//window width and hieght
				var w=400, h=200;
				//Offset to bring the window higher up
				var yOffset = 70;
				// Setting the initial values
				var x = 0, y = 0;
				x = (x_res/2) - (w/2);
				y = (y_res/2) - (h/2) - yOffset;
				win = window.open("passwordForm.asp","Select_Recipients","left=" + x + ",top=" + y + ",height="+h+",width="+w+",resizeable=no,scrollbars=yes");
	}
