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=confirmorder222222"
							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=getdetails2&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[6]!='')
		  {
			var cell1 = row.insertCell(1);
			var sel = document.createElement('select');
			sel.name = "linen|"+return_text_array[1];
			sel.id = "linen|"+return_text_array[1];
			var return_text_array1=return_text_array[6].split("<<++>>");
			var i=0;
			for (i=0;i<return_text_array1.length;i++)
			{
				sel.options[i] = new Option(return_text_array1[i], return_text_array[1]+'/'+return_text_array1[i]+'/linen');
			}
					
			 cell1.appendChild(sel);
		  }
		  else
		  {
			// var cell1 = row.insertCell(1);
			 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
		  for(qq=0;qq<=1000;qq++)
			  {
				  sel2.options[qq] = new Option(qq, qq+"/"+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");
			   }
