OGPPattern = {	
	zipcode : /^\d{5}$/,	
	account: /^[a-z0-9]+$/i,
	email:/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i,
	
	format:function(value, pattern) {
		return pattern.test(value);
	}	
}

OGPError = {	
	E001:"'User ID' does not exist. Please check and try again.",
	E002:'The password is wrong. Check for spelling errors and Caps Lock key then try again.',
	E003:'Please enter your ID and Password.',
	E004:'Hey buddy, this is a member\'s only area. If you are already a member, please log in now."',
	E005:'You typed in an invalid e-mail address. Please check and try again.',
	E006:'The e-mail you entered was not found.',
	E007:'Please enter your e-mail you used at OGPlanet registration.',
	E008:'You have entered invalid information. Please check and try again.',
	E009:'You typed in an invalid e-mail address. Please check and try again.',
	E010:'Please enter your ID and E-mail.',
	E011:'You have entered invalid information. Please check and try again.',
	E012:'Please enter the security answer you used at OGPlanet registration.',
	E013:'Your security answer must be 3 to 20 characters in length.',
	E014:'Please answer the security question.',
	E015:'Please enter all input fileds befor you click submit.',
	E016:'The password is wrong. Check for spelling errors and Caps Lock key then try again.',
	E017:'You must confirm your password. Please check for spelling errors and retype your password.',
	E018:'Please enter new password you want to change.',
	E019:'You typed in an invalid e-mail address. Please check and try again.',
	E020:'You must confirm your e-mail address. Please check and retype your e-mail address.',
	E021:'Please enter all input fileds befor you click submit.',
	E022:'You have entered invalid information. Please check and try again.',
	E023:'Select a reason for closing your account.',
	E024:'\'User ID\' is already in use. Please try a new ID.',
	E025:'Your ID must be between 4 to 20 characters in length. Please try again.',
	E026:'You cannot include words such as admin, manager, operator, etc. in your ID. Please select another ID.',
	E027:'Your ID should not contain symbols.',
	E028:'Your ID should not contain any spaces. For more information, please refer to Help! Section.',
	E029:'Sorry, the ID you\'ve chosen is unsuitable. Please select another.',
	E030:'Check whether the ID you selected is available for use.',
	E031:'Please type an ID. (*Required)',
	E032:'Your password pattern is too obvious for others to guess. For your security, please select another password.',
	E033:'Your password must be between 6 to 15 characters in length. Please try again.',
	E034:'Please enter a password(*Required)',
	E035:'You must confirm your password. Please check for spelling errors and retype your password.',
	E036:'Please enter your password one more time in the re-type password slot.(*Required)',
	E037:'Please select the security question. (*Required)',
	E038:'Your security answer must be 3 to 20 characters in length.',
	E039:'Please answer the security question. (*Required)',
	E040:'You typed in an invalid e-mail address. Please check and try again.',
	E041:'Please enter in your e-mail address. (*Required)',
	E042:'You must confirm your e-mail address. Please check for spelling errors and retype your e-mail address.',
	E043:'Please enter your e-mail address one more time in the re-type e-mail address slot.(*Required)',
	E044:'Please enter you first name. (* Required)',
	E045:'Please enter your last name. (* Required)',
	E046:'Please select your date of birth. (* Required)',
	E047:'Please select your gender. (* Required)',
	E048:'Please select your country.',
	E049:'You have entered an invalid e-mail address.', 
	E050:'Please enter your parent\'s valid e-mail address.',
	E051:'You must agree to the Terms of Use and Privacy Policy before joining our site.', 
	E052:'\'User ID\' does not exist. Please check and try again.', 
	E053:'The password is wrong. Check for spelling errors and Caps Lock key then try again.',
	E054:'You have entered invalid information. Please check and try again.',
	E055:'You typed in an invalid e-mail address. Please check and try again.',
	E056:'Please type in your e-mail address. (*Required)',
	E057:'You must confirm your e-mail address. Please check for spelling errors and retype your e-mail address.',
	E058:'Please type your e-mail address one more time in the re-type e-mail address slot.(*Required)',
	E059:'Please enter a keyword for your search.',
	E060:'Please select a game.',
	E061:'Please select a category.',
	E062:'Please enter your ID.',
	E063:'Please enter you name.',
	E064:'Please enter an e-mail address to receive replies for your inquiry.',
	E065:'You typed in an invalid e-mail address. Please check and try again.',
	E066:'Please write the subject.',
	E067:'Please write a message before clicking the submit button.', 
	E068:'You can write up to 1000 characters in length at a time.',
	E069:'Attached file must be less than 2MB in size.',
	E070:'The attached file type is not supported. Please try another.', 
	E071:'Please enter you oder ID.',
	
	showErrorMessageArray:function(array) {
		message = array.join("<br>");
		this.showErrorMessage(message);
	},
	
	showErrorMessage:function(message){
		ogpError = document.getElementById("OGPError");
		ogpError.innerHTML = message;
		ogpError.style.display = ""
	},
	
	hideErrorMessage:function() {
		ogpError = document.getElementById("OGPError");
		ogpError.innerHTML = "";
		ogpError.style.display = "none"
	}
}
 
var SingUpContainer = {
	elementNameArray:[],
	elementValidationArray:[],
			
	doValidations:function(elementId) {		
		obj = this.getValidation(elementId);
		return obj.doValidations();	
	},
	
	getValidation:function(elementId) {
		for(i = 0; i < this.elementNameArray.length; i++) {
			if(this.elementNameArray[i] == elementId) {
				return this.elementValidationArray[i].validation;				
			}
		}
	},
	
	setMessage:function(elementId, orgs) {			
		obj = this.getValidation(elementId);
		
		originDisplayMessageWhenEmpty = obj.displayMessageWhenEmpty;
		
		if(obj.displayMessageWhenEmpty == undefined) obj.displayMessageWhenEmpty = true;
		if(obj.displayMessageWhenEmpty == false) obj.displayMessageWhenEmpty = true;		
		
		obj.doValidations();		
		obj.message = orgs.message;		
		
		if(orgs.valid == 1) {			
			obj.onValid();
		} else {						
			obj.validationFailed = true;
			obj.onInvalid();
		}		
		obj.displayMessageWhenEmpty	= originDisplayMessageWhenEmpty;		
	},
	
	massValidate:function() {
		len = this.elementValidationArray.length;		
		var returnValue = true;	
		for(var i = 0; i < len ; i++) {
			obj = this.elementValidationArray[i];			
			if(obj.defalutInitValue.checkRequired) {
				var valid = obj.validation.validate();
				if(returnValue) returnValue = valid;
			}
		}
		return returnValue;
	}
}

var SingUp = function(elementName, optionsObj) {	
	optionsObj = optionsObj || {};
	this.initialize(elementName, optionsObj);	
}

SingUp.prototype = {
	
	initialize:function(elementName, optionsObj){	
		this.validation = null,	
		this.defalutInitValue = {validMessage: " ", wait:200, checkRequired:true};	  
		this.ValidatePresenceValue = {failureMessage:" "};
		this.ValidateLengthValue = {wrongLengthMessage:" ", tooShortMessage:" ", tooLongMessage:" "};
		this.ValidateFormatValue = {failureMessage:" "};
		this.ValidateConfirmation = {};
		this.ValidateEmailValue = {failureMessage:" "};
		this.ValidateExclusionValue = {within: ["-1"], failureMessage:" "};
		this.ValidateAcceptanceValue = {failureMessage:" "};			
		this.ValidateCustomValue = {failureMessage : " "};		
		optionsObj = optionsObj || {};		
		this.defalutInitValue = SingUp.extend(this.defalutInitValue, optionsObj);					
		this.validation = new LiveValidation(elementName, this.defalutInitValue);		
		SingUpContainer.elementNameArray.push(elementName);
		SingUpContainer.elementValidationArray.push(this);	//this.validation	
		return this;
	},
	
	add:function(validateType, optionsObj) {		
		optionsObj = optionsObj || {};
		switch(validateType)
		{
			case Validate.Presence:
				optionsObj = SingUp.extend(this.ValidatePresenceValue, optionsObj);
				break;
			case Validate.Length:
				optionsObj = SingUp.extend(this.ValidateLengthValue, optionsObj);
				break;
			case Validate.Format:
				optionsObj = SingUp.extend(this.ValidateFormatValue, optionsObj);
				break;
			case Validate.Confirmation:
				optionsObj = SingUp.extend(this.ValidateConfirmation, optionsObj);
				break;				
			case Validate.Email:
				optionsObj = SingUp.extend(this.ValidateEmailValue, optionsObj);
				break;
			case Validate.Exclusion:
				optionsObj = SingUp.extend(this.ValidateExclusionValue, optionsObj);
				break;				 	
			case Validate.Acceptance:
				optionsObj = SingUp.extend(this.ValidateAcceptanceValue, optionsObj);
				break;	
			case Validate.Custom:
				optionsObj = SingUp.extend(this.ValidateAcceptanceValue, optionsObj);
				break;				
		}
		this.validation.add(validateType, optionsObj);		
		return this;
	}	
}

SingUp.extend = function() {	
	var args = arguments;
	args = (args[1]) ? [args[0], args[1]] : [this, args[0]];
	for (var property in args[1]) args[0][property] = args[1][property];
	return args[0];
}

CommonUtil={
	trim:function(str) {
		var strTemp = str;
    	strTemp = CommonUtil.rtrim(strTemp);
		strTemp = CommonUtil.ltrim(strTemp);
		return strTemp;
	},

	rtrim:function(strTemp)	{
 		var nLoop = 0;
		var strReturn = strTemp;
		while (nLoop < strTemp.length){
			if ((strReturn.substring(strReturn.length - 1, strReturn.length) == " ")) {
				strReturn = strTemp.substring(0, strTemp.length - (nLoop + 1));
			} else {
				break;
			}
			nLoop++;
		}
		return strReturn;
	},
	
	ltrim:function(strTemp)	{
		var nLoop = 0;
		var strReturn = strTemp;
		while (nLoop < strTemp.length) {
			if ((strReturn.substring(0, 1) == " ")) {
				strReturn = strTemp.substring(nLoop + 1, strTemp.length);
			} else {
				break;
			}
			nLoop++;
		}
		return strReturn;
	}	
}


function popup(URLID) {	
	switch(URLID) {
		case 2 :
			URL = "http://www.ogplanet.com/about.og?op=privacypolicy";break;
		case 1 :
			URL = 'http://www.ogplanet.com/about.og?op=useragreement';break;	
	}
	day = new Date();
	//id = day.getTime();
	id = '235';
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=600');");
}
