function IsEmpty(aTextField) 

{

   if ((aTextField.value.length==0) ||

   (aTextField.value==null)) {

      return true;

   }

   else { return false; }

}

 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;
   }
 function IsNumeric_quantity(strString)

   //  check for valid numeric strings	

   {

   var strValidChars = '-,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,.,:,;,",<,>,?,/,~,`,!,@,#,$,%,^,&,*,(,),_,+,=,{,},[,],\,|';

   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;

   }
   //==============================================  

function isValidEmail(str) 

{

   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

 

}

//==================================================================

function IsEmpty(aTextField) {

   if ((aTextField.value.length==0) ||

   (aTextField.value==null)) {

      return true;

   }

   else { return false; }

}



 //============================================================

function isValidDate(dateStr) 

{

// Checks for the following valid date formats:

// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY

// Also separates date into month, day, and year variables



var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;



// To require a 4 digit year entry, use this line instead:

// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;



var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {

alert("Date is not in a valid format.")

return false;

}

month = matchArray[1]; // parse date into variables

day = matchArray[3];

year = matchArray[4];

if (month < 1 || month > 12) { // check month range

alert("Month must be between 1 and 12.");

return false;

}

if (day < 1 || day > 31) {

alert("Day must be between 1 and 31.");

return false;

}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {

alert("Month "+month+" doesn't have 31 days!")

return false

}

if (month == 2) { // check for february 29th

var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));

if (day>29 || (day==29 && !isleap)) {

alert("February " + year + " doesn't have " + day + " days!");

return false;

   }

}

return true;  // date is valid

}

//============================================
function GetXmlHttpObject()

{ 

	var objXMLHttp=null

	if (window.XMLHttpRequest)

	{

	objXMLHttp=new XMLHttpRequest()

	}

	else if (window.ActiveXObject)

	{

	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")

	}

	return objXMLHttp

} 

//============================================

function show_image(image_name)

{

		product_id="asd"
		//alert (image_name);
		
		xmlHttp=GetXmlHttpObject()

		if (xmlHttp==null)

		{

			alert ("Browser does not support HTTP Request")

			return false;

		} 

		document.getElementById("show_image_tag").innerHTML="<span class='style1'>Retrieving Image..</span>"

		var url="modify.php?mode=getimage&product_id="+product_id+"&image_name="+image_name

		xmlHttp.onreadystatechange=stateChanged		

		xmlHttp.open("GET",url,true)

		xmlHttp.send(null)

		//return false;
		
	

}

function stateChanged() 

{ 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

	{ 

		document.getElementById("show_image_tag").innerHTML=xmlHttp.responseText

	} 

}

/////////////////////////
function formatCurrency(num) 
			{
				num = num.toString().replace(/\$|\,/g,'');
				if(isNaN(num))
				num = "0";
				sign = (num == (num = Math.abs(num)));
				num = Math.floor(num*100+0.50000000001);
				cents = num%100;
				num = Math.floor(num/100).toString();
				if(cents<10)
				cents = "0" + cents;
				for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
				num = num.substring(0,num.length-(4*i+3))+
				num.substring(num.length-(4*i+3));
				return ( num + '.' + cents);
			}
			
			
/////////////////////////////

 			function place_order()
			   {
			   		all_total1=document.getElementById("all_total").innerHTML
					if(all_total1=="$0.00")
					{
						alert ("Please Plan Your Order before Submitting");	
						return false;		
					}
					else
					{
						name1=document.getElementById('name1')//c_position
						address=document.getElementById('address')//c_position				
						phone=document.getElementById('phone')	
						email=document.getElementById('email')	
						event_type=document.getElementById('event_type')	
						date_of_event=document.getElementById('date_of_event')	
						if(name1.value=="")					
						{				
							alert("Please enter Name");				
							name1.focus();				
							return false;				
						}				
						else if(address.value=="")					
						{
							alert("Please enter Address");				
							address.focus();				
							return false;	
						}
						else if(IsNumeric(phone.value)==false)					
						{
							alert("Please enter Valid Phone");				
							phone.focus();				
							return false;	
						}
						else if(isValidEmail(email.value)==false)					
						{
							alert("Please enter valid Email");				
							email.focus();				
							return false;	
						}
						else if(event_type.value=="")					
						{
							alert("Please enter Event Type");				
							event_type.focus();				
							return false;	
						}
						else if(date_of_event.value=="")					
						{
							alert("Please enter Valid date");				
							date_of_event.focus();				
							return false;	
						}
						else
						{					
							//alert("Thank you! A confirmation mail has been sent your mail.\nOur representative will contact you within 24 hours to discuss your plans");
							document.form1.action = "modify.php?mode=confirmorder"
							window.document.form1.submit()
						}
					}
			   }
			   
  //////////////////////////////////////////////////////
function addRowToTable(aa)
{
  /////////////////////////////////////////
 product_id=document.getElementById("prod"+aa)
 product_id_value=product_id.value
 if(product_id_value!="")
 {
	existing_shown_product_ids=document.getElementById("shown_product_ids");
	//alert (existing_shown_product_ids.value)
	if(existing_shown_product_ids.value.search(product_id_value)<0)
	{
		//alert (existing_shown_product_ids.value)
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request")
			return false;
		} 
		var url="modify.php?mode=getdetails&product_id="+product_id_value
		xmlHttp.onreadystatechange=stateChanged2
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
 
 }
  ////////////////////////////////////////////
  
}
function stateChanged2() 

{ 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

	{ 
		//tblSample category_id+|+product_id+|+product_name+|+price+|+func2
		return_text=xmlHttp.responseText
		//alert(return_text)
		var return_text_array=return_text.split("+|+");
		product_price="$"+formatCurrency(return_text_array[3])
		existing_shown_product_ids=document.getElementById("shown_product_ids");
		//alert (existing_shown_product_ids.value)
		if(existing_shown_product_ids.value=="1")
		{
			existing_shown_product_ids.value=return_text_array[1]
		}
		else
		{
			existing_shown_product_ids.value=existing_shown_product_ids.value+"/"+return_text_array[1]
		}
		var tbl = document.getElementById(return_text_array[0]);
		  var lastRow = tbl.rows.length;
		  // if there's no header row in the table, then iteration = lastRow + 1
		  var iteration = lastRow;
		  var row = tbl.insertRow(lastRow);
		  
		  // left cell
		  var cell0 = row.insertCell(0);
		  var textNode0 = document.createTextNode(return_text_array[2]);
		  cell0.appendChild(textNode0);
		  
		 ////////////////////////////////////////////////////////////////
		  var cell1 = row.insertCell(1);
		 if(return_text_array[5]==400952)
		  {
			var sel = document.createElement('select');
			sel.name = "linen|"+return_text_array[1];
			sel.id = "linen|"+return_text_array[1];
				  if(return_text_array[6]==3658537)
				  {				  
					 sel.options[0] = new Option('---Pintuck---', 'Pintuck');
					 sel.options[1] = new Option('-Apple', return_text_array[1]+'/Pintuck-Apple/linen');
					 sel.options[2] = new Option('-Bronze', return_text_array[1]+'/Pintuck-Bronze/linen');
					 sel.options[3] = new Option('-Burgundy', return_text_array[1]+'/Pintuck-Burgundy/linen');
					 sel.options[4] = new Option('-Burnt Orange', return_text_array[1]+'/Pintuck-Burnt Orange/linen');
					 sel.options[5] = new Option('-Copper', return_text_array[1]+'/Pintuck-Copper/linen');
					 sel.options[6] = new Option('-Fire Orange', return_text_array[1]+'/Pintuck-Fire Orange/linen');
					 sel.options[7] = new Option('-Fuchsia', return_text_array[1]+'/Pintuck-Fuchsia/linen');
					 sel.options[8] = new Option('-Gold Turquiose', return_text_array[1]+'/Pintuck-Gold Turquiose/linen');
					 sel.options[9] = new Option('-Gold Navy', return_text_array[1]+'/Pintuck-Gold Navy/linen');
					 sel.options[10] = new Option('-Hot Pink', return_text_array[1]+'/Pintuck-Hot Pink/linen');
					 sel.options[11] = new Option('-Lime Purple', return_text_array[1]+'/Pintuck-Lime Purple/linen');
					 sel.options[12] = new Option('-Moss Pintuck', return_text_array[1]+'/Pintuck-Moss Pintuck/linen');
					 sel.options[13] = new Option('-Paradise Pintuck', return_text_array[1]+'/Pintuck-Paradise Pintuck/linen');
					 sel.options[14] = new Option('-Red Jade', return_text_array[1]+'/Pintuck-Red Jade/linen');
				  }
				  else if(return_text_array[6]==2547220)
				  {
					 sel.options[0] = new Option('----Organza----', 'Organza');
					 sel.options[1] = new Option('-Celadon Organza', return_text_array[1]+'/Organza-Celadon Organza/linen');				 
					 sel.options[2] = new Option('-Dusty Rose Organza Sash', return_text_array[1]+'/Organza-Dusty Rose Organza Sash/linen');
					 sel.options[3] = new Option('-Gold Organza', return_text_array[1]+'/Organza-Gold Organza/linen');
				  }
			 /////////////////////////////////////////////////
				 else
				 {
					 sel.options[0] = new Option('----Color----', 'Color');
					 sel.options[1] = new Option('-Amethyst', return_text_array[1]+'/Color-Amethyst/linen');
					 sel.options[2] = new Option('-Baby Blue', return_text_array[1]+'/Color-Baby Blue/linen');
					 sel.options[3] = new Option('-Black', return_text_array[1]+'/Color-Black/linen');
					 sel.options[4] = new Option('-Bubble Gum', return_text_array[1]+'/Color-Bubble Gum/linen');
					 sel.options[5] = new Option('-Burgundy', return_text_array[1]+'/Color-Burgundy/linen');
					 sel.options[6] = new Option('-Buttercup', return_text_array[1]+'/Color-Buttercup/linen');
					 sel.options[7] = new Option('-Canary', return_text_array[1]+'/Color-Canary/linen');				 
					 sel.options[8] = new Option('-Checker', return_text_array[1]+'/Color-Checker/linen');
					 sel.options[9] = new Option('-Chocolate', return_text_array[1]+'/Color-Chocolate/linen');
					 sel.options[10] = new Option('-Copper', return_text_array[1]+'/Color-Copper/linen');
					 sel.options[11] = new Option('-Diane Gold', return_text_array[1]+'/Color-Diane Gold/linen');
					 sel.options[12] = new Option('-Dusty Rose', return_text_array[1]+'/Color-Dusty Rose/linen');				
					 sel.options[13] = new Option('-Hunter Green', return_text_array[1]+'/Color-Hunter Green/linen');
					 sel.options[14] = new Option('-Grey', return_text_array[1]+'/Color-Grey/linen');
					 sel.options[15] = new Option('-Hot Pink', return_text_array[1]+'/Color-Hot Pink/linen');
					 sel.options[16] = new Option('-Kelly Green', return_text_array[1]+'/Color-Kelly Green/linen');
					 sel.options[17] = new Option('-Light blue', return_text_array[1]+'/Color-Light blue/linen');
					 sel.options[18] = new Option('-Magenta', return_text_array[1]+'/Color-Magenta/linen');
					 sel.options[19] = new Option('-Mint', return_text_array[1]+'/Color-Mint/linen');
					 sel.options[20] = new Option('-Olive', return_text_array[1]+'/Color-Olive/linen');
					 sel.options[21] = new Option('-Navy', return_text_array[1]+'/Color-Navy/linen');
					 sel.options[22] = new Option('-Orange', return_text_array[1]+'/Color-Orange/linen');
					 sel.options[23] = new Option('-Red', return_text_array[1]+'/Color-Red/linen');
					 sel.options[24] = new Option('-Regal Purple', return_text_array[1]+'/Color-Regal Purple/linen');
					 sel.options[25] = new Option('-Regal Teal', return_text_array[1]+'/Color-Regal Teal/linen');
					 sel.options[26] = new Option('-Royal Blue', return_text_array[1]+'/Color-Royal Blue/linen');
					 sel.options[27] = new Option('-Shrimp', return_text_array[1]+'/Color-Shrimp/linen');
					 sel.options[28] = new Option('-Turquoise', return_text_array[1]+'/Color-Turquoise/linen');						 
			  	}
			 cell1.appendChild(sel);
		  }
		  else
		  {
			  var textNode1 = document.createTextNode('');
		  		cell1.appendChild(textNode1);	
		  }
		 ////////////////////////////////////////////////////////////////////
		  var cell2 = row.insertCell(2);
		   var sel2 = document.createElement('select');
		  sel2.name = "qua"+return_text_array[1];
		  sel2.id = "qua"+return_text_array[1];
		  sel2.onchange = keyPressTest;
		  ww=0//427965
		 if(return_text_array[5]==400952 || return_text_array[5]==3399574 || return_text_array[5]==79924 || return_text_array[5]==7055358 || return_text_array[5]==3146860 || return_text_array[5]==6165347 || return_text_array[5]==427965)
		  {
			  for(qq=0;qq<=25;qq++)
			  {
				  sel2.options[qq] = new Option(qq, qq+"/"+return_text_array[1]+"/"+product_price+"/quantity");	
				  //ww=ww+25			
			  }	
		  }
		  else
		  {
			  for(qq=0;qq<=20;qq++)
			  {
				  sel2.options[qq] = new Option(ww, ww+"/"+return_text_array[1]+"/"+product_price+"/quantity");	
				  ww=ww+25			
			  }
		  }
		 cell2.appendChild(sel2);
		  /////////////////////////////////////
		  var cell3 = row.insertCell(3);
		  var textNode3 = document.createTextNode(product_price);
		  cell3.appendChild(textNode3);		  
		  var cell4 = row.insertCell(4);
		  cell4.id=return_text_array[1];
		 var textNode4 = document.createTextNode("$0.00");
		  cell4.appendChild(textNode4);
		 
	} 

}
///////////////////////////////////

//////////////////////////////////////
function open_win(url_add)
{
	window.open(url_add,"welcome","width=600,height=300,status=yes,menubar=no,location=yes,scrollbars=yes");
}
////////////////////////////////////////////
function removeRowFromTable(b)
{
  var tbl = document.getElementById(b);
  var lastRow = tbl.rows.length;
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}
function openInNewWindow(frm)
{
  // open a blank window
  var aWindow = window.open('', 'TableAddRowNewWindow',
   'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');
   
  // set the target to the blank window
  frm.target = 'TableAddRowNewWindow';
  
  // submit
  frm.submit();
}
function validateRow(frm)
{
  var chkb = document.getElementById('chkValidate');
  if (chkb.checked) {
    var tbl = document.getElementById('tblSample');
    var lastRow = tbl.rows.length - 1;
    var i;
    for (i=1; i<=lastRow; i++) {
      var aRow = document.getElementById('txtRow' + i);
      if (aRow.value.length <= 0) {
        alert('Row ' + i + ' is empty');
        return;
      }
    }
  }
  openInNewWindow(frm);
}
  //////////////////////////////////////////////////////////
  function open_win23(url_add)
			   {
			   window.open(url_add,"welcome","width=600,height=400,resizable=yes");
			   }