<?php 
if($_REQUEST['action']='Edit')
{
	$GetSQL=DB_query("select * from crm_accounts_new where accid='".$_REQUEST['AccID']."'",$db);
	$GetDetail=DB_fetch_array($GetSQL);
	extract($GetDetail);
}
?>
<?php 
error_reporting(0);  
//****************MODIFY BY AMIT SINGH ************D&D************************23-11-2012*********************************
include('Class_PickListEditor.php');
include("Class_Branch.php");
include("ClassRole.php");
//echo  $_REQUEST['action'];
$catid= $s->GetFieldValue('crm_picklist',"picklist_title='Leads' and status=1",'picklist_id');

$catid= $s->GetFieldValue('crm_picklist',"picklist_title='Leads' and status=1",'picklist_id');
$table="crm_accounts_new";
$max_size='2000';
$flag=0;
function extension($filename)
{
$name_brk=explode('.',$filename);
return  $name_brk[1];
}
  


//************************SAVE RECORDS IN THE TABLES*************************START HERE***********************************
if($_REQUEST['Save']!='')
{
 echo $_FILES['leadfile']['size'];
 exit;


$cilentcode=DB_query("select * from clientmaster",$db);
if(DB_num_rows($cilentcode)>0)
{
	$ClCOdeSQL=DB_query("select client_code from clientmaster order by id desc limit 1",$db);
	$CliCode=DB_fetch_array($ClCOdeSQL);
	$CliCode['client_code'];
	$Exp=explode("-",$CliCode['client_code']);
	$finid=$Exp[1]+1;
	$finalAccCode=$Exp[0].'-'.$finid;
}
else
{
	$finalAccCode='Account'.'-'.'1';
}
		$datax['c_name']=$_REQUEST['clientname'];
		$datax['client_code']=$finalAccCode;
		$datax['Site']=$_REQUEST['mst_branchid'];
		$datax['pre_address1']=$_REQUEST['address'];
		$datax['pre_phone1']=$_REQUEST['phone'];
		$datax['fax']=$_REQUEST['fax'];
		$datax['pre_mobile']=$_REQUEST['mobile'];
		$datax['per_email']=$_REQUEST['email'];
		$datax['pre_state']=$_REQUEST['state'];
		$datax['pre_city']=$_REQUEST['city'];
		$datax['pre_country']=$_REQUEST['country'];
		$datax['pre_pincode']=$_REQUEST['zipcode'];
		//$datax['client_code']="AC-".$_REQUEST['AccountName'];
		$datax['Zone']='25';
		$s->RecordInsert('clientmaster', $datax);//NEW CLIENT INTO CLIENTMASTER
		$lastid=DB_Last_Insert_ID($db,'clientmaster', 'id');
		
		$data23['ledgertype']='client';
		$data23['UnderGroup']=$s->GetFieldValue('accountgroupmaster',"GroupName='Sundry Creditor'  ",'GroupId');
		$data23['AccountName']=$_REQUEST['clientname'];
		$data23['openingdate']=date('Y-m-d');
		$data23['CompanyId']=$_SESSION['ACGCompanyId'];
		//$data['vender_client']=$_REQUEST['leadid'];
		$s->RecordInsert('accountledger', $data23);//CREATE NEW ACCOUNT IN ACCOUNTLEDGER
		
		
		$data3['master_code']=$lastid;
		$data3['master_prefix']='C';
		$data3['person']=$_REQUEST['contact_name'];
		$data3['department']=$_REQUEST['department'];
		$data3['designation']=$_REQUEST['designation'];
		$data3['phone']=$_REQUEST['phone'];
		$data3['email']=$_REQUEST['email'];
		$s->RecordInsert('contact_information_master', $data3);
		
				
		
	
	
	
	$data['branch']=$_REQUEST['mst_branchid'];
	$data['store']=$_REQUEST['store'];
	$data['accdate']=ConvertSQLDate($_REQUEST['Acc_date']);
	$data['account_code']=$finalAccCode;
	$data['client']=$lastid;
	$data['contact_person']=$_REQUEST['contact_name'];
	$data['group_name']=$_REQUEST['groupname'];
	$data['first_name']=$_REQUEST['fname'];
	$data['middle_name']=$_REQUEST['mname'];
	$data['last_name']=$_REQUEST['lname'];
	$data['department']=$_REQUEST['mst_departmentid'];
	$data['destination']=$_REQUEST['designation'];
	$data['address']=$_REQUEST['address'];
	$data['email_id']=$_REQUEST['email'];
	$data['phonno']=$_REQUEST['phone'];
	$data['mobile']=$_REQUEST['mobile'];
	$data['faxno']=$_REQUEST['fax'];
	$data['zipcode']=$_REQUEST['zipcode'];
	$data['country']=$_REQUEST['country'];
	$data['city']=$_REQUEST['city'];
	$data['state']=$_REQUEST['state'];
	$data['remark']=$_REQUEST['remark'];
	if($_REQUEST['groupid']!='0'){
	$data['group_id']=trim(implode(',',$_REQUEST['groupid']));
	}
	if($_REQUEST['leaduserid']){
	$data['asignto']=trim(implode(',',$_REQUEST['leaduserid']));
	}
	$data['created_by']=trim($_SESSION['UserID']);
	$data['CompanyId']=trim($_SESSION['ACGCompanyId']);
	
	$leadfile=$_FILES['leadfile']['name'];
	if($leadfile!=''){
	$type=extension($leadfile);
	
	$maxid=DB_query("select Max(accid) from crm_accounts_new",$db);
	$maxiddata=DB_fetch_array($maxid);
	$maxnumber=$maxiddata['Max(accid)']+1;
	

	 $tmp_name=$_FILES['leadfile']['tmp_name'];
	
	if($_FILES['leadfile']['size']>$max_size*1024)
	{
	echo "<strong>Sorry! Size Limit Exceeded</strong>";
	}
	 else
	 $new_name=$maxnumber.'.'.$type;
	 $path="CRM/AccDoc/";	
	if(move_uploaded_file($_FILES['leadfile']['tmp_name'],$path.$new_name))
	{
	
	echo "<strong>Copy Unsuccessful</strong>";
	
	}
	}
	$data['attach_file']=trim($new_name);
	$row= $s->RecordInsert($table, $data);
	$lastid=DB_Last_Insert_ID($db,'crm_accounts_new', 'accid');
	
	

	
	
	
	for($i=0;$i<count($_REQUEST['item_code']);$i++)
	{
	$data_arr['item_id']=$_REQUEST['item_code'][$i];
	$data_arr['qty']=$_REQUEST['stock_qty'][$i];
	$data_arr['per_unit']=$_REQUEST['stock_perunit'][$i];
	$data_arr['price']=$_REQUEST['stock_price'][$i];
	$data_arr['value']=$_REQUEST['stock_value'][$i];
	$data_arr['total_stock_qty']=$_REQUEST['total_stock'][$i];
	$data_arr['parant_id']=$lastid;
	$rowinsert= $s->RecordInsert('crm_accounts_new_details', $data_arr);
	}
	
	if($_REQUEST['leaduserid']!='')
	{
		for($i=0;$i<count($_REQUEST['leaduserid']);$i++)
		{
		$email[]=$s->GetFieldValue('www_users',"id='".$_REQUEST['leaduserid'][$i]."'",'email');
		}
	$emails=implode(",",$email);
	 $to=$emails;
	$subject="Hi This A New Enquiry For You";
	$message="Hi This is New Enquiry For You";
	$from="someonelse@example.com";
	$headers = "From:" . $from;
	mail($to,$subject,$message,$headers);
	echo 'mail successfully send';
	}
	
	
	$s->pageLocation("index.php?route=CRM/ViewAccounts".$rurl);
}
//************************SAVE RECORDS IN THE TABLES*************************END HERE***********************************

?>
<!------------------JS FILES---------------START HERE------------------------------------------------------------------->
<script type="text/javascript" language="javascript">
function addRow(tableID) 
{

	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	
	var newcell = row.insertCell(i);
	//newcell.style.background='#e7e7e7';
	newcell.className='tabledata';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id_hidden = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id_chk = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	document.getElementById("stock_perunit_"+rowCount).value='1';
}


function open_items()
{
var site=document.getElementById("mst_branchid").value;
var store=document.getElementById("store").value;
var date=document.getElementById("Acc_date").value;

window.open("TelephonicItems.php?site="+site+"&store="+store+"&date="+date+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}


function deleteRowOrder(tableID) 
{
	try 
	{
	var table = document.getElementById(tableID);
	//alert(table);
	var rowCount = table.rows.length;
	//alert(rowCount);
	for(var i=0; i<rowCount; i++) 
	{
	var row = table.rows[i];
	var chkbox = row.cells[0].childNodes[0];
	if(null != chkbox && true == chkbox.checked) 
	{
	if(rowCount <= 1) 
	{
	alert("Cannot delete all the rows.");
	break;
	}
	table.deleteRow(i);
	rowCount--;
	i--;
	}
	}
	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
	alert(e);
	}
}


function CalculateTotalLeadAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[2];
	// var stock_perunit = document.getElementById("stock_perunit_+"+i).value;
	if(id_brk.length>2)
	{
	var stock_perunit = document.getElementById("stock_perunit_"+i).value;
	var stock_price = document.getElementById("stock_price_"+i).value;
	var stock_qty = document.getElementById("stock_qty_"+i).value;
	document.getElementById("stock_value_"+i).value=(stock_price*stock_qty )/stock_perunit;
	document.getElementById("total_stock_"+i).value=document.getElementById("stock_qty_"+i).value;
	}
	else
	{
	var stock_perunit = document.getElementById("stock_perunit").value;
	var stock_price = document.getElementById("stock_price").value;
	var stock_qty = document.getElementById("stock_qty").value;
	document.getElementById("stock_value").value=(stock_price*stock_qty )/stock_perunit;
	document.getElementById("total_stock").value=document.getElementById("stock_qty").value;
	}
}


function filldefaultAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[2];
	if(id_brk.length>2)
	{
	document.getElementById("stock_perunit_"+i).value=1;
	}
	else
	{
	document.getElementById("stock_perunit").value=1;
	}
}
</script>
<!------------------JS FILES---------------END HERE------------------------------------------------------------------->

<script type="text/javascript" language="javascript">
function validate()
{
	//if(document.getElementById("mst_branchid").value=='000')
//	{
//	alert("First Branch must be filled out");
//	return false;
//	}
//	if(document.getElementById("Acc_date").value=='')
//	{
//	alert("Date must be filled out");
//	return false;
//	}
//	//if(document.getElementById("lead_subject").value=='')
////	{
////	alert("Subject must be filled out");
////	return false;
////	}
//	if(document.getElementById("lead_Priority").value=='0')
//	{
//	alert("Lead Priority  must be filled out");
//	return false;
//	}
//	//if(document.getElementById("lead_Category").value=='0')
////	{
////	alert("Lead Category  must be filled out");
////	return false;
////	}
//	//if(document.getElementById("lead_status").value=='0')
////	{
////	alert("Lead Status must be filled out");
////	return false;
////	}
//	if(document.getElementById("contact_name").value=='')
//	{
//	alert("Contact Name must be filled out");
//	return false;
//	}
//	if(document.getElementById("company_name").value=='')
//	{
//	alert("Company Name  must be filled out");
//	return false;
//	}
	
}

function calcValue1(str,id)
{
	var brk=id.split('_');
	if(brk.length==2)
	{
	   if(parseFloat(str)>parseFloat(document.getElementById("total_stock").value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("stock_qty").value='';
	   return false;
	   }
       else
	   {	
		var price=document.getElementById("stock_price").value;
		if(price!=''){
		var perunit=document.getElementById("stock_perunit").value;
		var tot=str*(price/perunit);
		document.getElementById("stock_value").value=tot;}
		}
	}
	else
	{
	  if(parseFloat(str)>parseFloat(document.getElementById("total_stock_"+brk[2]).value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("stock_qty_"+brk[2]).value='';
	   return false;
	   }
		var price=document.getElementById("stock_price_"+brk[2]).value;
		if(price!=''){
		var perunit=document.getElementById("stock_perunit_"+brk[2]).value;
		var tot=str*(price/perunit);
		document.getElementById("stock_value_"+brk[2]).value=tot;}
	}
}


function calcValue2(str,id)
{
	var brk=id.split('_');
	if(brk.length==2)
	{
		var qty=document.getElementById("stock_qty").value;
		if(qty!=''){
		var perunit=document.getElementById("stock_perunit").value;
		var tot=qty*(str/perunit);
		document.getElementById("stock_value").value=tot;}
	}
	else
	{
		var qty=document.getElementById("stock_qty_"+brk[2]).value;
		if(qty!=''){
		var perunit=document.getElementById("stock_perunit_"+brk[2]).value;
		var tot=qty*(str/perunit);
		document.getElementById("stock_value_"+brk[2]).value=tot;}
	}
}

function calcValue3(str,id)
{
	var brk=id.split('_');
	if(str==''){str=1;}
	if(brk.length==2)
	{
		var qty=document.getElementById("stock_qty").value;
		if(qty!=''){
		var price=document.getElementById("stock_price").value;
		var tot=qty*(price/str);
		document.getElementById("stock_value").value=tot;}
	}
	else
	{
		var qty=document.getElementById("stock_qty_"+brk[2]).value;
		if(qty!=''){
		var price=document.getElementById("stock_price_"+brk[2]).value;
		var tot=qty*(price/str);
		document.getElementById("stock_value_"+brk[2]).value=tot;}
	}
}


function checkReqDate()
{

var curr_date2='';	
var curr_month2='';
var d = new Date();

//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();


var curr_month1 = d.getMonth();

var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}


var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);

var date1=document.getElementById("Acc_date").value;
var str1 = date1;
var str2 = datedat;
    var dt1  = parseInt(str1.substring(0,2),10);
    var mon1 = parseInt(str1.substring(3,5),10);
    var yr1  = parseInt(str1.substring(6,10),10);
    var dt2  = parseInt(str2.substring(0,2),10);
    var mon2 = parseInt(str2.substring(3,5),10);
    var yr2  = parseInt(str2.substring(6,10),10);
    var date1 = new Date(yr1, mon1, dt1);
    var date2 = new Date(yr2, mon2, dt2);
    if(date2 > date1)
    {
        alert("Date Can't Be Less than Current Date");
		document.getElementById("Acc_date").value='';
		//document.getElementById("Acc_date").style.borderColor="#FF0000";
		document.getElementById("Acc_date").focus();
        return false;
    }
    else
    {
        return true;
        
    } 




}
</script>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Account Management</h1>
<form action=""	 method="post" enctype="multipart/form-data">				
<table width="100%" border="0" cellspacing="0" cellpadding="3">
			<?php
	if(count($msgErr)>0)
	{?>
		<tr class="row1">
	<td colspan="4">
		<?php 
		for($i=0;$i<count($msgErr);$i++)
		{
		echo "<div class='error'>".$msgErr[$i]."</div>";	
		}?>
		</td>
		</tr>
		<?php
	}
	
	?>
</table> 
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td colspan="6"><h3 style="color:#003399">General Information</h3></td>
  </tr>
   <tr class="row1">
    <td class="tabledata1" >Branch<font color="#FF0000">*</font></td>
    <td><?php echo $s->GetFieldValue('locations',"loccode='".$branch."'",'locationname'); ?>
	<?php  	 //echo $ClassBranch->SiteRecord('mst_branchid',$mst_branchid,'leads');
		$sql_state=DB_query("SELECT loccode,locationname FROM  locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."') ",$db);?> 
		<!--<select name="mst_branchid" id="mst_branchid" style="width:150px;" onChange="showstorecode(this.value)">
			<option value="000">Select Branch</option>
			<?php while($SiteName=DB_fetch_array($sql_state)) {?>]
			<option value="<?php echo $SiteName['loccode']; ?>"><?php echo $SiteName['locationname']; ?></option>
			<?php }?>
		</select><div id="hid-Godown-div"><select name="store"  style="width:150px;" id="store">
		<?php $store_sql = "SELECT id, StoreName,StoreCode FROM storetype where Store_Site = '".$_GET['site']."'";
		
		$store_result = DB_query($store_sql,$db);
			while($store_row = DB_fetch_array($store_result))
			{
				;
				$p='';
				if($store_row['id'] == $_POST['store'])
				$p="selected";
				?>
				<option value="<?php echo $store_row['id']; ?>"<?php echo $p; ?>><?php echo $store_row['StoreName']; ?></option>
	<?php } ?>
		</select>-->
		
	</td>
	<td class="tabledata1">Account No.</td>
    <td class="tabledata1"><div id='hid_leads'><input readonly="" type="text" name="leadcode" style="width:150px;" value="<?php echo $account_code; ?>" /></div></td>
    <td class="tabledata1" >Date<font color="#FF0000">*</font></td>
    <td style="width:200px;"><input type="text" name="Acc_date" class="datepicker" style="width:150px;" value="<?php echo ConvertSQLDate($accdate); ?>" id="Acc_date" onChange="return checkReqDate();" /></td>
  </tr>
 <tr class="row1">
    <td colspan="6"><h3 style="color:#003399">Contact Person information</h3></td>
  </tr>
   <tr class="row1">
   <td  class="tabledata1">Client name <font color="#FF0000">*</font></td>
    <td style="width:200px;">
		<input readonly="" type="text" name="clientname" id="clientname" style="width:150px;" value="<?php echo $s->GetFieldValue('clientmaster',"id='".$client."'",'c_name'); ?>">
	</td>
    <td  class="tabledata1">Contact Person Name <font color="#FF0000">*</font></td>
    <td  class="tabledata1" id="ContactPerson"><input type="text" name="contact_name" id="contact_name" style="width:150px;" value="<?php echo $s->GetFieldValue('contact_information_master',"master_code='".$client."'",'person'); ?>" /></td>
    
    <td  class="tabledata1">Group Name</td>
    <td><input type="text" readonly="" name="groupname" style="width:150px;" value="<?php echo $group_name; ?>" /  /></td>
  </tr>
  <tr>
    <td class="tabledata1" >Dept.</td>
    <td id="DEPT"><select name="mst_departmentid" style="width:150px;"  onchange="ShowDiv(this.value,'hid_POrder','disp_department.php')"><option value="0">Select</option>
	<?php 
	$sqldept=DB_query("select * from deptmaster",$db);
	while ($dept_row=DB_fetch_array($sqldept)) {
		$sel1='';
		if($dept_row['id']==$department)
		$sel1='selected';
			?>
		<option value="<?php echo $dept_row['id'];?>" <?php echo $sel1;?>><?php echo $dept_row['deptname']; ?></option>
		<?php }	?>
</select>
  </td>
    <td class="tabledata1" >Designation</td>
    <td >
    	<div id='hid_POrder'>
    		<select name="designation"  id="designation" style="width:150px;" >
    <option value="0">Select</option>
    <?php
    $sql_po= "select * from desigmaster Where mst_departmentid ='".$department."'";
	 $result=DB_query($sql_po,$db);
    while($myrow=DB_fetch_array($result))
	{
		
	?>
	<option value="<?php echo $myrow['id'];?>"<?php echo $destination==$myrow['id']?'selected':'';?>><?php echo $myrow['designame'];?></option>
	<?php }?> 
    
    </select>
    </div></td>
    <td class="tabledata1" >Function</td>
    <td ><input type="text" readonly="" name="lead_function" style="width:150px;"  value="<?php echo $function;?>"/></td>
  </tr>




<tr class="row1">
    <td colspan="6"><h3 style="color:#003399">Contact & Communication Details</h3></td>
  </tr>

  <tr class="row1">
    <td class="tabledata1" >First Name</td>
    <td id="firstname"><input type="text" name="fname" id="fname" style="width:150px;" value="<?php  echo $first_name;?>" /></td>
    <td class="tabledata1" >Middle Name</td>
    <td id="middlename"><input type="text" name="mname" id="mname" style="width:150px;" value="<?php  echo $middle_name;?>"/></td>
    <td  class="tabledata1" >Last Name</td>
    <td id="LastName"><input type="text" name="lname" id="lname" style="width:150px;" value="<?php  echo $last_name;?>"/></td>
  </tr>
  <tr class="row1">
    <td  class="tabledata1" >Address </td>
    <td id="Add1"><input type="text" name="address" id="address" style="width:150px;"   value="<?php  echo $address;?>"/></td>
	<td class="tabledata1" >Email Id</td>
    <td id="Email"><input type="text" name="email" id="email" style="width:150px;" value="<?php  echo $email_id;?>" /></td>
    <td class="tabledata1" >Phone No.</td>
    <td id="Phone"><input type="text" name="phone" id="phone" style="width:150px;"  value="<?php  echo $phonno;?>"/></td>
  </tr>
  <tr class="row1">
    <td class="tabledata1" >Mobile No.</td>
    <td id="mobl"><input type="text" name="mobile" id="mobile" style="width:150px;"value="<?php  echo $mobile;?>" /></td>
	  <td class="tabledata1" >Fax No.</td>
    <td id="Fax"><input type="text" name="fax" id="fax" style="width:150px;" value="<?php  echo $faxno?>" /></td>
    <td class="tabledata1" >Zip Code</td>
    <td id="ZIPC"><input type="text" name="zipcode" id="zipcode" style="width:150px;"  value="<?php  echo $zipcode?>" /></td>
  </tr>
  <tr class="row1">
    <td class="tabledata1" >Country</td>
    <td id="COUNTRY">
    	<?php //echo $country.$city.$state;?>
		<select name="country" style="width:150px;" id="country" onChange="ShowDiv(this.value,'show_state','emp_state.php')"><option value="0">Select</option>
	<?php 
	$sql_country=DB_query("select * from country_master",$db);
	while ($country_row=DB_fetch_array($sql_country)) {
			?>
		<option value="<?php echo $country_row['id'];?>"<?php echo $country==$country_row['id']?'selected':''?>><?php echo $country_row['country']; ?></option>
		<?php }	?>
    </select>
	</td>
	<td class="tabledata1" >State</td>
    <td>
    <div id='show_state'>
    <select name="state" onChange="ShowDiv(this.value,'show_city','emp_city.php')" id="state" style="width:150px;"  >
    <option value="0">Select</option>
    <?php
    $sql_po= "select * from state_master Where country ='".$country."'";
	 $result=DB_query($sql_po,$db);
    while($myrow=DB_fetch_array($result))
	{
		
	?>
	<option value="<?php echo $myrow['id'];?>"<?php echo $state==$myrow['id']?'selected':''?>><?php echo $myrow['state'];?></option>
	<?php }?> 
    
    </select>
    </div>
 </td>
     <td class="tabledata1" >City</td>
    <td >
    	 <div id='show_city'>
    	 	<select name="city"  id="city" style="width:150px;"  >
    <option value="0">Select</option>
    <?php
    $city_sql=DB_query("select * from city_master where state='".$state."'",$db);
     while($city_row=DB_fetch_array($city_sql))
    {
  ?>
    <option value="<?php echo $city_row['id'];?>"<?php echo $city==$city_row['id']?'selected':'';?>><?php echo $city_row['city'];?></option>
    <?php } ?>
</select>
    	
    	</div>
    	</td>
	</tr>

<tr class="row1">
    <td colspan="6"><h3 style="color:#003399">Product Information</h3></td>
  </tr>
  <tr class="row1">
<td colspan="4" style="background-color:#e7e7e7"><p align="left" style="padding-top:5px; padding-bottom:5px;">
<input type="button" onClick="addRow('dataTable')" value="Add More" class="search" />&nbsp;
<input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="open_items()" class="search" />
<input type="button" class="search"  onclick="deleteRow('dataTable')" value="Delete" />
</p></td></tr>
</table> 
 
<div style="overflow: auto; width:956px;">
<div id="showdata">
<table align="center" width="100%;" border="1" cellpadding="3" cellspacing="0">
<tr class="row1"><td class="tabledata" style="text-align:center;" colspan="11">Item Details</td></tr>
<tr class="row1">
	<td class="tabledata">Sr. No.</td>
	<td class="tabledata">&nbsp;</td>
    <td class="tabledata">Item Code</td>
    <td class="tabledata">Item Name</td>
    <td class="tabledata">Qty.</td>
    <td class="tabledata">Per Unit</td>
	<td class="tabledata">Price</td>
    <td class="tabledata">Value</td>
    <td class="tabledata">Total stock Qty</td>
</tr>
  <tbody id="dataTable">
  	<tr class="row1">
<td style="white-space:nowrap;" class="tabledata"><input name="delitem[]" type="checkbox" value="" />
</td>	
<td class="tabledata"><input type="hidden" name="item_code[]" id="itemid" /></td>
<td class="tabledata"><input type="text" name="" value="" id="itemcode" size="9" /></td>
<td class="tabledata" style="white-space:nowrap"><input type="text" name="" value="" id="itemname" /></td>
<td class="tabledata"><input type="text" name="stock_qty[]"  id="stock_qty" size="9" onKeyUp="calcValue1(this.value,this.id)" /></td>
<td class="tabledata"><input type="text" name="stock_perunit[]" id="stock_perunit" size="9" value="1" onKeyUp="calcValue3(this.value,this.id)"/></td>
<td class="tabledata"><input type="text" name="stock_price[]" value="" id="stock_price" size="6" onKeyUp="calcValue2(this.value,this.id)"/></td>
<td class="tabledata"><input type="text" name="stock_value[]" value="" id="stock_value" size="9"/></td>
<td class="tabledata"><input type="text" name="total_stock[]" id="total_stock" style="width:50px;"  readonly="true" /></td>
</tr>
</tbody>
 </table>
 </div>
 </div>

<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
 <input type="hidden" name="" value="" id="edit_cnt" />

<div >

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr class="row1">
    <td class="tabledata1" colspan="4"><h3 style="color:#003399">Groups & Users Assignment :-</h3></td>
  </tr>

  <tr class="row1">
    <td class="tabledata1" >Groups Name <label><font color="#FF0000">*</font></label></td>
    <td><?php echo $ClassRole->Role();?>	 </td>
    <td class="tabledata1" >Users Name <label><font color="#FF0000">*</font></label></td>
    <td>
	<div id='hid-Roleid'>
<?php  
 echo "<select name='leaduserid[]' style='width:107px;'>";
echo "<option value='000'>---</option>";
 echo "</select>";
	
?>	
	</div>
	
	 </td>
  </tr>
  
</table>



</div><!-- form 5 close -->

<div >

<table width="100%" border="0" cellspacing="2" cellpadding="3">
<tr class="row1">
    <td colspan="4"><h3 style="color:#003399">Add Doc/PDF :-</h3></td>
  </tr>

<tr class="row1">
    <td class="tabledata1" > Attach File</td>
    <td width="28%"> <input type="file" name="leadfile" id="leadfile" value="" /></td>
	
	</td>
<tr class="row1">
    <td colspan="4"><h3 style="color:#003399">Others :-</h3></td>
  </tr>

  <tr class="row1">
    <td class="tabledata1" >Remarks</td>
    <td width="28%"><textarea style="width:700px; height:50px;" name="remark"> <?php  echo $description;?></textarea></td>
	
	</td>
  </tr>

  <tr class="row1">
    <td width="28%" colspan="2"><p align="center"><input type="submit" value="<?php if($_REQUEST['action']=='Edit'){echo 'Update';}else{echo 'Save';} ?>"  name="Save" onClick="return validate();" class="search"/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Reset" class="search" /></p></td>
	
	</td>
  </tr>
</table>
</div><!-- form 6 close -->
	</form>
</div>
	</div> <!-- form1 div close -->


<script>
function showstorecode(str)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	var data=xmlhttp.responseText.split("__");	
	
	document.getElementById("hid-Godown-div").innerHTML=data[0];
    //document.getElementById("empdta").innerHTML=data[1];
	
    }
  }
  xmlhttp.open("GET","lead_storecode.php?site="+str,true);
	xmlhttp.send();
}



function GetClientDetails(str)
{
	if(str=='new'){
	document.getElementById("hid-newclient").style.display='block';
	document.getElementById("contact_name").value='';
	document.getElementById("contact_name2").value='';
	document.getElementById("designation").value='';
	document.getElementById("fname").value='';
	document.getElementById("mname").value='';
	document.getElementById("lname").value='';
	document.getElementById("address1").value='';
	document.getElementById("address2").value='';
	document.getElementById("address3").value='';
	document.getElementById("email").value='';
	document.getElementById("phone").value='';
	document.getElementById("mobile").value='';
	document.getElementById("fax").value='';
	document.getElementById("zipcode").value='';
	document.getElementById("country").value='0';
	document.getElementById("state").value='0';
	document.getElementById("city").value='0';
	}
	else
	{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");	
	document.getElementById("ContactPerson").innerHTML=data[0];
	document.getElementById("firstname").innerHTML=data[1];
	document.getElementById("middlename").innerHTML=data[2];
	document.getElementById("LastName").innerHTML=data[3];
	document.getElementById("Add1").innerHTML=data[4];
	document.getElementById("Add2").innerHTML=data[5];
	document.getElementById("Add3").innerHTML=data[6];
	document.getElementById("Email").innerHTML=data[7];
	document.getElementById("Phone").innerHTML=data[8];
	document.getElementById("mobl").innerHTML=data[9];
	document.getElementById("Fax").innerHTML=data[10];
	document.getElementById("ZIPC").innerHTML=data[11];
	document.getElementById("COUNTRY").innerHTML=data[12];
	document.getElementById("show_state").innerHTML=data[13];
	document.getElementById("show_city").innerHTML=data[14];
	document.getElementById("hid_POrder").innerHTML=data[15];
	}
	}
	xmlhttp.open("GET","CRM_leadclient.php?site="+str,true);
	xmlhttp.send();
	}
}

</script>


