<?php $PageSecurity = 11;
include('includes/SQL_CommonFunctions.inc');
if(isset($_POST['submit']))
{		
	$client_sql = "SELECT client_code FROM `clientmaster` order by client_code desc limit 1";
	$client_result = DB_query($client_sql ,$db);
	$client_rows = DB_fetch_array($client_result);
	$code = $client_rows['client_code']; 
	if($code != '')
	{
		$code_val1 = substr($code, 0,2);
		$code_val2 = substr($code, -3);
		$increment = $code_val2 + 1;
		$strFinal = $code_val1.str_pad($increment,3,"0",STR_PAD_LEFT);
	}
	else
	{
		$strFinal = 'CL001';
	}
	
	 
	          if($_REQUEST['item']!=''){
				$itemArray=$_REQUEST['item'];
				$itemIds=implode(",",$itemArray);
				}else{
				$itemIds='';
				}
	
	

						$sql = "INSERT clientmaster SET
						`client_code`	='".$strFinal."',
						`c_name`		='".$_POST['c_name']."', 
						`short_name`	='".$_POST['short_name']."',  
						`tax`			='".$_POST['tax']."',  
						`cust_cate`		='".$_POST['cust_category']."',
						`industry_type`		='".$_POST['indust_type']."',  
						`payment_terms`	='".$_POST['payment_terms']."',
						`ledger_id`		='".$_POST['ledger_id']."',
						`ccategory`		='".$_POST['ccategory']."', 
						`pre_address1`	='".$_POST['pre_address1']."',
						`pre_address2`	='".$_POST['pre_address2']."',
						`pre_address3`	='".$_POST['pre_address3']."',  
						`pre_area`		='".$_POST['pre_area']."', 
						`fax`			='".$_POST['pre_fax']."', 
						`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']."',
						`lst_no`		='".$_POST['lst_no']."', 
						`cst_no`		= '".$_POST['cst_no']."', 
						`excies_no`		='".$_POST['excies_no']."',  
						`pan_no` 		= '".$_POST['pan_no']."',
						`tin_no` 		= '".$_POST['tin_no']."',
						`Extension`		='".$_POST['pre_ext']."',
						`pre_phone1`	='".$_POST['pre_phone1']."',
						`pre_phone2`	='".$_POST['pre_phone2']."',
						`cl_range`		='".$_POST['cl_range']."',
						`cl_division`	='".$_POST['cl_division']."',
						`Site`			='".$_POST['Site']."',
						`Store`			='".$_POST['dealer']."',
						`Zone`			='".$_POST['areacode']."',	
						`engineer`		='".$_POST['engineer_code']."',	
						`pnf_charges`	='".$_POST['pnf_charges']."',
						`discount`		='".$_POST['DISCOUNT']."',
						`freight_charges`='".$_POST['freight_charges']."',
						`incidental_charges`='".$_POST['incidental_charges']."',
						`service_tax_no`='".$_POST['service_tax_no']."',
						`commisinerate`='".$_POST['commisinerate']."',						
						`CompanyId`		='".$_POST['CompanyName']."',
						`subzone`		='".$_POST['subzone']."',
						`dealer`		='".$_POST['dealer']."',
						`assigned_items`='".$itemIds."'";
						
						
						$res = DB_query($sql,$db,$ErrMsg,$DbgMsg);
					  	$lastid=DB_Last_Insert_ID($db,'clientmaster', 'id')		;
						
					$data['AccountName']=$_POST['c_name'];
					$data['vender_client']=DB_Last_Insert_ID($db,'clientmaster', 'id');
					$data['UnderGroup']=$_POST['ledger_id'];
					$data['CompanyId']=1;
					$data['ledgertype']='client';
						$rowinsert= $s->RecordInsert('accountledger', $data);

	
						
						

					for($CR=1;$CR<$_REQUEST['cnt'];$CR++)
					{
						 $insert_contact="Insert into contact_information_master set
												id='', 
												master_code='".$lastid."',  
												master_prefix='C',  
												person ='".$_REQUEST['person'][$CR]."', 
												designation='".$_REQUEST['designation'][$CR]."',  
												phone='".$_REQUEST['phone'][$CR]."',
												email='".$_REQUEST['contact_email'][$CR]."' ";	
						$insert_res=DB_query($insert_contact,$db);			
					}	
					
					 for($CR=0;$CR<=count($_REQUEST['chargedetails']);$CR++)
					{
					    if($_REQUEST['chk'][$CR]!='N' && $_REQUEST['chk'][$CR]!='' )
						{
						  $insert_contact1="Insert into dbl_customer_charges set
												id='', 
												parentid='".$_REQUEST['id']."',  
												chargeid ='".$_REQUEST['chargeid'][$CR]."', 
												status='".$_REQUEST['chk'][$CR]."'";	
						$insert_res1=DB_query($insert_contact1,$db);			
						}
				   
				   
				   
				 
				   }
					
					
					
					
					
					
					//echo "<pre>";
					//print_r($insert_contact);	 exit;
 $s->pageLocation('index.php?route=DealerDistrbutions/Show_client&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
?>
<style type="text/css">
.mandatory{
 color:#FF0000;
}
.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: 9px 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>
<?php
if(isset($_POST['update'])){
				
				  
				$itemArray='';
				if($_REQUEST['item']!=''){
				$itemArray=$_REQUEST['item'];
				$itemIds=implode(",",$itemArray);
				}else{
				$itemIds='';
				}
				
			 	$sql = "Update clientmaster SET
				`c_name`		='".$_POST['c_name']."', 
				`short_name`	='".$_POST['short_name']."',  
				`ccategory`		='".$_POST['ccategory']."',
				`tax`			='".$_POST['tax']."',
				`cust_cate`		='".$_POST['cust_category']."',
				`industry_type`	='".$_POST['indust_type']."',
				`payment_terms`	='".$_POST['payment_terms']."', 
				`ledger_id`		='".$_POST['ledger_id']."',    
				`pre_address1`	='".$_POST['pre_address1']."',
				`pre_address2`	='".$_POST['pre_address2']."',
				`pre_address3`	='".$_POST['pre_address3']."',  
				`pre_area`		='".$_POST['pre_area']."', 
				`fax`			='".$_POST['pre_fax']."', 
				`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']."',
				`lst_no`		='".$_POST['lst_no']."', 
				`cst_no`		= '".$_POST['cst_no']."', 
				`excies_no`		='".$_POST['excies_no']."',  
				`pan_no` 		= '".$_POST['pan_no']."',
				`tin_no` 		= '".$_POST['tin_no']."',
				`Extension`		='".$_POST['pre_ext']."',
				`pre_phone1`	='".$_POST['pre_phone1']."',
				`pre_phone2`	='".$_POST['pre_phone2']."',
				`cl_range`		='".$_POST['cl_range']."',
				`cl_division`	='".$_POST['cl_division']."',
				`Site`			='".$_POST['Site']."',
				`Store`			='".$_POST['dealer']."',
				`Zone`			='".$_POST['areacode']."',
				`pnf_charges`	='".$_POST['pnf_charges']."',
				`discount`		='".$_POST['DISCOUNT']."',
				`freight_charges`='".$_POST['freight_charges']."',
				`incidental_charges`='".$_POST['incidental_charges']."',
				`service_tax_no`='".$_POST['service_tax_no']."',
				`commisinerate`='".$_POST['commisinerate']."',						
				`CompanyId`		='".$_POST['CompanyName']."',
				`subzone`		='".$_POST['subzone']."',
				`engineer`		='".$_POST['engineer_code']."',	
				`dealer`		='".$_POST['dealer']."',
				`assigned_items`='".$itemIds."'
				 where id='".$_GET['id']."' ";
				//echo "<pre>";
//				print_r($sql); exit;
				$res = DB_query($sql,$db,$ErrMsg,$DbgMsg);
	


	
$data['AccountName']=$_REQUEST['c_name'];
$data['vender_client']=$_GET['id'];
 $data['UnderGroup']=$_REQUEST['ledger_id'];
$data['CompanyId']=1;
$data['ledgertype']='client';


$chkledgerExist=DB_query("select * from accountledger where AccountName='".$_REQUEST['c_name']."' and UnderGroup='".$_REQUEST['ledger_id']."' and ledgertype='client'",$db);
if(DB_num_rows($chkledgerExist)==0)
{
 	$rowinsert= $s->RecordInsert('accountledger', $data);
 }
else
{
 $cond="AccountName='".$_REQUEST['c_name']."'";
 $rowinsert= $s->RecordEdit('accountledger', $data, $cond);
}
    if(count($_REQUEST['row_id'])>0)
   {
				
				for($c=1;$c<=count($_REQUEST['row_id']);$c++)
				{
 					if($_REQUEST['row_id'][$c]!=''){				
		     	 	$update_contact="Update contact_information_master set 
													person='".$_REQUEST['person'][$c]."', 
													designation='".$_REQUEST['designation'][$c]."',  
													phone='".$_REQUEST['phone'][$c]."',    
													email='".$_REQUEST['contact_email'][$c]."' 
													where  id='".$_REQUEST['row_id'][$c]."'";
													$update_res=DB_query($update_contact,$db);
													echo "<br>";
				   }else
				   {
				   
				     $insert_contact="Insert into contact_information_master set
												id='', 
												master_code='".$_REQUEST['id']."',  
												master_prefix='C',  
												person ='".$_REQUEST['person'][$c]."', 
												designation='".$_REQUEST['designation'][$c]."',  
												phone='".$_REQUEST['phone'][$c]."',
												email='".$_REQUEST['contact_email'][$c]."' ";	
						$insert_res=DB_query($insert_contact,$db);			
				   
				   }
				   }
				   
				   
				   $del=DB_query("delete from dbl_customer_charges where parentid='".$_REQUEST['id']."'",$db);
				   
				   
				  
				   for($CR=0;$CR<=count($_REQUEST['chargedetails']);$CR++)
					{
					    if($_REQUEST['chk'][$CR]!='N' && $_REQUEST['chk'][$CR]!='' )
						{
						  $insert_contact1="Insert into dbl_customer_charges set
												id='', 
												parentid='".$_REQUEST['id']."',  
												chargeid ='".$_REQUEST['chargeid'][$CR]."', 
												status='".$_REQUEST['chk'][$CR]."'";	
						$insert_res1=DB_query($insert_contact1,$db);			
						}
				   
				   
				   
				 
				   }
  }
				
		$s->pageLocation('index.php?route=DealerDistrbutions/Show_client&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
			}
?>
<style type="text/css">
    .cap{
    text-transform:uppercase
    };
	</style>
<?php 
if($_GET['action']=='editRec')
{
$SQL =  "select * from clientmaster Where clientmaster.id='".$_GET['id']."' "; 
$result = DB_query($SQL,$db,$ErrMsg);
$row = DB_fetch_assoc($result);
//echo "<pre>";
//print_r($row);
$c_name	= $row['c_name'];
$short_name= $row['short_name'];
$ccategory= $row['ccategory'];
$tax=$row['tax'];
$payment_terms=$row['payment_terms'];
$ledger_id=$row['ledger_id'];
$code= $row['client_code'];
$industry_type=$row['industry_type'];
$engineer_code=$row['engineer'];
$cust_cate=$row['cust_cate'];
$pre_address1= $row['pre_address1'];
$pre_address2= $row['pre_address2'];
$pre_address3= $row['pre_address3'];
$pre_area= $row['pre_area'];
$pre_country=  $s->GetFieldValue('city_master',"id='".$row['pre_city']."'" ,'country');  
$pre_state=  $s->GetFieldValue('city_master',"id='".$row['pre_city']."'" ,'state');
$pre_city= $row['pre_city'];
$pre_pincode= $row['pre_pincode'];
$pre_ext= $row['Extension'];
$pre_phone1= $row['pre_phone1'];
$pre_phone2= $row['pre_phone2'];
$pre_fax= $row['fax'];
$pre_mobile= $row['pre_mobile'];
$per_email= $row['per_email'];
$lst_no= $row['lst_no'];
$cst_no= $row['cst_no'];
$excies_no= $row['excies_no'];
$company_req_date= $row['company_req_date'];
$pan_no= $row['pan_no'];
$Store= $row['Store'];
$tin_no= $row['tin_no'];
$cl_division =$row['cl_division'];
$cl_range =$row['cl_range'];
$assigned_items =$row['assigned_items'];
$Site=$row['Site'];
$Zone=$row['Zone'];
$pnf_charges=$row['pnf_charges'];
$discount=$row['discount'];
$freight_charges=$row['freight_charges'];
$incidental_charges=$row['incidental_charges'];
$service_tax_no=$row['service_tax_no'];
$commisinerate=$row['commisinerate'];	
$division=$row['division'];						
$subzone=$row['subzone'];
$company=$row['CompanyId'];
$dealer=$row['dealer'];
}
else
{
$c_name	= $_REQUEST['c_name'];
$Store=$_REQUEST['Dealer'];
$short_name= $_REQUEST['short_name'];
$ccategory= $_REQUEST['ccategory'];
$tax= $_REQUEST['tax'];
$engineer_code=$_REQUEST['engineer_code'];
$payment_terms= $_REQUEST['payment_terms'];
$ledger_id=$_REQUEST['ledger_id'];
$code= $_REQUEST['code'];
$pre_address1= $_REQUEST['pre_address1'];
$pre_address2= $_REQUEST['pre_address2'];
$pre_address3= $_REQUEST['pre_address3'];
$pre_area= $_REQUEST['pre_area'];
$pre_country= $_REQUEST['pre_country'];
$pre_state= $_REQUEST['pre_state'];
$pre_city= $_REQUEST['pre_city'];
$pre_pincode= $_REQUEST['pre_pincode'];
$pre_ext= $_REQUEST['pre_ext'];
$pre_phone1= $_REQUEST['pre_phone1'];
$pre_phone2= $_REQUEST['pre_phone2'];
$pre_fax= $_REQUEST['pre_fax'];
$pre_mobile= $_REQUEST['pre_mobile'];
$per_email= $_REQUEST['per_email'];
$lst_no= $_REQUEST['lst_no'];
$cst_no= $_REQUEST['cst_no'];
$excies_no= $_REQUEST['excies_no'];
$pan_no= $_REQUEST['pan_no'];
$tin_no= $_REQUEST['tin_no'];
$cl_division =$_REQUEST['cl_division'];
$cl_range =$_REQUEST['cl_range'];

for($m=1;$m<$_REQUEST['cnt'];$m++)
{
		$person=$_REQUEST['person'][$m];
		$designation=$_REQUEST['designation'][$m];	
		$phone=$_REQUEST['phone'][$m];	
		$contact_email=$_REQUEST['email'][$m];
}
}
?>
<link rel="stylesheet" href="css/new_mxerp1.css">
<div class="body_contain">
<div class="tab_div">
<h1>Customer Master</h1>
<form  enctype="multipart/form-data" method="post" action="" onsubmit="return validation(this.form);">
<input type="hidden" name="id" value="<?php if(isset($row['id'])) echo $row['id']; ?>" />
<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="#">STATUATORY DETAILS</a></h3></div>
		<!--<div class="tab"><h3 class="tabtxt" title="fifth" style="border:none;"><a href="#">PRODUCT ASSIGNMENT</a></h3></div>-->
		<div class="tab"><h3 class="tabtxt" title="fifth" style="border:none;"><a href="#">CLIENT POLICY & CHARGES DETAILS</a></h3></div>
<div class="tab"><h3 class="tabtxt" title="fifth" style="border:none;"><a href="#">OTHER DETAILS</a></h3></div>			
		<div class="boxholder">
			<div class="box"><fieldset><legend><strong>General Informations</strong></legend>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
      <td class="tabledata1"><strong>Company<span class="mandatory"><strong>*</strong></span></strong></td>
      <td>
	  <?php if(!isset($_SESSION['dealerid']))
	    $onchage='onchange="showroles(this.value)"';
	  else
	  $onchage='';
	  ?>
	  <select name="CompanyName" id="CompanyName" style="width:150px;" <?php echo $onchage; ?> >
			<?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>Customer  Name<span class="mandatory"><strong>*</strong></span></strong></td>
      <td><input   name="c_name" type="text" class="cap" id="c_name" value='<?php if(isset($c_name)) echo $c_name; ?>' style="width:150px;"maxlength="60" />      </td>
		</tr>
<tr class="row1">
      <td class="tabledata1"><strong>Short Name </strong></td>
      <td><input name="short_name" type="text" class="cap" id="short_name" value='<?php if(isset($short_name)) echo $short_name; ?>'  style="width:150px;"/></td>
      <td class="tabledata1"><strong>Associate<span class="mandatory"><strong>*</strong></span></strong></td>
      <td>
	<select name="dealer" id="dealer" style="width:150px;" onchange="GetMarginfac(this.value)">
		<?php 
	if($_SESSION['dealerid']!=0)
	{
	$dea=DB_query("select * from dbl_dealer where  company='".$_SESSION['ACGCompanyId']."' and id='".$_SESSION['dealerid']."'",$db);
	$sql2= "select * from dbl_dealer where  company='".$_SESSION['ACGCompanyId']."' and id='".$_SESSION['dealerid']."'";
	}
	else
	{
	$dea=DB_query("select * from dbl_dealer where  company='".$_SESSION['ACGCompanyId']."'",$db);
	$sql2= "select * from dbl_dealer where  company='".$_SESSION['ACGCompanyId']."'";
	}
	while($dea1=DB_fetch_array($dea))
	{
	?>
	<option value="<?php echo $dea1['id']; ?>" <?php echo($dealer==$dea1['id']?'selected':'');?>><?php echo $dea1['dealer_name']; ?></option>
	<?php } ?>
	</select>
	<?php //echo $sql2; ?>
	<div id="mrgfact" style="display:none;">
	<input type="text" name="dealerMarFac" id="dealerMarFac" value="">
	</div>	</td>  
		</tr>
<tr class="row1">
      <td class="tabledata1"><strong>Customer Code</strong></td>
      <td>
	  <?php if(isset($_GET['id']) && $_GET['id'] != '')
	  { ?>
	  <input type="text" name="code" value="<?php echo $code; ?>" id="code" readonly="true" style="width:150px;"/>
	  <?php } 
	  else {?>
  	 <input name="code" type="text" id="code" value="Will be generated on saving" style="width:150px;" readonly="true"/>
   <?php } ?></td>
  
      <td class="tabledata1"><strong>Area</strong></td>
      <td>  
   <select name="areacode" style="width:150px;" onchange="showzone(this.value)" id="areacode">
     
     <?php
	 if($_SESSION['dealerid']!=0)
	 {
	 $dealerzone=$s->getField('dbl_dealer','id',$_SESSION['dealerid'],'area_code');
	 $ZoneName=DB_query("SELECT DISTINCT ZoneTitle,id FROM zone_master where CompanyId='".$_SESSION['ACGCompanyId']."' and id='".$dealerzone."'",$db);
	 }
	 else
	 {
	 ?>
	 <option value="0">--Select--</option>
	<?php		
	$ZoneName=DB_query("SELECT DISTINCT ZoneTitle,id FROM zone_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	}
	while($ZoneRow=DB_fetch_array($ZoneName))
	{ ?>
     <option value="<?php echo $ZoneRow['id']?>"<?php echo($Zone==$ZoneRow['id']?'selected':'');?>><?php echo $ZoneRow['ZoneTitle']?></option>
     <?php	}
			
			   
			?>
   </select></td>
   </tr>
<tr class="row1">
      <td class="tabledata1"><strong>Sub Area Code<span class="mandatory"><strong>*</strong></span></strong></td>
   <?php 
   	$acc_sql="Select GroupId from accountgroupmaster where GroupName LIKE '%debtor%' and MainGroupId='0'";
  	$acc_res=DB_query($acc_sql,$db);
  	$acc_row=DB_fetch_array($acc_res);
   	$AccountId=$acc_row['GroupId'];
 
   ?>
   <td><div id="subareacode">
   <select name="subarea_code" id="subarea_code" style="width:150px;" >
	     <?php
		 if($_SESSION['dealerid']!=0)
	     {	
		 $sql=DB_query("select * from subzone_master where zone='".$dealerzone."'",$db);
		 }
		 else
		 { 
		 ?>
		 <option value="0">Select</option>
		 <?php
		 $sql=DB_query("select * from subzone_master ",$db);
		 }
		 while($row=DB_fetch_array($sql))
		 { 
		 ?>
	     <option value="<?php echo $row['id']; ?>" <?php echo($subarea_code==$row1['id']?'selected':'');?>><?php echo $row['subzone']; ?></option>
		 <?php } ?>
		 </select></div></td>
      <td class="tabledata1"><strong>Pneumatic  potential</strong></td>
   	<td><input type="text" name="pneumatic" value="<?php echo $pneumatic; ?>" id="pneumatic"  style="width:150px;"/></td>
</tr>
<tr class="row1">
      <td class="tabledata1"><strong>Account Group </strong></td>
	   <?php 
		$acc_sql="Select GroupId from accountgroupmaster where GroupName LIKE '%sale%' and MainGroupId='0'";
		$acc_res=DB_query($acc_sql,$db);
		$acc_row=DB_fetch_array($acc_res);
		$AccountId=$acc_row['GroupId'];?>
   <td>
   <select name="ledger_id" id="ledger_id" style="width:150px;">
   
   <?php 
   	$account_sql=DB_query("Select GroupId,GroupName from accountgroupmaster where MainGroupId='".$AccountId."'",$db);
   	while($account_res=DB_fetch_array($account_sql))
	{?>
	<option value="<?php echo $account_res['GroupId'];?>"<?php echo ($ledger_id==$account_res['GroupId']?'selected':'')?>><?php echo $account_res['GroupName']?></option>
	<?php 	
	}
   ?>
   </select></td>
   <td class="tabledata1"><strong>Customer Catagory</strong></td>
   <td>
   		<select name="cust_category" id="cust_category" style="width:150px;">
			<option value="">Select</option>
			<?php $sql12A=DB_query("SELECT * FROM customer_category where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
			while($cateCust=DB_fetch_array($sql12A)){
			$sqlw1='';
			if($cust_cate==$cateCust['id'])
			$sqlw1='selected';
			
			?>
			<option value="<?php echo $cateCust['id']; ?>" <?php echo $sqlw1; ?>><?php echo $cateCust['cust_cate']; ?></option>
			<?php }?>
		</select>   </td>
   	</tr>
<tr class="row1">
	 <td class="tabledata1"><strong>Industry Type</strong></td>
   <td><select name="indust_type" id="indust_type" style="width:150px;">
			<option value="">Select</option>
			<?php $sql12A1=DB_query("SELECT * FROM industry_type where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
			while($indtype=DB_fetch_array($sql12A1)){
			$sqlw11='';
			if($industry_type==$indtype['id'])
			$sqlw11='selected';
			?>
			<option value="<?php echo $indtype['id']; ?>" <?php echo $sqlw11; ?>><?php echo $indtype['industry_type']; ?></option>
			<?php }?>
		</select>   </td>
   <td><strong>Engineer </strong></td>
      <td><select name="engineer_code" id="engineer_code" style="width:150px;">
	<option value="0">Select</option>
	   <?php
	   if($_SESSION['dealerid']!=0)
	    {
		 $sql=DB_query("select * from dbl_engineer_dealer_maste  where dealer='".$_SESSION['dealerid']."'",$db);
		 }
		 else
		 {
		 $sql=DB_query("select * from dbl_engineer_dealer_maste where company='".$_SESSION['ACGCompanyId']."'",$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>
</tr>
</table>
</fieldset></div>
<div class="box">
<fieldset><legend><strong>ADDRESS & Communication Details</strong></legend>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
    <td class="taledata1" rowspan="2"><p><strong> Address<span class="mandatory"><strong>*</strong></span></strong></p>      </td>
   	<td rowspan="2">
    <textarea  name="pre_address1" id="pre_address1" style="width:150px;"><?php if(isset($pre_address1)) echo $pre_address1; ?></textarea></td>
    <td class="taledata1"><strong>Pin Code</strong></td>
    <td><input type="text" id="pre_pincode" name="pre_pincode" onblur="chkpincode()" style="width:150px;" value='<?php if(isset($pre_pincode)) echo $pre_pincode; ?>'></td>
  </tr>
<!--<tr class="row1">
    <td class="taledata1"><strong>Extension</strong></td>
    <td><input type="text" id="pre_ext" name="pre_ext" style="width:150px;" value='<?php if(isset($pre_ext)) echo $pre_ext; ?>' /></td>
  </tr>-->
<tr class="row1">
    <td class="taledata1"><strong>Phone </strong></td>
    <td><input type="text" id="pre_phone1"   name="pre_phone1" style="width:150px;" value='<?php if(isset($pre_phone1)) echo $pre_phone1; ?>' /></td>
  </tr>
<tr class="row1">
    <td class="taledata1"><strong>Area</strong></td>
    <td><input   name="pre_area" type="text" class="cap" id="pre_area" value='<?php if(isset($pre_area)) echo $pre_area; ?>' style="width:150px;"  /></td>
    <td class="taledata1"><strong>Phone 2</strong></td>
    <td><input type="text" id="pre_phone2" name="pre_phone2" style="width:150px;" value='<?php if(isset($pre_phone2)) echo $pre_phone2; ?>' /></td>
  </tr>
<tr class="row1">
    <td class="taledata1"><strong>City<span class="mandatory"><strong>*</strong></span></strong></td>
    <td><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>
    <td class="taledata1"><strong>Fax</strong></td>
    <td><input type="text" id="pre_fax" name="pre_fax" style="width:150px;" value='<?php if(isset($pre_fax)) echo $pre_fax; ?>' /></td>
  </tr>
<tr class="row1">
    <td class="taledata1" colspan="2" style="padding:0px; margin:0px;"><div id="searchstate">
	  <table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
    <td class="taledata1" width="27%"><strong>State</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="taledata1"><strong>Country</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="taledata1"><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="taledata1"><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 INFORMATION</strong></legend>
<table width="100%" cellpadding="3" cellspacing="0" >	
<?php
if($_REQUEST['action']=='editRec')
{
  $contact_sql="Select * from contact_information_master 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];?>" />
	  <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];?>"  /></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];?>" size="15" 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" /></td>
    </tr>
 		<?php $k++; } ?>	
	<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];?>"  />
	<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];?>"  /></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];?>" size="15" 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" /></td></tr>
<?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];?>" />
	  <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];?>"  /></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];?>" size="15" 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" /></td>
    </tr>
<?php 
}
}  
 
?>



<input type="hidden" name="cnt" id="cnt" value="<?php echo $j;?>"/>
</table>
</fieldset>
			</div>			
			<div class="box">
			<fieldset><legend><strong>Statutory  Details</strong></legend>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1"><strong>Excise No</strong></td>
   <td colspan="2"><input type="text" id="excies_no" onblur="chkexciseno()"   name="excies_no" style="width:150px;" value='<?php if(isset($excies_no)) echo $excies_no; ?>' /></td>
   <td class="tabledata1"><strong>PAN No.</strong></td>
   <td><input type="text" id="pan_no"   name="pan_no" onblur="return checkpanno()" style="width:150px;" value='<?php if(isset($pan_no)){echo $pan_no ;} ?>'/></td>
</tr>
	
	<tr class="row1">
     <td class="tabledata1"><strong>Tin No.</strong></td>
      <td colspan="2"><input type="text" id="tin_no" onblur="chktinNo()"   name="tin_no" style="width:150px;" value='<?php if(isset($tin_no)) echo $tin_no; ?>' /></td>
    <td class="tabledata1"><strong>CST No. </strong></td>
	<td><input type="text" id="cst_no"   name="cst_no" style="width:150px;" value='<?php if(isset($cst_no)) echo $cst_no; ?>' /></td>
	</tr>
	<tr class="row1">
     <td class="tabledata1"><strong>Service Tax No.</strong></td>
      <td colspan="2"><input type="text" id="service_tax_no"   name="service_tax_no" style="width:150px;" value='<?php if(isset($service_tax_no)) echo $service_tax_no; ?>'></td>
        	</tr>
</table>
</fieldset>
			</div>
			<!--<div class="box"><fieldset><legend><strong>ASSIGN ITEMS</strong></legend>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
<td class="tabledata1" width="25%"><strong>
    	Enter Part Name Of Item
    	</strong></td>
    	<td colspan="4"><input type="text" name="itemName" value="" onkeyup="showItems(this.value)" style="width:150px;" /></td>
    </tr>
	
<tr class="row1">
<td class="tabledata1"><strong>Items</strong></td>
    <td colspan="4"><div id="itemid">
	<div style="overflow:auto; height:150px; width:500px; border:1px solid; " >
	<?php 
	$items=explode(",",$assigned_items);
	//print_r($items);
	
	$item_sql=DB_query("select id,StockID,item_name from item_master ",$db);
	$c3=0;
	while($row3=DB_fetch_array($item_sql))
	{ 
		$checked='';
		for($x=0;$x<count($items);$x++)
		{	
			 if($items[$x]==$row3['id'])
			 $checked="checked";
		}
		
		
	?>
	<input type="checkbox" name="item[<?php echo $c3;?>]" id="item_<?php echo $c3;?>" value="<?php echo $row3['id'];?>" <?php echo $checked;?>/><?php echo $row3['StockID']." - ".$row3['item_name'];?><br />
	<?php 	
	$c3++;
	}
	?>
	</div>
		
	</div></td>
  </tr>
</table>
</fieldset></div>-->
<div class="box">
			<fieldset><legend><strong>Client Policy & Charges Details</strong></legend>
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
<td width="46%">
<h1>Policy Setting</h1>
<table width="100%">
<tr class="row1">
 <td width="51%" class="tabledata1"><strong>Margin Factor<span class="mandatory"><strong>*</strong></span></strong></td>
      <td width="49%"><input type="text" name="marginfac" id="marginfac" style="width:150px;"  value='<?php if(isset($margin_factor)) {echo $margin_factor;}else{echo '1';} ?>' onKeyUp="ChkmarginFactor(this.value)" />	</td>

</tr>
<tr class="row1">
<td class="tabledata1"><strong>Discount.</strong></td>
   <td><input type="text" id="DISCOUNT"   name="DISCOUNT" style="width:150px;" value='<?php if(isset($discount)){echo $discount ;} ?>'/></td>


</tr>

<tr class="row1">
<td class="taledata1"><strong>Range </strong></td>
    <td><input type="text" name="cl_range" id="cl_range" style="width:150px;" value="<?php echo $cl_range;?>" /></td>

   
</tr>
<tr class="row1">
	<td class="taledata1"><strong>Commisinerate</strong></td>
    <td colspan="3"><input type="text" name="commisinerate" id="commisinerate" style="width:150px;" /></td>
</tr>
<tr class="row1">
	<td class="taledata1"><strong>Division</strong></td>
    <td colspan="3"><input type="text" name="cl_division" id="cl_division" style="width:150px;" value="<?php echo $cl_division;?>" /></td>
</tr>
<tr class="row1">
	<td class="taledata1"><strong>P & F</strong></td>
    <td colspan="3"><input type="text" name="pnf_charges" id="pnf_charges" style="width:150px;" value="<?php echo $pnf_charges;?>" /></td>
</tr>
<tr class="row1">
	<td class="taledata1"><strong>Incidental Charges</strong></td>
    <td colspan="3"><input type="text" name="incidental_charges" id="incidental_charges" style="width:150px;" value="<?php echo $incidental_charges;?>" /></td>
</tr>
</table>
</td>
<td width="54%" valign="top">
<h1>Charge Details</h1>
<table width="101%" height="88">
<?php

if($_REQUEST['action']=='editRec')
{
$sql1=DB_query("select * from dbl_customer_charges where parentid='".$_REQUEST['id']."'",$db);
while($row2=DB_fetch_array($sql1))
{
$assign_data[]=$row2['chargeid'];
}
if(!empty($assign_data))
$assign1=implode(",",$assign_data);
else
$assign1='';

}


$i=1; 
$sql_charges=DB_query("select * from dbl_dealer_charge_master where company='".$_SESSION['ACGCompanyId']."'",$db);
while($row=DB_fetch_array($sql_charges))
{
$c=''; 
if($assign_data!='')
{
if(in_array($row['id'],$assign_data))
{
$c='checked="checked"';
}
}
else
$c='';
 ?>

<tr class="row1">
<td width="23%" class="tabledata1"><strong><?php echo $row['charge_name']; ?></strong></td>
<td width="44%" valign="top"><input type="text" id="chargedetails"   name="chargedetails[]" style="width:150px;" value='<?php echo $row['taxrate']; ?>' readonly="readonly"   >
<input type="hidden" name="chargeid[<?php echo $i; ?>]" value="<?php echo $row['id']; ?>"  />
</td>
<td width="33%"><input type="checkbox" name="chk[<?php echo $i; ?>]" id="chk_<?php echo $i; ?>"  value="Y" <?php echo $c; ?>>Active
<input type="checkbox" name="chk[<?php echo $i; ?>]" id="chk_<?php echo $i; ?>"  value="N" >InActive
</td>

</tr>
<?php $i++; } ?>

</table>



</td>
</table>
</fieldset>
			</div>
			
<div class="box">
			<fieldset><legend><strong>Others Details</strong></legend>

</fieldset>
			</div>			


						
			
			
			
			
		</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></table>
    <script type="text/javascript">
	Element.cleanWhitespace('content');
	init();
</script>
</form>
<script>
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 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("areacode").innerHTML=data[1];
	
    }
  }
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("c_name").value=='')
	{
		alert("Please Fill Customer Name First");
		document.getElementById("c_name").focus();
		return false;
	}
	if(document.getElementById("dealer").value=='')
	{
		alert("Please Select The Associate First");
		document.getElementById("dealer").focus();
		return false;
	}
	
	if(document.getElementById("areacode").value=='0')
	{
		alert("Please Select The Area First");
		document.getElementById("areacode").focus();
		return false;
	}
	
	
	if(document.getElementById("subzone").value=='0')
	{
		alert("Please Select The Sub Area First");
		document.getElementById("subzone").focus();
		return false;
	}
	
	
	if(document.getElementById("pneumatic").value=='')
	{
		alert("Please Fill The Pneumatic First");
		document.getElementById("pneumatic").focus();
		return false;
	}
	
	if(document.getElementById("engineer_code").value=='0')
	{
		alert("Please Select The Engineer  First");
		document.getElementById("engineer_code").focus();
		return false;
	}
	if(document.getElementById("subarea_code").value=='0')
	{
		alert("Please Select The Sub Area Code First");
		document.getElementById("subarea_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;
	}
	
	
	
	
	
	
	
	
}

function ChkmarginFactor(val)
{
	var dealermf=document.getElementById("dealerMarFac").value;
	if(dealermf=='')
	{
		alert("First Select The Associate");
		return false;
	}
	else
	{
		if(val>dealermf)
		{
			alert("You Can Not Take Margin Factor Greater Than Dealer Margin Factor");
			document.getElementById("marginfac").value='';
			document.getElementById("marginfac").focus();
			return false;
		}
	}
}


function GetMarginfac(val)
{
	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("mrgfact").innerHTML=data[1];
	document.getElementById("areacode").innerHTML=data[0];
	
	}
	}
	xmlhttp.open("GET","GetmrgFact.php?dealerId="+val,true);
	xmlhttp.send();
	
}


function checkpanno()
{
var obj=document.getElementById("pan_no").value;
 var regpan = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;

if(regpan.test(obj) == false)
{
alert("Permanent Account Number is not yet valid.");
document.getElementById("pan_no").value='';
document.getElementById("pan_no").focus();
return false;
}
}


function chktinNo()
{
	var tinno=document.getElementById("tin_no").value;
	var tinlength=tinno.length;
	if(tinlength<11 || tinlength>11)
	{
		alert("TIN No Should 11 Digit");
		document.getElementById("tin_no").value='';
		document.getElementById("tin_no").focus();
		return false;
	}
}


function chkpincode()
{
	var pinno=document.getElementById("pre_pincode").value;
	var pinnolength=pinno.length;
	if(pinnolength<6 || pinnolength>6)
	{
		alert("PIN No Should 6 Digit");
		document.getElementById("pre_pincode").value='';
		document.getElementById("pre_pincode").focus();
		return false;
	}
}

function chkexciseno()
{
	var exno=document.getElementById("excies_no").value;
	var Exclength=exno.length;
	if(Exclength<15 || Exclength>15)
	{
		alert("Excise No Should 15 Digit");
		document.getElementById("excies_no").value='';
		document.getElementById("excies_no").focus();
		return false;
	}
}


function showactive(str)
{


}
</script>
  