// Created  : 02/11/2000
// Updated  : 
// Module   : razinfunc.js
// Remarks  : clean the whole page text objects in all form needs the vfuncstr.js for Trim
// work with explorer netscape opera
// 	(C) Raz Information Systems.
// *******************************************
//The function read use as a part of reading limited records proccess
////////////////////////////////////////////////////////////
//HEADER FUNCTIONS
///////////////////////////////////////////////////////////
function MoveRecords(direction,mod,page)
{
	var position=window.parent.LINE.document.LineForm.start.value*(1);
	var end=window.parent.LINE.document.LineForm.end.value*(1);
	
	
	if(mod!='UPDATE')
	{
		if(mod=='SEARCH')
				window.parent.LINE.document.LineForm.mod.value='SEARCH';	
				
		if(direction=='f')
		{	
			window.parent.LINE.document.LineForm.start.value=position-(-step);	
			window.parent.LINE.document.LineForm.direction.value='f';	
			window.parent.LINE.document.LineForm.template.value=page+"_line.html";
			window.parent.LINE.document.LineForm.submit();
		}
		else if(position>0)
		{
			window.parent.LINE.document.LineForm.start.value=position-(step);	
			window.parent.LINE.document.LineForm.direction.value='b';	
			window.parent.LINE.document.LineForm.template.value=page+"_line.html";
			window.parent.LINE.document.LineForm.submit();
		}
	}
}
//////////////////////////////////////////////////
function SubmitFrm(mod,rid,page)
{
	//UNDO
	if(mod=='UNDO')
	{
		//window.parent.location.reload();
		document.SubmitForm.template.value = page + '.html';
		var buf = GetElements(document.SubmitForm);
		buf = ReplaceBlank(buf);
		window.parent.HEADER.location.href = '/razinf-bin/merge.pl'+buf;				
		document.SubmitForm.template.value = page + '_line.html'

		buf = GetElements(document.SubmitForm);
		buf = ReplaceBlank(buf);
		window.parent.LINE.location.href = '/razinf-bin/merge.pl'+buf;

		return;
	}
	
	if(mod=='UPDATE' && rid=='')
	{
		alert('No object was selected');
		return;
	}
	
	//check validation
	if(mod=='INSERT' || mod=='UPDATE')
	{
		if (!(ChkSubmit()))
			return;
	}
	
	// init request
	window.parent.LINE.document.LineForm.start.value='0';
	InitFields();
	
	document.SubmitForm.mod.value=mod;
	
	if(mod=='UPDATE')
	{
		document.SubmitForm.location_line.value=window.parent.LINE.document.LineForm.location_line.value;
		document.SubmitForm.location_head.value=window.parent.LINE.document.LineForm.location_head.value;
		document.SubmitForm.submit();
	}
	else if(mod=='SEARCH')
	{	
		var buf = GetElements(document.SubmitForm);

		buf = ReplaceBlank(buf);
		
		window.parent.LINE.location.href = '/razinf-bin/merge.pl'+buf;
		
		document.SubmitForm.target='HEADER';
		document.SubmitForm.template.value=page+'.html';
		document.SubmitForm.submit();
		
		document.SubmitForm.reset();
	}
	else
	{

		var buf = GetElements(document.SubmitForm);

		buf = ReplaceBlank(buf);
		
		window.parent.LINE.location.href = '/razinf-bin/merge.pl'+buf;

		document.SubmitForm.target='HEADER';
		document.SubmitForm.template.value=page+'.html';
		document.SubmitForm.submit();
		document.SubmitForm.reset();

	}
}
//////////////////////////////////////////////////
//Help
function Help(lang)
{	
	if(lang=='HEBREW')
	{
		var	myWin=open("/razinf/heb-help.html","Help","width=600,height=450,left=50,top=8,status=no,scrollbars=yes,toolbar=no,menubar=no");
	}
	else
	{
		var	myWin=open("/razinf/help.html","Help","width=600,height=450,left=50,top=8,status=no,scrollbars=yes,toolbar=no,menubar=no");		
	}
}
//////////////////////////////////////////////////
function Exit()
{
	parent.close();
}
//////////////////////////////////////////////////
function Print()
{
	window.print();
}
///////////////////////////////////////////////////
function CityTbl()
{
	// cleaning up before choosing a new street
	document.SubmitForm.streetid.value = '';
	document.SubmitForm.streetname.value = '';
	document.SubmitForm.housenum.value = '';
	document.SubmitForm.zipcode.value = '';
	
	var str=prompt('Enter a city to search','%');
	var template = "heb-citytbl.html";
	var	template_line = "heb-guest_line.html";
	
	if (str!=null)
	{
		var	yWin=open("","CityTbl","width=250,height=250,status=no,scrollbars=yes,toolbar=no,menubar=no");
	
		document.SubmitForm.target = "CityTbl";
		document.SubmitForm.template.value = template;
		document.SubmitForm.str.value = str;
	
		document.SubmitForm.submit();
	
		document.SubmitForm.target = "Line";
		document.SubmitForm.template.value = template_line;
	}
}
///////////////////////////////////////////////////
function StreetTbl()
{
	if(document.SubmitForm.cityname.value == '')
	{
		alert('A city must be chosen before street!');
		return;
	}
	
	// cleaning up before choosing a new street
	document.SubmitForm.housenum.value = '';
	document.SubmitForm.zipcode.value = '';
	
	var str=prompt('Enter a street to search','%');
	var template = "heb-streettbl.html";
	var	template_line = "heb-guest_line.html";
	
	if (str!=null)
	{
		var	yWin=open("","StreetTbl","width=250,height=250,status=no,scrollbars=yes,toolbar=no,menubar=no");
	
		document.SubmitForm.target = "StreetTbl";
		document.SubmitForm.template.value = template;
		document.SubmitForm.str.value = str;
	
		document.SubmitForm.submit();
	
		document.SubmitForm.target = "Line";
		document.SubmitForm.template.value = template_line;
	}
}
//////////////////////////////////////////////////
function CheckEmail()
{
	var email = document.SubmitForm.email.value;
	var ind = email.indexOf('@');
	
	if(ind!=-1 && email.indexOf('.',ind)!=-1)
		return 1;
			
	return 0;
}
///////////////////////////////////////////////////
function GetSelectedIndex(obj,val)
{
	var i=0;

	while (obj.options[i] != null)
	{
		if(obj.options[i].value==val)
		{
			break;
		}
			
		i++;
	}
	
	return i;
}
////////////////////////////////////////////////////////////////////////////////
//LINES FUNCTIONS
////////////////////////////////////////////////////////////////////////////////
function OrderTable(element,mod,note)
{
	if(mod!='PRE_UPDATE')
	{ 
		// keep the search mod
		if(mod=='SEARCH')
		{
			document.LineForm.mod.value=mod;	
		}
		
		if(mod=='DELETE')
		{
			document.LineForm.mod.value='SEARCH';	
		}  		document.LineForm.order_by.value=element;		
		
		if(!document.LineForm.order_direction.value){document.LineForm.order_direction.value='desc';}
		if(document.LineForm.order_direction.value=='asc')
		{
			document.LineForm.order_direction.value='desc';		
			document.LineForm.image.value="/razinf/gif/down.gif";		
		}
		else
		{
			document.LineForm.order_direction.value='asc';
			document.LineForm.image.value="/razinf/gif/up.gif";		
		}

		
		document.LineForm.template.value=note+'_line.html';	
		document.LineForm.target='LINE';
		document.LineForm.start.value='0';
		document.LineForm.submit();
	}
}
////////////////////////////////////////
function DoSub(mod,rid,inmod,note,authorization)
{	
	//exit in case of pre-update
	if((mod=='UPDATE' || mod=='DELETE')&& inmod=='PRE_UPDATE')
	{
		return;
	}
	
	if(mod=='UPDATE' || mod=='DELETE')
	{
		if (authorization == 'NO_AUTHORIZE')
		{
			alert('You are not the owner of this record and have no authorization to update or delete it');
			return;
		}
	}
	
	if(mod=='UPDATE')
	{
		document.LineForm.location_line.value=location.href;		
		
		if(inmod != 'SEARCH' && inmod != '')
			KillMod(location.href);
		
		document.LineForm.location_head.value=window.parent.HEADER.location.href;		
		document.LineForm.mod.value='UPDATE';		
		document.LineForm.rid.value=rid;		
		document.LineForm.template.value=note+'.html';	
		document.LineForm.target='HEADER';
		
		var buf = GetElements(document.LineForm);

		buf = ReplaceBlank(buf);

		window.parent.HEADER.location.href = '/razinf-bin/merge.pl'+buf;
		
		document.LineForm.mod.value='PRE_UPDATE';		
		document.LineForm.rid.value=rid;		
		document.LineForm.template.value=note+'_line.html';	
		document.LineForm.target='LINE';
		
		document.LineForm.submit();
	}
	if(mod=='DELETE')
	{
		var answer=confirm('Are you sure you want to delete the record?');
		if(!answer)
		{
			return;
		}
		document.LineForm.mod.value='DELETE';		
		document.LineForm.rid.value=rid;		
		document.LineForm.template.value=note+'_line.html';	
		document.LineForm.target='LINE';
		
		window.parent.LINE.location.href = '/razinf-bin/merge.pl'+buf;
		document.LineForm.submit();
	}
}
////////////////////////////////////////
function KillMod(str)
{
	var pre,post;
	pre=str.indexOf('&mod=');
	post=str.indexOf('&',pre+1);
	document.LineForm.location_line.value=str.substr(0,pre)+str.substr(post);
}
/////////////////////////////////////////////////////////////////////////
function DoCookie()
{
	var expiration = new Date();
	var cookie = new Date() -1;
	
	expiration.setTime(expiration.getTime() +  315360000000); // 10 years
	SetCookie("razinf",cookie,expiration,null,null,null,document);
	return cookie;
}
/////////////////////////////////////////////////////////////////////////
function CheckCookie()
{
	var cookie = GetCookie("razinf");
	if(!cookie)
	{
	    cookie = DoCookie(); // set the cookie
	}
	
	document.sidForm.sid.value = cookie;
}
/////////////////////////////////////////////////////////////////////////
function CleanSubmitForm()
{
	var i;
	
	for (i=0; document.SubmitForm.elements[i]!=null; i++)
	{
		document.SubmitForm.elements[i].value='';
	}
}
/////////////////////////////////////////////////////////////////////////



