// JavaScript Document

//use this function using the onkeypress event (e.g : onkeypress="return numOnly(event, 0)")
function numOnly(evt, mode) { // mode 0-> number only, 1 -> phone no (can enter '-' symbol)
	var charCode = (evt.which) ? evt.which : event.keyCode

// 31 -> backspace, 45 -> '-'
	if(charCode == 31 || charCode == 8 || (mode == 1 && charCode == 45) || (charCode >= 48 && charCode <= 57)) return true
	else {
		alert('Only Number Allow')
		return false
	}
}

//use this function using the onkeypress event
function alphabetOnly(evt) { 
	var charCode = (evt.which) ? evt.which : event.keyCode

	if(charCode >= 48 && charCode <= 57) {
		alert('Only Alphabet Allow')
		return false
	} else return true
}

//allow alphabet and number only
function alphaNumOnly(evt) { 
	var charCode = (evt.which) ? evt.which : event.keyCode

	if((charCode >= 48 && charCode <= 57) || (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122)) return true
	else {
		alert('Only Alphabet And Number Allow')
		return false
	}
}

//return false if wrong format
function verifyEmail(getValue) {
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	
    if(getValue.search(emailRegEx) == -1) return false
	else return true
}

function openWin(url, title, conf) {
	//var winOpen = window.open('orderProduct.php?id=' + id, 'orderProduct', 'toolbar=0, resizable=1, scrollbars=1, width=675, height=400')
	var winOpen = window.open(url, title, conf)
	winOpen.focus()
}

function bookmark(url, sitename) {
	ns = "Netscape and FireFox users, use CTRL+D to bookmark this site."

	if((navigator.appName=='Microsoft Internet Explorer') && (parseInt(navigator.appVersion)>=4)) window.external.AddFavorite(url, sitename);
	else if(navigator.appName=='Netscape') alert(ns);
}
