﻿function opent(id){

url='files/opent.php?id='+id;

window.open(url,'view_photo','width=400,height=350,titlebar=0,menubar=0,toolbar=0,addressbar=0,resizable=0,status=0')

}

var NS = (navigator.appName=='netscape')?true:false;

function fitter(){

iWidth = (NS)?window.innerWidth:document.body.clientWidth;

iHeight = (NS)?window.innerHeight:document.body.clientHeight;

iWidth = document.images[0].width - iWidth;

iHeight = document.images[0].height - iHeight;

window.resizeBy(iWidth,iHeight);

self.focus();

}


function assignTOfield(fvalue)
{
active_field=document.brnme.active_field.value;
faddress=eval("document.brnme."+active_field);
faddress.value='< '+fvalue+' >';
}

function eORd(scope)
{
add=document.forms[0];
if(scope=='whole')
{
add.origion.disabled=true;
add.town.disabled=true;
}
else if(scope=='province')
{
add.origion.disabled=false;
add.town.disabled=false;
}
}

function changeCode()
{
document.images['icode'].src="scripts.js";
}


function activate_it(add)
{
if((add=='working')||(add=='finished'))
{
document.repbrnme.c_name.disabled=false;
}
else
{
document.repbrnme.c_name.disabled=true;
}
}

function showPage(item_id)
{
EL=document.getElementById('active_val');
if(item_id!=EL.innerHTML)
{
document.getElementById('conbox').filters[0].apply();
AI="item_"+EL.innerHTML;
ACO="content_"+EL.innerHTML;
NI="item_"+item_id;
NCO="content_"+item_id;
taddr=document.getElementById('stheme').innerHTML;
document.getElementById(ACO).style.display="none";
document.getElementById(NCO).style.display="block";
a_addr=document.getElementById(AI);
n_addr=document.getElementById(NI);
a_addr.className="btitle";
n_addr.className="atitle";
EL.innerHTML=item_id;
document.getElementById('conbox').filters[0].play(duration=.6);
}
else { return false; }
}

function showPageII(item_id)
{
EL=document.getElementById('active_valII');
if(item_id!=EL.innerHTML)
{
document.getElementById('sconbox').filters[0].apply();
AI="sitem_"+EL.innerHTML;
ACO="s"+EL.innerHTML;
NI="sitem_"+item_id;
NCO="s"+item_id;
taddr=document.getElementById('stheme').innerHTML;
document.getElementById(ACO).style.display="none";
document.getElementById(NCO).style.display="block";
a_addr=document.getElementById(AI);
n_addr=document.getElementById(NI);
a_addr.className="btitle";
n_addr.className="atitle";
EL.innerHTML=item_id;
document.getElementById('sconbox').filters[0].play(duration=.6);
}
else { return false; }
}


function showSub(item_id)
{
EL=document.getElementById('mactive_val');

if(item_id!=EL.innerHTML)
{
document.getElementById('mconbox').filters[0].apply();
AI="menu_"+EL.innerHTML;
ACO="sub_"+EL.innerHTML;
NI="menu_"+item_id;
NCO="sub_"+item_id;
taddr=document.getElementById('mstheme').innerHTML;
document.getElementById(ACO).style.display="none";
document.getElementById(NCO).style.display="block";
a_addr=document.getElementById(AI);
n_addr=document.getElementById(NI);
a_addr.className="btitle";
n_addr.className="atitle";
EL.innerHTML=item_id;
document.getElementById('mconbox').filters[0].play();
}
else { return false; }
}


function showOrgan(FORM,OPT)
{
if(OPT=="simpleuser")
{
document.forms[FORM].organization.disabled=false;
document.getElementById('organ').style.display="block";
}
else
{
document.forms[FORM].organization.disabled=true;
document.getElementById('organ').style.display="none";
}
}


function toggleK(row)
{
re="re_"+row;
addr=document.getElementById(re).style;
if(addr.display=="none")
{
addr.display="block";
}
else
{
addr.display="none";
}
}


function toggleJ(id,row)
{
row_name=id+row;
addr=document.getElementById(row_name).style;
if(addr.display=="block")
{
addr.display="none";
}
else
{
addr.display="block";
}
}


function ConDel()
{
if(confirm("آیا برای حذف موارد انتخاب شده اطمینان دارید ؟"))
{
return true;
}
else
{
return false;
}
}

function openH(row)
{
row_name='h'+row;
addr=document.getElementById(row_name).style;
if(addr.display=='block')
{
addr.display="none";
}
else
{
addr.display="block";
}
}


function addItem()
{
table=document.getElementById("items_table");
t_rows=table.getElementsByTagName("tr");
a_num="a"+(t_rows.length-1);
document.brnme.active_field.value=a_num
row=document.getElementById("items_table").insertRow(1);
cell1='<td width="50%" align="<?php echo $lang_alignment ?>" dir="<?php echo $lang_direction; ?>"><input autocomplete="off" type="text" class="textbox2" name="good_id[]" id="'+a_num+'" style="width:100%" onkeyup="openList(this.value)" onfocus="this.form.active_field.value=this.id"></td>';
cell2='<td width="50%" align="<?php echo $lang_alignment ?>" dir="<?php echo $lang_direction; ?>"><input type="text" class="textbox2" name="good_owner[]" style="widh:100%"></td>';
cell3='<td align="<?php echo $lang_alignment ?>" dir="<?php echo $lang_direction; ?>"><input type="text" class="textbox2" name="good_num[]" style="widh:100%"></td>';
cell4='<td align="<?php echo $lang_alignment ?>" dir="<?php echo $lang_direction; ?>"><input type="text" class="textbox2" name="good_wei[]" style="widh:100%"></td>';
//document.getElementById("items_table").rows[1].className="list_row";
c1=row.insertCell(0);
c2=row.insertCell(1);
c3=row.insertCell(2);
c4=row.insertCell(3);
c1.innerHTML=cell1;
c2.innerHTML=cell2;
c3.innerHTML=cell3;
c4.innerHTML=cell4;
}

function createXmlhttp() {
if(window.XMLHttpRequest){
http = new XMLHttpRequest();
}
else if(window.ActiveXObject) {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
return http;
}

function loadCon(qstring,url,container)
{
xmlhttp=createXmlhttp();
xmlhttp.open("POST", url);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.responseText!=""){
document.getElementById(container).filters[0].apply();
document.getElementById(container).innerHTML=xmlhttp.responseText;
document.getElementById(container).filters[0].play(duration=.5);
}
}
}
xmlhttp.send(qstring);
}

function loadConII(qstring,url,container)
{
xmlhttp=createXmlhttp();
xmlhttp.open("POST", url);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.responseText!=""){
document.getElementById(container).innerHTML=xmlhttp.responseText;
}
}
}
xmlhttp.send(qstring);
}

function validateForm(fname,qstring){
xmlhttp=createXmlhttp();
xmlhttp.open("GET",qstring);
xmlhttp.onreadystatechange=function()
{
if((xmlhttp.readyState==4)&&(xmlhttp.status==200))
{
if(xmlhttp.responseText!=""){
document.getElementById('er').style.display="block";
document.getElementById('errors').innerHTML=xmlhttp.responseText;
}
else if(xmlhttp.responseText=="")
{
document.forms[fname].submit();
}
}
}
xmlhttp.send(null);
}



function openList(word){
xmlhttp=createXmlhttp();
url='ajax/goodreq/goodreq.php';
qstring='word='+word;
xmlhttp.open("POST", url);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.responseText!=""){
document.getElementById('brnme_goods').filters[0].apply();
document.getElementById('brnme_goods').innerHTML=xmlhttp.responseText;
document.getElementById('brnme_goods').filters[0].play(duration=.5);
}
}
}
xmlhttp.send(qstring);
}

function showOwners(word)
{
xmlhttp=createXmlhttp();
url='ajax/owners/owners.php';
qstring='word='+word;
xmlhttp.open("POST", url);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.responseText!=""){
document.getElementById('owners_list').filters[0].apply();
document.getElementById('owners_list').innerHTML=xmlhttp.responseText;
document.getElementById('owners_list').filters[0].play(duration=.5);
}
}
}
xmlhttp.send(qstring);
}

function assignTOfieldII(fvalue)
{
faddress=document.owners.sowner;
faddress.value='< '+fvalue+' >';
}

function enableDate()
{
faddr=document.forms['repgio'].fdate;
taddr=document.forms['repgio'].tdate;
f_addr=document.forms['repgio'].st;
if(f_addr.value!="0")
{
faddr.disabled=false;
taddr.disabled=false;
}
else
{
faddr.disabled=true;
taddr.disabled=true;
}
}

function enableRow(el)
{
if(el=='amvali')
{
xmlhttp=createXmlhttp();
url='ajax/reports/repgoods.rows.php';
xmlhttp.open("GET",url);
xmlhttp.onreadystatechange=function()
{
if((xmlhttp.readyState==4)&&(xmlhttp.status==200))
{
document.getElementById('rows_s').innerHTML=xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
else
{
document.forms['repgoods'].rows.disabled=true;
enableGoods();
}
}



function enableGoods()
{
xmlhttp=createXmlhttp();
addr=document.forms['repgoods'];
url='ajax/reports/repgoods.goods.php';

if((addr.rows.value!="0")||(addr.units.value!="0"))
{
url+="?";
}
if(addr.rows.value!="0")
{
url+="row="+addr.rows.options[addr.rows.selectedIndex].value;
}
if((addr.rows.value!="0")&&(addr.units.value!="0"))
{
url+="&";
}
if(addr.units.value!="0")
{
url+="unit="+addr.units.options[addr.units.selectedIndex].value;
}
cat=document.forms['repgoods'].cat.value;
if(cat=='amvali')
{
if((addr.rows.value!="0")||(addr.units.value!="0"))
{
url+="&cat_name=amvali";
}
else
{
url+="?cat_name=amvali";
}
}
else if(cat=='masrafi')
{
if((addr.rows.value!="0")||(addr.units.value!="0"))
{
url+="&cat_name=masrafi";
}
else
{
url+="?cat_name=masrafi";
}
}
xmlhttp.open("GET",url);
xmlhttp.onreadystatechange=function()
{
if((xmlhttp.readyState==4)&&(xmlhttp.status==200))
{
document.getElementById('goods_s').innerHTML=xmlhttp.responseText;
}
}
xmlhttp.send(null);
}

function showDF(dt)
{
if(dt=='pdate')
{
document.getElementById('s_from').style.display="block";
document.getElementById('s_to').style.display="block";
document.getElementById('s_recdate').style.display="none";
}
else if(dt=='spdate')
{
document.getElementById('s_from').style.display="none";
document.getElementById('s_to').style.display="none";
document.getElementById('s_recdate').style.display="block";
}
}

function loadUsers(organ)
{
addr=document.getElementById('users_s');
xmlhttp=createXmlhttp();
url='ajax/reports/repreq.users.php?organ='+organ;
xmlhttp.open("GET",url);
xmlhttp.onreadystatechange=function()
{
if((xmlhttp.readyState==4)&&(xmlhttp.status==200))
{
addr.innerHTML=xmlhttp.responseText;
}
}
xmlhttp.send(null);
}

function hide_or_show(ptype)
{
        a1=document.getElementById('c1');
        a2=document.getElementById('c2');
        a3=document.forms['payment'].pric;
        a4=document.forms['payment'].lpric;
        if(ptype=='pcash')
        {
                a1.style.display='none';
                a2.style.display='none';
                a3.disabled=false;
                a4.disabled=false;
        }
        else
        {
                a1.style.display='block';
                a2.style.display='block';
                a3.disabled=true;
                a4.disabled=true;
        }
}

function validateForm(formName,url)
{
	xmlhttp=createXmlhttp();
	xmlhttp.open("POST", url);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	qstring="";
	add=document.forms[formName];
	for(i=0;i<add.elements.length;i++)
	{
    		if(i<add.elements.length-1)
    		{
    				qstring+=add.elements[i].name+"="+add.elements[i].value+"&";
    		}
    		else
    		{		    		qstring+=add.elements[i].name+"="+add.elements[i].value;
    		}
	}
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			if(xmlhttp.responseText!="")
			{

					document.getElementById('errorPAN').innerHTML=xmlhttp.responseText;
                    document.getElementById('erow').style.display="block";
                    window.scrollTo(0,0);
			}
			else
			{					add.submit();
			}
		}
	}
	xmlhttp.send(qstring);
	return false;
}

function pasteStar(formName,fieldName,fieldType,conId,fieldWidth,dir)
{		add=eval('document.forms["'+formName+'"].'+fieldName);
		if(add.value=="")
		{        		add.value="*";
        		add.className="box3";
        		//if(fieldType)
        		//{
    	        		//f='<input type="'+fieldType+'" class="box2" name="'+fieldName+'" style="width:'+fieldWidth+'" onfocus="delStar(\''+formName+'\',\''+fieldName+'\',\''+fieldType+'\',\''+conId+'\',\''+fieldWidth+'\',\''+dir+'\')" onblur="pasteStar(\''+formName+'\',\''+fieldName+'\',\''+fieldType+'\',\''+conId+'\',\''+fieldWidth+'\',\''+dir+'\')">';
		        		//co_add=document.getElementById(conId);
		        		//co_add.innerHTML=f;
		        		//fi=eval('document.forms[\''+formName+'\'].'+fieldName);
		        		//fi.focus();
        		//}
		}
}


function delStar(formName,fieldName,fieldType,conId,fieldWidth,dir)
{		add=eval('document.forms["'+formName+'"].'+fieldName);
        if(add.value=="*")
        {
				add.value="";
				add.className="box2";
				//if(fieldType)
				//{
    	        		//f='<input type="'+fieldType+'" class="box2" name="'+fieldName+'" style="width:'+fieldWidth+'" onfocus="delStar(\''+formName+'\',\''+fieldName+'\',\''+fieldType+'\',\''+conId+'\',\''+fieldWidth+'\',\''+dir+'\')" onblur="pasteStar(\''+formName+'\',\''+fieldName+'\',\''+fieldType+'\',\''+conId+'\',\''+fieldWidth+'\',\''+dir+'\')">';
		        		//co_add=document.getElementById(conId);
		        		//co_add.innerHTML=f;
		        		//fi=eval('document.forms[\''+formName+'\'].'+fieldName);
		        		//fi.focus();
				//}
		}
}