//
// Validate compulsory radio button set
//
function checkRadio(obj) {
  var rtnStr = "";

  for (var i=0; i<obj.length; i++)
    if (obj[i].checked)
      rtnStr = obj[i].value;

  if (rtnStr.length > 0)
    return true;
  else
    return false;
}

function cvtUpperCase(textObj) {
  if (textObj != null) textObj.value = textObj.value.toUpperCase();
}

function cvtLowerCase(textObj) {
  if (textObj != null) textObj.value = textObj.value.toLowerCase();
}

//
// check numeric value
//
function isNumeric(sText) {
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;

  for (i = 0; i < sText.length && IsNumber == true; i++) {
    Char = sText.charAt(i);
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }
  return IsNumber;
}

//
// check numeric value
//
function isAtoZ(sText) {
  var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  var IsNumber=true;
  var Char;

  for (i = 0; i < sText.length && IsNumber == true; i++) {
    Char = sText.charAt(i);
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }
  return IsNumber;
}

//
// check HK tel number
//
function isHKTel(sNumber) {
  var validPrefix = "236789";
  var firstDigit = sNumber.substring(0,1);
  if (sNumber.length < 8)
    return false;

  if (validPrefix.indexOf(firstDigit) > -1)
    return true;
  else
    return false;
}

//
// check HK mobile number
//
function isHKMobile(sNumber) {
  var validPrefix = "689";
  var firstDigit = sNumber.substring(0,1);
  if (sNumber.length < 8)
    return false;

  if (validPrefix.indexOf(firstDigit) > -1)
    return true;
  else
    return false;
}

//
// Validate number of selected checkbox options see if it
// exceed the max allowance
//
function cbxValidate(cbx, maxChoices) {
  var i;
  var choice = 0;
  for (i=0; i<cbx.length; i++) {
    if (cbx[i].checked) choice++;
    if (choice > maxChoices) return false;
  }
  return true;
}

function win(imgname,imgname2){ 
win2=window.open("","","width=400,height=443,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0") 
if (win2){
win2.focus()
win2.document.open()
win2.document.write("<head><title>Yiu Wing Polybags Fty</title></head>")
win2.document.write("<BODY BGCOLOR='#ffffff' LEFTMARGIN='0' TOPMARGIN='0' MARGINWIDTH='0' MARGINHEIGHT='0'>") 
win2.document.write("<TABLE BORDER='0' CELLSPACING='0' CELLPADDING='0' WIDTH='400'><tr bgcolor='#999999'><td><font size=4 color='#FFFFFF'><span style='margin:5px 0px 10px 5px'>"+imgname2+"</span></font></td></tr><TR><TD VALIGN='top'>") 
win2.document.write("<IMG SRC="+'"'+imgname+'"'+" WIDTH='400' HEIGHT='400' BORDER='0'></TD></TR>") 
win2.document.write("<TR><TD VALIGN='top' ALIGN='right' BGCOLOR='#999999'><A HREF='javascript:top.window.close()'><IMG SRC='images/btn_close.gif' WIDTH='72' HEIGHT='20' BORDER='0' ALT='CLOSE'></A></TD></TR></TABLE>")
win2.document.write("</BODY>")
win2.document.close()
}
else
alert("Failed in spawning a new window!")
}