<script type="text/javascript" src="script/Validator.js"></script>
<script src="<{$config.weburl}>/script/jquery.niceforms.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
	$(".radio").dgStyle();
});
var city='<{$de.city}>';
var province='<{$de.province}>';
function getHTML(v)
{	
	var ob="city";
	var url = '<{$config.weburl}>/ajax_back_end.php';
	var sj = Math.random();
	var pars = 'shuiji=' + sj+'&prov_id='+v;
	$.post(url, pars,showResponse);
	function showResponse(originalRequest)
	{
		var tempStr = 'var MyMe = ' + originalRequest; 
		var i=0;var j=0;
		eval(tempStr);
		for(var s in MyMe)
		{
			++j;
		}
		document.getElementById(ob).options.length =j+1;
		for(var k in MyMe)
		{
			var cityId=MyMe[k][0];
			var ciytName=MyMe[k][1];
			document.getElementById(ob).options[k].value = cityId;
			document.getElementById(ob).options[k].text = ciytName;
			if(city!=''&&city==ciytName)
				document.getElementById(ob).options[k].selected = true;
	　	}
	 }
　}
<{if $de.city}>
getHTML('<{$de.province}>');
<{/if}>
</script>
<script src="script/my_lightbox.js" language="javascript"></script>
<{$slogin}>
<div class="admin_right_top"><{$lang.profile}></div>
<form action="" name="form" method="post" enctype="multipart/form-data" onSubmit="return Validator.Validate(this,3)&&check_value()">
<table class="admin_table">
    <tr>
    	<td colspan="2" class="sheader"><{$lang.company_base}></td>
    </tr>
    <tr>
        <td width="20%" class="td"><{$lang.company}><em>*</em></td>
        <td><input name='company' type='text' value="<{$de.company}>" dataType="Limit" min=5 msg="<{$lang.ar_company}>"></td>
    </tr>
    <tr>
        <td class="td"><{$lang.con_user}><em>*</em> </td>
        <td><input name='contact' type='text' id="contact" value="<{$de.contact}>" dataType="Require" msg="<{$lang.ar_con_user}>"></td>
    </tr>
    <tr>  
        <td class="td">Company phone<em>*</em> </td>
        <td><input name='tel' type='text' value="<{$de.tel}>" dataType="Require" msg="<{$lang.ar_tel}>">
    </td>
    </tr>
    <tr>
        <td class="td">Company fax</td>
        <td><input name='fax' type='text' value="<{$de.fax}>" ></td>
    </tr>
    <tr>
        <td class="td">Postal code</td>
        <td><input maxlength="6" name='zip' type='text' value="<{$de.zip}>"></td>
    </tr>
    <tr>
        <td class="td">Company address<em>*</em> </td>
        <td><input name='addr' type='text' value="<{$de.addr}>" maxlength="200" dataType="Require" msg="<{$lang.ar_addr}>" ></td>
    </tr>
    <tr>
        <td class="td"><{$lang.url}></td>
        <td><input name='url' type='text' value="<{if $de.url!=''}><{$de.url}><{else}>http://<{/if}>" maxlength="50"></td>
    </tr>
    <tr>
        <td class="td">Host cities<em>*</em> </td>
        <td>
        <input name="country" type="hidden" value="" />
        <{if $de.country>0}>
        <input class="w150" id="province" name="province" type="text" value="<{$de.province}>"/>
        <input class="w150" id="city" name="city" type="text" value="<{$de.city}>"/>
        <{else}>
        <select  name="province" id="province" onChange="getHTML(this.value)" />
        <option value=""><{$lang.ar_province}></option>
        <{$prov}>
        </select>
        <select name="city" id="city" />
        <option value=""><{$lang.ar_city}></option>
        </select>
        <{/if}>
        </td>
    </tr>
    <tr>
    	<td colspan="2" class="sheader"><{$lang.company_biz}></td>
    </tr>
    <tr>
        <td class="td"><{$lang.company_type}><em>*</em> </td>
        <td>
        <{foreach item=list from=$companyType}>
        <label class="radio"><input <{if $de.ctype==$list}>checked="checked"<{/if}> name="ctype" type="radio" value="<{$list}>" /><{$list}></label>
        <{/foreach}> 
        </td>
    </tr>
    <{if $com_cat.0.catid&&$config.display_cat==1}>
    <tr>
        <td class="td"><{$lang.company_cat}><em>*</em> </td>
        <td>
        <select onChange="getHTMLs(this.value,'tcatid')" name="catid" id="catid">
        <{foreach item=list from=$com_cat}>
        <option value="<{$list.catid}>" ><{$list.cat}></option>
        <{/foreach}>
        </select>
        <select name="tcatid" id="tcatid" onChange="getHTMLs(this.value,'scatid')" style="visibility:hidden;">
        </select>
        <select name="scatid" id="scatid" onChange="getHTMLs(this.value,'fcatid')" style="visibility:hidden;">
        </select>
        <select name="fcatid" id="fcatid" style="visibility:hidden;"></select>
        <br/>
        <p><{$lang.select_category}><br/>
        <input name="Submitadd" type="button"  value="<{$lang.add_category}>" style="padding:3px;" onclick="doSubmit1('select')" />
        <input name="Submitdel" type="button"  value="<{$lang.remove_category}>" style="padding:3px;" onclick="doSubmit1('deselect')"/>
        </p>
        <select name="right_category_id[]"  size="8" multiple="multiple" id="right_category_id">
            <{foreach item=list from=$de.catinfo}> <{if $list.cat!=''}>
            <option value="<{$list.catid}>"><{$list.cat}></option>
            <{/if}> <{/foreach}>
        </select>
        </td>
    </tr>
    <{/if}>
    <tr>
        <td class="td"><{$lang.main_pro}><em>*</em></td>
        <td>
        <div id="main_pro">
            <{section name=foo loop=9}>
            <{if $smarty.section.foo.index>0&&$smarty.section.foo.index%3==0}><br />
            <{/if}>
            <input name='main_pro[]' type='text' class="w150" style="margin:2px 3px;" maxlength="20" value="<{foreach item=item key=num from=$de.main_pro_list}><{if $num==$smarty.section.foo.index}><{$item}><{/if}><{/foreach}>">
            <{/section}>
        </div>
        <font color="#999999"><{$lang.10chair}></font>
        </td>
    </tr>
    <tr>
        <td class="td"><{$lang.purchase}></td>
        <td>
        <div id="purch_pro">
            <{section name=foo loop=9}>
            <{if $smarty.section.foo.index>0&&$smarty.section.foo.index%3==0}><br />
            <{/if}>
            <input name='purch_pro[]' type='text' style="width:120px; margin:2px 3px;" maxlength="20" value="<{foreach item=item key=num from=$de.purch_pro_list}><{if $num==$smarty.section.foo.index}><{$item}><{/if}><{/foreach}>">
            <{/section}>
        </div>
        <font color="#999999"><{$lang.10chair}></font>
        </td>
    </tr>
    <tr>
        <td class="td"><{$lang.employees}><em>*</em></td>
        <td><input name='staff_num' type='text' value="<{$de.staff_num}>" dataType="Require" msg="Please fill in the number of employees"></td>
    </tr>
    <tr>
        <td class="td"><{$lang.registered_capital}>(<{$lang.unit}>)<em>*</em></td>
        <td><input name='registered_capital' type='text' value="<{$de.registered_capital}>" dataType="Require" msg="Please fill in the registered capital"></td>
    </tr>
    <tr>
        <td class="td"><{$lang.turnover}>(<{$lang.unit}>)</td>
        <td><input name='turnover' type='text' value="<{$de.turnover}>"></td>
    </tr>
    <tr>
        <td class="td"><{$lang.company_logo}></td>
        <td>
        <input name="logo" type="text" id="logo" value="<{$de.logo}>" />
        <p>
        [<a href="javascript:uploadfile('Style images','logo',<{$config.logo_width}>,<{$config.logo_height}>)"><{$lang.upload}></a>] 
        [<a href="javascript:preview('logo');"><{$lang.preview}></a>]
        [<a href="javascript:delet_pic('logo');"><{$lang.delete}></a>]
        </p>
        </td>
    </tr>
    <tr>
        <td class="td">The two-dimensional code</td>
        <td>
        <p class="pic"><img src="<{$config.weburl}>/uploadfile/phpqrcode/<{$buid}>.jpg" /></p>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input onclick="select_all();" type='submit' name='Submit' value='<{$lang.submit}>' />
            <input name="action" type="hidden" id="action" value="submit" />
        </td>
    </tr>
</table>
</form>
<script>
function removeOptions(src, dst)
{
	for(var i = 0; i < src.length; i++)
	{
		if(src[i].selected) src[i] =null;
	}
}
function getHTMLs(v,ob)
{	
	if(ob=='tcatid')
	{
		document.getElementById('tcatid').options.selected =false;
		document.getElementById('tcatid').options.length =0;
		document.getElementById('scatid').options.length =0;
		document.getElementById('fcatid').options.length =0;
		document.getElementById('tcatid').style.visibility="hidden";
		document.getElementById('scatid').style.visibility="hidden";
		document.getElementById('fcatid').style.visibility="hidden";
	}
	else if(ob=='scatid')
	{
		document.getElementById('scatid').options.selected =false;
		document.getElementById('scatid').options.length =0;
		document.getElementById('fcatid').options.length =0;
		
		document.getElementById('scatid').style.visibility="hidden";
		document.getElementById('fcatid').style.visibility="hidden";
	}
	else if(ob=='fcatid')
	{
		document.getElementById('fcatid').options.length =0;
	}
	var url = 'ajax_back_end.php';
	var sj = Math.random();
	var pars = 'shuiji=' + sj+'&cattype=com&pcatid='+v;
	$.post(url, pars,showResponse);
	function showResponse(originalRequest)
	{
		var tempStr = 'var MyMe = ' + originalRequest; 
		if(originalRequest!='{};')
		{
			var i=0;var j=0;
			eval(tempStr);
			for(var s in MyMe)
			{
				++j;
			}
			if(j>0)
				document.getElementById(ob).style.visibility="visible";
			else
				document.getElementById(ob).style.visibility="hidden";
			document.getElementById(ob).options.length =j;
			for(var k in MyMe)
			{
					var cateId=MyMe[k][0];
					var cateName=MyMe[k][1];
					document.getElementById(ob).options[i].value = cateId;
					document.getElementById(ob).options[i].text = cateName;
					i++;
		　	}
		}
	 }
　}

 function doSubmit1(button_clicked)
 {
		var tmpform = document.form;
		var selected_categories = tmpform.right_category_id.options;
		var len = selected_categories.length;
		if( button_clicked !='select'&& button_clicked !='deselect')
		{
			if(testColum())
			{
				var selected_categories = tmpform.right_category_id.options;
				var len = selected_categories.length;
				if ( (len == 0 || len > 6)  )
				{
					alert("请选择1－6个业务范围！");
					companyError('选择业务范围');
					return false;
				}
				return true;
			}
			else
				return false;
		}
		if(button_clicked &&(button_clicked == "deselect"||button_clicked == "select"))
		{
		   var fCategories = tmpform.fcatid.options;
		   var sCategories = tmpform.scatid.options;
		   var tCategories = tmpform.tcatid.options;
		   var Categories  = tmpform.catid.options;
		   if(button_clicked == 'select')
		   {
				if(fCategories.length==0)
				{ 
					if(sCategories.length==0)
					{
						if(tCategories.length==0)
							addOptions(Categories, selected_categories,fCategories,sCategories,tCategories,Categories);
						else
							addOptions(tCategories, selected_categories,fCategories,sCategories,tCategories,Categories);
					}
					else 
						addOptions(sCategories, selected_categories,fCategories,sCategories,tCategories,Categories);
		       }
			   else
			  	  addOptions(fCategories, selected_categories,fCategories,sCategories,tCategories,Categories);
		   }
		   else
		   {
				if(button_clicked == 'deselect')
				{   // Remove from right pane
					removeOptions(selected_categories, fCategories);
				}
				button_clicked = '';
				return false;
         }
       }
	}
 function addOptions(src, dst,fCategories,sCategories,tCategories,Categories)
 {
    var selected_value = [];
    var selected_text = [];
	var fV = fCategories;
  	var sV = sCategories;
	var tV = tCategories;
   	var V  = Categories;
	var Flag = false;
  	var tFlag = false;
   	var sFlag = false;
   	var fFlag = false;
	var sValue = '';
	
	for(var i = 0;i<fCategories.length;i++)
	{
		if(fCategories[i].selected)
		{
			fV= fCategories[i].text;
			fFlag = true;
			fValue = fCategories[i].value;
			break;
		}
	}
	for(var i = 0;i<sCategories.length;i++)
	{
		if(sCategories[i].selected)
		{
			sV= sCategories[i].text;
			sFlag = true;
			sValue = sCategories[i].value;
			break;
		}
	}
	for(var i = 0;i<tCategories.length;i++)
	{
		if(tCategories[i].selected)
		{
			tV= tCategories[i].text;
			tFlag = true;
			tValue = tCategories[i].value;
			break;
		}
	}
	for(var i = 0;i<Categories.length;i++)
	{
		if(Categories[i].selected)
		{
			V= Categories[i].text;
			Flag = true;
			break;
		}
	}
    // Get items from dst
    for(var i = 0; i < dst.length; i++)
	{
		selected_value[selected_value.length] = dst[i].value;
		selected_text[selected_text.length] = dst[i].text;
    }
	var len = selected_value.length;
	if( len >= 6 )
	{
		alert('您最多可选择6个“业务范围”！');
		return ;
	}
    // Get items from src
	for(var i = 0; i < src.length; i++)
	{
		if(src[i].selected)
		{
			var exists = 0;
			fFlag  = true;
			for(var j = 0; j < dst.length; j++)
			{
				if(dst[j].value == src[i].value)
				{
					exists = 1;
					break;
				}
			}
			if(exists&&exists==1)
			{
				alert('您已经选择过该“业务范围”！');
				return;
			}
			if(!exists)
			{
				selected_value[selected_value.length] = src[i].value;
				if(fV==src[i].text)
					selected_text[selected_text.length] = V+"/"+tV+"/"+sV+"/"+fV;
				else if(sV==src[i].text)
					selected_text[selected_text.length] = V+"/"+tV+"/"+sV;
				else if(tV==src[i].text)
					selected_text[selected_text.length] = V+"/"+tV;
				else
				{
					selected_text[selected_text.length] = V;
				}
			}
		}
	}

	if(Flag ==false && tFlag==false&& sFlag==false&& fFlag==false)
	{
		alert("您还未选择“业务范围”！");
		return ;
	}
	else
	{
		if(tFlag ==false&&document.getElementById('tcatid').style.visibility=="visible")
		{
			alert("您的“业务范围”未选择完整，请继续选择业务范围大类！")
			return;
		}
		else if(sFlag ==false&&document.getElementById('scatid').style.visibility=="visible")
		{
			alert("您的“业务范围”未选择完整，请继续选择业务范围大类！")
			return;
		}
		else if(fFlag ==false&&document.getElementById('fcatid').style.visibility=="visible")
		{
			alert("您的“业务范围”未选择完整，请继续选择业务范围大类！")
			return;
		}
	}
	
	while(dst.length > 1) dst[1] = null;
	
	for(var j = 0; j < selected_value.length; j++)
	{
	  dst[j] = new Option(selected_text[j], selected_value[j]);
	}
  }
  
  function select_all()
  {
  		for(i=0;i<document.getElementById('right_category_id').options.length;i++)
		{
			document.getElementById('right_category_id').options[i].selected = true;
		}
  }
  function check_value(){
	  var mp = document.getElementById('main_pro').getElementsByTagName('input');
	  var mp_valid = false;
	  for(var i=0;i<mp.length;i++){
		  if(mp[i].value!=''){
			  mp_valid = true;
			  break;
		  }
	  }
	  if(!mp_valid)
	  {
		  alert('主营产品不能为空');
		  return false;
	 }
	  var purch = document.getElementById('purch_pro').getElementsByTagName('input');
	  var purch_valid = false;
	  for(var i=0;i<purch.length;i++){
		  if(purch[i].value!=''){
			  purch_valid = true;
			  break;
		  }
	  }
  }
</script>
