//to check the charactors in search price
function printSelection(image,code,desc,price){
  var content="<img alt='products/"+image+"' title='products/"+image+"' src='products/"+image+"'><br>"; 
   content+="<div id='lbCaption'>Code:"+code+"<br/>Decription:"+desc+"<br/>Price:"+price+"</div>";
  var pwin=window.open('','print_content','width=600,height=700,scrollbars=1');

  pwin.document.open();
  pwin.document.write('<html><body onload="window.print()">'+content+'</body></html>');
  pwin.document.close();
 
  setTimeout(function(){pwin.close();},15000);

} 

function valsearch()
{
 	 var frm=document.advform;
	 var checkStr=frm.price1.value;
	 var checkStr1=frm.price2.value;
		ch1= checkStr1;
	  var checkOK = "/\\\'!@#$%^&*()<>;,.=+|\"" ;
 	     ch= checkStr;
		for (j = 0;  j < checkOK.length;  j++)
 		{
			if (ch==checkOK.charAt(j))
 			{
            alert("This field cannot have any of these characters: / \\ \' \" ! @ # $ % ^ & * ( )  < > ; , . = + | ");
			frm.price1.focus();
			return false;
			}
			if (ch1==checkOK.charAt(j))
 			{
            alert("This field cannot have any of these characters: / \\ \' \" ! @ # $ % ^ & * ( )  < > ; , . = + | ");
			frm.price2.focus();
			return false;
			}
		 } // for j
		 
			frm.action="product_search.php";
			frm.submit();
		
		
	
 } //end CheckChar

//This validation for register page

function validregister()
{
 		var frm = document.frmregister;
		if(!isValidEntry(frm.firstname, " Name"))
			return false;
		if(!isValidAlphabet(frm.firstname,'Name','yes'))
            return false;
		if(!isValidEntry(frm.lastname, " Last Name"))
			return false;
		if(!isValidAlphabet(frm.lastname,'Name','yes'))
            return false;
		if(!isValidEntry(frm.address, "Address"))
			return false;
		if(!isValidEntry(frm.city, "City"))
			return false;
		if(!isValidZipcode(frm.zip,'yes'))
	        return false;
		if(!isValidEmail(frm.email,'yes'))
		    return false;
		if(!isValidPhone(frm.dayphone,'Phone Number','yes'))
		    return false;
		if(!isValidSelect(frm.contacttime,'Contact Time'))
           return false;
		
		frm.kw.value='ADDBILL';
}

//checking the validation for search bar

function check_cat()
{
   var frm=document.searchform;
   if(frm.product.value=="--Keyword--")
   {
   alert("Enter a keyword to search");
   frm.product.focus();
   return false;
   }
  if(!isValidEntry(frm.product, "Keyword"))
	return false;
 if(!isValidAlphabet(frm.product,'Keyword','yes'))
     return false; 
  if(frm.searchit.value=="")
  {
    alert("Please select the option");
	frm.searchit.focus();
	return false;
  }
 
  if(frm.searchit.value=="products")
  {
    frm.action="cart_index.php";
	frm.submit();
  }
 
  if(frm.searchit.value=="service")
  {
    prod=frm.product.value;
	cat=frm.category.value;
	srch=frm.searchit.value;
    frm.action="services2.php?product="+prod+'& category='+cat+'& searchit='+srch;
	frm.submit();
  }
}

//to add the cart items 
function addtocart(pid,price,frmval)
{   
	var frm = frmval;
	frm.fileid.value=pid;
	frm.priceval.value=price;
	frm.action="addtocart.php";
	frm.submit();
}


function validate1()

	{

		var frm=document.frmcart;

		var id=0;

		flag="No"
		

		if(document.frmcart.chk)

		{
			i=document.frmcart.chk.length
			if (i>1)
			{
				for(i1=0;i1<i;i1++)
				{
					if(document.frmcart.chk[i1].checked)
					{	
						flag="yes";

						id = id+","+document.frmcart.chk[i1].value;

					}

				}

			}

			else

			{
				if(document.frmcart.chk.checked)

				{
					flag="yes";

					id = id+","+document.frmcart.chk.value;

				}

			}

		}

		if (flag=="yes")

		{
			document.frmcart.ids.value = id
			document.frmcart.action='viewcart.php';
			document.frmcart.hidval.value="del";
			document.frmcart.submit();
		}
		else
		{
			alert("Please Select an Item to Delete");
			return false;
		}
	}
	//Cart Page Functions Start

function funempty()

{

	if(confirm("Are you sure to empty the cart?"))
	{
	var frm=document.frmcart;
	frm.hidval.value="empty";
	frm.action='viewcart.php';
	frm.submit();
	}

}

function validatesearch()
{
	var frm=document.frmleft;
	frm.action="viewsearchproducts.php";
	frm.submit();
}
function viewitemimage(id,act,sid)
	{
	URL = act+"?id="+id;
	var newWin = window.open(URL,'myChild',"height=600,width=600,menubar=no,resizable=no, scrollbars=no")
	newWin.focus()
	}
	function validateApptmnt()
	{
		var frm = document.apptmnt;
		//alert(parseInt(frm.fhour.value));
		if(!isValidEntry(frm.cust_name, "Name"))
			return false;	
		if(!isValidPhone(frm.cust_phno,'Phone Number','yes'))
		    return false;
		if(!isValidEmail(frm.email,'yes'))
		    return false;
		if(!isValidEntry(frm.cust_addr, "Address"))
			return false;	
		
		if(!isValidSelect(frm.service_req,'Category'))
            return false;
		if(frm.sub_service.value==0)
		{
			alert("Please Select Service");
			frm.sub_service.focus();
            return false;
		}
		if(!isValidEntry(frm.appt_desc, "Specifications"))
			return false;	
			var date=frm.date.value;
			var temp_date = new Array();
			temp_date = date.split('-');
		var dtDiff=dateDiff(temp_date[0], temp_date[1], temp_date[2], '');	
		//alert(dtDiff);
		if(dtDiff<=0)
		{
			alert('Please Select Valid Date.');
			return false;
		}
		if(!isValidSelect(frm.fhour,' Start Time'))
            return false;
		if(!isValidSelect(frm.thour,'End Time'))
            return false;
		if(frm.fhour.value>=frm.thour.value)
		{
			alert('Please Select Valid Period!');
			return false;
		}
		//frm.submit();
 }
		function doCancel()
	{	
		document.Form1.kw.value='CANCELORDER';
		document.Form1.action='nocartdetails.php';
		document.Form1.submit();
	}
	//validate confirm billing address
	function validcheck()
	{
		var frm = document.checkoutfrm;
		if(!isValidEntry(frm.name, " Name"))
			return false;
		if(!isValidAlphabet(frm.name,'Name','yes'))
            return false;
		if(!isValidEntry(frm.lastname, " Last Name"))
			return false;
		if(!isValidAlphabet(frm.lastname,'Name','yes'))
            return false;
		if(!isValidPhone(frm.phone,'Phone Number','yes'))
		    return false;
		if(!isValidEmail(frm.email,'yes'))
		    return false;
		if(!isValidEntry(frm.company, "Company"))
			return false;
		if(!isValidEntry(frm.address, "Address"))
			return false;	
		if(!isValidEntry(frm.city, "City"))
			return false;
		if(!isValidAlphabet(frm.city,'Name','yes'))
            return false;
		if(!isValidSelect(frm.state,'State'))
            return false;
		if(!isValidZipcode(frm.zip,'yes'))
	        return false;
		frm.kw.value='ADDBILL';
		
	}
		// character counting
	function textCounter(field,maxlimit) 
	{
		if (field.value.length > maxlimit)
		{ 
		field.value = field.value.substring(0, maxlimit);
		alert("Characters should not be greater than 250")
		}
	
	}
	//date comparision validation
		function dateDiff(strMonth, strDay, strYear, strTime)
	{
		if(strTime=='')
			strTime='00:00:00 AM';
		var dtNow=new Date();
		dtNow.a
		var dtToCompare = new Date(strMonth+'/'+strDay+'/'+strYear+' '+strTime)    
		var milliSecDiff=dtToCompare-dtNow;	
			
		var dateDiff = Math.round(milliSecDiff/(1000*60*60*24)+1);
		//alert(dateDiff);
		return dateDiff;
	}
	
	//to check the charactors in posting articles

function CheckChar (item)
{
 	// make sure there's not anything in checkOK
 	  var checkStr = item.value;
 	  var checkOK = "/\\\'!@#$%^&*()<>;,.=+|\"" ;
 	  var allValid = false;
 	  for (i = 0;  i < checkStr.length;  i++)
 	  {
 		ch = checkStr.charAt(i);
 		for (j = 0;  j < checkOK.length;  j++)
 		{
 			if (ch == checkOK.charAt(j))
 			{
            alert("This field cannot have any of these characters: / \\ \' \" ! @ # $ % ^ & * ( )  < > ; , . = + | ");
			item.value="";
			item.focus();
			return false
			}
 		} // for j
	} // for i
 } //end CheckChar
 
 
 //to clear the search text

function clr_txt(fld)
{
	if(fld.value=="--Keyword--")
	{
		fld.value="";
	}
	else if(IsEmpty(fld.value))
	{
		fld.value="--Keyword--";
	}

	return true;
}
function IsEmpty(s) {
  return ((s == null) || (s.length == 0));
}
//Fixed phone number validation

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);

}

function check()
{

var frm=document.form1;

		if(!isValidEntry(frm.name, "Your Name"))
			return false;
		if(!isValidAlphabet(frm.name,'First Name','yes'))
            return false;
		 if(!isValidEmail(frm.email,'yes'))
	 		return false;
		if ((frm.mobileph.value==null)||(frm.mobileph.value=="")){
		alert("Please Enter your Mobile Number")
		frm.mobileph.focus()
		return false;
		}
		if (checkInternationalPhone(frm.mobileph.value)==false){
		alert("Please Enter a Valid Mobile Number")
		frm.mobileph.value="";
		frm.mobileph.focus();
		return false;
		}
		
		if ((frm.officeph.value==null)||(frm.officeph.value=="")){
		alert("Please Enter your Office Phone Number")
		frm.officeph.focus()
		return false;
		}
		if (checkInternationalPhone(frm.officeph.value)==false){
		alert("Please Enter a Valid Office Phone Number")
		frm.officeph.value=""
		frm.officeph.focus()
		return false;
		}
		if(!isValidEntry(frm.city, "City"))
			return false;
		if(!isValidAlphabet(frm.city,'City','yes'))
            return false;
		if(!isValidZipcode(frm.zip,'yes'))
	 	    return false;
		if(!isValidEntry(frm.Organization, "Your Organization or Company"))
			return false;
		
		
		flag="No";
		var c_value=0;
		for (var i=0; i < frm.option.length; i++)
		   {
		   if (frm.option[i].checked)
			  {
			  flag="yes";
			  c_value = c_value+","+ frm.option[i].value;
			  
			  }
			  
		   }
	
  if (flag=="yes")
		{
			frm.option2.value =c_value;
			frm.action = "service_quote.php";
		}

}

//category onchange

function listboxItemSelected(oList1,oList2)

{  
 	id="";
 
	if (oList2!=null){

	clearComboOrList(oList2);

	if (oList1.selectedIndex == -1){

	oList2.options[oList2.options.length] = new Option('Please make a selection from the list', '');

	} else {

	//alert(oList1.name + '=' + oList1.options[oList1.selectedIndex].value)

	fillListbox(oList2, oList1.name + '=' + oList1.options[oList1.selectedIndex].value);

	//alert(getvalue(oList1,k));

	}

	}

}

	

function clearComboOrList(oList)

{

	for (var i = oList.options.length - 1; i >= 0; i--)

	{

		oList.options[i] = null;

	}

	oList.selectedIndex = -1;

	if (oList.onchange)	

		oList.onchange();

}

	

function fillListbox(oList, vValue)

{

	if (vValue != '') {

	if (assocArray[vValue]){

	var arrX = assocArray[vValue];

	for (var i = 0; i < arrX.length; i = i + 2){

	if (arrX[i] != 'EOF') 

	{

			s1=arrX[i + 1];

		oList.options[oList.options.length] = new Option(s1.replace("&#39","'"), arrX[i]);

	}

	}

	//alert (oList.options.length)

	if (oList.options.length == 1){

	//oList.selectedIndex=0;

	if (oList.onchange)	oList.onchange();

	}

	} else {

			

			oList.options[0] = new Option('', '');

	}

	}

}
//popup window for images view
function popup(id,act)
	{
		
	URL = act+"?id="+id;
	var newWin = window.open(URL,'myChild',"height=407,width=413,menubar=no,resizable=no, scrollbars=no")
	newWin.focus()
	}
function validateTest()
{
	var frm=document.frmtestimonial;
		frm.kw.value='ADD_TESTIMONIAL';
		if(!isValidAlphabet(frm.fname, "First Name",'yes'))
			return false;
		if(!isValidAlphabet(frm.lname,'Last Name','yes'))
            return false;
		 if(!isValidEmail(frm.email,'yes'))
	 		return false;
		if(!isValidPhone(frm.phone, "Phone",'yes'))
			return false;
		if(!isValidEntry(frm.comp,'Company Name'))
            return false;
		if(!isValidEntry(frm.desc,'Testimonial'))
            return false;
		for (var i=0; i<frm.rate.length; i++) {
		if (frm.rate[i].checked == true) {
		break;
		} 
		else {
			alert("Please Select rate");
			return false;
		}
		}
}

