var date = new Date();
var year = date.getFullYear();
var monthnum = date.getMonth();
var daynum = date.getDay();
var day = date.getDate();

var MonthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October","November","December");

var DayArray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");




   function addCart(QTYin,productID)
    {

      if  (!IsNumeric(QTYin)) {
        alert('Please ensure that the quantity is numeric.');
        eval('products.QTY' + productID).focus();
      return false;
      }


    document.getElementById('divQTY' + productID).innerHTML = "Added&nbsp;&nbsp;-&nbsp;&nbsp;<a href='cart.php'>view cart</a>";

    if (QTYin == 0){
     QTYin = 1;
     eval('products.QTY' + productID).value = QTYin;
    }

     //var t=setTimeout("addCart()",1000);
     ajaxAddCartFunction(productID,QTYin)



    //document.getElementById('divQTY' + productID).innerHTML = "<a href=\"#\" onclick=\"Javascript:addCart(document.products.QTY" + productID + ".value,'" + productID + "')\">Add to Cart</a>";


    }



 function ajaxAddCartFunction(productID,QTY){
	var ajaxRequest;  // The variable that makes Ajax possible!

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Please use the site with a recent browser.");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function thisone(){
		if(ajaxRequest.readyState == 4){
              /* if  (ajaxRequest.responseText.trim()!="") {
                alert("The file name is already taken by another page, please choose a different file name.");
               managePage.FILE_NAME.focus();
               document.execCommand('Stop');
               return;
            }  else {
                return true;
            }   */
        }
	}

	ajaxRequest.open("GET", "/addCart.php?i=" + productID + "&q=" + QTY, true);
	ajaxRequest.send(null);





}


function RemoveItem(productID,adminpiece) {
     window.location = "updateCart.php?" + adminpiece + "i=" + productID + "&q=0";
}

 function UpdateItem(productID,quantity,hinge,adminpiece) {
     if  (IsNumeric(quantity)) {
     window.location = "updateCart.php?" + adminpiece + "i=" + productID + "&h=" + hinge + "&q=" + quantity;
     } else {
        alert('Please ensure that the quantity is numeric.');
        eval('dacart.UPDATE_QUANTITY_' + productID).focus();
        return false;

     }
}



function isEmail(elm){
	if(elm.value.indexOf("@") != "-1" && elm.value.indexOf(".") != "-1" && elm.value != " ")
	return true;
	else return false;
}
function isFilled(elm) {
	ssubmittedvalue = elm.value;
	if(ssubmittedvalue == "" || ssubmittedvalue == null)
	   return false;
	   else return true;
}



   // Displays the Credit Card form
    function ShowFullCCForm() {
       ccformtable.style.display = "block";
       chformtable.style.display = "none";

    }

      // Displays the Cheque form
    function ShowFullChequeForm() {
       ccformtable.style.display = "none";
       chformtable.style.display = "block";

    }

    function IsNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
