function Get_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )	{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) return null;
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {expires = expires * 1000 * 60 * 60 * 24;}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function updatefavorites(id, firsttime, addfav, remfav, seaadv, myfav) {
	var favorites= Get_Cookie( 'espac_favorites' ), temp = new Array(), found= false, i, str;
	if (favorites!= null) {
		temp = favorites.split(';'); 
		for(var i=0, len=temp.length; i<len; i++) {
			if(temp[i]==id) {
				found= true;
				temp.splice(i,1);
				break;
			}
		}
		if (found== false) temp.splice(0,0,id);
			favorites= temp.join(';');
	} else favorites= id;
	if (firsttime==false) {Set_Cookie('espac_favorites',favorites,'16','/','','');found= !found;}
	if (found) document.getElementById("favorites").innerHTML='<a href="javascript:void updatefavorites(\''+id+'\',false,\''+addfav+'\',\''+remfav+'\',\''+seaadv+'\',\''+myfav+'\')" class="remfav">'+remfav+'</a>';
	else document.getElementById("favorites").innerHTML='<a href="javascript:void updatefavorites(\''+id+'\',false,\''+addfav+'\',\''+remfav+'\',\''+seaadv+'\',\''+myfav+'\')" class="addfav">'+addfav+'</a>';
	favorites= Get_Cookie( 'espac_favorites' );
	if ((favorites!=null) && (favorites.length>1)) {
		favcnt=favorites.split(';').length-1; document.getElementById("myfavorites").innerHTML='<span>'+favcnt+'</span><div><a href="comprar/favoritos/'+favorites+'">'+myfav+'</a></div>';}
	else {favcnt=0;	document.getElementById("myfavorites").innerHTML='<span>'+favcnt+'</span><div>'+myfav+'</div>';}
}

function isfavorite(id) {
	var favorites=Get_Cookie('espac_favorites'),temp=new Array(),found=false,i;
	if (favorites!= null) {
		temp= favorites.split(';');
		for(i=0;i<temp.length;i++){if(temp[i]==id){found= true;break}}}
	return found;}

function isfavoritecol(id,row) {
	if (isfavorite(id))	document.write('<div class="lprowy">');
	else {
		if (row%2) document.write('<div class="lproww">');
		else document.write('<div class="lprowg">');}}

function cancelprop(e){e.cancelBubble=true;if (e.stopPropagation) e.stopPropagation()}

function updatecontact(yourname, youremail, yourphone, message, name, email, agentmsg) {
	var contact= Get_Cookie('espac_contact');
	if (contact!= null) {
		temp= contact.split(';;');
		if (yourname!= '') temp[0]= yourname;
		if (youremail!= '') temp[1]= youremail;
		if (yourphone!= '') temp[2]= yourphone;
		if (message!= '') temp[3]= message;
		if (name!= '') temp[4]= name;
		if (email!= '') temp[5]= email;
		if (agentmsg!= '') temp[6]= agentmsg;
		contact= temp.join(';;');
	} else contact= yourname+';;'+youremail+';;'+yourphone+';;'+message+';;'+name+';;'+email+';;'+agentmsg;
	Set_Cookie('espac_contact',contact,'1','/','','');
}

function checkemail(email){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(email)) return true;
	else return false;
}

function translate(lngs,lngd){google.language.translate(document.getElementById('text_'+lngs).innerHTML, lngs, lngd, function(result){if(!result.error){document.getElementById('text_'+lngd).innerHTML=result.translation;}})}