ie  =  (document.all)  ?  1  :  0;
n = !ie;

function Go(){
	document.onkeypress = keyDown;
	if (n) {
	    document.captureEvents(Event.KEYPRESS);
	}
}

var Operation = "Choose";
var Type 	  = "Choose";
var Format 	  = "Choose";
var Browser   = "Choose";
var country   = "SELECT";
var tempC     = "";
var tempO     = "";
var tempT     = "";
var tempF     = "";
var tempB     = "";

function checkform ( form )
{

  if (form.first.value == "") {
    alert( "Please enter your first name." );
    form.first.focus();
    return false ;
  }
  
  if (form.last.value == "") {
    alert( "Please enter your last name." );
    form.last.focus();
    return false ;
  }
  
  if (form.name.value == "") {
    alert( "Please enter your user name." );
    form.name.focus();
    return false ;
  }
  
  if (!EmailCheck(form.email)) return false;
  if (!checkOperation()) return false;
  if (!checkType()) return false;
  if (!checkFormat()) return false;
  if (!checkBrowser()) return false;

  if (form.error.value == "") {
    alert( "Please description your error." );
    form.error.focus();
    return false ;
  }
  
  return true ;
}

function CheckO(option){
	tempO = option.value;
	//alert("tempO = " + tempO);
}

function checkOperation() {
	
  if ( tempO == Operation ) {
	alert("You are not select a operation system. Please select a operation system");
	return false;
  } else {
	  //alert("tempO = " + tempO + ", Operation = " + Operation);
	return true;
  }
}

function CheckT(option){
	tempT = option.value;	
	//alert("temp T = " + tempT);
}

function checkType() {
		
  if ( tempT == Type ) {
	alert("You are not select a connection type. Please select a connection type");
	return false;
  } else {
	  //alert("tempT = " + tempT + ", Type = " + Type);
	return true;
  }
}

function CheckF(option){
	tempF = option.value;	
	//alert("tempF = " + tempF);
}

function checkFormat() {
	
  if ( tempF == Format ) {
	alert("You are not select a access format. Please select a access format");
	return false;
  } else {
	 // alert("tempF = " + tempF + ", Format = " + Format);
	return true;
  }
}

function CheckB(option){
	tempB = option.value;	
	//alert("tempB = " + tempB);
}
function checkBrowser() {
  
  if ( tempB == Browser ) {
	alert("You are not select a browser.Please select a browser");
	return false;
  } else {
	 // alert("tempB = " + tempB + ", Browser = " + Browser);
	return true;
  }
}

function keyDown(e) {
	var keycode;
	
	if (window.event) keycode = window.event.keyCode;
	
	else if (e) 
		keycode = e.which;
	
	else 
		return true;
	
	    if ( keycode==96 || keycode==126 || keycode==34 || keycode==39 || 
	         keycode==40 || keycode==92 || keycode==47 || keycode==58 || 
	         keycode==42 || keycode==60 || keycode==62 || keycode==124 || 
	         keycode==63)
	    {
	        return false;
	    }
}

function oSubmit (form)  {
	
	if (!UserID(form.userID)) return false;
	if (!FullName(form.fullName)) return false;
	if (!EmailCheck(form.email)) return false;
	if (!rPassword(form)) return false;
	if (!checkCountry()) return false;
	
	
	return true;
	
}

count = 0;

function timeout()
{

setTimeout("timeout()",1000);

	key = document.getElementById("count");
	temp = 7;
	//key.innerHTML= "Thank you for your interest. An activation email will be send to your email shortly.<br/> auto refresh " + (temp - count) + " second";

	if ( count == 7 )
		window.location.href = "index.html";
	
		count = count + 1;
}

function FullName(field) {
	
	var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "
	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" || field.value == "" ) {
		
		
		alert("Full name only characters are accepted!");
		return false;
	}
	 
	return true;		
}

function UserID(field) {
	
	var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"
	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("User ID not allowed special character input. (e.g \"user_123\")");
		return false;
	} else if ( field.value == "" ) {
		alert("User ID can not be empty!");
		return false;
	}
	 
	return true;		
}

function EmailCheck(field) {
	
	mail = field.value;
	
	if ( mail == "" ) {
		//form.email.focus();
		alert("Please enter your email");
		return false;
	}
		
	if (mail.indexOf("@")<3){
		//form.email.focus();
		alert("Please"+" check the prefix and '@' sign.");
		return false;
	}
	
	if ((mail.indexOf(".com")<5)&&(mail.indexOf(".org")<5)
		&&(mail.indexOf(".gov")<5)&&(mail.indexOf(".net")<5)
		&&(mail.indexOf(".mil")<5)&&(mail.indexOf(".edu")<5)
		&&(mail.indexOf(".tv")<5)){
			
		//form.email.focus();
		alert("This email address seems wrong. Please"
		+" check the suffix for accuracy. (It should include a "
		+".com, .edu, .net, .org, .gov, .mil or .tv)");		

		return false;
   }

   return true;
}


function rPassword(form) {
	
	pw1 = form.password.value;
	pw2 = form.rpassword.value;

	if (pw1 != pw2) {
		alert ("You did not enter the same new password twice. Please re-enter your password.")
		return false;
	} else if ( pw1 == "" || pw2 == "" ) {
		alert ("Empty password.")
		return false;
	}
	
	return true;
}

function checkCountry(){
	
	if ( tempC == country ) {
		alert("You are not select a country.Please select a country");
		return false;
	} else {
		//alert(tempC + country);
		return true;
	}
}

function selectC(option){
	
	//bj.selectedIndex // returns the index of the selected option, ie: 0,1,2...
	
	tempC = option.value ;
	//alert(tempC + country);
	//obj.options[obj.selectedIndex].text // returns the text nested in the selected option
}

