<?php
if($_REQUEST['DeleteId'] && $_REQUEST['flag']!='')
{
if($_REQUEST['flag']=='APO'){
/****************************DELETE FROM PURCHASEORDER Ammendment TABLE ******************/
	$slq_del=DB_query("delete from purchorderdetails_ammd where orderno='".$_REQUEST['DeleteId']."'",$db);
	$sql_del1=DB_query("delete from purchorders_ammd where orderno='".$_REQUEST['DeleteId']."'",$db);
}
elseif($_REQUEST['flag']=='PO'){
/****************************DELETE FROM PURCHASEORDER  TABLE ******************/
	$slq_del=DB_query("delete from purchorderdetails where orderno='".$_REQUEST['DeleteId']."'",$db);
	$sql_del1=DB_query("delete from purchorders where orderno='".$_REQUEST['DeleteId']."'",$db);
}
}


if($_REQUEST['CencelId'] && $_REQUEST['flag']!='')
{
if($_REQUEST['flag']=='PO'){
/****************************UPDATE STATUS IN PURCHASEORDER  TABLE ******************/
	$cencl=DB_query("update purchorders set po_ammendment_status='0', Po_recive_status='Cancel' where orderno='".$_REQUEST['CencelId']."'",$db); }
elseif($_REQUEST['flag']=='APO'){
	/****************************UPDATE STATUS IN PURCHASEORDER_AMMD  TABLE ******************/
	$cencl=DB_query("update purchorders_ammd set  Po_recive_status='Cancel' where orderno='".$_REQUEST['CencelId']."'",$db); }
}

if($_REQUEST['requiDetIds'])
{ 
    if($_REQUEST['flag']=='false')
    {
        $mainreqIDS=explode(',', $_REQUEST['ReqiAIdnot']);
    for($i=0;$i<count($mainreqIDS);$i++)
	{
    
    $startYr = explode('-', $_SESSION['financialYrStart']);
	$endYr = explode('-', $_SESSION['financialYrEnd']);
	$startYr[0];
	$endYr[0];
	$financial=substr($startYr[0],-2)."-".substr($endYr[0],-2); 
        //$prefixcode='RFQ';
	$prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$_REQUEST['frmid']."' and module_id='".$_REQUEST['modid']."' ",$db);
	$prefix_row=DB_fetch_array($prefix_sql);
	$prefixcode=$prefix_row['prefix_code'];
        $branch=$_REQUEST['site'];
        
          $sql="select mapNo from indentpr_mapping where CompanyId='".$_SESSION['ACGCompanyId']."' and site='".$_REQUEST['site']."' and INSTR(`mapNo`, '$financial') > 0 order by id DESC LIMIT 0,1";
        $result = DB_query($sql,$db);
        $myrow=DB_fetch_array($result);
        $numrows = DB_num_rows($result);
        //echo $myrow['mapNo'];
		if($numrows>0)
		{
			//$myrow=DB_Fetch_array($result);
			$ExplBill=explode("/",$myrow['mapNo']);
			$maxval = $ExplBill[3];
			
		}
		else
		{$maxval=0;}
         $strChar=$branch."/".$financial."/".$prefixcode."/";
         $strFinal = $maxval+1;    
         $strBothFinal = $strChar.str_pad($strFinal,5,"0",STR_PAD_LEFT); 
        
         $postingDate1=explode("/",$_REQUEST['postingDate']);
         $postingDate=$postingDate1['2']."-".$postingDate1['1']."-".$postingDate1['0'];

         $openingDate1=explode("/",$_REQUEST['openingDate']);
         $openingDate=$openingDate1['2']."-".$openingDate1['1']."-".$openingDate1['0'];

         
           $itemsss= $_REQUEST['ItemID'][$i];
           $mapqty=$_REQUEST['mappedQty'][$i]; 
            $mainReqid=$_REQUEST['ReqiAId'][$i]; 
        $data['mapNo']=$strBothFinal;
        $VendorUniId=implode(",",$_REQUEST['vendorId']);
		$data['indentPrno']=$mainReqid;
        $data['requiDetIds']=$_REQUEST['requiDetIds'];
		$data['mapped_vendor']=$VendorUniId;
        $data['mappedQty']=$mapqty;
        $data['ItemID']=$itemsss;
        $data['flag']=$_REQUEST['flag'];
        $data['site']=$_REQUEST['site'];
		$data['quotaion_status']=0;
		$data['CompanyId']=$_SESSION['ACGCompanyId'];
        $data['createdDate']=date('Y-m-d');
        $data['createdBy']=trim($_SESSION['UserID']);
       // $data['postingDate']=FormatDateFORSQL($_REQUEST['postingDate']);
       // $data['openingDate']=FormatDateFORSQL($_REQUEST['openingDate']);

        $data['postingDate']=$postingDate;
        $data['openingDate']=$openingDate;
        
	$s->RecordInsert('indentpr_mapping',$data);
}
    }
 else {
     
        $startYr = explode('-', $_SESSION['financialYrStart']);
	$endYr = explode('-', $_SESSION['financialYrEnd']);
	$startYr[0];
	$endYr[0];
	$financial=substr($startYr[0],-2)."-".substr($endYr[0],-2); 
        $prefixcode='RFQ';
        $branch=$_REQUEST['site'];
        
        $sql="select mapNo from indentpr_mapping where CompanyId='".$_SESSION['ACGCompanyId']."' and site='".$_REQUEST['site']."' and INSTR(`mapNo`, '$financial') > 0 order by mapNo DESC LIMIT 0,1";
        $result = DB_query($sql,$db);
        $numrows = DB_num_rows($result);
		if($numrows>0)
		{
			$myrow=DB_Fetch_array($result);
			$ExplBill=explode("/",$myrow['mapNo']);
			$maxval = $ExplBill[3];
		}
		else
		{$maxval=0;}
         $strChar=$branch."/".$prefixcode."/".$financial."/";
         $strFinal = $maxval+1;    
         $strBothFinal = $strChar.str_pad($strFinal,5,"0",STR_PAD_LEFT); 
         
        $data['mapNo']=$strBothFinal;
        $VendorUniId=implode(",",$_REQUEST['vendorId']);
	$data['indentPrno']=implode(',', $_REQUEST['ReqiAId']);
        $data['requiDetIds']=$_REQUEST['requiDetIds'];
	$data['mapped_vendor']=$VendorUniId;
        $data['mappedQty']=implode(',', $_REQUEST['mappedQty']);
        $data['ItemID']=implode(',',$_REQUEST['ItemID']);
        $data['flag']=$_REQUEST['flag'];
        $data['site']=$_REQUEST['site'];
	$data['quotaion_status']=0;
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
        $data['createdDate']=date('Y-m-d');
        $data['createdBy']=trim($_SESSION['UserID']);
        
	
	$s->RecordInsert('indentpr_mapping',$data);
    }
    
        
         
        
        $detailsArray=explode(',', $_REQUEST['requiDetIds']);
        foreach($detailsArray as $reqdetID)
        {
                $datapers['mapped_vendor_status']=1;
		$Conds="id='".$reqdetID."'";
	$s->RecordEdit('requisitionorderdetails',$datapers,$Conds);
        
              
        
        $parentQry="select requsitionno from requisitionorderdetails where id='".$reqdetID."'";
       $parentQryExec=DB_query($parentQry,$db);
       $parentQryData=DB_fetch_array($parentQryExec);
       $parentID[]=$parentQryData['requsitionno'];
        }
        
        
        $parentIDS=array_unique($parentID);
        foreach($parentIDS AS $mainReqID)
        {
            $chkQuery="select mapped_vendor_status from requisitionorderdetails where requsitionno='".$mainReqID."'";
            $chkQueryExec=DB_query($chkQuery,$db);
             $numRows=DB_num_rows($chkQueryExec);
             $flag=0;
            while($chkQueryData=DB_fetch_array($chkQueryExec))
            {
            $mapedStatus=$chkQueryData['mapped_vendor_status'];
                if($mapedStatus==1)
                {
                    $flag=$flag+1;
                }
                
             }
             //echo $flag.''.$numRows;exit();
             if($flag==$numRows){
                $dataper['mapped_vendor_status']=1;
		
             }
            else {
                $dataper['mapped_vendor_status']=2;
            }
                $Cond="requisitionno='".$mainReqID."'";
                $s->RecordEdit('materialrequisitions',$dataper,$Cond); 
          }
       
       
   $s->pageLocation("index.php?route=POModule/map_vendor_for_quotation".$rurl);
}
if($_REQUEST['requiDetIds1'])
{
	        
       
        $VendorUniId=implode(",",$_REQUEST['vendorId']);
	$data['indentPrno']=$_REQUEST['ReqiAId'];
        $data['requiDetIds']=$_REQUEST['requiDetIds1'];
	$data['mapped_vendor']=$VendorUniId;
        $data['mappedQty']=$_REQUEST['mappedQty'];
        $data['ItemID']=$_REQUEST['ItemID'];
        $data['flag']=$_REQUEST['flag'];
	$data['modifiedDate']=date('Y-m-d');
        $data['modifiedBy']=trim($_SESSION['UserID']);
        
//	echo '<pre>';
//        print_r($data);
//        exit();
    $Cond1="id='".$_REQUEST['indentID']."'";
	$s->RecordEdit('indentpr_mapping',$data,$Cond1);
        
         $detailsArrayUnchk=explode(',', $_REQUEST['requiDetIds1unchk']);
        foreach($detailsArrayUnchk as $reqdetIDunchk)
        {
                $datapersun['mapped_vendor_status']=0;
		$Condsun="id='".$reqdetIDunchk."'";
	$s->RecordEdit('requisitionorderdetails',$datapersun,$Condsun);
        }
        
         $detailsArray=explode(',', $_REQUEST['requiDetIds1']);
        foreach($detailsArray as $reqdetID)
        {
                
                $datapers['mapped_vendor_status']=1;
		$Conds="id='".$reqdetID."'";
	$s->RecordEdit('requisitionorderdetails',$datapers,$Conds);
        
              
        
        $parentQry="select requsitionno from requisitionorderdetails where id='".$reqdetID."'";
       $parentQryExec=DB_query($parentQry,$db);
       $parentQryData=DB_fetch_array($parentQryExec);
       $parentID[]=$parentQryData['requsitionno'];
        }
        $parentIDS=array_unique($parentID);
        foreach($parentIDS AS $mainReqID)
        {
            $chkQuery="select mapped_vendor_status from requisitionorderdetails where requsitionno='".$mainReqID."'";
            $chkQueryExec=DB_query($chkQuery,$db);
             $numRows=DB_num_rows($chkQueryExec);
             $flag=0;
            while($chkQueryData=DB_fetch_array($chkQueryExec))
            {
            $mapedStatus=$chkQueryData['mapped_vendor_status'];
                if($mapedStatus==1)
                {
                    $flag=$flag+1;
                }
                
             }
             //echo $flag.''.$numRows;exit();
             if($flag==$numRows){
                $dataper['mapped_vendor_status']=1;
		
             }
            else {
                $dataper['mapped_vendor_status']=2;
            }
                $Cond="requisitionno='".$mainReqID."'";
                $s->RecordEdit('materialrequisitions',$dataper,$Cond); 
          }
       
       
   $s->pageLocation("index.php?route=POModule/map_vendor_for_quotation".$rurl);
}

?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Invite Vendors For Quote/Bids</h1>
<div class="new_tab">
<div class="inside_tab">
	<ul>
		<li><a href="index.php?route=POModule/map_vendor_for_quotation&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&tab=2&type=POModule/pending_for_mapping">Pending For Invitation</a></li>
		<li><a href="index.php?route=POModule/map_vendor_for_quotation&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&tab=2&type=POModule/mapped_indent">Invited Vendors</a></li>
		<li><a id="indenthelp" href="#">Help</a></li>
	</ul>
</div>
</div>
<?php 
if($_REQUEST['type']=='POModule/pending_for_mapping') { ?>
<h3>Pending for Invitation</h3>
<form action="" method="post" name="mainForm" onsubmit="return validation()">
<table width="100%" border="0" cellspacing="0" cellpadding="3">	
<tr class="row1">
    <td width="13%" align="right">Branch <font color="red">*</font></td>
    <td width="20%"><select name="sitecode" id="sitecode" >
		<option value="0">----Select----</option>
		<?php	
		//echo "select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."'  and loccode in ('".$_SESSION['AssignedBranch']."')";		
		$sqlsite=DB_query("select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."'  and loccode in ('".$_SESSION['AssignedBranch']."')",$db);		
		while($site_row=DB_fetch_array($sqlsite))
		{
				$p='';
				if($_REQUEST['sitecode']==$site_row['loccode'])
				$p="selected";
		?>
		 <option value="<?php echo $site_row['loccode'];?>" <?php echo $p;?>><?php echo $site_row['locationname'];?></option>
		<?php } ?>
	</select>
	</td>    
	<td width="13%" align="right">From Date</td>
	<td width="20%"><input type="text" readonly name="fdates" class="datepicker" id="fromdate" value="<?php echo ConvertSQLDate($_SESSION['financialYrStart']);?>" onchange="javascript:checkdate(this.value)" /></td>
	<td width="13%" align="right">To Date</td>
	<td><input type="text" readonly name="toDates" id="todate" value="<?php echo ConvertSQLDate($_SESSION['financialYrEnd']);?>"  onchange="javascript:checkdate(this.value)" class="datepicker"/>
		<input type="hidden" value="<?php echo ConvertSQLDate($_SESSION['financialYrStart']);?>" id='from'>
	<input type="hidden" value="<?php echo ConvertSQLDate($_SESSION['financialYrEnd']);?>" id='to'>
	</td>
</tr>
<tr class="row1">
	<td style="text-align:center;" colspan="6">
	<input type="submit" name="search" class="search" value="Search" />
	<input type="reset" value="Reset" class="search" name="reset" />
	</td>
</tr>
</table>
</form>
<?php } ?>
<?php
//if(in_array($_SESSION['UserID'],$Explode))
//{
if($_REQUEST['search'] || $_REQUEST['type']=='POModule/mapped_indent' || $_REQUEST['type']=='POModule/pending_for_mapping_edit')
{
      
    $todate=ConvertSQLDate($_REQUEST['toDates']);
	$fromdate=ConvertSQLDate($_REQUEST['fdates']);
	$Site=$_REQUEST['sitecode'];
	if($_REQUEST['toDates']!='' && $_REQUEST['fdates']!='' )
	{
	$filter[]="a.prdate between '".$fromdate."' and '".$todate."'";
	}
	if($_REQUEST['sitecode']!='0')
	{
	$filter[]="a.sitecode='".$Site."'";
	}
        if(!empty($filter))
	{
            $filter1=implode(" and ",$filter);
            //echo $filter1;
        }

?>
<div style="width:100%; ">

	<?php for($i=1; $i<3; $i++)
	{
		if($i==$_REQUEST['tab']){
	?>

			<?php
			if($_REQUEST['route']!=''&& $_REQUEST['type']!='')
			{
				include($_REQUEST['type'].".php");
			} ?>

	<?php }} 
	
	if($_REQUEST['tab']=='')
	{
	include("pending_for_mapping.php");
	}
	?>
</div>
<?php } ?>


<div style="display:none;" id="div_id">
</div>

<div id="PickedItems" style="display:none">
</div>

<div id="div_help_indent" style="display:none"></div>

<?php if(isset($_SESSION['success_msg']))
{ ?>
	<script> alert("<?php echo ($_SESSION['success_msg']);?>");</script>
<?php 
}	unset($_SESSION['success_msg']);
?>

</div>
</div>
<script type="text/javascript" language="javascript">
    function validation()
    {
       var site=document.getElementById("sitecode").value; 
       if(site==0)
           {
               alert('Select Branch');
               document.getElementById("sitecode").focus();
               return false;
           }
       return true;
    }
//$.noConflict();	

$(document).ready(function(){	
		$("#indenthelp").click(function(){
			$("#div_help_indent").dialog({
				title:'Help',
				modal: true,
				resizable: false,
				width:400,
				height:300,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				buttons: {
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
			});
		});
		
		

		var cnt=document.getElementById("count").value;
		$('input[name=ShowMappedVendors]').click(function(){
		
		var tt=this.id;
		var tt1=tt.split("_");
		var tt2=tt1[1];
		var indentid=document.getElementById("mapindentUniqid_"+tt2).value;
		var id=document.getElementById("mpavendindentid_"+tt2).value;
      var site=document.getElementById("site2_"+tt2).value;
			$("#div_id").dialog({
				title:'Mapped Vendors List',
				modal: true,
				resizable: false,
				width:500,
				height:500,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: {
					Save: function()
					{
						$("#myform").closest("form").submit();
					},
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
			
		CheckVendors(indentid,id,site);
		});
		
	
		var cnt=document.getElementById("count").value;
                
		$('input[name=mapvendor]').click(function(){
		
                var flag=1;
                var cnt=document.getElementById("count").value
                    for(var j=0;j<cnt;j++)
                    {
                       
                            if(document.getElementById("requiDetId_"+j).checked)
                            {
                               
                            
                                    var flag=0;
                                    break;
                            }
                    }
                
                if(flag==1)
                    {
                     alert('Please Select Items !!');
                     return false;
                    }
               
                     
               var quotepostingDate=document.getElementById("postingDate").value;
                var quoteopeningDate=document.getElementById("openingDate").value;
               if(quotepostingDate=='')
                   {
                       alert('Enter Quote Posting Date');
                       document.getElementById("postingDate").focus();
                       return false;
                   }
                else if(quoteopeningDate=='')
                   {
                       alert('Enter Quote Opening Date');
                       document.getElementById("openingDate").focus();
                       return false;
                   }
                   else if(quoteopeningDate < quotepostingDate)
                   {
                   		alert('Opening Date can not be less than Posting Date');
                   		document.getElementById("openingDate").focus();
                   		return false;
                   }
		var conso=document.getElementById("consolidate").checked;
                var site=document.getElementById("site1").value;
                //alert(site);
		//var site=document.getElementById("site1_"+tt2).value;
			$("#div_id").dialog({
				title:'Vendor List For Mapping',
				modal: true,
				resizable: false,
				width:500,
				height:500,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: {
					Save: function()
					{
						$("#myformin").closest("form").submit();
					},
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
			
		CheckVendors1(conso,site,quotepostingDate,quoteopeningDate);
                      });
		
	
		var cnt=document.getElementById("count").value;
                
		$('input[name=mapvendoredit]').click(function(){
		
                var flag=1;
                var cnt=document.getElementById("count").value
                    for(var j=0;j<cnt;j++)
                    {
                       
                            if(document.getElementById("requiDetId_"+j).checked)
                            {
                               
                            
                                    var flag=0;
                                    break;
                            }
                    }
                
                if(flag==1)
                    {
                     alert('Please Select Items !!');
                     return false;
                    }
                
                
                
                     
               
		var conso=document.getElementById("consolidate").checked;
                var indentIDS=document.getElementById("mainIndentID").value;
                
		var site=document.getElementById("site").value;
			$("#div_id").dialog({
				title:'Vendor List For Mapping',
				modal: true,
				resizable: false,
				width:500,
				height:500,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: {
					Save: function()
					{
						$("#myformin").closest("form").submit();
					},
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
			 CheckVendorsEdit1(conso,indentIDS,site);
                      });
		
	
	});
        
        function CheckVendorsEdit1(consol,indentIDlS,site)
        {
        	//alert(site);
                var count=document.getElementById("count").value;
                
                var sub_cat_array=Array();
                var subs_cat_array_uncheck=Array();
                for(var i=0;i<count;i++)
                {
                        var item_sub_category=document.getElementById("requiDetId_"+i).value;
                        //alert(document.getElementById("requiDetId_"+i).checked);
                        if(document.getElementById("requiDetId_"+i).checked==true)
                        {

                    sub_cat_array[i]=item_sub_category;
                        }
                        else{
                            
                            subs_cat_array_uncheck[i]=item_sub_category;
                        }
                        
                }
                //alert(sub_cat_array);
                //alert(subs_cat_array_uncheck);
                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("div_id").innerHTML=xmlhttp.responseText;
                        }
                }
                xmlhttp.open("GET","GetmappedVendorListMAPPED.php?q="+sub_cat_array+"&flag="+consol+"&branch="+site+"&indentID="+indentIDlS+"&q1="+subs_cat_array_uncheck,true);
                xmlhttp.send();

        }
        
	
	
//function getDetails(requisitionId)
//{
//	document.getElementById("ReqiAId").value=requisitionId;
//	document.getElementById("div_id").value=requisitionId;
//}


function validateForm()
{
	var vendors=$('#myformin input[name="vendorId[]"]');
	if(parseInt(vendors.length)>0){
	    return true;
    } else {
        alert("Please select at least one vendor!");
	    return false;
    }
    /*var x=document.AsignVendor.elements["vendorId[]"];
	var t=x.length;
	var chk=0;
	if(t==undefined)
	{
		chk=1;
	}
	else
	{
		for(var j=0;j<t;j++)
		{
			if(document.getElementById("vendorId_"+j).checked==true)
			{
				chk=1;
			}
		}
	}
	if(chk=='0')
	{
		alert("Please select at least one vendor!");
		return false;
	}*/
}

function CheckVendors(vendorid,id,site)
{
	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("div_id").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","GetUnmappedVendorList.php?VendorId="+vendorid+"&id="+id+"&site="+site,true);
	xmlhttp.send();
}

function CheckVendors1(conso,site,quotepostingDate,quoteopeningDate)
{
        //alert(site);
        var count=document.getElementById("count").value;
       
	var sub_cat_array= new Array();
	for(var i=0;i<count;i++)
	{
		//var item_sub_category=document.getElementById("requiDetId_"+i).value;
		if(document.getElementById("requiDetId_"+i).checked==true)
		{                     
                sub_cat_array[i]=document.getElementById("requiDetId_"+i).value;
		}
	}
        //alert(sub_cat_array);
	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("div_id").innerHTML=xmlhttp.responseText;
		}
	}

	xmlhttp.open("GET","GetmappedVendorList.php?q="+sub_cat_array+"&flag="+conso+"&branch="+site+"&openingDate="+quoteopeningDate+"&postingDate="+quotepostingDate,true);
	xmlhttp.send();
}



function CheckVendorIndent(vendorid)
{
	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("div_id").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","GetmappedVendorList.php?VendorId="+vendorid,true);
	xmlhttp.send();
}

</script>

<style>
.main-dialog-class .ui-widget-header{background: url("/Images/your-background.png") repeat-x scroll 34px 42px #a4cf50;font-size:14px;border:0;text-transform:uppercase}
.main-dialog-class .ui-widget-content{background-image:none;background-color:#fff}
</style>

<script type="text/javascript">
	function checkdate(date)
{
	var from =document.getElementById('from').value;
	var to =document.getElementById('to').value;
	
		var cdate=date.split("/");
		var sdate=from.split("/");
		var edate=to.split("/");

		cdate[1]=cdate[1]-1;
		sdate[1]=sdate[1]-1;
		edate[1]=edate[1]-1;
			 
		var dateC = new Date(cdate[2], cdate[1], cdate[0]); //Year, Month, Date 
		var dateS = new Date(sdate[2], sdate[1], sdate[0]); //Year, Month, Date
	    var dateE = new Date(edate[2], edate[1], edate[0]); //Year, Month, Date

	    if (dateS > dateE) {
	        alert("Start Date is not greather then Date End.");
	        document.getElementById('fromdate').value=from;
	        document.getElementById('todate').value=to;
	        
	    }

	    if (dateC > dateE) {
	        alert("Date Not greather than "+to);
	       document.getElementById('fromdate').value=from;
	        document.getElementById('todate').value=to;
	       
	    }

	    if (dateC < dateS) {
	        alert(" Date Not less than "+from);
	        document.getElementById('fromdate').value=from;
	        document.getElementById('todate').value=to;
	       
	    }	
	
	
}
function search_vendor(){
    var venderNameSearch=document.getElementById("searchvender").value;
    if(venderNameSearch!=''){
        var conso=document.getElementById("consolidate").checked;
        var site=document.getElementById("site1").value;
        var quotepostingDate=document.getElementById("postingDate").value;
        var quoteopeningDate=document.getElementById("openingDate").value;
        var count=document.getElementById("count").value;
        var sub_cat_array= new Array();
        for(var i=0;i<count;i++)
        {
            if(document.getElementById("requiDetId_"+i).checked==true)
            {
                sub_cat_array[i]=document.getElementById("requiDetId_"+i).value;
            }
        }
        var url="GetmappedVendorListSearch.php";
        var params={};
        params['q']=sub_cat_array.join(",");
        params['flag']=conso;
        params['branch']=site;
        params['openingDate']=quoteopeningDate;
        params['postingDate']=quotepostingDate;
        params['venderNameSearch']=venderNameSearch;
        $.ajax({
            url:url,
            type:"GET",
            data:params,
            async: false,
            success:function(data){
                $('#venderData').html(data);
            }
        });
    }
}
function vendermap(obj){
    if($(obj).is(':checked')){
        var hiddenInput='<input type="hidden" value="'+$(obj).val()+'" name="vendorId[]">';
        $('#myformin').append(hiddenInput);
    } else {
        $('#myformin input[value="'+$(obj).val()+'"]').remove();
    }

}
</script>
<style>
	.ui-dialog .ui-dialog-buttonpane button { padding: 3px 8px 2px; }
</style>
</table>