// Basic framework javascript

 function openWindow(image) {

  // create a variable to hold all the options you can change
  var windowOptions = "location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=no,width=550,height=700,resizeable=yes";
 
  // create a new instance of the window with the name newWindow so we can write to it
  var newWindow = open(' ','WindowDemonstration',windowOptions);
  newWindow.document.write("<html>");
  newWindow.document.write("<head><title>TechScape LandScape</title><link href='/library/css/ss_ie.css' rel='stylesheet' type='text/css'></head>");
  newWindow.document.write("<body bgcolor=#cccc99>");
  newWindow.document.write("<table border='0' cellpadding='0' cellspacing='0' align='center'>");
  newWindow.document.write("<tr><td>");
  newWindow.document.write("<img src='"+image+"' border='0'>");
  newWindow.document.write("</td></tr>");
  newWindow.document.write("<tr><td>");
  newWindow.document.write("&nbsp;");
  newWindow.document.write("</td></tr>");
  newWindow.document.write("<tr><td align='center'class='closeWin'>");
  newWindow.document.write("<a href='javascript: window.close()'>Close Window</a>");
  newWindow.document.write("</td></tr>");
  newWindow.document.write("</table>");
  newWindow.document.write("</body>");
  newWindow.document.write("</html>");
  newWindow.document.close();
  newWindow.focus();
 }


// open a popup window
function ShowPopup(url, name, width, height ) {
	popURL = (typeof(url) == "string" && url.length) ? url : "''";
	MyWindowName = (name.length) ? name : "MyPopupWindow";
	MyWidth = (width > 0) ? width : 300;
	MyHeight = (height > 0) ? height : 300;

    if (document.all)
         xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
             xMax = window.outerWidth, yMax = window.outerHeight;
        else
             xMax = 640, yMax=480;
     xOffset = (xMax - MyWidth)/2, yOffset = (yMax - MyHeight)/2;
a = window.open(popURL,MyWindowName,'scrollbars=1,width='+MyWidth+',height='+MyHeight+',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
}


// validate the number of characters a user enters into a textarea tag
function validateLength(value, limit, formName, elementName) {
	if (value.length > limit) {
		alert("ERROR! You have specified " + value.length + " characters!  You can only specify " + limit + " characters for this field.  Please modify your input.");
		eval("document." + formName + "." + elementName + ".focus();");
		eval("document." + formName + "." + elementName + ".select();");
	} else {
		// do nothing
	}
}


// this javascript supports the pop-up calendar selection functions.
var today = new Date();
var day   = today.getDate();
var month = today.getMonth();
var year  = today.getFullYear();
var text_field = "";

function padout(number) {
	return (number < 10) ? '0' + number : number;
}

function restart() {
    text_field.value = '' + padout(month - 0 + 1) + '/' + padout(day) + '/' + year;
	//text_field.value = '' + padout(month - 0 + 1) + '/' + year;
    mywindow.close();
}

function newWindow(fieldname,evnt,path) {
    c_today = new Date();
    day = c_today.getDate();
    month = c_today.getMonth();
    year = c_today.getFullYear();
    text_field = fieldname;
    var properties = "left=" + (evnt.screenX + 20);
    properties += ",top=" + (evnt.screenY + 1);
    properties += ",titlebar=0,resizable=no,width=205,height=255";
    mywindow=open(path,'myname',properties);
    mywindow.location.href = path;
    if (mywindow.opener == null) mywindow.opener = self;
    mywindow.focus();
}
// end of calendar javascript support

// added by mjr on 04/12/2002
function validateEmailAddress(emailAddress, formField, formName) {
	var regexp  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	if (regexp.test(emailAddress)) {
		return true;
	} else {
		eval("document." + formName + "." + formField + ".focus();");
		eval("document." + formName + "." + formField + ".select();");
		alert("Sorry, you entered an invalid email address.  Please correct the email address.");
		return false;
	}
}

function writeBrowserSpecificCSS(path) {

	var ua = navigator.userAgent;
	var l = '<link rel="stylesheet" type="text/css" href="' + path + '/ss_';
	var c = '.css">';
	
	if (ua.indexOf('IE 4') != -1) {
		document.write(l+'ie4'+c);
	}

	if (ua.indexOf('IE 5') != -1) {
		document.write(l+'ie5'+c);
	}

	if (ua.indexOf('IE 6') != -1) {
		document.write(l+'ie6'+c);
	}

	if (ua.indexOf("Opera 3") != -1) {
		document.write(l+'op3'+c);
	} else if (ua.indexOf("compatible") == -1) {

		if (ua.indexOf("/4") != -1) {
	  		document.write(l+'nn4'+c);
		}
	
		if (ua.indexOf("/5") != -1) {
			document.write(l+'nn5'+c);
		}
	}

	if (ua.indexOf('Opera 6.01') != -1) {
		document.write(l+'op6'+c);
	}

}

/*
Example:
	<a href="javascript:copyText(document.all.testCopy);">Copy Source to Clipboard</a>
*/
function copyText(obj) {
	if (obj.type=="text" || obj.type=="textarea") {
		var rng = obj.createTextRange();
	} else {
		var rng = document.body.createTextRange();
		rng.moveToElementText(obj);
	}

	rng.scrollIntoView();
	rng.select();

	if (confirm('Copy the selected text to the ClipBoard?')) {
		rng.execCommand("Copy");
	}

	rng.collapse(false);
	rng.select();
}

 function subscribe(emailaddress, formField, formName, form) {
	if(validateEmailAddress(emailaddress, formField, formName)) {
		return true;
	} else {
		return false;
	}
 }
 
 function searchString (value) {
 	if(value == '') {
		alert('Please provide a search string!');
		return false;
	} else {
		return true;
	}
 }
