// validation functions
function validate_quantities (){
	var qty_sum = document.getElementById('qty_sum').value;
	var sum = 0;
	
	//loop through and add all the different quantities of the different designs (if the text box value is not 0)
	for (i=1;i<=document.getElementById('total_num_design').value ;i++)
	{
		if (document.getElementById('qty_design_'+i).value!="")	
			sum=parseInt(sum)+parseInt(document.getElementById('qty_design_'+i).value);
	}
	//alert ('qty_sum =' +qty_sum); alert ('sum =' +sum);
		
		//if sum is the same as qty sum then success else not success
		if (qty_sum == sum)
				return true;
			else  {
				alert('the total quantity you have entered is not equal to the sum of the individual design quantities you have entered')
				return false;
			}
		}
		
	
				
					
						//CUSTOM ALERT
						
						// constants to define the title of the alert and button text.
						var ALERT_TITLE = "possible error!";
						var ALERT_BUTTON_TEXT = "okay";
						
						// over-ride the alert method only if this a newer browser.
						// Older browser will see standard alerts
						if(document.getElementById) {
						  window.alert = function(txt) {
							createCustomAlert(txt);
						  }
						}
						
						function createCustomAlert(txt) {
						  // shortcut reference to the document object
						  d = document;
						
						  // if the modalContainer object already exists in the DOM, bail out.
						  if(d.getElementById("modalContainer")) return;
						
						  // create the modalContainer div as a child of the BODY element
						  mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
						  mObj.id = "modalContainer";
						   // make sure its as tall as it needs to be to overlay all the content on the page
						  mObj.style.height = document.documentElement.scrollHeight + "px";
						
						  // create the DIV that will be the alert 
						  alertObj = mObj.appendChild(d.createElement("div"));
						  alertObj.id = "alertBox";
						  alertObj.setAttribute("style","z-index: 999");
						  // MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
						  if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
						  // center the alert box
						  alertObj.style.left = 38 + "px";
						  
						  
						
						  // create an H1 element as the title bar
						  h1 = alertObj.appendChild(d.createElement("h1"));
						  h1.appendChild(d.createTextNode(ALERT_TITLE));
						
						  // create a paragraph element to contain the txt argument
						  msg = alertObj.appendChild(d.createElement("p"));
						  msg.innerHTML = txt;
						  
						  // create an anchor element to use as the confirmation button.
						  btn = alertObj.appendChild(d.createElement("a"));
						  btn.id = "closeBtn";
						  btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
						  btn.href = "#";
						  // set up the onclick event to remove the alert when the anchor is clicked
						  btn.onclick = function() { removeCustomAlert();return false; }
						}
						
						// removes the custom alert from the DOM
						function removeCustomAlert() {
						  document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
						}
					
	




//  FIELD ONLY ACCEPTS NUMERIC INPUT
function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }

//  FIELD ONLY ACCEPTS NUMERIC INPUT AND ONE DECIMAL

function getTarget(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}


function numbersonly(e) {
var key;
var keychar;

if (window.event) {
   key = window.event.keyCode;
}
else if (e) {
   key = e.which;
}
else {
   return true;
}
keychar = String.fromCharCode(key);

if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
   return true;
}
else if ((("0123456789").indexOf(keychar) > -1)) {
   return true;
}
else if ( ( (getTarget(e).value.indexOf('.')) == (-1) ) && (keychar == ".") ) { 
  return true;
}
else
   return false;
}

//  END FIELD ONLY ACCEPTS NUMERIC INPUT AND ONE DECIAL

//  FIELD ONLY ACCEPTS NUMERIC INPUT AND ONE HYPHEN
function numbersonlydash(e) {
var key;
var keychar;

if (window.event) {
   key = window.event.keyCode;
}
else if (e) {
   key = e.which;
}
else {
   return true;
}
keychar = String.fromCharCode(key);

if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
   return true;
}
else if ((("0123456789").indexOf(keychar) > -1)) {
   return true;
}
else if ( ( (getTarget(e).value.indexOf('-')) == (-1) ) && (keychar == "-") ) { 
  return true;
}
else
   return false;
}

//  END FIELD ONLY ACCEPTS NUMERIC INPUT AND ONE HYPHEN



//  ENTER KEY TABS TO NEXT BOX IN FORM INSTEAD OF SUBMITTING FORM

function EnterToTab(event,fld,next) {
  keyCode=(event.which)?event.which:event.keyCode;
  if(keyCode==13) {
    if (event.preventDefault) {
      event.preventDefault(); // Mozilla/firefox
      if (next) fld.form.elements[next].focus();
    }
  else event.keyCode=9;
  }
}
 
//this only works on IE, but not on FF
function TestMaxlength(strtxtBox, MaxChr) 
{
var MaxTxt = MaxChr + 1
var strTxt=document.MyForm.elements[strtxtBox].value
if(strTxt.length > MaxChr) {    
                //event.returnValue = false;
                alert(document.MyForm.elements[strtxtBox].name + " is limited to " + MaxTxt + " characters!") 
                MaxTxt = 0     
        }
}


