﻿//'''''''''''''''''''''''''''''''''''''''''''''''''
function loginInit()
{
	var obj	= window.document;
	
	obj.login.UserName.focus();
	
	window.moveTo(0,0);
	window.resizeTo(window.screen.width,window.screen.height-30);
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function setFocus(iROWS)
{
	try
	{
		if(!iROWS) return;

		var obj	= window.document.all;
		
		if(iROWS>99999)// hide buttons
		{
			for(var j=0; j<obj.length; j++)
			{
				if(!obj[j])				continue;
				if(!obj[j].id)			continue;
			
				if(obj[j].id.indexOf("Delete")>0||
					obj[j].id.indexOf("Edit")>0||
					obj[j].id.indexOf("Cancel")>0||
					obj[j].id.indexOf("Update")>0)
				{	
					obj[j].style.display	= "none";
				}
			}
			return;
		}
		

		for(var j=0; j<obj.length; j++)
		{
			if(!obj[j])				continue;
			if(!obj[j].type)		continue;
			if(!obj[j].name)		continue;
			if(obj[j].type=="text")
			{
				if(obj[j].name.indexOf("MyDataGrid")>=0)
				{
					obj[j].id			= obj[j].name;
					obj[j].className	= " fieldsBehavior ";
					obj[j].focus();
				}
			}
		}
	}
	catch(e)	{window.status=e.description}

}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function back2editForm(id)
{
	if(!id||id=="") return;		// site onload 

	try
	{
		//printThisCard("ccm");
		//window.location.href="../CCM/main/editForm.aspx?id="+id;
	}
	catch(e){alert(e.description)}
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function printThisCard(from)
{
	var obj	= document.all;
		if(obj["logo"])		obj["logo"].style.display="none";
		if(obj["sublogo"])	obj["sublogo"].style.display="none";
		if(obj["lang"])		obj["lang"].style.display="none";
		if(obj["footer"])		obj["footer"].style.display="none";
		if(obj["buttons"])	obj["buttons"].style.display="none";
		
		if(from=="site")	ieExecWB(7,1);
		else					window.print();
		//else					ieExecWB(7,1);
		
		if(obj["logo"])		obj["logo"].style.display="block";
		if(obj["sublogo"])	obj["sublogo"].style.display="block";
		if(obj["lang"])		obj["lang"].style.display="block";
		if(obj["footer"])		obj["footer"].style.display="block";
		if(obj["buttons"])	obj["buttons"].style.display="block";
		
		if(from!="site")	window.close();
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function printCard(id)
{
//alert("printCard#" + window.document.all["PartId"].innerText + "#");
	try
	{
		var url		= 'print.card.aspx?id='+window.document.all["PartId"].innerText;
		var newwin 	= window.open(url,"newwin","width=10, height=10, top=2000");
		newwin.focus();
		//var newwin 	= window.open(url,"newwin","width=1000, height=700, top=0");
	}
	catch(e){alert(e.description)}
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function printOpenedCard()
{
	try
	{
		window.print(); 
		window.close();	
	}
	catch(e){alert(e.description)}
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function preview(iROWS,sTABLE,sURL,returnRows)
{
	try
	{
		if(!iROWS)		 return;
		if(iROWS<99999) return;
	}
	catch(e)				{return;}
	alert("iROWS: " + iROWS+"");


	var obj	= document.all;

		if(obj["logoimages"])	obj["logoimages"].style.display	="none";
		if(obj["logo"])			obj["logo"].style.display			="none";
		if(obj["assist"])			obj["assist"].style.display		="none";
		if(obj["upperSide"])		obj["upperSide"].style.display	="none";
		if(obj["lang"])			obj["lang"].style.display			="none";
		if(obj["footer"])			obj["footer"].style.display		="none";
		if(obj["buttons1"])		obj["buttons1"].style.display		="none";
		if(obj["buttons"])		obj["buttons"].style.display		="none";
		
	if(sTABLE=="search")	// from search.asp
	{
		//ieExecWB(7,1);
		window.print();
		window.location.href=sURL+"?rip="+returnRows;
		return;
	}	

	try
	{
		ieExecWB(7,1);
	}
	catch(e)
	{
		window.print();
	}
	window.location.href=sURL+"?tbl="+sTABLE+"&rip="+returnRows;
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function ieExecWB( intOLEcmd, intOLEparam )
{
	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
 
		window.document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
 
		WebBrowser1.ExecWB( intOLEcmd, intOLEparam );
		WebBrowser1.outerHTML = "";
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
var fromlistbox;
//'''''''''''''''''''''''''''''''''''''''''''''''''
function reloadOpener(PartId)
{
		var url	= "../main/editForm.aspx?id="+PartId;
	
		window.opener.location.href	= url;
}
//'''''''''''''''''''''''''''''''''''''''''''''''''

function returnValue(thisid,hebValue,engValue)
{
	if(window.name)
	{
		var obj		= self.document.all;

		var toObj	= opener.document.all;
		var elem		= self.name;
		var objto0	= toObj[elem+"0"];
		var objto1	= toObj[elem];
		
		if(!isValueExistIn(objto0,thisid))
		{
			var newlen	= objto0.length;
			
			objto0.length	= newlen+1;
			objto1.length	= newlen+1;
			
			try
			{
				objto0.options[newlen].value	= thisid;				
				objto0.options[newlen].text	= hebValue;				
				objto1.options[newlen].value	= thisid;				
				objto1.options[newlen].text	= engValue;				
			}
			catch(e){alert(e.description)}
		}
		fromlistbox = thisid;	fonload (fromlistbox);
	}
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function isValueExistIn(objto,fromlistbox)
{
	for(var j=0; j<objto.length; j++)
	{
		if(objto[j].value==fromlistbox)
		{
			return true;
		}
	}
	return false;
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function fonload()
{
	try
	{
			var obj		= opener.document.editForm;
			var elem		= window.name;
			var objto	= obj[elem];
			var objto0	= obj[elem+"0"];
			
		for(var j=0; j<objto.length; j++)
		{
			if(objto[j].value==fromlistbox)
			{
				objto.selectedIndex=j;
				break;
			}
		}
		for(var j=0; j<objto0.length; j++)
		{
			if(objto0[j].value==fromlistbox)
			{
				objto0.selectedIndex=j;
				break;
			}
		}
		self.close();
	}
	catch(e){}	
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function initPage()
{
	var obj=window.editForm;
	
	//document.all.loading.style.display="none";
	
	for(var j=0; j<obj.length; j++)
	{
		if(!obj[j].id) continue;
		
		if(obj[j].tagName=="SELECT"||
			obj[j].tagName=="INPUT"||
			obj[j].tagName=="BUTTON"||
			obj[j].tagName=="SPAN"||
			obj[j].tagName=="TEXTAREA")
		{
			if(obj[j].id=="HolArmyUnitsS")	continue;
			if(obj[j].id=="HolArmyUnits0S")	continue;
			if(obj[j].id=="HolArmyJobS")		continue;
			if(obj[j].id=="HolArmyJob0S")		continue;

			obj[j].disabled=false;
		}
	}
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function deleteCard()
{
	var obj		= window.editForm;
	var objAll	= document.all;
	
	objAll["Div1"].style.display = "block";
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function cancelDeleteCard()
{
	var obj		= window.editForm;
	var objAll	= document.all;
	
	objAll["Div1"].style.display = "none";
}
//'''''''''''''''''''''''''''''''''''''''''''''''''
function resetForm()
{
	var obj		= window.editForm;
	var objAll	= document.all;
	
	if(objAll["imageId"])		objAll["imageId"].src				= "../Images/pixel.gif";
	if(objAll["buttonTdId"])	objAll["buttonTdId"].innerText	= "";
	if(objAll["PartId"])			objAll["PartId"].innerText			= "";
	if(objAll["PartName"])		objAll["PartName"].innerText		= "";

	for(var j=0; j<obj.length; j++)
	{
		if(!obj[j].id) continue;
		
		if(obj[j].tagName=="SELECT")
		{
			for(var i=obj[j].length-1; i>=0; i--)
			{
				if(obj[j][i].value=="") {var selectedindex = i; break;}
			}
			obj[j].selectedIndex=selectedindex;
		}
		if(obj[j].tagName=="TEXTAREA")
		{
			obj[j].value="";
		}
		if(obj[j].tagName=="INPUT")
		{
			if(obj[j].type=="text")			obj[j].value="";
			if(obj[j].type=="checkbox")	obj[j].checked=true;
			if(obj[j].id=="sexM")			obj[j].checked=true;
		}
	}
}
	
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function checkNames()
{
	var obj	= window.editForm;

	if(obj["LastName0"].value==""||obj["LastName"].value==""||obj["FirstName0"].value==""||obj["FirstName"].value=="")
	{
		if(obj["LastName0"].value==""&&obj["LastName"].value==""&&obj["FirstName0"].value==""&&obj["FirstName"].value=="")
		{
			return true;
		}
		alert("נא להזין שדות חובה");
		return false;
	}
}
//'************************************************************************
function CStr(vle,dflt)
{
       dflt += "";
    if(dflt=="undefined") dflt = "";
    if(dflt=="null")      dflt = "";
    
       vle += "";
    if(vle=="undefined") return dflt;
    if(vle=="null")      return dflt;
    
    return vle;
}
//'-------------------------------------------------------------------
function CInt(vle,dflt)
{
   var str	= trim(vle);
   var strd	= trim(dflt);
    
	var intg	= parseInt(str,10);
	var intd	= parseInt(strd,10);
	
		 intd	= (isNaN(intd)?0:intd);
    
	return (isNaN(intg)?intd:intg);
}
//'----------------------------------------------------------------------    
function trim(vle,dflt)
{
        var trm	= CStr(vle);
        var dfl	= CStr(dflt);
    
				trm	= trm.replace(/(^\s*)|(\s*$)/g, "");
				dfl	= dfl.replace(/(^\s*)|(\s*$)/g, "");
    
    return trm==""?dfl:trm;
}
//'----------------------------------------------------------------------    

