var timerScroll;
var posX;
var posY;
var Ver = parseFloat(navigator.appVersion);
var frm = 10;


fIE6 = true;
if(navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1) {
	if(navigator.appVersion.indexOf("MSIE 6.0b",0) != -1) {
		//IE5
		fIE5 = true;
		fIE55 = false;
		fIE6 = false;
	}else if(navigator.appVersion.indexOf("MSIE 6.0",0) != -1){
		//IE6
		fIE5 = false;
		fIE55 = false;
		fIE6 = true;
	}else if(navigator.appVersion.indexOf("MSIE 5.5",0) != -1){
		//IE5.5
		fIE5 = false;
		fIE55 = true;
		fIE6 = false;
	}else{
		//IE(other)
		fIE5 = false;
		fIE55 = false;
		fIE6 = true;
	}
}else{
	fIE5 = false;
	fIE55 = false;
	fIE6 = false;
}

if(navigator.appVersion.indexOf('Mac',0) != -1) {
	fMac = true;
}else{
	fMac = false;
}

if(navigator.appName.indexOf("Netscape",0) != -1) {
	fNN = true;
}else{
	fNN = false;
}

if((fMac && navigator.appVersion.indexOf('MSIE 4.',0) != -1)) {
	fMacIE4 = true;
} else {
	fMacIE4 = false;
}

if((fMac && navigator.appVersion.indexOf('MSIE 3.',0) != -1)) {
	fMacIE3 = true;
} else {
	fMacIE3 = false;
}

function getPosY() {
	if (fIE6) {
		//IE6
		if(document.body!=null){
			return document.body.scrollLeft;
		}else{
			return document.documentElement.scrollLeft;
		}
	} else if (fIE5 || fIE55) {
		//IE5 or IE5.5
		//return document.documentElement.scrollLeft;
		return document.body.scrollLeft;
	}else if(window.pageXOffset){
		return window.pageXOffset;
	}else{
		return 0;
	}
}

function getPosX() {
	if (fIE6) {
		//IE6
		if(document.body!=null){
			return document.body.scrollTop;
		}else{
			return document.documentElement.scrollTop;
		}
		//return document.documentElement.scrollTop;
	} else if (fIE5 || fIE55) {
		//IE5 or IE5.5
		return document.body.scrollTop;
	} else if (window.pageYOffset) {
		return window.pageYOffset;
	} else {
		return 0;
	}
}

function scroll2Top(pos2X,pos2Y,pos3X,pos3Y) {
	if (timerScroll) {
		clearTimeout(timerScroll);
	}
	if (!pos2X || (pos2X < 0)) {
		pos2X = 0;
	}
	if (!pos2Y || (pos2Y < 0)) {
		pos2Y = 0;
	}
	if (!pos3X) {
		pos3X = 0 + getPosY();
	};
	if (!pos3Y) {
		pos3Y = 0 + getPosX();
	};

	if (pos2Y > pos3Y && pos2Y > (getAnchorPosObj2('end','enddiv').y) - getInnerSize().height) pos2Y = (getAnchorPosObj2('end','enddiv').y - getInnerSize().height) + 1;
	pos3X += (pos2X - getPosY()) / frm;
	if (pos3X < 0) pos3X = 0;
	pos3Y += (pos2Y - getPosX()) / frm;
	if (pos3Y < 0) pos3Y = 0;
	posX = Math.floor(pos3X);
	posY = Math.floor(pos3Y);
	window.scrollTo(posX, posY);
	//alert(posX +","+ pos2X +","+ posY +","+ pos2Y);
	if (posX != pos2X || posY != pos2Y) {
		timerScroll = setTimeout("scroll2Top("+pos2X+","+pos2Y+","+pos3X+","+pos3Y+")",10);
	}
}

function jumpToPageTop() {
	scroll2Top(0,0);
}



// ==================================================================¥Õ¥©¡¼¥à //
// This function checks if the username field
// is at least 6 characters long.
// If so, it attaches class="welldone" to the 
// containing fieldset.

function checkUsernameForLength(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length > 5) {
		fieldset.className = "welldone";
	}
	else {
		fieldset.className = "";
	}
}





// If the password is at least 4 characters long, the containing 
// fieldset is assigned class="kindagood".
// If it's at least 8 characters long, the containing
// fieldset is assigned class="welldone", to give the user
// the indication that they've selected a harder-to-crack
// password.

function checkPassword(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length > 3 && txt.length < 8) {
		fieldset.className = "kindagood";
	} else if (txt.length > 7) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}

// This function checks the email address to be sure
// it follows a certain pattern:
// blah@blah.blah
// If so, it assigns class="welldone" to the containing
// fieldset.

function checkEmail(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt)) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}




// this part is for the form field hints to display
// only on the condition that the text input has focus.
// otherwise, it stays hidden.

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


function prepareInputsForHints() {
  var inputs = document.getElementsByTagName("input");
  for (var i=0; i<inputs.length; i++){
    inputs[i].onfocus = function () {
      this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
    }
    inputs[i].onblur = function () {
      this.parentNode.getElementsByTagName("span")[0].style.display = "none";
    }
  }
}
addLoadEvent(prepareInputsForHints);
