function openNewWindow(URLtoOpen, windowName, windowFeatures) { 
	str = "factsheet.php?item_id=";
	replaceStr = "";		
	now = new String(URLtoOpen);
	newString = now.replace(str,replaceStr);
	newWindow = window.open(URLtoOpen, windowName+newString, windowFeatures);
}

function swaplanguage(lang) {
	if (lang == "tc") {
		origin = "en"
	} else if (lang == "en"){
		origin = "tc"
	}
	str = "\/" + origin + "\/";
	replaceStr = "\/" + lang + "\/";		
	now = new String(document.URL);
	newString = now.replace(str,replaceStr);
	//alert (str + "\n" + replaceStr + "\n" +  now + "\n" + newString);
	top.location = newString;
}
function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for (i=0; i < e.length ;i++) {
		if (ok.indexOf(e.charAt(i))<0) {
			return (false);
		}
	}
	re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
	re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if (!e.match(re) && e.match(re_two)) {
		return (true);
	} else {
		return (false);
	}
} 

function checkFill(myForm) {
	if (myForm.u_name.value != "") {
		if (check_email(myForm.email.value)) {
			myForm.submit();
		} else {
			alert("Please input a valid email.");
		}
	} else {
		alert("Please input your name.");
	}
}

function checkFill_J(myForm) {
	if (check_email(myForm.email.value)) {
		myForm.submit();
	} else {
		alert("Please input a valid email.");
	}
}

function MM_openBrWindow(theURL, winName, features) { 
	window.open(theURL, winName, features);
}

var checkForm;
function checkExpertForm(myForm) {
	checkForm = myForm;
	
	if (!checkTextValue('date')) {
		alert("Please input the Date !");
		checkForm['firstname'].focus()
		return false;
	}
	if (!checkTextValue('subject')) {
		alert("Please input the Subject of Your Enquiry !");
		checkForm['subject'].focus()
		return false;
	}
	if (!checkTextValue('prefix')) {
		alert("Please input the Salutation !");
		checkForm['prefix'].focus()
		return false;
	}
	if (!checkTextValue('first_name')) {
		alert("Please input the First Name !");
		checkForm['first_name'].focus()
		return false;
	}
	if (!checkTextValue('last_name')) {
		alert("Please input the Last Name !");
		checkForm['last_name'].focus()
		return false;
	}
	if (!checkMail('email')) {
		alert("Please input a vaild E-mail !");
		checkForm['email'].focus()
		return false;
	}
	if (checkForm['email'].value != checkForm['re_email'].value) {
		alert("Please re-type your E-mail !");
		checkForm['re_email'].focus()
		return false;
	}
	if (!checkTextValue('phone')) {
		alert("Please input the Contact Phone Number !");
		checkForm['phone'].focus()
		return false;
	}
	if (!checkRadioValue('prefer_lang')) {
		alert("Please chooose the Preferred Language !");
		checkForm['prefer_lang'].focus()
		return false;
	}
	if (!checkTextValue('brand')) {
		alert("Please chooose the Brand of Notebook !");
		checkForm['phone'].focus()
		return false;
	}
	// if (!checkRadioValue('brand')) {
	// 	alert("Please chooose the Brand of Notebook !");
	// 	checkForm['brand'].focus()
	// 	return false;
	// }
	/*if (!checkTextValue('model_no')) {
		alert("Please input the Model Number !");
		checkForm['model_no'].focus()
		return false;
	}*/
	if (!checkTextValue('question')) {
		alert("Please input the Question / Message !");
		checkForm['question'].focus()
		return false;
	}
	if (!checkCheckValue('agree_ok')) {
		alert("Please agree the Terms of Use and Privacy Policy !");
		checkForm['agree_ok'].focus()
		return false;
	}

	return true;
}

function checkRegisterForm(myForm) {
	checkForm = myForm;
	
	/*if (!checkTextValue('date')) {
		alert("Please input the Date !");
		checkForm['firstname'].focus()
		return false;
	}*/
	/*if (!checkTextValue('subject')) {
		alert("Please input the Subject of Your Enquiry !");
		checkForm['subject'].focus()
		return false;
	}*/
	if (!checkTextValue('prefix')) {
		alert("Please input the Salutation !");
		checkForm['prefix'].focus()
		return false;
	}
	if (!checkTextValue('first_name')) {
		alert("Please input the First Name !");
		checkForm['first_name'].focus()
		return false;
	}
	if (!checkTextValue('last_name')) {
		alert("Please input the Last Name !");
		checkForm['last_name'].focus()
		return false;
	}
	if (!checkMail('email')) {
		alert("Please input a vaild E-mail !");
		checkForm['email'].focus()
		return false;
	}
	if (checkForm['email'].value != checkForm['re_email'].value) {
		alert("Please re-type your E-mail !");
		checkForm['re_email'].focus()
		return false;
	}
	if (!checkTextValue('phone')) {
		alert("Please input the Contact Phone Number !");
		checkForm['phone'].focus()
		return false;
	}
	/*if (!checkRadioValue('prefer_lang')) {
		alert("Please chooose the Preferred Language !");
		checkForm['prefer_lang'].focus()
		return false;
	}
	if (!checkRadioValue('brand')) {
		alert("Please chooose the Brand of Notebook !");
		checkForm['brand'].focus()
		return false;
	}*/
	if (!checkTextValue('model_no')) {
		alert("Please input the Model Number !");
		checkForm['model_no'].focus()
		return false;
	}
	if (!checkTextValue('serial_no')) {
		alert("Please input the Serial Number !");
		checkForm['serial_no'].focus()
		return false;
	}
	/*if (!checkTextValue('question')) {
		alert("Please input the Question / Message !");
		checkForm['question'].focus()
		return false;
	}*/
	if (!checkTextValue('shop_name')) {
		alert("Please input the Name of Dealer / Shop !");
		checkForm['shop_name'].focus()
		return false;
	}
	if (!checkTextValue('shop_country')) {
		alert("Please input the Country where the Dealer / Shop is located !");
		checkForm['shop_country'].focus()
		return false;
	}
	if (!checkTextValue('shop_date')) {
		alert("Please input the Date of Purchase !");
		checkForm['shop_date'].focus()
		return false;
	}
	if (!checkTextValue('invoice_no')) {
		alert("Please input the Invoice Number !");
		checkForm['invoice_no'].focus()
		return false;
	}
	if (!checkCheckValue('agree_ok')) {
		alert("Please agree the Terms of Use and Privacy Policy !");
		checkForm['agree_ok'].focus()
		return false;
	}

	return true;
}

function checkWarRegisterForm(myForm) {
	checkForm = myForm;

	/*if (!checkTextValue('date')) {
		alert("Please input the Date !");
		checkForm['firstname'].focus()
		return false;
	}*/
	/*if (!checkTextValue('subject')) {
		alert("Please input the Subject of Your Enquiry !");
		checkForm['subject'].focus()
		return false;
	}*/
	if (!checkTextValue('prefix')) {
		alert("Please input the Salutation !");
		checkForm['prefix'].focus()
		return false;
	}
	if (!checkTextValue('first_name')) {
		alert("Please input the First Name !");
		checkForm['first_name'].focus()
		return false;
	}
	if (!checkTextValue('last_name')) {
		alert("Please input the Last Name !");
		checkForm['last_name'].focus()
		return false;
	}
	if (!checkMail('email')) {
		alert("Please input a vaild E-mail !");
		checkForm['email'].focus()
		return false;
	}
	if (checkForm['email'].value != checkForm['re_email'].value) {
		alert("Please re-type your E-mail !");
		checkForm['re_email'].focus()
		return false;
	}
	if (!checkTextValue('phone')) {
		alert("Please input the Contact Phone Number !");
		checkForm['phone'].focus()
		return false;
	}
	/*if (!checkRadioValue('prefer_lang')) {
		alert("Please chooose the Preferred Language !");
		checkForm['prefer_lang'].focus()
		return false;
	}
	if (!checkRadioValue('brand')) {
		alert("Please chooose the Brand of Notebook !");
		checkForm['brand'].focus()
		return false;
	}*/
	if (checkForm['product_name'].value == "Please choose from below pulldown.") {
		alert("Please choose the Product Name !");
		checkForm['product_name'].focus()
		return false;
	}
	if (!checkTextValue('model_no')) {
		alert("Please input the Model Number !");
		checkForm['model_no'].focus()
		return false;
	}
	if (!checkTextValue('serial_no')) {
		alert("Please input the Serial Number !");
		checkForm['serial_no'].focus()
		return false;
	}
	/*if (!checkTextValue('question')) {
		alert("Please input the Question / Message !");
		checkForm['question'].focus()
		return false;
	}*/
	if (!checkTextValue('shop_name')) {
		alert("Please input the Name of Dealer / Shop !");
		checkForm['shop_name'].focus()
		return false;
	}
	if (!checkTextValue('shop_country')) {
		alert("Please input the Country where the Dealer / Shop is located !");
		checkForm['shop_country'].focus()
		return false;
	}
	if (!checkTextValue('shop_date')) {
		alert("Please input the Date of Purchase !");
		checkForm['shop_date'].focus()
		return false;
	}
	if (!checkTextValue('invoice_no')) {
		alert("Please input the Invoice Number !");
		checkForm['invoice_no'].focus()
		return false;
	}
	if (!checkCheckValue('agree_ok')) {
		alert("Please agree the Terms of Use and Privacy Policy !");
		checkForm['agree_ok'].focus()
		return false;
	}

	return true;
}

function checkMail(inVar) {
	var x = checkForm[inVar].value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) {
		return true;
	} else {
		return false;
	}
}

function checkRadioValue(inVar) {
	var radio_choice = false;
	for (counter = 0; counter < checkForm[inVar].length; counter++) {
		if (checkForm[inVar][counter].checked) {
			radio_choice = true;
		}
	}
	return radio_choice;
}

function checkSelectValue(inVar, inVar2) {
	if (checkForm[inVar].selectedIndex < inVar2) {
		return false;
	}
	return true;
}

function checkCheckValue(inVar) {
	return checkForm[inVar].checked;
}

function checkTextValue(inVar) {
	if (checkForm[inVar].value == "") {
		return false;
	}
	return true;
}
