<?php
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
if($_REQUEST['action']=='delete' and $_REQUEST['Id']!='')
{
$del="delete from enquiry where id='".$_REQUEST['Id']."'";
$query=DB_query($del,$db);
$del1="delete from enquiry_details where parentId='".$_REQUEST['Id']."'";
$query1=DB_query($del1,$db);
 $s->pageLocation('index.php?route=enquiry_list&daction=Deleted'.$rurl);	
}
if($_REQUEST['Cancel']!='')
{
	unset($_SESSION['site']);
	unset($_SESSION['enquiryNo']);
	unset($_SESSION['enquiryDate']);
	unset($_SESSION['enquirySrc']);
	unset($_SESSION['enquiryParty']);
	unset($_SESSION['enquiryType']);
	unset($_SESSION['FinalEnquiryArray']);
	unset($_SESSION['partyContact']);
}
$rurl="&modid=".$modid."&frmid=".$frmid;
if(isset($_POST['Update']))
{
$update="update  enquiry set 
							site='".$_REQUEST['site']."',    
							enquiryNo='".$_REQUEST['enquiryNo']."',  
							enquiryDate='".$_REQUEST['enquiryDate']."',  
							enquirySrc='".$_REQUEST['enquirySrc']."',
							enquiryType='".$_REQUEST['enquiryType']."', 
							party='".$_REQUEST['enquiryParty']."',   
							partyContact='".$_REQUEST['partyContact']."',  
							createdDate='".FormatDateForSQL(date('d/m/Y'))."',  
							createdBy='".$_SESSION['UserID']."' where id='".$_REQUEST['Id']."'";
$result1=DB_query($update,$db);

for($j=0;$j<$_REQUEST['count'];$j++)
		{	
			 $insert2="update  enquiry_details set
							itemCode='".$_REQUEST['itemCode'][$j]."',  
							quantity='".$_REQUEST['quantity'][$j]."',   
							price='".$_REQUEST['price'][$j]."',
							pricePer='".$_REQUEST['pricePer'][$j]."',  
							totalValue='".$_REQUEST['totalValue'][$j]."',  
							requisitionDate='".FormatDateForSQL($_REQUEST['requisitionDate'][$j])."',  
							status='".$_REQUEST['status'][$j]."'  where parentId='".$_REQUEST['Id']."'";
		          	$result2=DB_query($insert2,$db);
		}	
		
	$s->pageLocation("index.php?route=enquiry_list&daction=Updated".$rurl);
	}
	
?>
<?php if($_REQUEST['action']==''){?>
<h2 align="center">Enquiry List</h2>
<a href="index.php?route=enquiry_management&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>">Add New</a>
<br><br>
<form action="" method="Post">
<table width="50%" border="0" cellpadding="2" cellspacing="2" align="center">
<tr><td><strong>Branch Wise</strong></td><td><select name="branch_id" style="width:auto">
	<option value="000">Select Branch</option>
    	<?php $site_sql=DB_query("Select loccode, locationname from locations ",$db);
    	while($site_row=DB_fetch_array($site_sql))
		{?>
			<option value="<?php echo $site_row['loccode'];?>"<?php echo($_SESSION['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
		<?php 	
		}
    	?></select></td>
    	<td><strong>Party Wise</strong></td>
    	<td><select name="party_id" style="width: 80%">
    		<option value="000">Select Party</option>
	<?php 
	$vendor_sql=DB_query("select id,client_code,c_name from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($vendor=DB_fetch_array($vendor_sql))
	{
	?>
      <option value="<?php echo $vendor['client_code'];?>"<?php echo ($_REQUEST['party']==$vendor['client_code']?'selected':'')?>><?php echo $vendor['c_name'];?></option>
      <?php } ?>
			</select></td>
    	<td><input type="submit" name="Search" value="Search" /></td>	
</tr></table>	
</form>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<th>Branch</th>
<th>Enquiry No.</th>
<th>Enquiry Date</th>
<th>Enquiry Source</th>
<th>Party</th>
<th>Follow Up</th>
<th>View</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php 
if(isset($_POST['Search']))
{
if($_REQUEST['branch_id']!='000')
{
	
$sql=DB_query("Select * from enquiry where site='".$_REQUEST['branch_id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
}
 if($_REQUEST['party_id']!='000') 
{
$sql=DB_query("Select * from enquiry where party='".$_REQUEST['party_id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);	
}
if($_REQUEST['branch_id']!='000' and $_REQUEST['party_id']!='000')
{
$sql=DB_query("Select * from enquiry where party='".$_REQUEST['party_id']."' and site='".$_REQUEST['branch_id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);	
}
$i=0;
$num=DB_num_rows($sql);

if($num>0)
{
while($myrow=DB_fetch_array($sql))
{
?>
<tr bgcolor="#FFFFFF">
<td><?php echo $myrow['site'];?></td>
<td><?php echo $myrow['enquiryNo'];?></td>
<td><?php echo $myrow['enquiryDate'];?></td>
<td><?php echo $myrow['enquirySrc'];?></td>
<td><?php echo  $unitName=$s->getField('clientmaster','client_code',$myrow['party'],'c_name');
?>	</td>
<td><div align="center"><a href="index.php?route=view_enquiry&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=follow&Id=<?php echo $myrow['id'];?>">Follow</a></div></td>
<td><div align="center"><a href="index.php?route=enquiry_list&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=view&Id=<?php echo $myrow['id'];?>">View</a></div></td>
<td><div align="center"><a href="index.php?route=enquiry_list&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=edit&Id=<?php echo $myrow['id'];?>">Edit</a></div></td>
<td><div align="center"><a href="index.php?route=enquiry_list&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=delete&Id=<?php echo $myrow['id'];?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a></div></td>
</tr>
<?php $i++;}}
else { ?>
	<tr bgcolor="#FFFFFF">
<td colspan="9">No Records Find</td>
</tr>
<?php } }  ?>
	
</table>
<?php }?>
<?php 
if($_REQUEST['Id']!='' && $_REQUEST['action']=='view')
{
	$sql1=DB_query("Select * from enquiry where id='".$_REQUEST['Id']."'",$db);
	$result1=DB_fetch_array($sql1);
	?>
<h2 align="center">View Enquiry</h2>	
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<table width="70%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <th width="19%" scope="row"><strong>Branch</strong></th>
    <td width="31%">
    <select name="site" style="width: 100%">
    	<?php $site_sql=DB_query("Select loccode, locationname from locations where loccode='".$result1['site']."'",$db);
    	while($site_row=DB_fetch_array($site_sql))
		{?>
			<option value="<?php echo $site_row['loccode'];?>"<?php echo($_SESSION['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
		<?php 	
		}
    	?>
    </select></td>
    <th width="25%"><strong>Enquiry No.</strong></th>
    <td width="25%" id="codeId"><input name="enquiryNo" type="text" value="<?php echo $result1['enquiryNo'];?>" size="25" style="width:100%;"/></td>
   </tr>
   <tr>
    <th scope="row"><strong>Date</strong></th>
    <td><input name="enquiryDate" type="text" value="<?php echo $result1['enquiryDate'];?>" size="25"  style="width:100%;" class="datepicker"/></td>
    <th><strong>Enquiry Source</strong></th>
    <td><select name="enquirySrc"  style="width:100%;">  
      <option value="CC"<?php echo ($result1['enquirySrc']=='CC'?'selected':'')?>>Cold Call</option>
      <option value="EC"<?php echo ($result1['enquirySrc']=='EC'?'selected':'')?>>Existing Customer</option>
      <option value="SG"<?php echo ($result1['enquirySrc']=='SG'?'selected':'')?>>Self Generated</option>
      <option value="EMP"<?php echo ($result1['enquirySrc']=='EMP'?'selected':'')?>>Employee</option>
      <option value="PTN"<?php echo ($result1['enquirySrc']=='PTN'?'selected':'')?>>Partner</option>
      <option value="DM"<?php echo ($result1['enquirySrc']=='DM'?'selected':'')?>>Direct Mail</option>
      <option value="WEB"<?php echo ($result1['enquirySrc']=='WEB'?'selected':'')?>>Web Site</option>
      <option value="O"<?php echo ($result1['enquirySrc']=='O'?'selected':'')?>>Other</option>
     </select></td>
   </tr>
   <tr>
    <th scope="row">Party Name</th>
    <td><select name="enquiryParty" style="width:100%;" onchange="partyDetails(this.value)">
      <?php 
      $party=DB_query("Select id,client_code,c_name from clientmaster where client_code='".$result1['party']."'",$db);
	  while($party_row=DB_fetch_array($party))
	  {?>
	  <option value="<?php echo $party_row['client_code'];?>"<?php echo($_SESSION['enquiryParty']==$party_row['client_code']?'selected':'')?>><?php echo $party_row['c_name'];?></option>	
	  <?php 	
	  }
      ?>
    </select></td>
    <th><strong>Type Of Enquiry</strong></th>
    <td><select name="enquiryType" style="width:100%;">
      <option value="M"<?php echo ($result1['enquiryType']=='M'?'selected':'')?>>Material</option>
      <option value="E"<?php echo ($result1['enquiryType']=='E'?'selected':'')?>>Export</option>
      <option value="R"<?php echo ($result1['enquiryType']=='R'?'selected':'')?>>Retail</option>
    </select></td>
  </tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="4">
 <div id="partyId" style="width:100%; margin:0 auto;">
    <table width="70%" cellpadding="2" cellspacing="1" border="0" align="center">
        
<?php 

	$sql222="Select * from clientmaster where client_code='".$result1['party']."'";
	$result222=DB_query($sql222,$db);
	$row222=DB_fetch_array($result222);

	$countryName=$s->getField('country_master','id',$row222['pre_country'],'country');
	$stateName=$s->getField('state_master','id',$row222['pre_state'],'state');
	$cityName=$s->getField('city_master','id',$row222['pre_city'],'city');

?> <tr>
<th width="19%" scope="row" rowspan="3"><strong>Address</strong></th>
<td width="31%"><input name="partyaddress1" type="text" value="<?php echo $row222['pre_address1'];?>" size="25"  style="width:100%;"/></td>
<th width="25%" scope="row"><strong>Contact Person</strong></th>
<td width="25%">
	<select name="partyContact" style="width: 100%" onchange="contactDetails(this.value)">
	<?php 
		
		$contact_sql=DB_query("Select * from contact_information_master where master_code='".$result1['party']."' and id='".$result1['partyContact']."' and master_prefix='C'",$db);
		while ($contact_row=DB_fetch_array($contact_sql)) 
		{?>
			<option value="<?php echo $contact_row['id'];?>"<?php echo ($_SESSION['partyContact']==$contact_row['id']?'selected':'')?>><?php echo $contact_row['person'];?></option>
		<?php 	
		}
	?>
	</select>
</td>
</tr>
    <tr>           
            <td><input name="partyaddress2" type="text" value="<?php echo $row222['pre_address2'];?>" size="25" style="width:100%;" /></td>
            <th scope="row"><strong>Mobile No.</strong></th>
            <?php      
            	$sql="Select phone from contact_information_master where id='".$result1['partyContact']."'";
				$result=DB_query($sql,$db);
				$myrow=DB_fetch_array($result);
            
            ?>
            <td id="contactId"><input name="ContactMobile" type="text" value="<?php echo $myrow['phone'];?>" size="25" style="width:100%;"/></td>
            </tr>
<tr>
<td><input type="text" name="partyaddress3" value="<?php echo $row222['pre_address3'].", ".$countryName.", ".$stateName.", ".$cityName;?>" style="width: 100%"></td>	
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br/>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<th>Item Code</th>
<th>Item Name</th>
<th>Unit</th>
<th>Qty</th>
<th>Price</th>
<th>Per Unit(s)</th>
<th>Value</th>
<th>Date Of Requisition</th>
<th>Status</th>
</tr>
<?php 
$details_sql=DB_query("Select * from enquiry_details where parentId='".$_REQUEST['Id']."'",$db);
	$i=0;
	while($details_row=DB_fetch_array($details_sql))
	{
		$item_sql=DB_query("Select * from item_master where StockID='".$details_row['itemCode']."'",$db);
		$item_row=DB_fetch_array($item_sql);	?>
<tr bgcolor="#FFFFFF">
<td><?php echo $details_row['itemCode'];?></td>
<td><?php echo $item_row['item_name'];?></td>
<td><?php 
$unitName=$s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname');
echo $unitName;?></td>
<td><input type="text" name="quantity[<?php echo $i;?>]" id="quantity_<?php echo $i;?>" value="<?php echo $details_row['quantity'];?>" readonly/></td>
<td><input type="text" name="price[<?php echo $i;?>]" id="price_<?php echo $i;?>" value="<?php echo $details_row['price'];?>" readonly/></td>
<td><input type="text" name="pricePer[<?php echo $i;?>]" id="pricePer_<?php echo $i;?>" value="<?php echo $details_row['pricePer'];?>" readonly/></td>
<td><input type="text" name="totalValue[<?php echo $i;?>]" id="totalValue_<?php echo $i;?>" value="<?php echo $details_row['totalValue'];?>" readonly/></td>
<td><input type="text" name="requisitionDate[<?php echo $i;?>]" id="requisitionDate_<?php echo $i;?>" value="<?php echo $details_row['requisitionDate']?>" readonly/></td>
<td>
<select name="status[<?php echo $i;?>]" style="width: 70px">
<option value="F"<?php echo($details_row['status']=='F'?'selected':'')?>>Forwarding</option>	
<option value="B"<?php echo($details_row['status']=='B'?'selected':'')?>>Block</option>
</select></td>
</tr>
<?php 	
}  ?></table><?php } ?>
<?php
if($_REQUEST['Id']!='' && $_REQUEST['action']=='edit')
{
	$sql1=DB_query("Select * from enquiry where id='".$_REQUEST['Id']."'",$db);
	$result1=DB_fetch_array($sql1);
	?>
<h2 align="center">Edit Enquiry</h2>
<form action="" method="post">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<table width="70%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <th width="19%" scope="row"><strong>Branch</strong></th>
    <td width="31%">
    <select name="site" style="width:100%;" onchange="generateCode(this.value)">
    	<?php $site_sql=DB_query("Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
    	while($site_row=DB_fetch_array($site_sql))
		{
		$kk='';
		if($site_row['loccode']==$result1['site'])
		{
		$kk="selected";	
		}	
			?>
			
			<option value="<?php echo $site_row['loccode'];?>"<?php echo $kk; ?>><?php echo $site_row['locationname'];?></option>
		<?php 	} 	?>
    </select></td>
    <th width="25%"><strong>Enquiry No.</strong></th>
    <td width="25%" id="codeId"><input name="enquiryNo" type="text" value="<?php echo $result1['enquiryNo'];?>" size="25" style="width:100%;"/></td>
  </tr>
  <tr>
    <th scope="row"><strong>Date</strong></th>
    <td><input name="enquiryDate" type="text" value="<?php echo $result1['enquiryDate'];?>" size="25"  style="width:100%;" /></td>
    <th><strong>Enquiry Source</strong></th>
    <td><select name="enquirySrc"  style="width:100%;">  
      <option value="CC"<?php echo ($result1['enquirySrc']=='CC'?'selected':'')?>>Cold Call</option>
      <option value="EC"<?php echo ($result1['enquirySrc']=='EC'?'selected':'')?>>Existing Customer</option>
      <option value="SG"<?php echo ($result1['enquirySrc']=='SG'?'selected':'')?>>Self Generated</option>
      <option value="EMP"<?php echo ($result1['enquirySrc']=='EMP'?'selected':'')?>>Employee</option>
      <option value="PTN"<?php echo ($result1['enquirySrc']=='PTN'?'selected':'')?>>Partner</option>
      <option value="DM"<?php echo ($result1['enquirySrc']=='DM'?'selected':'')?>>Direct Mail</option>
      <option value="WEB"<?php echo ($result1['enquirySrc']=='WEB'?'selected':'')?>>Web Site</option>
      <option value="O"<?php echo ($result1['enquirySrc']=='O'?'selected':'')?>>Other</option>
    </select></td>
  </tr>
  <tr>
    <th scope="row">Party Name</th>
    <td><select name="enquiryParty" style="width:100%;" onchange="partyDetails(this.value)">
      <?php 
      $party=DB_query("Select id,client_code,c_name from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	  while($party_row=DB_fetch_array($party))
	  {
	  $tt='';
	  if($party_row['client_code']==$result['party'])
	  {
	  $tt="selected";
	  }	
	  	?>
	  <option value="<?php echo $party_row['client_code'];?>"<?php echo $tt; ?> ><?php echo $party_row['c_name'];?></option>	
	  <?php 	
	  }
      ?>
     
    </select></td>
    <th><strong>Type Of Enquiry</strong></th>
    <td><select name="enquiryType" style="width:100%;">
      <option value="M"<?php echo ($result1['enquiryType']=='M'?'selected':'')?>>Material</option>
      <option value="E"<?php echo ($result1['enquiryType']=='E'?'selected':'')?>>Export</option>
      <option value="R"<?php echo ($result1['enquiryType']=='R'?'selected':'')?>>Retail</option>
    </select></td>
  </tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="4">
 <div id="partyId" style="width:100%; margin:0 auto;">
    <table width="70%" cellpadding="2" cellspacing="1" border="0" align="center">
        
<?php 

	$sql222="Select * from clientmaster where client_code='".$result1['party']."'";
	$result222=DB_query($sql222,$db);
	$row222=DB_fetch_array($result222);

	$countryName=$s->getField('country_master','id',$row222['pre_country'],'country');
	$stateName=$s->getField('state_master','id',$row222['pre_state'],'state');
	$cityName=$s->getField('city_master','id',$row222['pre_city'],'city');

?> <tr>
<th width="19%" scope="row" rowspan="3"><strong>Address</strong></th>
<td width="31%"><input name="partyaddress1" type="text" value="<?php echo $row222['pre_address1'];?>" size="25"  style="width:100%;"/></td>
<th width="25%" scope="row"><strong>Contact Person</strong></th>
<td width="25%">
	<select name="partyContact" style="width: 100%" onchange="contactDetails(this.value)">
	<?php 
		
		$contact_sql=DB_query("Select * from contact_information_master where master_code='".$result1['party']."' and id='".$result1['partyContact']."' and master_prefix='C'",$db);
		while ($contact_row=DB_fetch_array($contact_sql)) 
		{?>
			<option value="<?php echo $contact_row['id'];?>"<?php echo ($_SESSION['partyContact']==$contact_row['id']?'selected':'')?>><?php echo $contact_row['person'];?></option>
		<?php 	
		}
	?>
	</select>
</td></tr><tr>           
            <td><input name="partyaddress2" type="text" value="<?php echo $row222['pre_address2'];?>" size="25" style="width:100%;" /></td>
            <th scope="row"><strong>Mobile No.</strong></th>
            <?php 
     
            	$sql="Select phone from contact_information_master where id='".$result1['partyContact']."'";
				$result=DB_query($sql,$db);
				$myrow=DB_fetch_array($result);
            
            ?>
            <td id="contactId"><input name="ContactMobile" type="text" value="<?php echo $myrow['phone'];?>" size="25" style="width:100%;"/></td>
            </tr>
<tr>
<td><input type="text" name="partyaddress3" value="<?php echo $row222['pre_address3'].", ".$countryName.", ".$stateName.", ".$cityName;?>" style="width: 100%"></td>	
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br/>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<th>Item Code</th>
<th>Item Name</th>
<th>Unit</th>
<th>Qty</th>
<th>Price</th>
<th>Per Unit(s)</th>
<th>Value</th>
<th>Date Of Requisition</th>
<th>Status</th>
</tr>
<?php 
$details_sql=DB_query("Select * from enquiry_details where parentId='".$_REQUEST['Id']."'",$db);
	$i=0;
	while($details_row=DB_fetch_array($details_sql))
	{
		$item_sql=DB_query("Select * from item_master where StockID='".$details_row['itemCode']."'",$db);
		$item_row=DB_fetch_array($item_sql);	?>
<tr bgcolor="#FFFFFF">
<td><?php echo $details_row['itemCode'];?><input type="hidden" name="itemCode[<?php echo $i;?>]"  value="<?php echo $details_row['itemCode'];?>"></td>
<td><?php echo $item_row['item_name'];?></td>
<td><?php 
$unitName=$s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname');
echo $unitName;?></td>
<td><input type="text" name="quantity[<?php echo $i;?>]" id="quantity_<?php echo $i;?>" value="<?php echo $details_row['quantity'];?>" /></td>
<td><input type="text" name="price[<?php echo $i;?>]" id="price_<?php echo $i;?>" value="<?php echo $details_row['price'];?>" /></td>
<td><input type="text" name="pricePer[<?php echo $i;?>]" id="pricePer_<?php echo $i;?>" value="<?php echo $details_row['pricePer'];?>" /></td>
<td><input type="text" name="totalValue[<?php echo $i;?>]" id="totalValue_<?php echo $i;?>" value="<?php echo $details_row['totalValue'];?>" onfocus="calculateTotal(<?php echo $i;?>)"/></td>
<td><input type="text" name="requisitionDate[<?php echo $i;?>]" id="requisitionDate_<?php echo $i;?>" value="<?php echo $details_row['requisitionDate']?>"/></td>
<td>
<select name="status[<?php echo $i;?>]" style="width: 70px">
<option value="F"<?php echo($details_row['status']=='F'?'selected':'')?>>Forwarding</option>	
<option value="B"<?php echo($details_row['status']=='B'?'selected':'')?>>Block</option>
</select></td>
</tr>
	<?php $i++; } ?>
	<input type="hidden" name="count" value="<?php echo $i;?>" />
</table>
<p align="center"><input type="submit" name="Update" value="Update" /><input type="submit" name="Cancel" value="Cancel"></p>
</form>
<?php } ?>



<script language="JavaScript" type="text/javascript">
function partyDetails(str)
{
	if (str.length==0)
  {
  document.getElementById("partyId").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("partyId").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","showPartyDetails.php?code="+str,true);
xmlhttp.send();
}
function contactDetails(str)
{
	if (str.length==0)
  {
  document.getElementById("contactId").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("contactId").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","showPartyDetails.php?contact="+str,true);
xmlhttp.send();
}
function generateCode(str)
{
	
	if (str.length==0)
  {
  document.getElementById("codeId").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("codeId").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","codeGenerator.php?site="+str,true);
xmlhttp.send();
}
function item_window()
{
	window.open("EnquiryItems.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","item_popup_window","height=500,width=900,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
	
}
function calculateTotal(a)
{
	var qty=document.getElementById("quantity_"+a).value;
	var price=document.getElementById("price_"+a).value;
	var unit=document.getElementById("pricePer_"+a).value;
	
	
	var total=qty*(price/unit);
	document.getElementById("totalValue_"+a).value=total.toFixed(2);
}
</script>