//**********************************************************  
//**********************************************************  
//**********************************************************

function last(img,sel,path){
	var sel_oEl = bpc.xpath("//b:select[@id='"+sel+"']/b:option[@b:state='selected']")[0];
	var all_oEl = bpc.xpath("//b:select[@id='"+sel+"']/b:option");
	
	bpc.removeBXMLAttribute('b:state',sel_oEl);
	bpc.setBXMLAttribute('b:state','selected', all_oEl[all_oEl.length-1]);
	document.getElementById(img).src = path+bpc.getBXMLAttribute('b:value', all_oEl[all_oEl.length-1]);	
}


function first(img,sel,path){
	var sel_oEl = bpc.xpath("//b:select[@id='"+sel+"']/b:option[@b:state='selected']")[0];
	var all_oEl = bpc.xpath("//b:select[@id='"+sel+"']/b:option");
	
	bpc.removeBXMLAttribute('b:state',sel_oEl);
	bpc.setBXMLAttribute('b:state','selected', all_oEl[0]);
	document.getElementById(img).src = path+bpc.getBXMLAttribute('b:value', all_oEl[0]);	
}


function previous(img,sel,path){		
		var all_oEl = bpc.xpath("//b:select[@id='"+sel+"']/b:option");
		var sel_oEl = bpc.xpath("//b:select[@id='"+sel+"']/b:option[@b:state='selected']")[0];
				
		if (sel_oEl){
			for (var i = 0; i< all_oEl.length; i++)
				if (bpc.getBXMLAttribute('b:value',all_oEl[i]) == bpc.getBXMLAttribute('b:value',sel_oEl)) break;
			
			if (i == 0) i=all_oEl.length-1;
			
			bpc.removeBXMLAttribute('b:state',sel_oEl);
			bpc.setBXMLAttribute('b:state','selected', all_oEl[i-1]);
			document.getElementById(img).src = path+bpc.getBXMLAttribute('b:value', all_oEl[i-1]);
		}else{			
			bpc.setBXMLAttribute('b:state','selected',all_oEl[all_oEl.length-1]);
			document.getElementById(img).src = path+bpc.getBXMLAttribute('b:value',all_oEl[all_oEl.length-1]); 
		} 

}


function next(img,sel,path){		
		var all_oEl = bpc.xpath("//b:select[@id='"+sel+"']/b:option");
		var sel_oEl = bpc.xpath("//b:select[@id='"+sel+"']/b:option[@b:state='selected']")[0];
				
		if (sel_oEl){
			for (var i = 0; i< all_oEl.length; i++)
				if (bpc.getBXMLAttribute('b:value',all_oEl[i]) == bpc.getBXMLAttribute('b:value',sel_oEl)) break;
			
			if (i+1 == all_oEl.length) i=-1;
			
			bpc.removeBXMLAttribute('b:state',sel_oEl);
			bpc.setBXMLAttribute('b:state','selected', all_oEl[i+1]);
			document.getElementById(img).src = path+bpc.getBXMLAttribute('b:value', all_oEl[i+1]);
		}else{			
			bpc.setBXMLAttribute('b:state','selected',all_oEl[1]);
			document.getElementById(img).src = path+bpc.getBXMLAttribute('b:value',all_oEl[1]); 
		} 

}

function change(img,sel,path) {
	document.getElementById(img).src = path+ bpc.getBXMLAttribute('b:text', document.getElementById(sel));
}


//**********************************************************
function move(){
	//bpc.execute('<s:task b:action="invisible" b:target="id(\'readmore\')" />');
	bpc.execute('<s:task b:action="move" b:source="id(\'new\')"  b:destination="id(\'new_\')" b:mode="aslastchild" />');
	bpc.execute('<s:task b:action="move" b:source="id(\'promo\')"  b:destination="id(\'new_\')" b:mode="aslastchild" />');
	//bpc.execute('<s:task b:action="visible" b:target="id(\'readmore\')" />');
}//*********************************************************

//**********************************************************
function readmore_n(nid){
	send_data('','','','POST','readmore','admin/node.php?action=load_cont_id&id='+nid);
	//bpc.execute('<s:task b:action="load" b:url="admin/node.php?action=load_cont_id&amp;id='+nid+'" b:destination="id(\'readmore\')" />');
}//*********************************************************


//**********************************************************
function show_colection(nid){
	move();
	bpc.execute('<s:task b:action="load" b:url="admin/node.php?action=show_colection&amp;id='+nid+'" b:destination="id(\'readmore\')" />');
}//*********************************************************


//**********************************************************
function show_colection_page(page){
	bpc.execute('<s:task b:action="load" b:url="admin/node.php?action=show_colection&amp;page='+page+'" b:destination="id(\'readmore\')" />');
}//*********************************************************


//**********************************************************
function readmore(nid,p,resp){
	send_data('','','','POST',resp,'admin/node.php?action=load_cont_id&p='+p+'&id='+nid);
}//*********************************************************

//**********************************************************
function sendmail(){
	if (checkEMInput()== false) return;
	
	var name=document.getElementById('name').value;
	var email=document.getElementById('email').value;
	var comment=document.getElementById('comment').value;
	
	
	var data = 'name|split2|'+name+'|split1|email|split2|'+email+'|split1|comment|split2|'+comment; 
	//alert(data);
	
	
	send_data(data,'|split1|','|split2|','POST','result','tools/infusions/contactus/contactus.php?action=send');
}//*********************************************************

//**********************************************************
function checkEMInput(){
		var name=document.getElementById('name');
		
		if(name.value == "")	{
			alert("Pleace, enter your name.");
			name.focus();
			return false;
		}

		email = document.getElementById('email').value;

		if ((email.length < 3) || (email.length > 50) ||
			(email.charAt(0) == '@') || (email.charAt(email.length-1) == '@') ||
			(email.charAt(0) == '.') || (email.charAt(email.length-1) == '.') ||
			(email.indexOf('.') == -1) || (email.indexOf('@') == -1) ||
			(email.indexOf('@') != email.lastIndexOf('@')) ||
			(email.indexOf(' ') > 0) || (email.indexOf('?') > 0) || (email.indexOf('..') > 0)
			)
		{
			alert("Pleace, enter real e-mail addres.");
			document.getElementById('email').focus();
			return false;
		}   
    
    var comment=document.getElementById('comment');
		if(comment.value == "")
		{
			alert("Pleace, enter your comment or question.");
			comment.focus();
			return false;
		}
		return true;
}
//**********************************************************

//**********************************************************
function incl_phpfile(phppf,nid){
	send_data('','','','POST','readmore',phppf+'?nid='+nid);
}//*********************************************************
