<?php
error_reporting(0);
?>

<script type="text/javascript">
function checkval(){
	var idsite = document.getElementById("site").value;
	var idstore = document.getElementById("store1").value;
	var fromdate = document.getElementById("frmdate").value;
	var todate = document.getElementById("todate").value;
	if(idsite=='0'){
		alert("Select Site Name First.");
		return false;
	}
	if(idstore==''){
		alert("Select Store Name First.");
		return false;
	}
	if(fromdate=='' || todate=='')
	{
		alert("Select From - To date.");
		return false;
	}
	return true;
}
</script>
<link href="css/purchses.css" rel="stylesheet" type="text/css" />
<h3 style="font-size:18px;">Stock Summary</h3>
<form method="post" action="">

<table width="90%" border="0" cellspacing="0" cellpadding="3" style="border-collapse:collapse">
	<tr>
    	<td>Site<span style="color:#FF0000">*</span></td>
        <td>
			<select name="site" id="site" onchange="showsitename160(this.value)">
                <option value="0">Select Site</option>
                <?php 
				if($_SESSION['AssignedSites']!='0'){ 
					$site_sql = "SELECT loccode, locationname from locations ";
				}else{
					$site_sql = "SELECT loccode, locationname from locations";
				}
				$site_result = DB_query($site_sql,$db);
				while($site_row = DB_fetch_array($site_result))
				{
					$p='';
					if($site_row['loccode'] == $_POST['site'])	
					$p="selected";
				?>
                <option value="<?php echo $site_row['loccode']; ?>" <?php echo $p;?>><?php echo $site_row['locationname']; ?></option>
                <?php } ?>
        	</select>
		</td>
        <td>Store<span style="color:#FF0000">*</span></td>
        <td>
			<div id="storedata7">
            	<select name="store1" id="store1">
                <?php 
	 			$store_sql = "SELECT id, StoreName,storecode FROM storetype where Store_Site = '".$_REQUEST['site']."'";
	 			$store_result = DB_query($store_sql,$db);
	 			while($store_row = DB_fetch_array($store_result))
				{
					$p='';
					if($store_row['id'] == $_REQUEST['store1'])
						$p="selected";
	 			?>
                <option value="<?php echo $store_row['id'] ?>"<?php echo $p; ?>><?php echo $store_row['storecode']?></option>
                <?php } ?>
                </select>
          	</div>
		</td>
		<td>Enter Part Name Of Item</td>
		<td>
			<input type="text" name="itemName" value="" onkeyup="showItems(this.value)"   style="width:100%" /><br /><br />
		</td>
	</tr>
	<tr>
        <td>Date from :</td>
        <td><input type="text" name="from_date" value="<?php echo $_REQUEST['from_date'];?>" id="frmdate" class="datepicker"></td>
        <td>Date to : </td>
        <td><input type="text" name="to_date" value="<?php echo $_POST['to_date'];?>" id="todate" class="datepicker"></td>
		<td colspan="2">
			<strong>Select Item</strong><br />
			<div id="itemid">
                <div style="overflow:auto; height:100px; width:auto; border:1px solid;" >
                  <?php 
				  	$itemFilterSql = "select distinct item_master.id,item_master.StockID,item_master.item_name
					from item_master
					inner join opening_stockitemwise on opening_stockitemwise.mstid = item_master.id";
					$itemFilterWhere = array();
					if($_REQUEST['site']!='' && $_REQUEST['site']!='0')
						$itemFilterWhere[] = "opening_stockitemwise.site = '".$_REQUEST['site']."'";
					if($_REQUEST['store1']!='')
						$itemFilterWhere[] = "opening_stockitemwise.store = '".intval($_REQUEST['store1'])."'";
					$itemFilterWhere[] = "opening_stockitemwise.stock > 0";
					if(count($itemFilterWhere)>0)
						$itemFilterSql .= " where ".implode(" and ",$itemFilterWhere);
					$itemFilterSql .= " order by item_master.item_name";
					$item_sql=DB_query($itemFilterSql,$db);
					$c3=0;
					while($row3=DB_fetch_array($item_sql))
					{ 
						$c='';
						if($_REQUEST['item'][$c3]==$row3['id'])
							{$c="checked";}
					?>
                  <input type="checkbox" name="item[<?php echo $c3;?>]" id="item_<?php echo $c3;?>" value="<?php echo $row3['id'];?>" <?php echo $c;?>/>
                  <?php echo $row3['StockID']." - ".$row3['item_name'];?><br />
                  <?php 
		
					$c3++;
					}
					if($_REQUEST['view'] && $_REQUEST['item']){
						$itemString[]=$_REQUEST['item'];
						$a=implode(",", $_REQUEST['item']); 
					}	 
		
				?>
                </div>
              </div>
		</td>
    </tr>
</table>
		 
      
	    <p align="center">
          <input type="submit" name="view" value="View" onclick="return checkval()">
          
        </p>
		
</form>
<?php  if($_REQUEST['view']!=''){?>
<p align="right"><a href="stock_summary_print.php?site=<?php echo $_REQUEST['site'];?>&store_code=<?php echo $_REQUEST['store1']?>&fromdate=<?php echo $_REQUEST['from_date']?>&todate=<?php echo $_REQUEST['to_date']?>" target="_blank"><input type="button" name="print" value="Print" ></a></p>


<?php } ?>

  <?php
     if(isset($_POST['view']))
       {
	 	   
					$from_date=$_REQUEST['from_date'];
					$to_date=$_REQUEST['to_date'];	
					$from_date_brk=explode('/',$from_date);
					$from=$from_date_brk[2]."-".$from_date_brk[1]."-".$from_date_brk[0];
				
					$to_date_brk=explode('/',$to_date);
					$to=$to_date_brk[2]."-".$to_date_brk[1]."-".$to_date_brk[0];
				
					$site=$_REQUEST['site'];
					$store=$_REQUEST['store1'];
					$item=$_REQUEST['item'];					
					if($item!=''){
					$item_string=implode("','",$item); }
					$function_filter[]=$site;
					$function_filter[]=$store;	
					$function_filter[]=$from;
					$function_filter[]=$to;
					
	           $SiteName12=$s->GetFieldValue('locations',"loccode='".$_REQUEST['site']."'",'locationname'); 
			   $StoreName12=$s->GetFieldValue('storetype',"id='".$_REQUEST['store1']."'",'StoreName');   
	
	function privious_opening($function_filter,$item)
	{
	global $db;
	 $receive=array();
	 $issueqty=array();	
	 $site=$function_filter[0];
	 $store=$function_filter[1];
	 $fdate1= strtotime(date("Y-m-d", strtotime($function_filter[2])) . " -1 day");
	 $fdate= date("Y-m-d",$fdate1);
	/**************************************  MRN *********************************************/
	
	
	
	$sqlmrn=DB_query("select sum(reciveqty) as reciveqty from addmrnqty 
	inner join addmrn on addmrn.id=addmrnqty.issue_id  where site='".$site."'
	 and StoreCode='".$store."' and MRNDate <='".$fdate."' 
	 and mst_itemid in ('".$item."')",$db);	
	while($addmrn=DB_fetch_array($sqlmrn))
	{
	$receive[]=$addmrn['reciveqty'];
	}		   
	/**************************************  Issue *********************************************/
     
	$sqlissue=DB_query("SELECT sum(issueqty) AS issueqty FROM 
                        issueqty INNER JOIN addissue ON addissue.id=issueqty.issue_id where site='".$site."' and
						mst_storeid='".$store."' 
						and issuedate <='".$fdate."' and mst_itemid in ('".$item."') ",$db);	
	while($addissue=DB_fetch_array($sqlissue))
	{
	$issueqty[]=$addissue['issueqty'];
	}			
	/**************************************  Receive *********************************************/
	$sqlreceive=DB_query("SELECT sum(receiveqty) AS reciveqty
	                    FROM  material_return_details INNER JOIN material_return 
				        ON material_return.id=material_return_details.parentId where site='".$site."' and
						store='".$store."' and returndate <='".$fdate."'  
						and mst_itemid in ('".$item."')",$db);
	while($addreceive=DB_fetch_array($sqlreceive))
	{
	$receive[]=$addreceive['reciveqty'];
	}	
	/**************************************  site to site *********************************************/
	$sqlsite_site=DB_query("SELECT sum(issueqty) AS issueqty
	                     FROM  transfer_issue_details INNER JOIN transfer_issue 
				        ON transfer_issue.id=transfer_issue_details.transfer_issue_id where sitecode='".$site."' and
						fromstore='".$store."' and issuedate <= '".$fdate."'  
						and mst_itemid in ('".$item."')",$db);
	while($addsitetosite=DB_fetch_array($sqlsite_site))
	{
	$issueqty[]=$addsitetosite['issueqty'];
	}
	/**************************************  site to site receive *********************************************/
	$sqlsite_site1=DB_query("SELECT sum(reciveqty) AS reciveqty
	                      FROM  transfer_receipt_details INNER JOIN transfer_receipt 
				        ON transfer_receipt.id=transfer_receipt_details.transfer_receipt_id
						 where sitecode='".$site."' and
						store='".$store."' and MRNDate <= '".$fdate."' 
						and mst_itemid in ('".$item."')",$db);
	while($addsitetositereceive=DB_fetch_array($sqlsite_site1))
	{
	$receive[]=$addsitetositereceive['reciveqty'];
	}
	/**************************************  Material Return *********************************************/
	$sqlsite_site1=DB_query("SELECT sum(ReturnQty) AS issueqty
	                    FROM  inv_material_return_details INNER JOIN inv_material_return 
				        ON inv_material_return.id=inv_material_return_details.parentId where sitecode='".$site."' and
						storecode='".$store."' and Reqdate <= '".$fdate."'
						and mst_itemid in ('".$item."')",$db);
	while($addmrtov=DB_fetch_array($sqlsite_site1))
	{
	$issueqty[]=$addmrtov['issueqty'];
	}	
	/*******************************************  Opening ******************************************************/
	
	
	$sqlopen=DB_query("select reveive_date as date,mstid as itemid,stock as reciveqty
	from opening_stockitemwise  where site='".$site."'
	 and store='".$store."' and reveive_date <='".$function_filter[2]."' 
	  and mstid in ('".$item."')",$db);
	while($addopen=DB_fetch_array($sqlopen))
	{
	$receive[]=$addopen['reciveqty'];	
	}
	$receive=array_sum($receive);
	$issued=array_sum($issueqty);
	$receive1=str_replace(",","",$receive);
	$issued1=str_replace(",","",$issued);
	 $total=$receive1-$issued1;
	$qty=$total;	   
	return $qty;   
	}
	
	
	                function openingBalance($function_filter,$item)
							   {
								global $db;
								$site=$function_filter[0];
								$store=$function_filter[1];
								$from=$function_filter[2];								
								if($site!='')
								$filter[]="site = '".$site."'";
								if($store!='')
								$filter[]="store = '".$store."'";
								if($from!='--' && $to!='--')
								$filter[]="reveive_date <= '".$from."'";
								if($item!='')
								$filter[]="mstid = '".$item."'";
								
								$filter=implode(' and ',$filter);
								$sql1="Select stock, rate from opening_stockitemwise where $filter";
							
								$result1=DB_query($sql1,$db);
								$myrow1=DB_fetch_array($result1);
								return $myrow1['stock'];
							}
                     
                    function receivedMRN($function_filter,$item)
						{
							global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
					        $to=$function_filter[3];
							
							if($site!='')
							$filter[]="addmrn.site = '".$site."'";
							if($store!='')
							$filter[]="addmrn.StoreCode = '".$store."'";
							if($from!='--' && $to!='--')
					        $filter[]="addmrn.MRNDate between '".$from."' and '".$to."'";
							if($item!='')
							$filter[]="addmrnqty.mst_itemid = '".$item."'";
							
							$filter=implode(' and ',$filter);
						     	$sql1="Select SUM(addmrnqty.reciveqty) from addmrn left join addmrnqty 
							       on(addmrn.id=addmrnqty.issue_id) where Cancel_Status='N' and $filter";
								 
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(addmrnqty.reciveqty)'];
						}
						

							////1. Issue Slip/////
                       function issueSlip($function_filter,$item)
							{
								global $db;
								$site=$function_filter[0];
								$store=$function_filter[1];
								$from=$function_filter[2];
								 $to=$function_filter[3];
								if($site!='')
								$filter[]="addissue.site = '".$site."'";
								if($store!='')
								$filter[]="addissue.mst_storeid = '".$store."'";
								if($item!='')
								$filter[]="issueqty.mst_itemid = '".$item."'";
								if($from!='--' && $to!='--')
					          $filter[]="addissue.issuedate between '".$from."' and '".$to."'";
								
								$filter=implode(' and ',$filter);
							
							    	$sql1="Select SUM(issueqty.issueqty) from addissue left join 
								 issueqty on(addissue.id=issueqty.issue_id) where $filter";
								
								$result1=DB_query($sql1,$db);
								$myrow1=DB_fetch_array($result1);
								
								return $myrow1['SUM(issueqty.issueqty)'];
							}

				function receivedReturn($function_filter,$item)
				{
					global $db;
					$site=$function_filter[0];
					$store=$function_filter[1];
					$from=$function_filter[2];
					$to=$function_filter[3];
					
					if($site!='')
					$filter[]="material_return.site = '".$site."'";
					if($store!='')
					$filter[]="material_return.store = '".$store."'";
					if($from!='--' && $to!='--')
					$filter[]="material_return.returndate between '".$from."' and '".$to."'";
					if($item!='')
					$filter[]="material_return_details.mst_itemid = '".$item."'";
					
					$filter=implode(' and ',$filter);
					  $sql1="Select SUM(material_return_details.receiveqty)
					   from material_return left join material_return_details   
					   on(material_return.id=material_return_details.parentId) where $filter";
				 
					
					$result1=DB_query($sql1,$db);
					$myrow1=DB_fetch_array($result1);
					return $myrow1['SUM(material_return_details.receiveqty)'];
				}



				function receivedSiteToSite($function_filter,$item)
				{
					global $db;
					$site=$function_filter[0];
					$store=$function_filter[1];
					$from=$function_filter[2];
					$to=$function_filter[3];
					
					if($site!='')
					$filter[]="transfer_receipt.sitecode = '".$site."'";
					if($store!='')
					$filter[]="transfer_receipt.store = '".$store."'";
					if($from!='--' && $to!='--')
					$filter[]="transfer_receipt.MRNDate between '".$from."' and '".$to."'";
					if($item!='')
					$filter[]="transfer_receipt_details.mst_itemid = '".$item."'";
					
					$filter=implode(' and ',$filter);
					
					 $sql1="Select SUM(transfer_receipt_details.reciveqty) 
					 from transfer_receipt left join transfer_receipt_details 
					 on(transfer_receipt.id=transfer_receipt_details.transfer_receipt_id) where $filter";
					$result1=DB_query($sql1,$db);
					$myrow1=DB_fetch_array($result1);
					return $myrow1['SUM(transfer_receipt_details.reciveqty)'];
				}

						function issueSiteToSite($function_filter,$item)
						{
							global $db;
						 
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[3];
							
							if($site!='')
							$filter[]="transfer_issue.sitecode = '".$site."'";
							if($store!='')
							$filter[]="transfer_issue.fromstore = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="transfer_issue.issuedate between '".$from."' and '".$to."'";
							if($item!='')
							$filter[]="transfer_issue_details.mst_itemid = '".$item."'";
							
							$filter=implode(' and ',$filter);
								 $sql1="Select SUM(transfer_issue_details.issueqty)  
								 from transfer_issue left join transfer_issue_details 
								 on(transfer_issue.id=transfer_issue_details.transfer_issue_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							$return_array=$myrow1['SUM(transfer_issue_details.issueqty)'];
							//$avg_rate=$myrow1['SUM(transfer_issue_details.rate)'];
							//$return_array[]=$avg_rate;
							return $return_array;
							
						}

					function issueMatarialReturn($function_filter,$item)
					{
						global $db;
						$site=$function_filter[0];
						$store=$function_filter[1];
						$from=$function_filter[2];
						$to=$function_filter[3];
						
						if($site!='')
						$filter[]="inv_material_return.sitecode = '".$site."'";
						if($store!='')
						$filter[]="inv_material_return.storecode = '".$store."'";
						if($from!='--' && $to!='--')
						$filter[]="inv_material_return.Reqdate between '".$from."' and '".$to."'";
						if($item!='')
						$filter[]="inv_material_return_details.mst_itemid = '".$item."'";
						
						$filter=implode(' and ',$filter);
						
					    $sql1="Select SUM(inv_material_return_details.ReturnQty) 
					    from inv_material_return left join inv_material_return_details  
					    on(inv_material_return.id=inv_material_return_details.parentId) where $filter";
						$result1=DB_query($sql1,$db);
						$myrow1=DB_fetch_array($result1);
						return $myrow1['SUM(inv_material_return_details.ReturnQty)'];
					}


if($_REQUEST['site']!='0' && $_REQUEST['store1']!='' && $_REQUEST['from_date']!='' && $_REQUEST['to_date']!='') 
{
	 $massege="Showing Record For Site ".$SiteName12." And Store ".$StoreName12." From ".$_REQUEST['from_date']." To ".$_REQUEST['to_date']."";
}
//elseif($_REQUEST['site']!='0' && $_REQUEST['store1']!='' && $_REQUEST['from_date']!='' && $_REQUEST['to_date']!='' && $_REQUEST['itemName']=='' && $_REQUEST['item']!='')
//{
//	echo "Man";
//}
$_SESSION['mess']=$massege;
?>
<div>

  <table width="100%" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse;">
    <tr>
    <th rowspan="2">Item Name</th>
	<th rowspan="2">UOM</th>
    <th><center>Opening Balance</center></th>
    <th><center>Received</center></th>
    <th><center>Issued</center></th>
    <th>Closing Balance</th>
	
  </tr>
  <tr>
    <td >
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th><center>QTY.</center></th>
   <!--<th><center>Rate</center></th>
    <th><center>Value</center></th>-->
  </tr>
</table>	</td>
    <td>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th><center>QTY.</center></th>
  <!--<th><center>Rate</center></th>
    <th><center>Value</center></th>-->
  </tr>
</table>	</td>
    <td >
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th><center>QTY.</center></th>
   <!--<th><center>Rate</center></th>
    <th><center>Value</center></th>-->
  </tr>
</table></td>
   <td>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th><center>QTY.</center></th>
   <!-- <th><center>Rate</center></th>
    <th><center>Value</center></th>-->
  </tr>
</table></td>
  </tr>
  <?php
  if($item!='')
  {
  $sql1="select * from item_master where id in('".$item_string."')";
  }
  else
  {
  $sql1="select distinct item_master.* from item_master
  inner join opening_stockitemwise on opening_stockitemwise.mstid = item_master.id
  where opening_stockitemwise.site = '".$site."'
  and opening_stockitemwise.store = '".$store."'
  and opening_stockitemwise.stock > 0";
  }
  $sql=DB_query($sql1,$db);
   $_SESSION['sql1']=$sql1;
  while($row1=DB_fetch_array($sql))
  {
 
        $privious_open=privious_opening($function_filter,$row1['id']); 
     // $op=openingBalance($function_filter,$row1['id']);
	   $in_1=receivedMRN($function_filter,$row1['id']);
	  $out_1=issueSlip($function_filter,$row1['id']);
	  $out_2=issueSiteToSite($function_filter,$row1['id']);	
	  $in_2=receivedSiteToSite($function_filter,$row1['id']);
	  $out_3=issueMatarialReturn($function_filter,$row1['id']);
	  $in_3=receivedReturn($function_filter,$row1['id']);	
	  
	 
     $opening_stock=number_format($privious_open,5);
	 $opening_stock;
     $received=number_format(($in_1+$in_2+$in_3),5);
     $issueded=number_format(($out_1+$out_2+$out_3),5);
 
    $invalue=($privious_open+$in_1+$in_2+$in_3);
    $invalue1=number_format($invalue,5);
	$invalue2=str_replace(",","",$invalue1);
    $outvalue=($out_1+$out_2+$out_3);
	
	$outvalue1=number_format($outvalue,5);
	$outvalue2=str_replace(",","",$outvalue1);
    
    $closingQty = round((float)$invalue - (float)$outvalue,5);
	if($closingQty<=0){
		continue;
	}
    $tot=number_format($closingQty,5);
  ?>
   

    <tr>
  <td style="padding-left:5px; padding-top:5px; padding-bottom:5px;" ><font size="2"><strong><?php echo $s->getField('item_master','id',$row1['id'],'item_name');?></strong></font></td>
  <td style="padding-left:5px; padding-top:5px; padding-bottom:5px;" ><font size="2"><strong><?php $unit_id=$s->getField('item_master','id',$row1['id'],'unit'); echo $s->getField('unitsofmeasure','unitid',$unit_id,'unitname');?></strong></font></td>
    <td>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  	<tr>
    <td><center><?php if($opening_stock=='') { echo "0"; } else {	echo $opening_stock; }?></center></td>
   <!-- <th><center><?php //if($opening_rate=='') { echo "0"; } else {  echo $opening_rate;}?></center></th>
    <th><center><?php //if($opening_value=='') { echo "0"; } else { echo $opening_value;}?></center></th>-->
  </tr>
 
</table>	</td>
    <td>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
    <td><center><?php if($received=='') { echo "0"; } else {	echo $received; }?></center></td>
   <!--<th><center><?php // if($inrate=='') { echo "0"; } else {  echo $inrate;}?></center></th>
    <th><center><?php //if($inwards_qtydata['total']=='') { echo "0"; } else { echo $inwards_qtydata['total'];}?></center></th>-->
  </tr>
 
</table>	</td>
    <td>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><center><?php if($issueded=='') { echo "0"; } else {	echo $issueded; }?></center></td>
  <!-- <th><center><?php //if( $outrate=='') { echo "0"; } else {  echo  $outrate;}?></center></th>
    <th><center><?php //if($outwards_qtydata['totalout']=='') { echo "0"; } else { echo $outwards_qtydata['totalout'];}?></center></th>-->
  </tr>
</table></td>
   <td>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		 <tr>
    <td><center><?php if($tot=='') { echo "0"; } else {	echo $tot; }?></center></td>
  <!-- <th><center><?php //if($closeqty['closing_rate']=='') { echo "0"; } else {  echo $closeqty['closing_rate'];}?></center></th>
    <th><center><?php //if($closeqty['closing_value']=='') { echo "0"; } else { echo $closeqty['closing_value'];} ?></center></th>-->
  </tr>
   
</table></td>

  </tr>

    
    <?php } ?>
    
    
  </table>
  </div>


 

  <?php } 
?>






<script type="text/javascript">
function showItems(str)
{
    if(str=="")
  {
  document.getElementById("itemid").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("itemid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","Get_itemcode.php?partName="+str,true);
xmlhttp.send();
}
function showsitename160(str)
{

var xmlhttp;
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)
    {
	var data=xmlhttp.responseText.split("__");	
	document.getElementById("storedata7").innerHTML=data[0];
	  }
  }
  xmlhttp.open("GET","get_sitenamedata3.php?site="+str,true);
	xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

	
}
</script>
