// Form Validation
function NumberOnly(id) {

	var elm = document.getElementById(id)
	var val = document.getElementById(id).value
	var match = /^(\d|\s|[.])+$/.test(val)
	if (val=="")
		match=1
	if (!match) {
		elm.style.backgroundColor = "#ff0000"
		elm.focus()
		return false
	}
	elm.style.backgroundColor = "#fff"
	return true
}

function ValidEmail(id) {
	var elm = document.getElementById(id)
	var val = document.getElementById(id).value
//	var match = /^\S+\@\w+(\.\w+$)|(\.\w+\.\w+$)/.test(val)
	var match=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i.test(val)
	if (!match)  {
		elm.style.backgroundColor = "#ff0000"
		elm.focus()
		return false	}
		elm.style.backgroundColor = "#fff"
		return true
}

function ValidEmails(id) {
	var elm = document.getElementById(id)
	var val = document.getElementById(id).value
	re = /([0-9a-zA-Z\@\.\-_]*,*)/
	emaillist = val.split(re)
	alert(emaillist.length)
	for(i=0;i<emaillist.length;i++)
	{
		alert (i + '' + emaillist[i]);
		var match=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i.test(emaillist[i])
		if (!match)  {
			elm.style.backgroundColor = "#ff0000"
			alert (emaillist[i]);
			elm.focus()
			return false	}
	}
	elm.style.backgroundColor = "#fff"
	return true
}

function NotEmpty(id) {
	var elm = document.getElementById(id)
	var val = document.getElementById(id).value
	if (val=="") {
		elm.style.backgroundColor = "#ff0000"
		elm.focus()
		return false	}
		elm.style.backgroundColor = "#fff"
		return true
}

function NotSelected(id) {
	var elm = document.getElementById(id)
	var val = document.getElementById(id).value
	if (val=="0") {
		elm.style.backgroundColor = "#ff0000"
		elm.focus()
		return false	}
		elm.style.backgroundColor = "#fff"
		return true
}

function StringOnly(id) {
	var elm = document.getElementById(id)
	var val = document.getElementById(id).value
	var match = /^\w+$/.test(val)
	if (val=="")
	match=1
	if (!match) {
		elm.style.backgroundColor = "#ff0000"
		elm.focus()
		return false		}
		elm.style.backgroundColor = "#fff"
		return true
}

function ValidUsername(id) {
	var elm = document.getElementById(id)
	var val = document.getElementById(id).value
	var match = /^\w{6,10}/.test(val)
	if (!match) {
		elm.style.backgroundColor = "#ff0000"
		elm.focus()
		return false		}
		elm.style.backgroundColor = "#fff"
		return true
}

function ValidPassword(id) {
	var elm = document.getElementById(id)
	var val = document.getElementById(id).value
	var match = /^\w{6,10}/.test(val)
	if (!match) {
		elm.style.backgroundColor = "#ff0000"
		elm.focus()
		return false		}
		elm.style.backgroundColor = "#fff"
		return true
}

function validiate(form_id) {

	var form_id
	switch (form_id)
	{
		case "Contact_Form":
		if (!NotEmpty("CName") || !ValidEmail("Email") || !NotEmpty("Phone") || !NotEmpty("Message"))
		return false
		break

		case "Order_From":
		if (!NotEmpty("CName") || !NotEmpty("CCName") || !ValidEmail("Email") || !NotEmpty("Phone") || !NotEmpty("Message"))
		return false
		break


	} //end switch

	return true

} // end function

