	window.onload = function() {
		gameSelected();
	}

    var anum=/(^\d+$)|(^\d+\.\d+$)/;
    
    function gameSelected() {
		var gamename = document.signupform.gamename;
        if ( gamename.value == "Other" || gamename[gamename.selectedIndex].text == "Other"  ) {  
 		  	document.getElementById('supportedgame').style.visibility = 'hidden';
 		  	document.getElementById('supportedgame1').style.visibility = 'hidden';
	        document.getElementById('supportedgame').style.display = 'none';
	        document.getElementById('supportedgame1').style.display = 'none'; 
	        document.signupform.shortcut.value = "";  
	        document.signupform.username.value = "";  
            document.signupform.userpassword.value = "";  
            document.signupform.confirmpassword.value = "";    
	    } else {
		  	document.getElementById('supportedgame').style.visibility = 'visible';
		  	document.getElementById('supportedgame1').style.visibility = 'visible';
 	        document.getElementById('supportedgame').style.display = 'block';
	        document.getElementById('supportedgame1').style.display = 'block';        
	    }

	    if ( gamename.value == "World of Warcraft" || gamename[gamename.selectedIndex].text == "World of Warcraft" ) {
	    	document.getElementById('nonwowserver').style.visibility = 'hidden';
 		  	document.getElementById('wowserver').style.visibility = 'visible';
	        document.getElementById('nonwowserver').style.display = 'none';
	        document.getElementById('wowserver').style.display = 'block'; 
	        document.signupform.servername.value = "";
	    } else {
		  	document.getElementById('nonwowserver').style.visibility = 'visible';
		  	document.getElementById('wowserver').style.visibility = 'hidden';
 	        document.getElementById('nonwowserver').style.display = 'block';
	        document.getElementById('wowserver').style.display = 'none';        
	    }
    }
     
    function checkForm() {
        if ( document.signupform.guildname.value == "" ) {
	    	alert("Guild Name is required.");
            document.signupform.guildname.focus();
            return (false);
        } else if ( document.signupform.guildname.value.match(/^[a-zA-Z ]*$/) == null ) {
        	alert("Guild Name must consist of letters and spaces only.");
            document.signupform.guildname.focus();
            return (false);
		} else if ( document.signupform.gamename[document.signupform.gamename.selectedIndex].text == "" ) {
			alert("Game Name is required.");
            document.signupform.gamename.focus();
            return (false);
		}

        var gamename = document.signupform.gamename;
        if ( ! ( gamename.value == "World of Warcraft" || gamename[gamename.selectedIndex].text == "World of Warcraft" ) ) {
    	    if ( document.signupform.servername.value == "" ) {
		    	alert("Server Name is required.");
	            document.signupform.servername.focus();
	            return (false);
    	    }
		}

		if ( document.signupform.guildpassword.value == "" ) {
	    	alert("Guild Password is required.");
            document.signupform.guildpassword.focus();
            return (false);
		}
		
		if ( document.signupform.gamename[document.signupform.gamename.selectedIndex].text != "Other" ) {  
		    if ( document.signupform.shortcut.value == "" ) {
		    	alert("URL Shortcut is required.");
	            document.signupform.shortcut.focus();
	            return (false);
			} else {
				var RegExp = /^[A-Za-z][A-Za-z0-9-]*$/;
				if( ! RegExp.test(document.signupform.shortcut.value) ) {
	    			alert( "URL Shortcut can be letters and numbers only AND must begin with a letter." );
					document.signupform.shortcut.focus();
	    			return false;
				}
			}
		
			if ( document.signupform.username.value == "" ) {
		    	alert("Admin Username is required.");
	            document.signupform.username.focus();
	            return (false);
	        } else if ( ! checkUsername() ) {
	        	return (false);
			} else if ( document.signupform.userpassword.value == "" ) {
		    	alert("Admin Password is required.");
	            document.signupform.userpassword.focus();
	            return (false);
			} else if ( document.signupform.confirmpassword.value == "" ) {
		    	alert("Confirm Admin Password is required.");
	            document.signupform.confirmpassword.focus();
	            return (false);
			} else if ( document.signupform.userpassword.value != document.signupform.confirmpassword.value ) {
	        	alert("Admin Email and Confirm Admin Email must be the same.");
	        	document.signupform.confirmpassword.value = "";
	        	document.signupform.userpassword.focus();
	        	return (false);
	        } else if ( document.signupform.username.value == document.signupform.userpassword.value ) {
	        	alert("Admin Username and Admin Password must be the different.");
	        	document.signupform.userpassword.value = "";
	        	document.signupform.confirmpassword.value = "";
	        	document.signupform.email.focus();
	        	return (false);
	        } else if ( ! checkPassword() ) {
	        	return (false);
	        }
	    }
	    
	    
        if ( document.signupform.email.value == "" ) {
	   		alert("Admin Email is required.");
            document.signupform.email.focus();
            return (false);
		} else if ( document.signupform.confirmemail.value == "" ) {
	   		alert("Confirm Admin Email is required.");
            document.signupform.confirmemail.focus();
            return (false);
		} else if ( document.signupform.email.value.match(/^[\w\-\._\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/) == null ) {
	    	alert("Invalid Admin Email address format.");
            document.signupform.email.focus();
            return (false);
		} else if ( document.signupform.email.value != document.signupform.confirmemail.value ) {
        	alert("Admin Email and Confirm Admin Email must be the same.");
        	document.signupform.confirmemail.value = "";
        	document.signupform.email.focus();
        	return (false);
        }

        if ( ! document.signupform.agreetoterms.checked ) {
			alert("You must read and accept the Terms of Service to create a guild site.");
			document.signupform.agreetoterms.focus();
			return false;
        }
        
        var gn = document.signupform.gamename;
        if ( gn.options[gn.selectedIndex].text == "Other" ) {
            if ( document.signupform.comments.value.length == 0 ) {
                alert("Please enter the game you are playing in the comments section.");
                document.signupform.comments.focus();
                return false;
            }
        }
        
        return true;
    }
    
    function checkPassword() {    
        var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        var numeric = "1234567890";
               
        var acount = 0;
        var ncount = 0;
        var passwd = document.signupform.userpassword.value;
            
        for ( count = 0 ; count < passwd.length ; count++ ) {
            if ( alpha.indexOf( passwd.charAt(count) ) > -1 ) {
                acount++;
            } else if ( numeric.indexOf( passwd.charAt(count) ) > -1 ) {
                ncount++;
            } else if ( invalid.indexOf( passwd.charAt(count) ) > -1 ) {
                alert('Admin Password can not contain any of the characters < > ( ) % { } & = ; " \'');
                document.signupform.confirmpassword.value = "";
                document.signupform.userpassword.value = "";
                document.signupform.userpassword.focus();
                return (false);
            }
        }
            
        if ( acount < 6 || ncount < 2 ) {
            alert("Admin Passoword must contain at least 6 characters and 2 numbers.");
            document.signupform.confirmpassword.value = "";
            document.signupform.userpassword.value = "";
            document.signupform.userpassword.focus();
            return (false);
        }
        
        return (true);
    }
    
    function checkUsername() { 
        var userid = document.signupform.username.value;
        var invalid = '\'()<>%{}&=;"';
        
        for (i = 0 ; i < userid.length ; i++ ) {
	    	if ( invalid.indexOf( userid.charAt(i) ) > -1 ) {
	        	alert('Admin Username can not contain any of the characters < > ( ) % { } & = ; " \'');
                document.signupform.username.value = "";
				document.signupform.username.focus();
				return ( false ) ;
	    	} else if ( userid.charAt(i) == " " ) {
                alert('Admin Username can not contain a space.');
                document.signupform.username.value = "";
				document.signupform.username.focus();
				return ( false ) ;
            }
		}
	
		return ( true ) ;    
    }
    
    function wowServerZoneSelected() {
		if ( document.signupform.wowserverzone ) {
			var sz = document.signupform.wowserverzone.value;
			var ws = document.signupform.wowserver;
			if ( sz == 'us'  ) {
				ws.options.length = 0;

				for ( count = 0 ; count < wowusservers.length ; count++ ) {
		            ws.options.add( new Option( wowusservers[count].name, wowusservers[count].name ) ); 
		        }
			} else {
				ws.options.length = 0;

				for ( count = 0 ; count < woweuservers.length ; count++ ) {
		            ws.options.add( new Option( woweuservers[count].name, woweuservers[count].name ) ); 
		        }
			}
		}
    }

    function wowserver( name ) {
	   this.name = fixServerName(name);
    }

    function fixServerName(zn) {
        var result = zn;
        result = result.replace(/&lt;/g, "<");
		result = result.replace(/&gt;/g, ">");
		result = result.replace(/&quot;/g, "\"");
		result = result.replace(/&#039;/g, "\'");
		result = result.replace(/&#040;/g, "(");
		result = result.replace(/&#041;/g, ")");
		result = result.replace(/&#092;/g, "\\");
		result = result.replace(/&#123;/g, "{");
		result = result.replace(/&#125;/g, "}");
		result = result.replace(/&#091;/g, "[");
		result = result.replace(/&#093;/g, "]");
        
        return result;
    }
