function getWidth() {
	return screen.availWidth>800?screen.availWidth-50:screen.availWidth;
}

function getHeight() {
	return screen.availHeight;
}

function PickByType(bound_field,DataSource,textName,searchType) {
	try {
	document.all.hdScroll.value=document.body.scrollTop;
	}catch(e){}
	
	obj=document.getElementById(bound_field);
	var result=-1;
	if(!searchType)
		searchType='singleselect';
	if(obj)
		result=window.showModalDialog('SelectorFrame.php?DataSource='+DataSource+'&value='+obj.value+'&searchType='+searchType+'&textName='+textName,'','dialogwidth:'+getWidth()+'px; dialogheight:'+getHeight()+'px; resizable:yes; status:yes; closed:no; help:no; ');
		//	window.open('SelectorFrame.php?DataSource='+DataSource+'&value='+obj.value+'&searchType='+searchType+'&textName='+textName);		
	else 
	{
		obj=document.getElementById(bound_field+'[]');
		if(obj)
			result=window.showModalDialog('SelectorFrame.php?DataSource='+DataSource+'&value='+obj.value+'&searchType='+searchType,'','dialogwidth:'+getWidth()+'px; dialogheight:'+getHeight()+'px; resizable:yes; status:yes; closed:no; help:no; ');
			//window.open('SelectorFrame.php?DataSource='+DataSource+'&value='+obj.value+'&searchType='+searchType+'&textName='+textName);		
	}
	try {
		document.all.centralTabtr.style.display='none';
		document.all.tdHeader.rName=document.all.tdHeader.innerHTML;
		document.all.tdHeader.style.position='absolute';
		document.all.tdHeader.style.top='0px';
		document.all.tdHeader.style.width='100%';
		document.all.tdHeader.innerHTML='Refreshing data...';
	}catch(e){}
	if(result!=-1&&result!='undefined'&&result!=null) {
		try {
			var t=document.getElementById('selectedid');
			if(t) {
				
				t.value=textName+'#'+result;
			
			}
		}
		catch(e){}
	}
	else {
	}
	
}

function EditForm(viewId,command,ref_id,ref_table,id,ref_edit_id) {
	
	try {
	document.all.hdScroll.value=document.body.scrollTop;
	
	}catch(e){}
	if(!ref_edit_id)
		ref_edit_id='';
	else
		ref_edit_id='^ref_edit_id='+ref_edit_id;
	if(!id)
		id='';
	else
		id='^id='+id;
	var result=window.showModalDialog('SelectorFrame.php?url=EditForm.php?viewId='+viewId+id+'^command='+command+'^ref_id='+ref_id+'^ref_table='+ref_table+ref_edit_id,'','dialogwidth:'+getWidth()+'px;center:yes; dialogheight:'+getHeight()+'px; resizable:yes; status:yes; closed:no; help:no; ');
	try {
		document.all.centralTabtr.style.display='none';
		document.all.tdHeader.rName=document.all.tdHeader.innerHTML;
		document.all.tdHeader.style.position='absolute';
		document.all.tdHeader.style.top='0px';
		document.all.tdHeader.style.width='100%';
		document.all.tdHeader.innerHTML='Refreshing data...';
	}catch(e){}
	try {window.setTimeout("window.scrollTo(0,"+document.body.scrollTop+");",1);}catch(e){}
//	try {window.scrollTo(0,document.body.scrollTop);}catch(e){}
	if(result==-500) {
		window.returnValue=-500;
	//	document.clear();
		document.location.href='about:blank';
		window.close();
	//	window.setTimeout('window.returnValue=-500;window.close()',1);
	}
//	var result=window.open('SelectorFrame.php?url=EditForm.php?viewId='+viewId+id+'^command='+command+'^ref_id='+ref_id+'^ref_table='+ref_table+ref_edit_id);
}

function EditFormSp_Field(viewId,command,ref_id,ref_table,id,ref_edit_id,sp_field,field) {
	
	try {
	document.all.hdScroll.value=document.body.scrollTop;
	
	}catch(e){}
	if(!ref_edit_id)
		ref_edit_id='';
	else
		ref_edit_id='^ref_edit_id='+ref_edit_id;

	if(!sp_field)
		sp_field='';
	else {
		sp_field='^sp_fiels='+sp_field;
		
	}
	if(!id)
		id='';
	else
		id='^id='+id;
	var result=window.showModalDialog('SelectorFrame.php?url=EditForm.php?viewId='+viewId+id+'^command='+command+'^ref_id='+ref_id+'^ref_table='+ref_table+ref_edit_id+sp_field,'','dialogwidth:'+getWidth()+'px;center:yes; dialogheight:'+getHeight()+'px; resizable:yes; status:yes; closed:no; help:no; ');
	try {
	/*	alert(result);
		if(field) {
			if(result.indexOf('_!^')>-1) {
				result=result.split('_!^');
				document.all.field.innerHTML=result[1];
				result=result[0];
			}
		}*/
		document.all.centralTabtr.style.display='none';
		document.all.tdHeader.rName=document.all.tdHeader.innerHTML;
		document.all.tdHeader.style.position='absolute';
		document.all.tdHeader.style.top='0px';
		document.all.tdHeader.style.width='100%';
		document.all.tdHeader.innerHTML='Refreshing data...';
	}catch(e){}
	try {window.setTimeout("window.scrollTo(0,"+document.body.scrollTop+");",1);}catch(e){}
//	try {window.scrollTo(0,document.body.scrollTop);}catch(e){}
	if(result==-500) {
		window.returnValue=-500;
	//	document.clear();
		document.location.href='about:blank';
		window.close();
	//	window.setTimeout('window.returnValue=-500;window.close()',1);
	}
//	var result=window.open('SelectorFrame.php?url=EditForm.php?viewId='+viewId+id+'^command='+command+'^ref_id='+ref_id+'^ref_table='+ref_table+ref_edit_id);
}

function EditBookingForm(viewId,command,ref_id,ref_table,id,ref_edit_id) {
	

	if(!ref_edit_id)
		ref_edit_id='';
	else
		ref_edit_id='^ref_edit_id='+ref_edit_id;
	if(!id)
		id='';
	else
		id='^id='+id;
	
	var result=window.showModalDialog('SelectorFrame.php?url=bookingForm.php?viewId='+viewId+id+'^command='+command+'^ref_id='+ref_id+'^ref_table='+ref_table+ref_edit_id,'','dialogwidth:'+getWidth()+'px; dialogheight:'+getHeight()+'px; resizable:yes;center:yes; status:yes; closed:no; help:no; ');
	try {
		document.all.centralTabtr.style.display='none';
		document.all.tdHeader.rName=document.all.tdHeader.innerHTML;
		document.all.tdHeader.style.position='absolute';
		document.all.tdHeader.style.top='0px';
		document.all.tdHeader.style.width='100%';
		document.all.tdHeader.innerHTML='Refreshing data...';
	}catch(e){}
	if(result==-500) {
		window.returnValue=-500;
	//	document.clear();
		document.location.href='about:blank';
		window.close();
	//	window.setTimeout('window.returnValue=-500;window.close()',1);
	}
	//var result=window.open('SelectorFrame.php?url=bookingForm.php?viewId='+viewId+id+'^command='+command+'^ref_id='+ref_id+'^ref_table='+ref_table+ref_edit_id);
}

function EditFormByType(typenum,type,viewId,command,ref_id,ref_table,id,ref_edit_id) {
	try {
	document.all.hdScroll.value=document.body.scrollTop;
	}catch(e){}
	
	var ref_type='';
	if(typenum!=null&&typenum!='undefined') {
		ref_type='^ref_type='+typenum;
	}
	else {
		obj=document.getElementById(type);
		var result=-1;
		if(obj)
			ref_type='^ref_type='+obj.value;
			//	window.open('SelectorFrame.php?DataSource='+DataSource+'&value='+obj.value+'&searchType='+searchType+'&textName='+textName);		
		else 
		{
			obj=document.getElementById(type+'[]');
			if(obj)
				ref_type='^ref_type='+obj.value;
		}
	}
	
	if(!ref_edit_id)
		ref_edit_id='';
	else
		ref_edit_id='^ref_edit_id='+ref_edit_id;
	if(!id)
		id='';
	else
		id='^id='+id;
	var result=window.showModalDialog('SelectorFrame.php?url=EditForm.php?viewId='+viewId+id+ref_type+'^command='+command+'^ref_id='+ref_id+'^ref_table='+ref_table+ref_edit_id,'','dialogwidth:'+getWidth()+'px; dialogheight:'+getHeight()+'px; resizable:yes;center:yes; status:yes; closed:no; help:no; ');
	try {
		document.all.centralTabtr.style.display='none';
		document.all.tdHeader.rName=document.all.tdHeader.innerHTML;
		document.all.tdHeader.style.position='absolute';
		document.all.tdHeader.style.top='0px';
		document.all.tdHeader.style.width='100%';
		document.all.tdHeader.innerHTML='Refreshing data...';
	}catch(e){}
	if(result==-500) {
		window.returnValue=-500;
		window.close();
	}
	//var result=window.open('SelectorFrame.php?url=EditForm.php?viewId='+viewId+id+'^command='+command+'^ref_id='+ref_id+'^ref_table='+ref_table+ref_edit_id);
}

function CustomPick(userFunc,viewId,command,ref_id,ref_table,id,ref_edit_id,searchType,table,filter) {
	
	var rei=0;
	if(!searchType)
		searchType='singleselect';
	if(!ref_edit_id)
		ref_edit_id='';
	else {
		rei=ref_edit_id;
		ref_edit_id='^ref_edit_id='+ref_edit_id;
		
	}
	var fil='';
	if(filter)
		fil='^filter='+filter;
	if(!id)
		id='';
	else
		id='^id='+id;
	var result=window.showModalDialog('SelectorFrame.php?url=SearchForm.php?viewId='+table+'^searchtype='+searchType+fil,'','dialogwidth:'+getWidth()+'px; dialogheight:'+getHeight()+'px; resizable:yes; status:yes;center:yes; closed:no; help:no; ');
	try {
		document.all.centralTabtr.style.display='none';
		document.all.tdHeader.rName=document.all.tdHeader.innerHTML;
		document.all.tdHeader.style.position='absolute';
		document.all.tdHeader.style.top='0px';
		document.all.tdHeader.style.width='100%';
		document.all.tdHeader.innerHTML='Refreshing data...';
	}catch(e){}
	if(result!=-1&&result!='undefined'&&result!=null) {
		try {
			var t=document.getElementById('hdSpecial');
			if(t) {
				t.value=result+'|'+userFunc+'#'+viewId+'#'+command+'#'+ref_id+'#'+ref_table+'#'+id+'#'+rei;
			
			}
		}
		catch(e){}
	}
	else {
	}
//	var result=window.showModalDialog('SelectorFrame.php?url=SearchForm.php?viewId='+viewId+id+'^command='+command+'^ref_id='+ref_id+'^ref_table='+ref_table+ref_edit_id,'','dialogwidth:'+getWidth()+'px; dialogheight:'+getHeight()+'px; resizable:yes; status:yes; closed:no; help:no; ');
//	//var result=window.open('SelectorFrame.php?url=EditForm.php?viewId='+viewId+id+'^command='+command+'^ref_id='+ref_id+'^ref_table='+ref_table+ref_edit_id);
}



function PickForm(table,bound_field,view_field,textName,SearchType,filter) {
	
	var result=window.showModalDialog('SelectorFrame.php?url=SearchForm.php?viewId='+table+'^searchtype='+SearchType,'','dialogwidth:'+getWidth()+'px; dialogheight:'+getHeight()+'px; resizable:yes; status:yes; closed:no; help:no; ');
	try {
		document.all.centralTabtr.style.display='none';
		document.all.tdHeader.rName=document.all.tdHeader.innerHTML;
		document.all.tdHeader.style.position='absolute';
		document.all.tdHeader.style.top='0px';
		document.all.tdHeader.style.width='100%';
		document.all.tdHeader.innerHTML='Refreshing data...';
	}catch(e){}
	if(result!=-1&&result!='undefined'&&result!=null) {
		try {
			var t=document.getElementById('selectedid');
			if(t) {
				var s=textName.split("|");
				s[0]+='#'+result;
				t.value=s.join("|");
				//t.value=textName+'#'+result;		
			}
		}
		catch(e){}
	}
	else {
	}
	
}

function switchMenu(obj) {
	obj=document.getElementById(obj);
	if(obj) {
		if(obj.style.display=='none')
			obj.style.display='block';
		else 
			obj.style.display='none';
	}
	
}

function setMenuStyleOver(obj) {
	if(obj.firstChild.className=='normalLI')
		obj.firstChild.className='overLI';
	else
		obj.firstChild.className='overSelectedLI';	
}

function setMenuStyleOut(obj) {
	
	if(obj.firstChild.className=='overLI')
		obj.firstChild.className='normalLI';
	else
		obj.firstChild.className='downLI';	
}

function setMenuStyleClick(obj) {
	var arr=document.getElementsByTagName('LI');
	for(i=0;i<arr.length;i++) {
		arr[i].className='normalLI';
	}
	obj.firstChild.className='downLI';
	try {
	var t=obj.childNodes(0).childNodes(0);
	t.className='selectede';
	}catch(e){}
	
}

function closeForm(formName) {
	var par=1;
	if(window.returnValue==-500)
		par=2;
	var pageUrl='EditForm.php?unlock='+par;
	var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
	xmlRequest.open("GET", pageUrl, true); 
	xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	xmlRequest.send(null); 
	return xmlRequest; 
	return true;
}

function setTodo(id) {
	var pageUrl='SearchForm.php?callback=1&param='+id;
	var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
	xmlRequest.open("GET", pageUrl, false); 
	xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	xmlRequest.send(null); 
	return xmlRequest; 
	return true;	
}

function PrintInvoice(id) {
	window.open('Invoice.php?id='+id);
	//window.showModalDialog('SelectorFrame.php?url=Invoice.php?id='+id,'','dialogwidth:'+getWidth()+'px; dialogheight:'+getHeight()+'px; resizable:yes; status:yes; closed:no; help:no; ');
}
	
function isNum(checkFloat) {
	if(event.keyCode>=48&&event.keyCode<=57)
		return true;
	var val=event.srcElement.value;
	if(event.keyCode==45) {
		var val=event.srcElement.value;
		if(val.length>0)
			return false;
		return true;
			
	}
	if(checkFloat==true) {
		if(event.keyCode=='46'||event.keyCode=='44') {
			if(val.indexOf(',')>=0||val.indexOf('.')>=0)
				return false;
			return true;
		}
		return false;
	}
	return false;
	
}

function m_confirm(field) {
	var result=window.showModalDialog('SelectorFrame.php?dontlock=1&title=Password%20protected&url=confirmForm.php?field='+field,'','dialogwidth:'+400+'px; dialogheight:'+300+'px; resizable:yes; status:yes; closed:no; help:no; ');
	return result;
}

function checkForWarning() {
	var obj=document.getElementById('warning_msg');
	if(obj&&obj.innerText.length>0) {
		document.all.divWarning.style.display='block';
		obj.style.backgroundColor='pink';
	}
}

function viewFile(id,isFile,isGalery,dir) {
	var isg=0;
	if(isGalery==1)
		isg=1;
	var d='';
	if(dir) {
		d='&d='+dir;
	}
	
	if(isFile==1) {
		var h=window.open('/be/viewFile.php?id='+id+'&file=1&isGallery='+isg+d,'Picture');
		h.focus();
	}
	else {
		var h=window.open('/be/viewFile.php?id='+id+d,'Picture');
		h.focus();
	}
} 

document.onreadystatechange=fnStartInit;
//document.onload=new function(e) {try{window.scrollTo(0,200);}catch(e){}};

function fnStartInit()
{
	
   if (document.readyState=="complete")
   {
   		
      try {
      		window.scrollTo(0,document.all.hdScroll.value);
      		document.all.centralTabtr.style.display='block';
      		if(document.all.tdHeader.rName)
      			document.all.tdHeader.innerHTML=document.all.tdHeader.rName;
      		
      }
      catch(e){}
   }
}

function setDialogPosition(w,h) {
	if(w==0) {
		w=getWidth();
	}
	if(h==0) {
		h=getHeight();
	}
	rw=screen.availWidth;
	rh=getHeight();
	window.dialogLeft=(rw-w)/2+'px';
	window.dialogTop=(rh-h)/2+'px';
}

function movelist(obj1,obj2) {
	var o1=document.getElementById(obj1);
	var o2=document.getElementById(obj2);
	var hidden_field =document.getElementById('hd'+obj1);
	for(i=0;i<o2.options.length;i++)
		if(o2.options[i].selected) {
			if(o2.options[i].value==0)
				continue;
			var t=false;
			for(j=0;j<o1.options.length;j++)
				if(o1.options[j].value==o2.options[i].value) {
					t=true;
					break;;
				}
			if(t==true)
				continue;
			var oOption = document.createElement("OPTION");
			o1.options.add(oOption);
			oOption.innerText =o2.options[i].innerText;
			oOption.value = o2.options[i].value;
		}
	var com='';
	hidden_field.value='';
	if(hidden_field.value.length>0)
		com=',';
	
	for(i=0;i<o1.options.length;i++) {
		hidden_field.value+=com+o1.options[i].value;
		com=',';
	}
    
}

function removelist(obj1,obj2) {
	var o1=document.getElementById(obj1);
	var o2=document.getElementById(obj2);
	var hidden_field =document.getElementById('hd'+obj1);
	for(i=o1.options.length-1;i>=0;i--)
		if(o1.options[i].selected)
			o1.options.remove(i);
	var com='';
	hidden_field.value='';
	if(hidden_field.value.length>0)
		com=',';
	for(i=0;i<o1.options.length;i++) {
		hidden_field.value+=com+o1.options[i].value;
		com=',';
	}
}

function checkClientAdd(obj,table) {
	if(!table||table==''||table==undefined)
		table='clients'
	var hd=document.getElementById('btAddnew');
	if(hd) {
	var par=obj.parentElement;
	while(par.tagName!='BODY'&&par.tagName!='TABLE') {
		par=par.parentElement;
	}
	if(par.tagName=='TABLE')
		if(par.rows.length==2) {
			if(window.confirm("Do you want to use data in the filter!")) {
				hd.value=table;
				return;
			}
		}
	}
	
	
	EditForm(table,"add","","",null,0);
}

function sendInfo(id) {
	if(id&&id!='') {
		var arr=id.split(",");
		for(i=1;i<arr.length;i++) {
		//	(viewId,command,ref_id,ref_table,id,ref_edit_id) {
			EditForm('send_ridex_form','edit','client_id','clients',arr[0],arr[i])
		//	EditForm('send_ridex_form','add','','','',null);
		}
	}
}


function setWeight(weight_1,s,selected) {
	
//	var s=document.all.weight;
	if(s.options)
	for(i=s.options.length-1;i>=0;i--) {
		s.remove(i);
	}
	var oOption = document.createElement("OPTION");
		oOption.text='';
		oOption.value=0;
		s.add(oOption);
	var n=weight_1.selectedIndex;
	var st=0;
	var ed=0;
	switch(n) {
		case 0: {
			return;
		}
		case 1: {
			var index=1;
			for(i=5;i<19;i++) {
				for(j=0;j<14;j++)  {
					var oOption = document.createElement("OPTION");
					if(j!=0)
						oOption.text=i+'st '+j+'lbs';
					else 
						oOption.text=i+'st';
					
					oOption.value=index++;
				//	oOption.value=oOption.text;
					s.add(oOption);
					if(selected==oOption.value) {
						oOption.selected=true;
					}
				}
			}
			return;
		}
		case 2: {
			st=71;
			ed=255;
			break;
		}
		case 3: {
			st=32;
			ed=116;
			break;
		}
	}
	index=1;
	for(i=st;i<=ed;i++) {
		var oOption = document.createElement("OPTION");
		oOption.text=i+'';
		
		oOption.value=index++;
		//oOption.value=oOption.text;
		s.add(oOption);
		if(selected==oOption.index) {
			oOption.selected=true;
		}
	}
			
}

function setHeight(height_1,s,selected) {
	
//	var s=document.all.height;
	if(s.options)
	for(i=s.options.length-1;i>=0;i--) {
		s.remove(i);
	}
	var oOption = document.createElement("OPTION");
		oOption.text='';
		oOption.value=0;
		s.add(oOption);
	var n=height_1.selectedIndex;
	var st=0;
	var ed=0;
	switch(n) {
		case 1: {
			var index=1;
			for(i=4;i<7;i++) {
				for(j=0;j<12;j++)  {
					var oOption = document.createElement("OPTION");
					if(j!=0)
						oOption.text=i+'ft '+j+'ins';
					else 
						oOption.text=i+'ft';
					
					oOption.value=index++;
				//	oOption.value=oOption.text;
					s.add(oOption);
					if(selected==oOption.value) {
						oOption.selected=true;
					}
				}
			}
			return;
		}
		case 2: {
			index=1;
			var f=1.21;
			while(f<2.12) {
				var oOption = document.createElement("OPTION");
				oOption.text=f.toFixed(2);
				
				oOption.value=index++;
			//	oOption.value=oOption.text;
				s.add(oOption);
				if(selected==oOption.value) {
						oOption.selected=true;
				}
				f+=0.03;
			}
			break;
		}
		
	}

}


function calculatePrices(row,col) {
	var st=row;
	var en=row;
	if(row==0) {
		st=1;
		en=15;
	}
	
	for(row=st;row<=en;row++) {
		var objNett=document.getElementById('price_'+row+'_2');
		var objRack=document.getElementById('price_'+row+'_3');
		var objPack=document.getElementById('price_'+row+'_4');
		var supplierPrice=parseFloat(document.getElementById('price_'+row+'_1').value);
		if(supplierPrice==0) {
			objNett.value='0';
			objRack.value='0';
			try {
			objPack.value='0';
			}catch(e){}
			objNett.style.color='darkgray';
			objNett.style.backgroundColor='gray';
			objRack.style.color='darkgray';
			objRack.style.backgroundColor='gray';
			try {
				objPack.style.color='darkgray';
				objPack.style.backgroundColor='gray';
			}catch(e){}
			continue;
		}
		else {
			objNett.style.color='black';
			objNett.style.backgroundColor='white';
			objRack.style.color='black';
			objRack.style.backgroundColor='white';
			try {
				objPack.style.color='black';
				objPack.style.backgroundColor='white';
			}catch(e){}
		}
		var commissionRide=parseFloat(document.all.commission_ride.value);	
		var tip=0;
		if(document.all.tip) {
			tip=parseFloat(document.all.tip.value);	
		}
		var localTax=0;
		if(document.all.local_tax) {
			localTax=parseFloat(document.all.local_tax.value);	
		}
		var margin=parseFloat(document.all.our_margin.value);
		if(margin>=100.0) {
			alert("Please verify OUR MARGIN value (must be <100%)!");
			document.all.our_margin.select();
			document.all.our_margin.focus();
			return;
		}
		var rate=parseFloat(document.all.currency_rate.value);
		
		
		
		var nettVal=parseFloat(supplierPrice*((100-commissionRide)/100)+tip+localTax);
		
		if(row==3) {
			try {
				if(document.all.ch_single.checked)
					nettVal=parseFloat(supplierPrice+tip+localTax);
			}
			catch(e){}
		}
	//	if((Round(nettVal,0))==nettVal)
	//		objNett.value=Round(nettVal,0);
	//	else
		objNett.value=nettVal.toFixed(2);
		var rackVal=(nettVal/((100-margin)/100)/rate);
	//	if((Int(rackVal))==rackVal)
	//		objRack.value=Int(rackVal).toString();
	//	else
			objRack.value=rackVal.toFixed(2);
		
		var fa=0,ca=0,aa=0,ta=0;
		try {
			fa=parseFloat(document.all.flight_allowance.value);
		}catch(e){}
		try {
			ca=parseFloat(document.all.car_allowance.value);
		}catch(e){}
		try {
			aa=parseFloat(document.all.additional_accomm_allowance.value);
		}catch(e){}
		try {
			ta=parseFloat(document.all.transfer_price.value);
		}catch(e){}
		
		if(fa!=0||ca!=0||aa!=0||ta!=0)
		if(objPack) {
			try {
			var packVal=rackVal+fa+ca+aa+ta;
		//	if((Int(packVal))==packVal)
		//		objPack.value=Int(packVal).toString();
		//	else
				objPack.value=packVal.toFixed(2);
			}catch(e){}
		
		}

	}
}

function checkDivRegion(obj,e) {
	var bndRight = obj.getBoundingClientRect().right + document.body.scrollLeft;
    var bndLeft = obj.getBoundingClientRect().left +  document.body.scrollLeft;
    var bndTop = obj.getBoundingClientRect().top +   document.body.scrollTop;
	var bndBottom = obj.getBoundingClientRect().bottom + document.body.scrollTop;
	//alert(bndLeft+','+bndRight+','+bndTop+','+bndBottom+','+e.x+','+e.y);
	if(e.x>bndLeft&&e.x<bndRight&&e.y+document.body.scrollTop>bndTop&&e.y+document.body.scrollTop<bndBottom)
		return false;
	return true;

}

function gethdID(obj) {
	var s=obj.value;
	if(s.length==0)
		return false;
	s= s.split('(').join('');
	return s.split(')').join('');
}

function returnCalendarValues(fields) {
	 try {
	 	window.opener.document.all.selectedid.value=fields;
	 	window.opener.document.forms['__editForm'].submit();
	 	//getParentFormElement(window.opener.document.all.ride_availability_id).submit();
	 } catch(e) {
	 	alert("Parent window has been closed! Data cannot be changed!");
	 }
	 window.close();
}

function setHideDiv(obj) {
	
	try {
	var w=document.body.scrollWidth;
	var h=document.body.scrollHeight;
	obj.style.width=window.dialogWidth;
	obj.style.height=window.dialogHeight;
	obj.style.zIndex=999;
	obj1=document.all.frHide;
	obj1.width=document.body.scrollWidth;
	obj1.height=document.body.scrollHeight;
	}catch(e){}
	
//	obj1.width=w;
//	obj1.height=h;
	
}

function getMap(str_obj,gis_x,gis_y,l_obj) {
	var obj=document.getElementById(str_obj);
	if(obj) {
		if(obj.value=='') {
			alert("Enter post code!");
			return false;
		}
		var result=window.showModalDialog('SelectorFrame.php?url=map.php?pc='+escape(obj.value),'','dialogwidth:530px;center:yes; dialogheight:500px; resizable:no; status:yes; closed:no; help:no; ');
//		var result=window.open('map.php?pc='+escape(obj.value));
		if(result!=-1) {
			s=result.split(",");
			if(s.length!=2)
				return;
			if(s[0]==0&&s[1]==0)
				return;
			try {
				document.getElementById(gis_x).value=s[0];
				document.getElementById(gis_y).value=s[1];
				document.getElementById(l_obj).innerText='OK';
			}catch(e) {}
			
		}
	}
}

function getxmlHTTP() {
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}


/*************GALERY*****************/

var tout=null;
var shCurr_img=0;
function startSlide(img,speed,curr_img,str_img,dir) {
	var images=str_img.split(",");
	if(curr_img>=images.length)
		return;
	document.getElementById(img).src=dir+"/pic"+images[curr_img];

	var ni=curr_img+1;
	var sp=document.getElementById(speed);
	
	var spd=sp.options[sp.selectedIndex].value;
	tout=window.setTimeout('startSlide("'+img+'","'+speed+'",'+ni+',"'+images+'","'+dir+'")',spd);
	document.getElementById('lb_pic').innerText=(curr_img+1)+'/'+(images.length);
	shCurr_img=curr_img;
	setPicLinks(images.length-1);
}

function setPicLinks(len) {
	
	if(shCurr_img==len) {
		document.getElementById('a_np').style.display='none';
		document.getElementById('l_a_np').style.display='inline';
	}
	else {
		document.getElementById('l_a_np').style.display='none';
		document.getElementById('a_np').style.display='inline';
	}
	if(shCurr_img==0) {
		document.getElementById('a_pp').style.display='none';
		document.getElementById('l_a_pp').style.display='inline';
	}
	else {
		document.getElementById('a_pp').style.display='inline';
		document.getElementById('l_a_pp').style.display='none';
	}
}

function showPhoto(dir,img,str_img,folder) {
	
	cTimeOut();
	shCurr_img+=dir;
	var images=str_img.split(",");
	
	if(shCurr_img<0||shCurr_img>=images.length) {
		shCurr_img-=dir;
		setPicLinks(images.length-1);
		return;
	}
	setPicLinks(images.length-1);
	document.getElementById(img).src=folder+"/pic"+images[shCurr_img];
	
}

function cTimeOut() {
	if(tout!=null) {
		window.clearTimeout(tout);
		tout=null;
	}	
}


function expandLinkSelection(doc){
	var oSel=null;
	try {
  		oSel =  doc.selection.createRange();
	}catch(e) {
		alert("Cannot expand selection");
	}
	if(oSel==null)
		return;
  /*
    The selection is a control
    Maybe should make checks if this control make sense for linkig like IMG but not BUTTON
  */
  
  if(doc.selection.type=="Control"){
    return getParentElementByTagName(oSel(0),'A');
  }


  /*
    The selection is within a link 
  */
  
  var oEl = getParentElementByTagName(oSel.parentElement(),'A');
  if(oEl){
    oSel.moveToElementText(oEl);
	  oSel.select();	      
	  return oEl;
  }
  
	var oEl = oSel.parentElement();
	if(oEl){
	  
    oColl = oEl.getElementsByTagName('A');
    if(oColl.length==0)
      return null;
      
    oSelStart = oSel.duplicate();
    oSelStart.collapse();
    
    oSelEnd = oSel.duplicate();
    oSelEnd.collapse(false);
    
    oSelA = oSel.duplicate();
      
    for(var i = 0; i < oColl.length; i++){
      oSelA.moveToElementText(oColl(i));
      
      if(oSelA.inRange(oSelStart)){
        oSel.setEndPoint('StartToStart', oSelA);
        oSel.select();
        return oColl(i);
      }
      
      if(oSel.inRange(oSelA)){
        return oColl(i);
      }
      
      if(oSelA.inRange(oSelEnd)){
        oSel.setEndPoint('EndToEnd', oSelA);
        oSel.select();
        return oColl(i);
      }
      
    }
  }
  
  return null;
}

function createLink(doc, url, text, target,style){
  var oSel=null;
  try {
  	oSel =  doc.selection.createRange();
  }
  catch(e) {
  	alert("Cannot expand selection!");
  }
  if(oSel==null)
		return;
  if(!text)
  	text=url;
  if(doc.selection.type == "None"){
    if(text=='')
      text = url;
    oSel.text = text;
    oSel.moveStart('character', -text.length);
  } else {
    oSel.execCommand('Unlink');
  }
  oSel.execCommand('CreateLink', false, url);
  if(target!=''){
    var a = oSel.parentElement();
    if(a.tagName == "A"){
      if(style!=null)
      	a.className=style;
      a.target = target;
    }
  }
}

function getParentElementByTagName(oEl,sTag)
{
  while (oEl!=null && oEl.tagName!=sTag)
    oEl = oEl.parentElement
  return oEl
}

function changeCid(obj) {
	if(obj) {
		var cid=obj.options[obj.selectedIndex].value;
		if(cid==0)
			return false;
	//	if(window.location.pathname=='/books/catalog.php') {
	//		getParentFormElement(obj).submit();			
	//	}
	//	else {
			if(window.parent.frames.length&&window.parent.frames.length!='undefined') {
				window.parent.location='/?viewID=2&cid='+cid;
			}
			else {
				window.location='/?viewID=2&cid='+cid;
			}
	//	}
	}
	return false;
}

function setTown(obj) {
	var town=obj.options[obj.selectedIndex].value;
	if(town==0)
		return;
	if(window.parent.frames.length&&window.parent.frames.length!='undefined') {
		window.parent.location='/?viewID=4&town='+encodeURI(town);
	}
	else {
		window.location='/?viewID=4&town='+encodeURI(town);
	}
}

function goSearch(obj) {
	var s_obj=document.getElementById('search_by');
	var s_type=s_obj.options[s_obj.selectedIndex].value;
	self.location.href="/?viewID=2&st="+s_type+"&s="+encodeURI(document.getElementById('search_text').value);
	return false;
}