
// Writer : Andrew
// Lastupdate : 2005-11-07

var flagCheckID = false;		// Flag For ID Duplication checked

// check out Sign Up Form Value is valid.

function CheckSignup()
{

	if (isEmpty(frmSignUp.txLoginID, "", msgSIGNUP_LoginID))		return false;

	if (!flagCheckID)
	{
		alert(msgSIGNUP_CheckLoginID);
		frmSignUp.txLoginID.focus();
		return false;
	}
	
	// Check Password
	if (isEmpty(frmSignUp.pwPwd, "", msgSIGNUP_PWD)){
		frmSignUp.pwPwd.focus();
		return false;
	}

	if(!chkLength(frmSignUp.pwPwd,"Password",16,4,msgSIGNUP_PWDTOOSHORT)){
		frmSignUp.pwPwd.focus();
		return false;
	}
	if(!confirmPwd(frmSignUp.pwPwd,frmSignUp.pwConfirmPwd)){
		frmSignUp.pwPwd.value="";
		frmSignUp.pwConfirmPwd.value="";
		frmSignUp.pwConfirmPwd.focus();
		return false;
	}

	if (isEmpty(frmSignUp.txWebAddress, "Web Address", msgSIGNUP_WebAddress)){
		frmSignUp.txWebAddress.focus();
		return false;
	}

	//if (notWebAddress(frmSignUp.txWebAddress, "Web Address", msgSIGNUP_NotValidWebAddress)){
	//	frmSignUp.txWebAddress.focus();
	//	return false;
	//}

	if (isEmpty(frmSignUp.txCompanyName, "Company Name", msgSIGNUP_CompName)){
		return false;
	}
	
	if (!checkNameType(frmSignUp.txCompanyName,"Company Name","1")){
		frmSignUp.txCompanyName.focus();
		return false;
	}

	if (isEmpty(frmSignUp.txContactPhone, "Company Phone Number", msgSIGNUP_CompPhone)){
		frmSignUp.txContactPhone.focus();
		return false;
	}

	if(!checkNumDash(frmSignUp.txContactPhone,"Company Phone Number")){
		frmSignUp.txContactPhone.focus();
		return false;
	}

	if (isEmpty(frmSignUp.txAddress1, "Address1", msgSIGNUP_Address)){
		frmSignUp.txAddress1.focus();
		return false;
	}
		
	if (isEmpty(frmSignUp.txCity, "City", msgSIGNUP_City)){
		frmSignUp.txCity.focus();
		return false;
	}
	
	if(!checkOneType(frmSignUp.txCity, "City",'2')){
		frmSignUp.txCity.focus();
		return false;
	}

	if(!checkNumDash(frmSignUp.txContactFax,"Contact Fax Number")){
		frmSignUp.txContactFax.focus();
		return false;
	} 

	//if (!checkNumDash(frmSignUp.txContactPhone)) return false;

	if (isEmpty(frmSignUp.txMngName, "Contact Manager", msgSIGNUP_MngName)){
		frmSignUp.txMngName.focus();
		return false;
	}else if(!isEmpty(frmSignUp.txMngName, "Contact Manager", msgSIGNUP_MngName)){
		if(!checkOneType(frmSignUp.txMngName,"Contact Manager",'2')){
			frmSignUp.txMngName.focus();
			return false;
		}
	}

	if (isEmpty(frmSignUp.txMngPhone, "Contact Phone Number", msgSIGNUP_MngPhone)){
		frmSignUp.txMngPhone.focus();
		return false;
	}else{
		if (!checkNumDash(frmSignUp.txMngPhone,"Contact Phone Number")){
		frmSignUp.txMngPhone.focus();
		return false;
		}
	}


	if (isEmpty(frmSignUp.txMngEmail, "Email", msgSIGNUP_MngEmail)){
		frmSignUp.txMngEmail.focus();
		return false;
	}
	if (notEmail(frmSignUp.txMngEmail, "Email", msgSIGNUP_NotVldEmail)){
		frmSignUp.txMngEmail.focus();
		return false;
	}

	if (isEmpty(frmSignUp.txNotifyEmail, "Email Notification", msgSIGNUP_Email)){
		frmSignUp.txNotifyEmail.focus();
		return false;
	}
	if (notEmail(frmSignUp.txNotifyEmail, "Email Notification", msgSIGNUP_NotVldEmail)){
		frmSignUp.txNotifyEmail.focus();
		return false;
	}
	if (frmSignUp.selCountry.value == 0)
	{
		alert(msgSIGNUP_Country);
		frmSignUp.selCountry.focus();
		return false;
	}

	var txSSN = frmSignUp.txSSN1.value + frmSignUp.txSSN2.value + frmSignUp.txSSN3.value;
	if(frmSignUp.rdUSCitizen[0].checked == true){
		if(frmSignUp.txSSN1.value == ""){
			alert(msgSIGNUP_SSN);
			frmSignUp.txSSN1.focus();
			return false;
		}
		if(frmSignUp.txSSN2.value == ""){
			alert(msgSIGNUP_SSN);
			frmSignUp.txSSN2.focus();
			return false;
		}
		if(frmSignUp.txSSN3.value == ""){
			alert(msgSIGNUP_SSN);
			frmSignUp.txSSN3.focus();
			return false;
		}
	}

	if(frmSignUp.txLaunchDate.value==null){
		alert(msgSIGNUP_LaunchDate);
		frmSignUp.txLaunchDate.focus();
		return false;
	}else{
		if(!checkNumDash(frmSignUp.txLaunchDate,"Launch Date")){
			alert(frmSignUp.txLaunchDate.value);
			frmSignUp.txLaunchDate.focus();
			return false;
		}
	}

	if(frmSignUp.txTargetMarket.value==null){
		alert(msgSIGNUP_TargetMarket);
		frmSignUp.txTargetMarket.focus();
		return false;
	}else{
		if(!checkOneType(frmSignUp.txTargetMarket,"Geographical Target Market","3")){
			frmSignUp.txTargetMarket.focus();
			return false;
		}
	}

	return true;
}


//'===========================================================================================================
//' Addtional Functions were added by sooyong Kim
//'===========================================================================================================

//
function CheckIDOK(field)
{

	//var loginid = document.frmSignUp.txLoginID.value;
	var loginid = field.value;
	//var format = /^\[ \t]+$/;
	if (loginid == "")
	{
		alert(msgSIGNUP_LoginID);
		//document.frmSignUp.txLoginID.focus();
		field.focus();
		return;
	}
	
	for (i = 0 ; i < loginid.length ; i++) {
		chkId = loginid.charAt(i);
		if ((chkId < '0' || chkId > '9')&&(chkId < 'a' || chkId > 'z')&&(chkId < 'A' || chkId > 'Z')) {
			alert("You can only use numeric or alphabetical characters.\n\n Neither are spcial characters such as %,#,and @ nor spaces allowed to use");
			loginid = "";
			//document.frmSignUp.txLoginID.focus();
			field.focus();
			return;
		}
	}

	if(loginid.charAt(0)>0 || loginid.charAt(0)<9)
	{
		alert("You can't have your ID starting with a numeric character.");
		//document.frmSignUp.txLoginID.focus();
		field.focus();
		return;
	}

	if(loginid.length < 4 || loginid.length >16){
		alert("The length of your ID should be either \n\nlonger that 4 characters or shorter than 16 characters.");
		//document.frmSignUp.txLoginID.focus();
		field.focus();
		return;
	}
	openWnd('mdCheckIDOK.asp?loginid=' + loginid,'CHECKID',200,300,0,0,0,1,1,0,0);
	flagCheckID = true;
}


// This function calls a pop-up window where a user should check the ID
function CheckID()
{
	var loginid = document.frmSignUp.txLoginID.value;
	alert("You provided "+loginid+". \n\n Please check your ID if it's validate");
}

function confirmPwd(field1,field2)
{
	var fstPwd=field1.value;
	var sndPwd=field2.value;

	if (fstPwd != sndPwd)
	{
		alert(msgSIGNUP_PWDNOMATCH);
		fstPwd = "";
		sndPwd = "";
		field1.focus();
		return false;
	}
	return true;
}

// Check Number Or Dash Character
function checkNumDash(field,fieldName)
{

	if(field.value=="")
	{
		return true;
	}else{
		var regNumDash = /^[0-9 ]+([0-9 ]|[\- ]{1})+$/; 

		pattern = regNumDash;

		if(!pattern.test(field.value))
		{ 
			alert("The "+fieldName+" that you provided is Invalid Type.\nYou Should Provide Numbers or - (dash) For "+fieldName+".\n"); 
			field.focus(); 
			return false; 
		}
		field.value=trim(field.value);
		return true; 
	}
}

// Check PostelCode
function checkPostelCode(field,fieldName)
{

	if(field.value=="")
	{
		return true;
	}else{
		var regNumDash = /^([a-zA-Z ]|[0-9])+([a-zA-Z ]|[0-9 ]|[\- ]{1})+$/; 

		pattern = regNumDash;

		if(!pattern.test(field.value))
		{ 
			alert("The "+fieldName+" that you provided is Invalid Type.\nYou Should Provide Alphabet or Numbers or - (dash) For "+fieldName+".\n"); 
			field.focus(); 
			return false; 
		}
		field.value=trim(field.value);
		return true; 
	}
}

// type==1 the name of a company
// type==2 a person's name


function checkNameType(field,fieldName,types){
	

	if(field.value=="")
	{
		
		return true;
	}else{
		
		
		if(types=='1'){
			
			var regNameType=/^([a-zA-Z ]|[0-9])+(([0-9]|[a-zA-Z])|[\'\., ])+([0-9]|[a-zA-Z \.,]{1})+$/;
			var msg="The "+fieldName+" that you provided is Invalid Type.\nYou Should Provide Alphabets,Numbers or '(single quote) For "+fieldName+".\n";
			
		}else if(types=='2'){
			var regNameType=/^[a-zA-Z ]+([a-zA-Z]|[\. ])+([a-zA-Z\. ]{1})+$/;
			var msg="The "+fieldName+" that you provided is Invalid Type.\nYou Should Provide Alphabets or .(dot) For "+fieldName+".\n";
		}
		pattern=regNameType;
		
		if(!pattern.test(field.value))
		{
			alert(msg); 
			field.focus(); 
			return false; 
		}else{
			field.value=trim(field.value);
			return true; 
		}
		
	}

}


// type 1 : for numbers
// type 2 : for characters
// type 3 : for characters and comma
function checkOneType(field,fieldName,types){
	if(field.value=="")
	{
		return true;
	}else{
		if(types=='1'){
			var regOneType=/^[0-9 ]+$/;
			var msg="You should use ONLY NUMBERS for "+fieldName;
		}else if(types=='2'){
			var regOneType=/^[a-zA-Z ]+$/;
			var msg="You should use only Alphabets for "+fieldName;
		}else if(types=='3'){
			var regOneType=/^[a-zA-Z ,]+$/;
			var msg="You should use Alphabets and , (comma) for "+fieldName;
		}
		pattern=regOneType;

		if(!pattern.test(field.value)){
			alert(msg);
			field.focus();
			return false;
		}else{
			field.value=trim(field.value);
			return true;
		}
	}
}

function checkEmail(field,fieldName,msg)
{
	
	if(field.value=="")
	{
		return true;
	}else{
		var msg=null;
		var retn_value=notEmail(field, fieldName, msg);
		return retn_value;
	}
}

function checkDateType(field,fieldName){
	if(field.value==""){
		return true;
	}else{
		var regDate=/^([0-9]|[0-9][0-9]){1}\-([0-9]|[0-9][0-9]){1}\-([0-9]{2}|[0-9]{4}){1}$/
		var msg="The Date,"+field.value+", you provided is invalid type\n\nPlease check it again.\n\nex) 11-19-2005(month-day-year)";

		pattern=regDate;
		if(!pattern.test(field.value)){
			alert(msg);
			field.focus();
			return false;
		}else{

			return true;
		}
	}
}

function checkAddress(field,fieldName){
	if(field.value==""){
		return true;
	}else{
		var regAddr=/^([0-9#@ ]|[a-zA-Z@# ])+[\w\.\s\-@&,]*([0-9\. ]|[a-zA-Z\. ])$/
		var msg="The Address, "+field.value+", That You Provide \nIs Invalid Type.Please Check It Again.";

		pattern=regAddr;
		if(!pattern.test(field.value)){
			alert(msg);
			field.focus();
			return false;
		}else{

			return true;
		}
	}
}

