// For SurfGold Only Function 

function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function CheckPassword(inText1,inText2,errMsg){
	if(inText1.value != inText2.value ){
		alert("\n\n" + errMsg + "\n\n");
		inText.focus();
		return false;
	}
	return true;
}
function CheckText(inText,errMsg){
	if(inText.value == ""){
		alert("\n\n" + errMsg + "\n\n");
		inText.focus();
		return false;
	}
	return true;
}

function CheckFriend(inText1,inText2,inText3,errMsg){
	if(inText1.value == "" && inText2.value == "" && inText3.value == ""){
		alert("\n\n" + errMsg + "\n\n");
		inText1.focus();
		return false;
	}
	return true;
}

function CheckAllEmail(inText1,inText2,errMsg){
	if(inText1.value != "" && inText2.value == "" ){
		alert("\n\n" + errMsg + "\n\n");
		inText2.focus();
		return false;
	}
	return true;
}

function CheckSelect(E,errMsg){
	if(E.options[0].selected)
	{
		alert("\n\n" + errMsg + "\n\n");
		E.focus();
		return false;
	}else{
		return true;
	}
}

function CheckEmail(z,errMsg){

    for ( i=0; i<= z.value.length - 1 ;i++ ){
		x = z.value.charAt(i)
		y = escape( x)
		if ( y != x && y !='%40'){
			alert("\n\n" + errMsg + "\n\n");
			z.focus();
			return false;
			i = z.value.length;
		}
	}
	
	if ( z.value.indexOf('@') == -1 ){
		alert("\n\n" + errMsg + "\n\n");
		z.focus();
		return false;
	}

	if ( z.value.indexOf('.') == -1 ){
		alert("\n\n" + errMsg + "\n\n");
		z.focus();
		return false;
	}

	return true;
}



/* 
dataType :	0: Any character
			1: Must be a numeric, include integer and float
			2: Must be a letter, not include any 0-9
			3: Include only a-z, A-Z And 0-9
			4: mail format check , a-z, A-Z , 0-9 , @ and _ , - , .
			5: Must be a numeric, include 0-9
*/
function CheckTextValue(inText,minLength,maxLength,dataType,errMsg){
	if((inText.value.length < minLength)||(inText.value.length > maxLength)){
		alert("\n\n" + errMsg + "\n\n");
		inText.focus();
		return false;
	}

	if((dataType == 1) && isNaN(inText.value)){
		alert("\n\n" + errMsg + "\n\n");
		inText.focus();
		return false;
	}

	if(dataType == 2){
		var s;
		var dataString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
		for(var i=0;i<inText.value.length;i++){
			s = inText.value.substring(i,i+1);
			if(dataString.indexOf(s)<0){
				alert("\n\n" + errMsg + "\n\n");
				inText.focus();
				return false;
			}
		}
	}

	if(dataType == 3){
		var s;
		var dataString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
		for(var i=0;i<inText.value.length;i++){
			s = inText.value.substring(i,i+1);
			if(dataString.indexOf(s)<0){
				alert("\n\n" + errMsg + "\n\n");
				inText.focus();
				return false;
			}
		}
	}

	if(dataType == 4){
		var s;
		var dataString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"
		if(inText.value.indexOf("\@")<1){
			alert("\n\n" + errMsg + "\n\n");
			inText.focus();
			return false;
		}else{
			for(var i=0;i<inText.value.length;i++){
				s = inText.value.substring(i,i+1);
				if(dataString.indexOf(s)<0){
					alert("\n\n" + errMsg + "\n\n");
					inText.focus();
					return false;
				}
			}
		}
	}

    if(dataType == 5){
		var s;
		var dataString = "0123456789"
		for(var i=0;i<inText.value.length;i++){
			s = inText.value.substring(i,i+1);
			if(dataString.indexOf(s)<0){
				alert("\n\n" + errMsg + "\n\n");
				inText.focus();
				return false;
			}
		}
	}
	if(dataType == 6){
		var s;
		var dataString = "0123456789";
		var inum = parseInt(inText.value,10);  
		if(inum < 1900 || inum >=2002 ){           
	        alert('抱歉！這不是一個合理的西元年份')           
	        inText.focus();
			inText.select();
	        return false;           
  		 }   
			for(var i=0;i<inText.value.length;i++){
				s = inText.value.substring(i,i+1);
				if(dataString.indexOf(s)<0){
					alert("\n\n" + errMsg + "\n\n");
					inText.focus();
					return false;
				}
			}
		   
	}
	return true;
}

        
function CheckTextValue_1(inText,minLength,maxLength,mustNumeric,mustLetter,errMsg){
	var RE=/[a-zA-Z0-9]{5}/;

	if((inText.value.length < minLength)||(inText.value.length > maxLength)){
		alert("\n\n" + errMsg + "\n\n");
		return false;
	}

	if(!RE.test(inText.value)){
		alert("\n\n" + errMsg + "\n\n");
		return false;
	}
	return true;
}

function CheckRadio(inRadio,errMsg){
	for(var i=0;i<inRadio.length;i++){
		if(inRadio[i].checked){
			return true;
		}
	}
	alert("\n\n" + errMsg + "\n\n");
	return false;
}

function CheckCheckbox(inCheckbox,errMsg){
	for(var i=0;i<inCheckbox.length;i++){
		if(inCheckbox[i].checked){
			return true;
		}
	}
	alert("\n\n" + errMsg + "\n\n");
	return false;
}

function CheckOther(inCheckbox,inOthertext,errMsg){
	for(var i=0;i<inCheckbox.length;i++){
		if(inCheckbox[i].checked){
			if (inCheckbox[i].value == "other")  {
				if (inOthertext.value != "") {
				return true;
				}
				else{
				alert("\n\n" + errMsg + "\n\n");
				inOthertext.focus();
				return false;
				}
			}
		}
	}
	return true;
}



function CheckID(ss,errMsg){

	var c, n, i;
	var t= "ABCDEFGHJKLMNPQRSTUVXYWZIO";
	s = ss.value;

	c= s.substring(0,1);
	c= t.indexOf(c.toUpperCase());
	if((s.length!= 10) || (c<0)){
		alert("\n\n" + errMsg + "\n\n");
		ss.focus();
		return false;
	}

	n= parseInt(c/10)+ c%10*9+ 1;
	for(i=1; i<9; i++) n= n+ parseInt(s.substring(i,i+1))* (9-i);
	n= (10- (n% 10))% 10;
	if(n!= parseInt(s.substring(9,10))){
		alert("\n\n" + errMsg + "\n\n");
		ss.focus();
		return false;
	}

	return true;
}

function CheckProduct(ss,errMsg){
	
	var c, s;
	var t1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var t2 = "012";
	var t3 = "0123456789ABC";
	var t4 = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
	
	s = ss.value;
	
	if (s.length!= 10) {
		alert("\n\n" + errMsg + "\n\n");
		ss.focus();
		return false;
	}

	c = s.substring(0,1);
	c = t1.indexOf(c.toUpperCase());
	if ( c < 0 ) {
		alert("\n\n" + errMsg + "\n\n");
		ss.focus();
		return false;
	}
	
	c = s.substring(1,2);
	c = t1.indexOf(c.toUpperCase());
	if ( c < 0 ) {
		alert("\n\n" + errMsg + "\n\n");
		ss.focus();
		return false;
	}

	c = s.substring(2,3);
	c = t2.indexOf(c.toUpperCase());
	if ( c < 0 ) {
		alert("\n\n" + errMsg + "\n\n");
		ss.focus();
		return false;
	}

	c = s.substring(3,4);
	c = t3.indexOf(c.toUpperCase());
	if ( c < 0 ) {
		alert("\n\n" + errMsg + "\n\n");
		ss.focus();
		return false;
	}

	c = s.substring(4,5);
	c = t4.indexOf(c.toUpperCase());
	if ( c < 0 ) {
		alert("\n\n" + errMsg + "\n\n");
		ss.focus();
		return false;
	}
	return true;
}