<?php $PageSecurity = 11;
include('includes/SQL_CommonFunctions.inc');
include('includes/Class_www_users.php');

if(isset($_POST['submit']))
{		                 

                          $store1=array();

                         for($i=0;$i<count($_POST['choose']);$i++)
						 {						
                          $val=$_POST['choose'][$i];
						  $store1[]=$_POST['store'][$val];
						  }	 
						 
						 
						 if(count($store1)>1)
						 $storetype=implode(",",$store1);
						 else
						 $storetype=$store1[0];	
						 
						 
						 if($_REQUEST['other_dispatch_exciaable']!=''){
				         $itemArray=$_REQUEST['other_dispatch_exciaable'];
				        $itemIds=implode(",",$itemArray);
				        }else{ $itemIds='';}	
						
						 if($_REQUEST['other_dispatch_nonexciaable']!=''){
				         $itemArray1=$_REQUEST['other_dispatch_nonexciaable'];
				        $itemIds1=implode(",",$itemArray1);
				        }else{ $itemIds1='';}
						 
						 
										 
 	 
                         $sql = "INSERT dbl_dealer SET
						`dealer_name`       ='".$_POST['short_name']."',
						`dealer_short_name`	='".$_POST['delershot']."', 
						`dealer_code`	    ='".$_POST['code']."',  
						`branch`	        ='".$_POST['Site']."',  
						`store`	            ='".$storetype."',
						`area_code`	        ='".$_POST['areacode']."',
						`subarea_code`	    ='".$_POST['subzone']."',
						`engineer_code`	    ='".$_POST['engineer_code']."',
						`tin_no`	        ='".$_POST['tinno']."',
						`pan_no`	        ='".$_POST['panno']."',
						`margin_factor`	    ='".$_POST['marginfac']."',
						`party_code`	    ='".$_POST['partycode']."',
						`range`	            ='".$_POST['range']."',
						`pre_address1`	   ='".$_POST['pre_address1']."',
						`pin_no`	       ='".$_POST['pre_address1']."',
						`pre_country`	   ='".$_POST['pre_country']."',  
						`pre_mobile`	   ='".$_POST['pre_mobile']."',
						`pre_state`		   ='".$_POST['pre_state']."', 
						`pre_city`		   ='".$_POST['pre_city']."', 
						`pre_pincode`	   ='".$_POST['pre_pincode']."',
						`per_email`        ='".$_POST['per_email']."',
						`pre_phone1`	   ='".$_POST['pre_phone1']."',						
						`vat_cst_no`	   ='".$_POST['vat_cst_no']."',
						`discount`	       ='".$_POST['discount']."',
						`max_price`	       ='".$_POST['max_price']."',
						`default_dispatch_excisable`='".$_POST['default_location_exciaable']."',
						`default_dispatch_nonexcisable`='".$_POST['default_location_nonexcisable']."',
						`other_dispatch_excisable`='".$itemIds."',
						`other_dispatch_nonexciable`='".$itemIds1."',						
						`company`='".$_POST['CompanyName']."'";						
						
						$res = DB_query($sql,$db,$ErrMsg,$DbgMsg);
					  	$lastid=DB_Last_Insert_ID($db,'Dealer', 'id');
						

					for($CR=1;$CR<$_REQUEST['cnt'];$CR++)
					{
						 $insert_contact="Insert into dbl_dealer_contact_information_maste set
												id='', 
												master_code='".$lastid."',  
												master_prefix='D',  
												person ='".$_REQUEST['person'][$CR]."', 
												designation='".$_REQUEST['designation'][$CR]."',  
												phone='".$_REQUEST['phone'][$CR]."',
												email='".$_REQUEST['contact_email'][$CR]."' ";	
						$insert_res=DB_query($insert_contact,$db);			
					}	
					
					
					
 $s->pageLocation('index.php?route=Storetype1&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}


if($_REQUEST['action']=='Edit'  && isset($_POST['update']))
{

                    
 

                        $store1=array();

                         for($i=0;$i<count($_POST['choose']);$i++)
						 {						
                          $val=$_POST['choose'][$i];
						  $store1[]=$_POST['store'][$val];
						  }
						 
						 
						 
						 if(count($store1)>1)
						 $storetype=implode(",",$store1);
						 else
						 $storetype=$store1[0];	
						 
						 if($_REQUEST['other_dispatch_exciaable']!=''){
				         $itemArray=$_REQUEST['other_dispatch_exciaable'];
				        $itemIds=implode(",",$itemArray);
				        }else{ $itemIds='';}	
						
						 if($_REQUEST['other_dispatch_nonexciaable']!=''){
				         $itemArray1=$_REQUEST['other_dispatch_nonexciaable'];
				        $itemIds1=implode(",",$itemArray1);
				        }else{ $itemIds1='';}
						 
						
                         $update="update dbl_dealer set
	                    `dealer_name`       ='".$_POST['short_name']."',
						`dealer_short_name`	='".$_POST['delershot']."', 
						`dealer_code`	    ='".$_POST['code']."',  
						`branch`	        ='".$_POST['Site']."',  
						`store`	            ='".$storetype."',
						`area_code`	        ='".$_POST['areacode']."',
						`subarea_code`	    ='".$_POST['subzone']."',
						`engineer_code`	    ='".$_POST['engineer_code']."',
						`tin_no`	        ='".$_POST['tinno']."',
						`pan_no`	        ='".$_POST['panno']."',
						`margin_factor`	    ='".$_POST['marginfac']."',
						`party_code`	    ='".$_POST['partycode']."',
						`range`	            ='".$_POST['range']."',
						`pre_address1`	   ='".$_POST['pre_address1']."',
						`pin_no`	       ='".$_POST['pre_address1']."',
						`pre_country`	   ='".$_POST['pre_country']."',  
						`pre_mobile`	   ='".$_POST['pre_mobile']."',
						`pre_state`		   ='".$_POST['pre_state']."', 
						`pre_city`		   ='".$_POST['pre_city']."', 
						`pre_pincode`	   ='".$_POST['pre_pincode']."',
						`per_email`        ='".$_POST['per_email']."',
						`pre_phone1`	   ='".$_POST['pre_phone1']."',
						`vat_cst_no`	   ='".$_POST['vat_cst_no']."',
						`discount`	       ='".$_POST['discount']."',
						 `max_price`	       ='".$_POST['max_price']."',
						`default_dispatch_excisable`='".$_POST['default_location_exciaable']."',
						`default_dispatch_nonexcisable`='".$_POST['default_location_nonexcisable']."',
						`other_dispatch_excisable`='".$itemIds."',
						`other_dispatch_nonexciable`='".$itemIds1."',	
						`company`		   ='".$_POST['CompanyName']."'
						 where id='".$_REQUEST['id']."'";	
						
                        $updatequery=DB_query($update,$db);

                      for($CR=1;$CR<$_REQUEST['cnt'];$CR++)
					{
						 $insert_contact="update  dbl_dealer_contact_information_maste set
												master_prefix='D',  
												person ='".$_REQUEST['person'][$CR]."', 
												designation='".$_REQUEST['designation'][$CR]."',  
												phone='".$_REQUEST['phone'][$CR]."',
												email='".$_REQUEST['contact_email'][$CR]."'
												where master_code='".$_REQUEST['id']."'";	
						$insert_res=DB_query($insert_contact,$db);			
					}	
					
				


$s->pageLocation('index.php?route=Storetype1&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');

}

if($_REQUEST['action']=='delete')
{
$del1=DB_query("delete from dbl_dealer_contact_information_maste where master_code='".$_REQUEST['id']."'",$db);
$del=DB_query("delete from dbl_dealer where id='".$_REQUEST['id']."'",$db);
$s->pageLocation('index.php?route=Storetype1&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');


}





if($_REQUEST['action']=='Edit')
{
$sql=DB_query("select * from dbl_dealer where id='".$_REQUEST['id']."'",$db);
$row1=DB_fetch_array($sql);
extract($row1);
}


?>
<style type="text/css">
.mandatory{
 color:#FF0000;
}
</style>
<style type="text/css">

a{
color: #171717;
text-decoration: none;

}
a:hover{
color: #fff;

text-decoration: none;
}

#wrapper{
width:882px;
margin:auto;
}
.box{
background: #fff;

}
.boxholder{
clear: both;
padding: 5px;
border:#737373 5px solid;
padding-bottom:15px;

}
.tab{
float:left;
height:32px;
width:125px;
margin:0 1px 0 0;
text-align: center;
background:url(images/greentab.jpg) no-repeat;
}
.tabtxt{
margin: 0;
color: #fff;
font-size: 12px;
font-weight: bold;
padding: 5px 0 0 0;

}
</style>
<script type="text/javascript" src="js/prototype.lite.js"></script>
<script type="text/javascript" src="js/moo.fx.js"></script>
<script type="text/javascript" src="js/moo.fx.pack.js"></script>
<script type="text/javascript">
function init(){
	var stretchers = document.getElementsByClassName('box');
	var toggles = document.getElementsByClassName('tab');
	var myAccordion = new fx.Accordion(
		toggles, stretchers, {opacity: false, height: true, duration: 600}
	);
	//hash functions
	var found = false;
	toggles.each(function(h3, i){
		var div = Element.find(h3, 'nextSibling');
			if (window.location.href.indexOf(h3.title) > 0) {
				myAccordion.showThisHideOpen(div);
				found = true;
			}
		});
		if (!found) myAccordion.showThisHideOpen(stretchers[0]);
}
</script>
<script>
function validation(form)
{
	

if(document.getElementById('c_name').value=='')
{alert('Name should not be empty');
document.getElementById('c_name').focus();
return false;
}/*
	
if(document.getElementById('short_name').value==''){
alert('Short name should not be empty');
document.getElementById('short_name').focus();
return false;
}
	

if(document.getElementById('ccategory').value==''){
alert('Category should not be empty');
document.getElementById('ccategory').focus();
return false;}
	
*/
if(document.getElementById('pre_address1').value==''){
alert('Address should not be empty');
document.getElementById('pre_address1').focus();
return false;
}
	if(document.getElementById('pre_city').value==''){
alert('Select your city');
document.getElementById('pre_city').focus();
return false;
}
	
if(document.getElementById('pre_country').value==''){
alert('Select your country');
document.getElementById('pre_country').focus();
return false;
}
	
if(document.getElementById('pre_state').value==''){
alert('Select your state');
document.getElementById('pre_state').focus();
return false;
}


if(document.getElementById('pre_pincode').value==''){
alert('Pin code should not be empty');
document.getElementById('pre_pincode').focus();
return false;
}
	
if(isNaN(document.getElementById('pre_pincode').value)){
alert('Pin Code number should be numberic');
document.getElementById('pre_pincode').focus();
return false;
}
	
if(document.getElementById('pre_phone1').value =="")
{
alert('Phone number should not be empty');
document.getElementById('pre_phone1').focus();
return false;
}
if(isNaN(document.getElementById('pre_phone1').value)){
alert('Phone number should be numberic');
document.getElementById('pre_phone1').focus();
return false;
}
	

if(document.getElementById('tin_no').value =="")
{
alert('Tin number should not be empty');
document.getElementById('tin_no').focus();
return false;
}
if(isNaN(document.getElementById('tin_no').value)){
alert('Tin number should be numberic');
document.getElementById('tin_no').focus();
return false;
}
	
if(document.getElementById('person_1').value=='' && document.getElementById('person_2').value=='' && document.getElementById('person_3').value=='')
{
alert('Please enter atleast one contact person');
document.getElementById('person_1').focus();
return false;
}

/*if(document.getElementById('pre_mobile').value==''){
alert('Mobile number should not be empty');
document.getElementById('pre_mobile').focus();
return false;
}
*/	
/*if(isNaN(document.getElementById('pre_mobile').value)){
alert('Mobile number should be numberic');
document.getElementById('pre_mobile').focus();
return false;
}
*/	
/*if(document.getElementById('per_email').value==''){
alert('Email Id should not be empty');
document.getElementById('per_email').focus();
return false;
}
*/		
return true;
}	

function search_state(str)
{
	//alert(str);
if (str.length==0)
  {
  document.getElementById("searchstate").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("searchstate").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_state.php?country="+str,true);
xmlhttp.send();
}

 
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_category.php?partName="+str,true);
xmlhttp.send();
}
</script>

<style type="text/css">
    .cap{
    text-transform:uppercase
    };
	</style>
<link rel="stylesheet" href="css/new_mxerp1.css">
<div class="body_contain">
<div class="tab_div">
<h1>Dealer Master</h1>
<form  enctype="multipart/form-data" method="post" action="" onsubmit="return validation(this.form);">

  <div id="wrapper">
	<div id="content">
<h3 class="tab" title="first" style="padding:0px;border:none;"><div class="tabtxt"><a href="#">GENERAL  INFORMATION</a></div></h3>
<div class="tab"><h3 class="tabtxt" title="second" style="border:none;"><a href="#">ADDRESS & COMMUNICATION</a></h3></div>
		<div class="tab"><h3 class="tabtxt" title="third" style="border:none;"><a href="#">CONTACT PERSONS DETAILS</a></h3></div>
		<div class="tab"><h3 class="tabtxt" title="fourth" style="border:none;"><a href="#">DEALER POLICY SETTING</a></h3></div>
		<div class="tab"><h3 class="tabtxt" title="fifth" style="border:none;"><a href="#">STATUOTARY DETAIL</a></h3></div>
		<div class="tab"><h3 class="tabtxt" title="sixth" style="border:none;"><a href="#">DISPATCH/STORE LOCATIONS</a></h3></div>
		<!--<div class="tab"><h3 class="tabtxt" title="seven" style="border:none;"><a href="#">DEALER ERP SETTING</a></h3></div>
		-->
		
		<div class="boxholder">
			<div class="box">
			<fieldset><legend><strong>GENERAL  INFORMATION</strong></legend>

<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
      <td class="tabledata1"><strong>Company</strong><span class="mandatory"><strong>*</strong></span></td>
      <td>
	  <select name="CompanyName" id="CompanyName" style="width:150px;" onchange="showroles(this.value)" >
			<option value="0">--Select--</option>
			<?php
			$CompanyName=DB_query("Select * from companies where 1=1",$db);
			while($CompanyRow=DB_fetch_array($CompanyName))
			{ ?>
			<option value="<?php echo $CompanyRow['CompanyId']?>"<?php echo ($company == $CompanyRow['CompanyId']?'selected':'');?>><?php echo $CompanyRow['CompanyName']?></option>	
				
		<?php	}
			
			   
			?>
	  </select></td>
      <td class="tabledata1"><strong>Dealer Name<span class="mandatory"><strong>*</strong></span></strong></td>
      <td><input name="short_name" type="text" class="cap" id="short_name" value='<?php if(isset($dealer_name)) echo $dealer_name; ?>'  style="width:150px;"/></td>
    </tr>
<tr class="row1">
      <td class="tabledata1"><strong>Short Name</strong></strong></td>
      <td>
	  <input type="text" name="delershot" id="delershort" style="width:150px;" value="<?php if(isset($dealer_short_name)) echo $dealer_short_name; ?>"  /></td>  
	  <td class="tabledata1"><strong>Dealer Code</strong></td>
      <td>	 
  	 <input name="code" type="text" id="code" value="<?php if(isset($dealer_code)) echo $dealer_code; ?>" style="width:150px;"   onkeyup="showdealercode(this.value)"/>
	 <div id="showmessage"></div>
	 
	 </td>
   </tr>
  
<tr class="row1">
	<td class="tabledata1"><strong>Area Code<span class="mandatory"><strong>*</strong></span></strong></td>
   	<td><!--where CompanyId='".$_SESSION['ACGCompanyId']."' -->
		<select name="areacode" id="areacode" style="width:150px;" onchange="showzone(this.value)">
	    <option value="">Select</option>
		<?php 
		$sql=DB_query("select * from zone_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
		while($row1=DB_fetch_array($sql))
		{
		?>
		<option value="<?php echo $row1['id']; ?>" <?php echo($area_code==$row1['id']?'selected':'');?>><?php echo $row1['ZoneTitle']; ?></option>
		
	<?php } ?>
	</select>
	</td>
   	<td class="tabledata1"><strong>Sub Area Code</strong></td>
   	<td><div id="subareacode">
	
	<select name="subzone" id="subzone" style="width:150px;" >
	     <option value="0">Select</option>
		 <?php
		 $sql=DB_query("select * from subzone_master where zone='".$area_code."' ",$db);
		 while($row=DB_fetch_array($sql))
		 { 
		 ?>
	     <option value="<?php echo $row['id']; ?>" <?php echo($subarea_code==$row['id']?'selected':'');?>><?php echo $row['subzone']; ?></option>
		 <?php } ?>
		 </select>	
	
	</div>
	</td>
   	
   	</tr>
<tr class="row1">
   	<td class="tabledata1"><strong>Engineer Code<span class="mandatory"><strong>*</strong></span></strong></td>
   	<td><select name="engineer_code" id="engineer_code" style="width:150px;">
	<option value="0">Select</option>
	<?php
		 $sql=DB_query("select * from dbl_engineer_master",$db);
		 while($row=DB_fetch_array($sql))
		 { 
		 ?>
	     <option value="<?php echo $row['id']; ?>" <?php echo($engineer_code==$row['id']?'selected':'');?>><?php echo $row['engineer_name']; ?></option>
		 <?php } ?>
	</select>
	
	</td>
   	<td class="tabledata1"><strong>Party Code</strong></td>
      <td>	 
  	 <input name="partycode" type="text" id="partycode"  value='<?php if(isset($party_code)) echo $party_code; ?>' style="width:150px;" /></td>
   	</tr>
</table>
</fieldset>
			</div>
		
			<div class="box">
			<fieldset><legend><strong>ADDRESS & COMMUNICATION DETAILS</strong></legend>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
   	<td class="tabledata1" rowspan="3"><p><strong>Address<span class="mandatory"><strong>*</strong></span></strong></p></td>
      <td rowspan="3">
  	  <textarea  name="pre_address1" id="pre_address1"  cols="20" rows="3" style="width:150px;"><?php if(isset($pre_address1)) echo $pre_address1; ?></textarea>	   </td>
      <td class="tabledata1"><strong>Pin Code</strong></td>
      <td><input type="text" id="pre_pincode" name="pre_pincode" value='<?php if(isset($pre_pincode)) echo $pre_pincode; ?>' style="width:150px;"></td>
    </tr>
    
<tr class="row1">
   	<td class="tabledata1"><strong>Phone</strong></td>
      <td><input type="text" id="pre_phone1"  name="pre_phone1" value='<?php if(isset($pre_phone1)) echo $pre_phone1; ?>' style="width:150px;" /></td>
    </tr>
<tr class="row1">
   	<td class="tabledata1"><strong> City<span class="mandatory"><strong>*</strong></span></strong></td>
      <td colspan="2">
	   <select name="pre_city" id="pre_city" style="width:150px;" onchange="ShowDiv(this.value,'searchstate','get_state.php?type=client')" >
       <option value="">---Select City---</option>
	   <?php 
	   $sql = "select * from city_master where 1=1";
	   $result = DB_query($sql,$db);
	   while($city_row = DB_fetch_array($result))
	   {
	   		$p='';
			if($city_row['id'] == $pre_city)
			$p="selected";
	   ?>
	  <option value="<?php echo $city_row['id']; ?>" <?php echo ($pre_city==$city_row['id']?"selected":"") ?>><?php echo $city_row['city']; ?></option>
	   <?php }?>
      </select>	  </td>
    </tr>
	
	
<tr class="row1">
   	<td class="tabledata1" colspan="2" rowspan="2" style="padding:0px; margin:0px;"><div id="searchstate">
	  
	  <table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
    <td class="tabledata1" ><strong>State<span class="mandatory"><strong>*</strong></span></strong></td>
    <td>
 
	<select name="pre_state" id="pre_state" style="width:150px;" onchange="search_city(this.value)">
 	   <?php 
	    $sql = "select * from state_master where id = '".$pre_state."' ";
		$result=DB_query($sql,$db);
		while($myrow=DB_fetch_array($result))
		{ 
			$p='';
			if($myrow['id'] == $pre_state)
			$p="selected";
		?>
		<option value="<?php echo $myrow['id'];?>" <?php echo ($row['pre_state']==$myrow['id']?"selected":"") ?>><?php echo $myrow['state']; ?></option>
		<?php }
	   ?>
      </select></td>
  </tr>
<tr class="row1">
    <td class="tabledata1" ><strong>Country<span class="mandatory"><strong>*</strong></span></strong></td>
    <td>
	 
	<select name="pre_country" id="pre_country" style="width:150px;"  >
          <option value="">---Select Country---</option>
        <?php 
			$c_sql = "select * from country_master where id='".$pre_country."'";
			$c_result = DB_query($c_sql,$db);
			while($c_row=DB_fetch_array($c_result))
			{
				$p='';
				if($c_row['id']==$pre_country)
				$p= "selected";
			?>
				<option value="<?php echo $c_row['id']; ?>"<?php echo ($pre_country==$c_row['id']?"selected":"") ?>><?php echo $c_row['country']; ?></option>
	  <?php }
		?>
		</select></td>
  </tr>
</table>
	  </div></td>
      <td class="tabledata1" ><strong>Mobile</strong></td>
      <td><input type="text" id="pre_mobile" name="pre_mobile" style="width:150px;" value='<?php if(isset($pre_mobile)) echo $pre_mobile; ?>' /></td>
    </tr>
	
  <tr class="row1">
      <td class="tabledata1" ><strong> Email Id</strong></td>
      <td><input type="text" id="per_email" name="per_email" style="width:150px;" value='<?php if(isset($per_email)) echo $per_email; ?>'></td>
    </tr>
	 
 </table>
</fieldset>
			</div>

			
		
			<div class="box">
			<fieldset><legend><strong>CONTACT PERSONS DETAILS: </strong></legend>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr class="row1">
<td>
	<table width="100%" cellpadding="3" cellspacing="0">	
<?php
if($_REQUEST['action']=='Edit')
{
   $contact_sql="Select * from dbl_dealer_contact_information_maste where master_code='".$_REQUEST['id']."'";
$contact_res=DB_query($contact_sql,$db);
	$k=1;
	while($contact_row=DB_fetch_array($contact_res))
	{
		$id[$k]=$contact_row['id'];
		$row_id[$k]=$contact_row['id'];
	  	$person[$k]=$contact_row['person'];
		$designation[$k]=$contact_row['designation'];	
		$phone[$k]=$contact_row['phone'];	
		$contact_email[$k]=$contact_row['email'];
		?>
<tr class="row1">
      <td class="tabledata1" ><strong>Contact Person <?php echo $k;?> </strong></td>
      <td><input type="text" name="person[<?php echo $k;?>]" class="cap" id="person_<?php echo $k;?>" value="<?php echo $person[$k];?>" style="width:100%;"  />
	  <input type="hidden" name="row_id[<?php echo $k;?>]" value="<?php echo $contact_row['id'];?>" /></td>
      <td class="tabledata1" ><strong>Designation</strong></td>
      <td><input type="text" name="designation[<?php echo $k;?>]" class="cap" id="designation_<?php echo $k;?>" value="<?php echo $designation[$k];?>" style="width:100%;" /></td>
	  <td class="tabledata1" ><strong>Phone/Mobile</strong></td>
	  <td><input type="text" name="phone[<?php echo $k;?>]" id="phone_<?php echo $k;?>" value="<?php echo $phone[$k];?>" style="width:100%;" class="cap" /></td>
	  <td class="tabledata1" ><strong>Email Id </strong></td>
	  <td><input type="text" name="contact_email[<?php echo $k;?>]" id="contact_email_<?php echo $k;?>" value="<?php echo $contact_email[$k];?>" class="cap" style="width:100%;"/></td>
</tr>
 		<?php 
 	$k++;
	}?>
	
	<input type="hidden" name="cnt" id="cnt" value="<?php echo $k;?>"/>

	
	<?php 
 }
  else{
 
 for($j=1;$j<6;$j++)
{?>
<tr class="row1">
	  <td class="tabledata1"><strong>Contact Person <?php echo $j;?> </strong></td>
	  <td><input type="text" name="person[<?php echo $j;?>]" class="cap" id="person_<?php echo $j;?>" value="<?php echo $person[$j];?>" style="width:100%;"  />
	  <input type="hidden" name="row_id[<?php echo $j;?>]" value="<?php echo $id[$j];?>" /></td>
	  <td class="tabledata1"><strong>Designation</strong></td>
	  <td><input type="text" name="designation[<?php echo $j;?>]" class="cap" id="designation_<?php echo $j;?>" value="<?php echo $designation[$j];?>"  style="width:100%;"/></td>
	  <td class="tabledata1"><strong>Phone/Mobile</strong></td>
	  <td><input type="text" name="phone[<?php echo $j;?>]" id="phone_<?php echo $j;?>" value="<?php echo $phone[$j];?>" style="width:100%;" class="cap" /></td>
	  <td class="tabledata1"><strong>Email Id </strong></td>
	  <td><input type="text" name="contact_email[<?php echo $j;?>]" id="contact_email_<?php echo $j;?>" value="<?php echo $contact_email[$j];?>" class="cap" style="width:100%;"/></td>
    </tr>
<?php 
}
?>
<input type="hidden" name="cnt" id="cnt" value="<?php echo $j;?>"/>

<?php }  
 
?>



</table></td>  
   	</tr>
</table>
</fieldset>
			</div>			
			<div class="box">
			<fieldset><legend><strong>DEALER POLICY SETTING</strong></legend>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
      <td class="tabledata1"><strong>Margin Factor<span class="mandatory"><strong>*</strong></span></strong></td>
      <td><input type="marginfac" id="marginfac" style="width:150px;"  value='<?php if(isset($margin_factor)) echo $margin_factor; ?>' />	</td>
      <td class="tabledata1"><strong>Discount<span class="mandatory"><strong>*</strong></span></strong></td>
      <td><input name="discount" type="text" class="cap" id="discount"  value='<?php if(isset($discount)) echo $discount; ?>'  style="width:150px;"/></td>
    </tr>
  <tr class="row1">
      <td class="tabledata1"><strong> Maximum allowed Numbers of price requests<span class="mandatory"><strong>*</strong></span></strong></td>
      <td colspan="3">
 <input type="text" name="max_price" id="max_price" style="width:150px;"  value='<?php if(isset($max_price)) echo $max_price; ?>' />		</td>  
	  </tr>
</table>
</fieldset>
			</div>
			<div class="box">
			<fieldset><legend><strong>STATUOTARY DETAIL</strong></legend>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
 <tr class="row1">
      <td class="tabledata1"><span class="mandatory"><strong>*</strong></span><strong>Tin No </strong></td>
      <td><input name="tinno" type="delershot" id="tinno" style="width:150px;"  value='<?php if(isset($tin_no)) echo $tin_no; ?>'></td>
      <td class="tabledata1"><strong>Pan No </strong></td>
      <td><input name="panno" type="text" class="cap" id="panno"  value='<?php if(isset($pan_no)) echo $pan_no; ?>'  style="width:150px;"/></td>
    </tr>
  <tr class="row1">
      <td class="tabledata1"><strong> VAT/CST No  </strong></td>
      <td colspan="3">
	  <input  type="text" name="vat_cst_no" id="vat_cst_no" style="width:150px;"  value='<?php if(isset($vat_cst_no)) echo $vat_cst_no; ?>' />		</td>  
	  
	  </tr>
</table>
</fieldset>	</div>
			
			
			
<div class="box">
			<fieldset><legend><strong>DISPATCH/STORE LOCATIONS</strong></legend>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
      <td class="tabledata1"><span class="mandatory"><strong>*</strong></span><strong>Default Dispatch Location(Excisable) </strong></td>
      <td><select name="default_location_exciaable" id="default_location_exciaable" style="width:150px;" onchange="showotherexcisable(this.value,document.getElementById('CompanyName').value)">
	  <option value="0">Select</option>
	  <?php
	  $sql1=DB_query("select * from locations where exciable='Y' ",$db);
	  while($row1=DB_fetch_array($sql1))
	  {
	  ?>
	  <option value="<?php echo $row1['loccode']; ?>"<?php echo ($default_dispatch_excisable==$row1['loccode']?"selected":"") ?>><?php echo $row1['locationname']; ?></option>
	  
	  <?php } ?>
	  </select>	  </td>
      <td class="tabledata1"><strong>Default Dispatch Location (Non Excisable)</strong></td>
      <td><select name="default_location_nonexcisable" id="default_location_nonexcisable" style="width:150px;" onchange="showothernonexcisable(this.value,document.getElementById('CompanyName').value)">
	  <option value="0">Select</option>
	  <?php
	  $sql1=DB_query("select * from locations where non_exciable='Y'",$db);
	  while($row1=DB_fetch_array($sql1))
	  {
	  ?>
	  <option value="<?php echo $row1['loccode']; ?>" <?php echo ($default_dispatch_nonexcisable==$row1['loccode']?"selected":"") ?>><?php echo $row1['locationname']; ?></option>
	  
	  <?php } ?>
	  </select></td>
    </tr>
  <tr class="row1">
      <td class="tabledata1" colspan="2" style="text-align:center;"><strong>Other Dispatch Location(Excisable)</strong></td>
      <td class="tabledata1" colspan="2" style="text-align:center;"><strong>Other Dispatch Location(Non Excisable)</strong></td>
      </tr>
	<tr class="row1"><td colspan="4"><table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
    <td><div id="otherexcisable">
	<div style="overflow:auto; height:150px; width:410px; border:1px solid; " >
	<?php 
	$items=explode(",",$other_dispatch_excisable);
	//print_r($items);
	
	$item_sql=DB_query("select * from locations  ",$db);
	$c3=0;
	while($row3=DB_fetch_array($item_sql))
	{ 
		$checked='';
		for($x=0;$x<count($items);$x++)
		{	
			 if($items[$x]==$row3['loccode'])
			 $checked="checked";
		}
		
		
	?>
	<input type="checkbox" name="other_dispatch_exciaable[]"  value="<?php echo $row3['id'];?>" <?php echo $checked;?>/><?php echo $row3['loccode']." - ".$row3['locationname'];?><br />
	
	<?php 	
	$c3++;
	}
	?>
	</div>
		
	</div></td>
    <td><div id="othernonexcisable12">
	<div style="overflow:auto; height:150px; width:410px; border:1px solid; " >
	<?php 
	$items1=explode(",",$other_dispatch_nonexciable	);
	//print_r($items);
	
	$item_sql=DB_query("select * from locations  ",$db);
	$c3=0;
	while($row3=DB_fetch_array($item_sql))
	{ 
		$checked='';
		for($x=0;$x<count($items1);$x++)
		{	
			 if($items1[$x]==$row3['loccode'])
			 $checked="checked";
		}
		
		
	?>
	<input type="checkbox" name="other_dispatch_nonexciaable[]"  value="<?php echo $row3['id'];?>" <?php echo $checked;?>/><?php echo $row3['loccode']." - ".$row3['locationname'];?><br />
	
	<?php 	
	$c3++;
	}
	?>
	</div>
		
	</div></td>
  </tr>
</table>

	  
	  
	  
	<tr class="row1">
	  <td class="tabledata1" colspan="4" style="text-align:center;"><strong>STORE LOCATION</strong></td>     
	 </tr>
	 <tr class="row1"><td colspan="4" align="center">
	 <table width="100%" height="37" border="1" >
	 <tr class="row1">
	 <td class="tabledata1">Select</td>
	 <td class="tabledata1">Store Name</td>
	 <td class="tabledata1">Status</td>
	 </tr>
	  <?php
	  $i=0; 
	  $store5=explode(",",$store);
	    $sql=DB_query("select * from dbl_dealer_store ",$db);
	  while($row1=DB_fetch_array($sql))
	  {
	  ?>  
	 <tr class="row1">
	  <td width="10%"><input type="checkbox" name="choose[]" id="choose_<?php echo $row1['id']; ?>" onclick="showactive(<?php echo $row1['id']; ?>)"  value="<?php echo $row1['id']; ?>" <?php if($store5[$i]==$row1['id']) { ?> checked="checked"<?php } ?>/></td>
	  <td width="70%"><?php echo $row1['dealer_store_name']; ?>
		  <input type="hidden" name="store[<?php echo $row1['id']; ?>]" value="<?php echo $row1['id']; ?>" />	  </td>
	  <td width="20%">Active &nbsp;
	    <input type="checkbox" name="active[<?php echo $row1['id']; ?>]" value="y" id="active_<?php echo $row1['id']; ?>" 
		<?php if($store5[$i]==$row1['id']) { ?> checked="checked"<?php } ?>  disabled="disabled"/></td>
	 </tr>
	  <?php $i++; } ?>
	 
	  
	 
	  </table></td></tr>
</table>
</fieldset>
			</div>	
			<?php /*?><div class="box">
			<fieldset>
			<legend><strong>DEALER ERP SETTING</strong></legend>
            <table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
      <th width="10%"><span class="mandatory"><strong>*</strong></span><strong>User ID </strong></td>
      <td width="26%"><input type="text" name="userid" id="userid" style="width:150px;"  value='<?php if(isset($userid)) echo $userid; ?>' />	</td>
      <th width="13%"><strong>Password </strong></td>
      <td width="51%"><input name="password" type="password" class="cap" id="password"  value='<?php if(isset($password)) echo $password; ?>'  style="width:150px;"/>
	  <input type="hidden" name="www_user" value="<?php echo $www_userid; ?>" />
	  </td>
    </tr>	
	
	<tr><th><strong>Role</strong></td>
	<td colspan="3"> <div id='txtCompanyRole'>
	<?php
	$rolepid=$s->getField('www_users','id',$www_userid,'rolepid');
	$pcode= $rolepid;
		function CategoryShow1($pcode, $PcateID, $dashVal)
		{
			global $db;
			$dashVal = $dashVal . "&nbsp;&nbsp;&nbsp;&nbsp;";
			$sqlCate = "select * from securityroles  where  rolepid  = '".$PcateID."'";
			$rsCate  = DB_query($sqlCate,$db);	
			 
			if(DB_num_rows($rsCate)>0)
			{
				while($rowCate = DB_fetch_array($rsCate))
				{
					$sqlCateSel = "select * from securityroles where rolepid =".$rowCate['rolepid']." ";
					$rsCateSel	= DB_query($sqlCateSel,$db);
					$px='';
					 if($rowCate['secroleid']==$pcode)
					 $px="selected";
			?>
					<option value="<?php echo $rowCate['secroleid'];?>" <?php echo $px ?>><?php echo $dashVal;?>
					 <?php echo $rowCate['role_name'];?> </option>
		   <?php			
					   CategoryShow1( $pcode,$rowCate['secroleid'], $dashVal);
				}
			}
		} 
		
		$dashVal = "&nbsp;&nbsp;&nbsp;";
		$query=DB_query("select * from securityroles where rolepid=0 and companyid ='".$company."'",$db);
		?>
	
		  <select name="rolepid" id="rolepid"  multiple="multiple" style="height:200px; width:800px">
            <?php
		if(DB_num_rows($query)>0){
		 
		  while($row=DB_fetch_array($query))
		  {		  
		  	$p='';
			if($row['secroleid']==$rolepid)
			{
			   $p="selected";
			}
		 ?>
            <option value="<?php echo $row['secroleid'] ?>" <?php echo $p; ?> ><?php echo $row['role_name'] ?></option>
            <?php 
		   CategoryShow1($rolepid, $row['secroleid'], $dashVal);
		}} ?>
          </select>
		</div>
	
	
	
	
	
	
	
	
	
	
	
	
	</td></tr>    
</table>
</fieldset>
			</div><?php */?>
						
			
			
			
			
		</div>
		
	<div style="clear:both;"></div>
	</div>
</div>


 
  
  <table>
	<tr><td align="center" style="text-align:center;  padding:5px 0px 5px 0px;" colspan="2" >
	<span style="text-align:center;">
	<?php if(isset($_GET['action'])=='editRec') { ?>
	<input type="submit" value="Update" class="search" name="update" />
	<?php }else{ ?>
	<input type="submit" value="Save" class="search" onclick="return validate()" name="submit" />
	<?php } ?>
	<input name="reset" type="reset" class="search" value="Reset" />
	</span></td>
	</tr><tr><td>&nbsp;</td>
  </tr></table></form>
</div>
</div>
  
  <script type="text/javascript">
	Element.cleanWhitespace('content');
	init();
</script>
  
<script language="javascript">
function showdealercode(str)
{
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("showmessage").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","checkcode.php?country="+str,true);
xmlhttp.send();


}

function showzone(str)
{

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("subareacode").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","showzonedata.php?str1="+str,true);
xmlhttp.send();




}


function showotherexcisable(str,str1)
{

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("otherexcisable").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","showexcisabledata.php?str1="+str+"&str2="+str1,true);
xmlhttp.send();




}


function showothernonexcisable(str,str1)
{

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("othernonexcisable12").innerHTML=xmlhttp.responseText;
    }
  }
  
xmlhttp.open("GET","shownonexcisabledata.php?str1="+str+"&str2="+str1,true);
xmlhttp.send();




}

function showactive(str)
{
if(document.getElementById("choose_"+str).checked ==true)
{
document.getElementById("active_"+str).checked=true;
}
else
{
document.getElementById("active_"+str).checked=false;
}

}



function showroles(str)
{
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("rolepid").innerHTML=data[0];
	document.getElementById("areacode").innerHTML=data[1];
	document.getElementById("default_location_exciaable").innerHTML=data[2];
	document.getElementById("default_location_nonexcisable").innerHTML=data[3];
    }
  }
xmlhttp.open("GET","dealer_role.php?q="+str,true);
xmlhttp.send();



}

function validate()
{
	if(document.getElementById("CompanyName").value=='0')
	{
		alert("Please Select The Company First");
		document.getElementById("CompanyName").focus();
		return false;
	}
	if(document.getElementById("short_name").value=='')
	{
		alert("Please Fill The Dealer Name First");
		document.getElementById("short_name").focus();
		return false;
	}
	if(document.getElementById("areacode").value=='')
	{
		alert("Please Select The Area Code First");
		document.getElementById("areacode").focus();
		return false;
	}
	if(document.getElementById("engineer_code").value=='0')
	{
		alert("Please Select The Engineer Code First");
		document.getElementById("engineer_code").focus();
		return false;
	}
	if(document.getElementById("pre_address1").value=='')
	{
		alert("Please Fill The Address First");
		document.getElementById("pre_address1").focus();
		return false;
	}
	if(document.getElementById("pre_city").value=='')
	{
		alert("Please Select The City First");
		document.getElementById("pre_city").focus();
		return false;
	}
	if(document.getElementById("marginfac").value=='')
	{
		alert("Please Fill The Margin Factor First");
		document.getElementById("marginfac").focus();
		return false;
	}
	if(document.getElementById("max_price").value=='')
	{
		alert("Please Fill The Maximum allowed Numbers of price requests  First");
		document.getElementById("max_price").focus();
		return false;
	}
	if(document.getElementById("discount").value=='')
	{
		alert("Please Fill The Discount  First");
		document.getElementById("discount").focus();
		return false;
	}
}



</script>  