function MM_openBrWindow(theURL,winName,features)
{ 
  carturl="http://www.teammate.com.hk/enquiry/enquiry_cart.php";
  open_win = window.open(theURL,winName,features);
  open_win.focus();
}


function autosave()
{
  if (!document.enquiry.action.value)
  {
    document.enquiry.action.value='save';
    document.enquiry.submit();
  }
}


function removeid(idvalue)
{
  document.enquiry.action.value='removeid';
  document.enquiry.id.value=idvalue;
  document.enquiry.submit();
}


function emptyall()
{
  document.enquiry.action.value='emptyall';
  document.enquiry.submit();
}


function sendform()
{
  document.enquiry.action.value='send';
  document.enquiry.submit();
}


function confirmform()
{
  document.enquiry.action.value='confirm';
  document.enquiry.submit();
}

function editform()
{
  document.enquiry.action.value='';
  document.enquiry.submit();
}

function submitadditem()
{
  if( document.enquiry.id.value == "" || document.enquiry.id.value=="Product / Model") 
  {
    alert( "Please Input Product Id / Name" );
    return false
  }
  else
  {     
    document.enquiry.action.value='additem';
    document.enquiry.submit();
  }
}

//Check input value==============
function submitregistration() 
{
  var r = new RegExp("[\<|\>|\"|'|\%|\;|\(|\)|\&|\+|\-]", "i");
  var isvalid = true
  if( document.enquiry.Name.value == "" ) 
  {
    document.getElementById('Name_div').style.color = "red";
    isvalid = false;
  }
  else 
  {
    document.getElementById('Name_div').style.color = "";
  }
	
  if( document.enquiry.ContactNo.value == "" ) 
  {
    document.getElementById('ContactNo_div').style.color = "red";
    isvalid = false;
  }
  else 
  {
    document.getElementById('ContactNo_div').style.color = "";
  }

//  if( document.enquiry.MailingAddress.value == "" ) 
//  {
//    document.getElementById('MailingAddress_div').style.color = "red";
//    isvalid = false;
//  }
//  else 
//  {
//    document.getElementById('MailingAddress_div').style.color = "";
//  }

  if( document.enquiry.Email.value == "" ) 
  {
    document.getElementById('email_div').style.color = "red";
    isvalid = false;
  }
  else 
  {
    document.getElementById('email_div').style.color = "";
  }

  if( document.enquiry.DeliveryAddress.value == "" ) 
  {
    if (enquiry.DeliveryOptions[1].checked) 
    {
      document.getElementById('DeliveryAddress_div').style.color = "red";
      isvalid = false;
    }
    else
    {
      document.getElementById('DeliveryAddress_div').style.color = "";
    }
  }
  else 
  {
    document.getElementById('DeliveryAddress_div').style.color = "";
  }

  var radio_choice = false;
  for (counter = 0; counter < enquiry.PaymentOptions.length; counter++) 
  {
    if (enquiry.PaymentOptions[counter].checked)
    radio_choice = true; 
  }
  if( !radio_choice ) 
  {
    document.getElementById('PaymentOptions_div').style.color = "red";
    isvalid = false;
  }
  else 
  {
    document.getElementById('PaymentOptions_div').style.color = "";
  }

  var radio_choice = false;
  for (counter = 0; counter < enquiry.DeliveryOptions.length; counter++) 
  {
    if (enquiry.DeliveryOptions[counter].checked)
    radio_choice = true; 
  }
  if( !radio_choice ) 
  {
    document.getElementById('DeliveryOptions_div').style.color = "red";
    isvalid = false;
  }
  else 
  {
    document.getElementById('DeliveryOptions_div').style.color = "";
  }

//  if( document.enquiry.PreferredDeliveryTime.value == "" ) 
//  {
//    document.getElementById('PreferredDeliveryTime_div').style.color = "red";
//    isvalid = false;
//  }
//  else 
//  {
//    document.getElementById('PreferredDeliveryTime_div').style.color = "";
//  }

  if( document.enquiry.ReceiverName.value == "" ) 
  {
    if (enquiry.DeliveryOptions[1].checked) 
    {
      document.getElementById('ReceiverName_div').style.color = "red";
      isvalid = false;
    }
    else
    {	
      document.getElementById('ReceiverName_div').style.color = "";
    }
  }
  else 
  {
    document.getElementById('ReceiverName_div').style.color = "";
  }

  if( !isvalid) 
  {
    alert("Please make sure the form is complete and valid." );
  }

  if(isvalid && document.getElementById('total_div').innerHTML==0)
  {
    alert( 'Sorry, Your chosen Items is empty.');
    return false;
  }

  if(isvalid && !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.enquiry.Email.value))) 
  {
    alert( 'Please enter a valid e-mail address.');
    return false;
  }

  if (isvalid)
  {
    document.enquiry.action.value='send';
    document.enquiry.submit();
  }
}

function add2cart(pid)
{
  carturl="../enquiry/enquiry_cart.php?action=additem&id="+pid
  uelite_cart_win = window.open(carturl,"enquiry",'scrollbars=yes,width=900,height=700');
  uelite_cart_win.focus();
}

function opencart()
{
  carturl="../enquiry/enquiry_cart.php";
  uelite_cart_win = window.open(carturl,"enquiry",'scrollbars=yes,width=900,height=700');
  uelite_cart_win.focus();
}

function choicecard(pid)
{
  document.cookie="#"+pid+"#"
  carturl="../enquiry/card_select.htm"
  uelite_cart_win = window.open(carturl,"choicecard_win",'modal=yes, scrollbars=yes,width=1000,height=750');
  uelite_cart_win.focus();
}

function viewproduct(theURL)
{
  open_win = window.open(theURL,'PGpop','scrollbars=yes,width=470,height=690');
  open_win.focus();
}

function sub(inputtext)
{
  document.getElementById(inputtext).innerHTML=parseInt(document.getElementById(inputtext).innerHTML)-1
  if (document.getElementById(inputtext).innerHTML<=0)
  {
    document.getElementById(inputtext).innerHTML=1
  }
  if (document.getElementById(inputtext).innerHTML==0)
  {
    document.getElementById(inputtext).innerHTML=1
  }
  form.elements[inputtext].value=parseInt(document.getElementById(inputtext).innerHTML)
  calc('test2')
}

function add(inputtext)
{
  form = document.forms['enquiry'];
  document.getElementById(inputtext).innerHTML=parseInt(document.getElementById(inputtext).innerHTML)+1
  form.elements[inputtext].value=parseInt(document.getElementById(inputtext).innerHTML)
  calc('test2')
}

function checkBoxValidate(cb)
{
  form = document.forms['enquiry'];
  for (j = 0; j < form.elements(cb.name).length; j++)
  {
    e=form.elements(cb.name)[j];
    if (eval("e.checked") == true)
    {
      e.checked = false;
      if (e.value == cb.value)
      {
        e.checked = true;
      }
    }
  }
}
