// JavaScript Document
function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.myForm.password.value;
var pw2 = document.myForm.password2.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password twice.');
return false;
}
// check for minimum length
if (document.myForm.password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.myForm.password.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter your password.");
return false;
}
else {
alert('Nice job.');
return true;
      }
   }
}

function setStyle(obj,style,value){
	getRef(obj).style[style]= value;
}

function cb_setStyle(obj,style,value){
	getRef(obj).style[style]= value;
}

function getRef(obj){
	return (typeof obj == "string") ?
		 document.getElementById(obj) : obj;
}


function setClass(id, newClass) {

identity=document.getElementById(id);

identity.className=newClass;

}


function numbonly(field) {
var valid = "0123456789"
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Please enter a number. Do not include commas or decimal points.");
field.focus();
field.select();
   }
}


function ignoreSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}

function CheckMaxLength(Object, MaxLen)
{
    return (Object.value.length <= MaxLen);
  }




function popup (earl, name, widgets, specialsURL) 
{
	var url = earl;
	popupWin = window.open(url, name, widgets);
	popupWin.opener.top.name = "opener";
	popupWin.focus();
}




function closepopup(){

	if(!popupWin || popupWin.closed){
	
	} else {
	popupWin.close();
	}
}




function loadFragmentInToElement(fragment_url, element_id) {
    var element = document.getElementById(element_id);
  /* element.innerHTML = '<p><em>Loading ...</em></p>'; */
    xmlhttp.open("GET", fragment_url);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            element.innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.send(null);
}

var dragapproved=false
var z,x,y
function move(){
if (event.button==1&&dragapproved){
z.style.pixelLeft=temp1+event.clientX-x
z.style.pixelTop=temp2+event.clientY-y
return false
}
}
function drags(){
if (!document.all)
return
if (event.srcElement.className=="drag"){
dragapproved=true
z=event.srcElement
temp1=z.style.pixelLeft
temp2=z.style.pixelTop
x=event.clientX
y=event.clientY
document.onmousemove=move
}
}
document.onmousedown=drags
document.onmouseup=new Function("dragapproved=false")

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function createRequestObject()
{
	var request_;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
		{
		request_ = new ActiveXObject("Microsoft.XMLHTTP");
		}
	else{
		request_ = new XMLHttpRequest();
		}
	return request_;
}
	
var http = new Array();
function createAJAX(fragment_url, element_id){
var curDateTime = new Date();
var ranNum= Math.floor(Math.random()*5000);
curDateTime = curDateTime + ranNum;
http[curDateTime] = createRequestObject();
http[curDateTime].open("get", fragment_url);
http[curDateTime].onreadystatechange = function()
	{
		if (http[curDateTime].readyState == 4)
		{
			if (http[curDateTime].status == 200 || http[curDateTime].status == 304)
			{
			var response = http[curDateTime].responseText;
			document.getElementById(element_id).innerHTML = response;
			}
		}
	}
	http[curDateTime].send(null);
}

function reloadcaptcha(){

createAJAX('/captcha/getcap.asp', 'capimg')


}

function  showLogin(){
setStyle('navlogin', 'display', 'block');
document.forms.navlogin.loginname.focus();
	
}

	function changecss(theClass,element,value) {
	//Last Updated on May 21, 2008
	//documentation for this script at
	//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 var added = false;
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    if(document.styleSheets[S][cssRules][R].style[element]){
	    document.styleSheets[S][cssRules][R].style[element] = value;
	    added=true;
		break;
	    }
	   }
	  }

	  if(!added){
	  if(document.styleSheets[S].insertRule){
			  document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
			} else if (document.styleSheets[S].addRule) {
				document.styleSheets[S].addRule(theClass,element+': '+value+';');
			}
	  }
	 }
	}


