var ThisSearch = new Search();
var isIE = navigator.userAgent.indexOf('MSIE') != -1;
var isMac = navigator.userAgent.indexOf('Safari') != -1;
var backsidesCount = 0;
var BackSelected = -1;
var rowspager = 4;
var step1_selectedphotourl = '';
var backSideIE = '<div class="top"><span name="spName" class="tit">[Backside] (%1)</span></div><div class="postcard"><div class="pleft"><div class="fotologurl" id="fotologurl">%4</div><div class="fotologurl postcardph">&nbsp;</div><p id="edit"></p></div><div class="pright"><div class="addressFields">%6</div><div class="countries%5">%3</div></div></div><div class="lnk addressFloat" onclick="return pop(\'%1\')"></div>%2';
var backSideNonIE = '<div class="top"><span name="spName" class="tit">[Backside] (%1)</span></div><div class="postcard"><div class="pleft"><div class="fotologurl" id="fotologurl">%4</div><div class="fotologurl postcardph">&nbsp;</div><p id="edit"></p></div><div class="pright"><div class="addressFields">%6</div><div class="countries%5">%3</div></div></div><div class="lnk addressFloat" onclick="return pop(\'%1\')"></div>%2';
var popUp = window.location.href.toLowerCase().indexOf('popup') != -1;
var ddlCountries = '';
var defaultCountry = 'US';
var linkleftopen = '';
var currentlanguage = 'en';
var step1_backgroundcolor = 'ffffff';
var step1_backgroundimage = null;
var step1_type = 'PC';
var currentWidth2 = 315;
var currentHeight2 = 250;
var step1_IdealWidth2 = 315;
var step1_IdealHeight2 = 250;
var currentWidth = 422;
var currentHeight = 310;
var step1_IdealWidth = 422;
var step1_IdealHeight = 310;
var step1_ImageFormat = 'stretch';
var step1_RotateStep = 0;
var	fondo= "#cbe4fa";
var color = "red";
var contest = 0;
var fondoaffiliate= "#fffde4";
var pagina = 1;
var user;
var country;
var fechadesde;
var fechahasta;
var csv =0;
var recipient = 1;
var anteriorrecipient = 1;
var totalpostcards = 0;
var cantidadpostcards = 1;
var postales=0;
var idpostcard = 0;
var primero = 1;
var ultimo = 0;
var ultimo2 =0;
var font= 'FACE=\'Arial\'';
var cardprimera = 0;
var arrrecipients = new Array();
var fields = new Array(
	new Array(207, 25),
	new Array(207, 25),
	new Array(207, 25),
	new Array(207, 25),
	new Array(207, 25));
var addressesToDelete = new Array();
var step1_frame = 0;
var create_1 = false;
var create_2 = false;
var create_3 = false;
var totaladdresses = 0;
var idshareanterior = 0;
var idmediaanterior = 0;
var masssending = 0;
var marcostotales;
var marcoanterior = 0;
var unica = true;
var imageSizeDefaultWidth = "422px";
var imageSizeDefaultHeight = "310px";
var imagePleaseWait = "step1yourphoto2.gif";
var logoeditor = '';
var backcheckout = '/Cart';
var enterEvent;
var photographername = '';
var logogallery = '';
var region = '';

function getFlashMovieObject(movieName)
	{
		if (window.document[movieName])
		{
			return window.document[movieName];
		}
		if (navigator.appName.indexOf("Microsoft Internet")==-1)
		{
			if (document.embeds && document.embeds[movieName])
			{
				return document.embeds[movieName];
			}
		}
		else
		{
			return document.getElementById(movieName);
		}
	}
function getFlashText(id)
{
	return getFlashMovieObject(id).GetVariable('txt_text');
}

function getFlashVar(id, varname)
{
	return getFlashMovieObject(id).GetVariable(varname);
}

function setFlashVar(id, varname, value)
{
	getFlashMovieObject(id).SetVariable(varname, value);
}

function setFlashText(id, value)
{
	getFlashMovieObject(id).SetVariable('txt_text', value);
}

function setFlashFont(id, font)
{
	getFlashMovieObject(id).SetVariable('nombre_txt', font);
}
	
function Search()
{
	var c;
	var page;
	var totalPages;
	var rows;
	var cols;
	var spanPager;
	var pagerAnchors;
	var maxPages;
	this.Load = function()
	{
		this.c = $('containerResults');
		this.page = null;
		this.rows = rowspager;
		this.cols = 4;
		this.maxPages = 10;
		if(photos.length > 0)
		{
			this.spanPager = $('spPager');
			this.CreatePager();
			this.LoadPage(0);
		}
	}
	
	this.CreatePager = function()
	{
		var p = new Array();
		this.totalPages = Math.ceil(photos.length / (this.cols * this.rows));
		if(this.totalPages > this.maxPages)
		{
			this.totalPages = this.maxPages;
		}
		for(var i = 0; i < this.totalPages; i++)
		{
			p.push('<a id="pa');
			p.push(i.toString());
			p.push('" href="javascript:ThisSearch.LoadPage(');
			p.push(i.toString());
			p.push(');">');
			p.push((i + 1).toString());
			p.push('</a>');
			if(i != this.totalPages - 1) p.push(' | ');
		}
		this.spanPager.innerHTML = p.join('');
		this.pagerAnchors = this.spanPager.getElementsByTagName('a');
		this.pagerAnchors = Array();
		for(var i = 0; i < this.totalPages; i++)
		{
			this.pagerAnchors.push($('pa' + i.toString()));
		}
	}
	
	this.LoadPage = function(wich)
	{
		if(this.page != wich)
		{
			//cambiar p'agina actual
			if(this.page != null)
			{
				this.pagerAnchors[this.page].innerHTML = this.pagerAnchors[this.page].innerHTML.replace(/<b>/i, '').replace(/<\/b>/i, '');
			}
			this.page = wich;
			this.pagerAnchors[this.page].innerHTML = '<b>' + this.pagerAnchors[this.page].innerHTML + '</b>';
			//
			var offset = this.cols * this.rows * this.page;
			var t = new Array();
			var currPhotoIdx = 0;
			var currPhoto = null;
			t.push('<table cellpadding="0" cellspacing="0" border="0" class="boxes" id="tblPhotos">');
			for(var i=0; i<this.rows; i++)
			{
				if(currPhotoIdx == photos.length - 1 && currPhotoIdx != 0) break;
				t.push('<tr>');
				for(var j=0; j<this.cols; j++)
				{
					var currPhotoIdx = offset + (this.rows * i) + j;
					var currPhoto = photos[currPhotoIdx];
					if(currPhoto != null)
					{
						if (popUp)
						{
							t.push('<td class="box"><div class="cimg"><a onClick="UseImg(\'');
							t.push(currPhoto['Id'].toString());
							t.push('\');" style="cursor: pointer;"');
						}
						else
						{
							t.push('<td class="box"><div class="cimg"><a href="javascript:ThisSearch.Select(');
							t.push(currPhoto['Id'].toString() + ');');
						}						
						t.push('"><img src="');
						t.push(currPhoto['ThumbUrl']);
						t.push('" /></a></div>');
						t.push('<div class="inputs"><div class="date">' + currPhoto['Date'] + '</div></div></td>');
						t.push('<td class="inter"></td>');
					}
					else
					{
						t.push('<td class="box"><img src="images/layout/t.gif" /></td><td class="inter"></td>');
					}
				}
				t.push('</tr><tr><td class="inter">&nbsp;</td></tr>');
				if(currPhoto == null)
				{
					break;
				}
			}
			t.push('</table>');
			this.c.innerHTML = t.join('');
		}
	}
	
	this.GoToFirst = function()
	{
		this.LoadPage(0);
	}
	
	this.GoToPrevious = function()
	{
		if(this.page != 0)
			this.LoadPage(this.page - 1);
	}
	
	this.GoToNext = function()
	{
		if(this.page != this.totalPages - 1)
			this.LoadPage(this.page + 1);
	}
	
	this.GoToLast = function()
	{
		this.LoadPage(this.totalPages - 1);
	}
	
	this.Select = function(v)
	{
		$('hdSelected').value = v;
		__doPostBack('Create');
	}
}

function AddBackSide(txt, addr, ctry)
{
	backsidesCount++;
	var b = (isIE ? backSideIE : backSideNonIE).replace(/%1/g, backsidesCount);
	b = b.replace(/%2/, '<div class="remove" id="remove' + backsidesCount.toString() + '"><a href="javascript:Remove(' + backsidesCount + ');">' + removeTranslation + '</a></div>');
	b = b.replace(/%3/, GetDdlCountries(backsidesCount));
	b = b.replace(/%4/, '<a target="_blank" href="' + fotologLink + '">' + fotologLink + '</a>');
	b = b.replace(/%5/g, isMac ? 'Mac' : '');
	
	var tFields = new Array();
	for(var i = 0; i < fields.length; i++)
	{
		tFields.push('<div class="addressField"><textarea type="text" id="addressField_' + i.toString() + '_' + backsidesCount.toString() + '" onkeyup="handleKey(this, event, \'' + 'addressField_' + (i+1).toString() + '_' + backsidesCount.toString() + '\');" style="width: ' + fields[i][0] + 'px;" maxlength="' + fields[i][1] + '" wrap="off"></textarea></div>');
	}
	
	b = b.replace(/%6/, tFields.join(''));
	var e = document.createElement('div');
	e.className = 'back';
	e.id = 'backside' + backsidesCount.toString();
	e.innerHTML = b;
	$('containerBacksides').appendChild(e);
	
	if(arguments.length > 0 && txt)
	{
		insertEditFlash('edit', txt,getFontFromBody(txt));
	}
	else
	{
		insertEditFlash('edit', '','Arial');
	}
	
	if(arguments.length > 1 && addr)
	{
		var pieces = addr.split('\r\n');
		for(var i = 0; i < pieces.length; i++)
		{
			var f = $('addressField_' + i.toString() + '_' + backsidesCount.toString());
			if(f)
			{
				f.value = pieces[i];
			}
		}
	}
	
	if(arguments.length > 2 && ctry)
	{
		DdlSelectByValue($('ddlCountries' + backsidesCount.toString()), ctry);
	}
	
	FixNumbers();
	FixRemoves();
}

function Remove(which)
{
	if(CountBackSidesReal() == 1)
	{
		alert('You can\'t remove this postcard.');
	}
	else
	{
		if(confirm(areyousureTranslation))
		{
			$('containerBacksides').removeChild($('backside' + which));
			FixNumbers();
		}
	}
	FixRemoves();
}

function CountBackSidesReal()
{
	var c = 0;
	for(var i = 0; i <= backsidesCount; i++)
	{
		if($('edit'))
		{
			c++;
		}
	}
	return c;
}

function FixNumbers()
{
	var spsName = document.getElementsByTagName('span');
	var cI = 0;
	for(var i = 1; i < spsName.length; i++)
	{
		if(spsName[i].className == 'tit')
		{
			cI++;
			spsName[i].innerHTML = backsideTranslation;
		}
	}
}

function FixRemoves()
{
	var rem;
	var realCount = CountBackSidesReal();
	for(var i = 0; i <= backsidesCount; i++)
	{
		rem = $('remove' + i.toString());
		if(rem)
		{
			//rem.style.display = realCount == 1 ? 'none' : '';
			rem.style.display = 'none';
		}
	}
}

function count(where, what)
{
	var from = 0;
	var c = 0;
	while(where.indexOf(what, from) >= 0)
	{
		c++;
		from = where.indexOf(what, from) + 1;
	}
	return c;
}

function size(e)
{
	if(isIE)
	{
		while(e.scrollHeight > e.clientHeight)
		{
			var range = document.selection.createRange();
			var stored_range = range.duplicate();
			stored_range.moveToElementText(e);
			stored_range.setEndPoint('EndToEnd', range);
			e.selectionStart = stored_range.text.length - range.text.length;
			e.selectionEnd = e.selectionStart + range.text.length;
			
			var a = e.value.substring(e.selectionStart, e.selectionStart + 2) == '\r\n';
			
			var preS = e.selectionStart - (a ? 0 : 1);
			e.value = e.value.substring(0, e.selectionStart - (a ? 0 : 1)) + e.value.substring(e.selectionEnd + (a ? 2 : 0), e.value.length);
	
			range.move('character', preS - count(e.value.substring(0, preS), '\r\n'));
			range.select();
		}
	}
	else
	{
		var a = false;
		if(e.scrollWidth > e.clientWidth)
		{
			var preS = e.selectionStart + 1;
			e.value = e.value.substring(0, e.selectionStart - 1) + ' ' + e.value.substring(e.selectionEnd - 1, e.value.length);
			e.selectionStart = preS;
			e.selectionEnd = preS;
			a = true;
		}
		while(e.scrollHeight > e.clientHeight)
		{
			var preS = e.selectionStart - (a ? 2 : 1);
			e.value = e.value.substring(0, e.selectionStart - (a ? 2 : 1)) + e.value.substring(e.selectionEnd, e.value.length);
			e.selectionStart = preS;
			e.selectionEnd = preS;
		}
	}
}

function step1_ImageSize(what,ismessage)
{
	if (ismessage == 0)
	{
		if (contest == 1)
		{
			var img = $('yourphoto');
			var spFill = $('step1_picture');
//			switch(what)
//			{
//				case 'stretch':
					img.style.width = currentWidth2 + 'px';
					img.style.height = currentHeight2 + 'px';
					step1_ImageFormat = what;
					img.style.marginTop = 0 + 'px';
					img.style.marginLeft = 0 + 'px';
//					break;
//				case 'fit':
//					img.style.width = step1_IdealWidth2 + 'px';
//					img.style.height = step1_IdealHeight2 + 'px';
//					img.style.marginTop = (currentHeight2 - step1_IdealHeight2)/2 + 'px';
//					img.style.marginLeft = (currentWidth2 - step1_IdealWidth2)/2 + 'px';
//					step1_ImageFormat = what;
//					break;
//			}
			$('yourphoto').style.display = '';
		}
		else
		{
			var img = $('yourphoto2');
			var spFill = $('step2_picture');
//			switch(what)
//			{
			
//				case 'stretch':
					step1_ImageFormat = what;
					img.style.marginTop = 0 + 'px';
					img.style.marginLeft = 0 + 'px';
//					break;
//				case 'fit':
//					img.style.width = step1_IdealWidth + 'px';
//					img.style.height = step1_IdealHeight + 'px';
//					img.style.marginTop = (currentHeight- step1_IdealHeight)/2 + 'px';
//					img.style.marginLeft = (currentWidth- step1_IdealWidth)/2 + 'px';
//					step1_ImageFormat = what;
//					break;
//			}
//			
			$('yourphoto2').style.display = '';
		}
	}
	else
	{
		var img = $('yourphoto');
			var spFill = $('step1_picture');
//			switch(what)
//			{
//				case 'stretch':
					img.style.width = currentWidth2 + 'px';
					img.style.height = currentHeight2 + 'px';
					step1_ImageFormat = what;
					img.style.marginTop = 0 + 'px';
					img.style.marginLeft = 0 + 'px';
//					break;
//				case 'fit':
//					img.style.width = step1_IdealWidth2 + 'px';
//					img.style.height = step1_IdealHeight2 + 'px';
//					img.style.marginTop = (currentHeight2- step1_IdealHeight2)/2 + 'px';
//					img.style.marginLeft = (currentWidth2- step1_IdealWidth2)/2 + 'px';
//					step1_ImageFormat = what;
//					break;
//			}
			$('yourphoto').style.display = '';
	}
	
	
}

function spyColor()
{
	return $('hdCurrentColor').value;
}

function changeColor(color, i)
{
	$('divPhotoContainer' + (arguments.length > 1 ? i.toString() : '')).style.backgroundColor = color;
	$('hdCurrentColor').value = color.replace('#', '');
}

function GenerateCountries()
{
	var c = new Array();
	c.push('<select id="ddlCountries%1" name="ddlCountries%1">');
	for(var i = 0; i < countries.length; i++)
	{
		c.push('<option value="');
		c.push(countries[i]['idcountry']);
		if(countries[i]['idcountry'] == defaultCountry)
			c.push('" selected>');
		else
			c.push('">');
		c.push(countries[i]['name']);
		c.push('</option>');
	}
	c.push('</select>');
	ddlCountries = c.join('');
}

function GetDdlCountries(idx)
{
	return ddlCountries.replace(/%1/g, idx);
}

function handleKey(t, e, n)
{
	var next = $(n);
	if(e.keyCode == 13)
	{
		if(next)
		{
			next.focus();
		}
		else
		{
			t.focus();
		}
		remLast(t, 1 + (isIE ? 1 : 0));
	}
	if(e.keyCode == 81)
	{
		var message = '';
		switch(currentlanguage)
		{
			case 'en' : message = 'You must enter a real mailing address'; break;
			case 'es' : message = 'Usted debe ingresar una direcci�n de correo real'; break;
			case 'br' : message = 'Voc� deve incorporar um endere�o do enviamento real'; break;
			case 'it' : message = 'Devi inserire un indirizzo email esistente'; break;
			case 'fr' : message = 'Vous devez entrer une vraie adresse.'; break;
			case 'de' : message = 'Bitte geben Sie eine reale Postadresse ein'; break;
		}
		
		alert(message);
		remlast(t, 1);
	}
	while(t.scrollWidth > t.clientWidth)
	{
		remLast(t, 1);
	}
}

function remLast(e, n)
{
	var t = e.value;
	e.value = t.substring(0, t.length - n);
	return t.substring(t.length - n, t.length - (n - 1));
}

function DdlSelectByValue(ddl, value)
{
	for(var i = 0; i < ddl.options.length; i++)
	{
		if(ddl.options[i].value == value)
		{
			ddl.options[i].selected = true;
			return;
		}
	}
}

function DdlGetSelectedValue(ddl)
{
	for(var i = 0; i < ddl.options.length; i++)
	{
		if(ddl.options[i].selected)
		{
			return ddl.options[i].value;
		}
	}
}

function openWindow(url, width, height, scrollbars, resizable)
{
	var w = window.open(url, 'pop' + GetDateTimeUid().toString(), 'top=50, left=50, height=' + height + ', width=' + width + ', scrollbars=' + (scrollbars ? '1' : '0') + ', menubar=no, titlebar=no, resizable=' + (resizable ? '1' : '0'));
}

function UseAddress(name)
{
	valido = false;
	
	var arrDatos = document.getElementsByName(name);
	for (var i = 0; i < arrDatos.length; i++)
	{
		if (arrDatos[i].checked)
		{
			var obj = (arrDatos[i].id.substring(4));
			arrDatos[i].checked = false;
			valido = true;
		}
	}

	if (valido)
	{
		if (totalpostcards >0)
		{
			for (x = 0; x<=totalpostcards;x++)
			{
				if (x == 0)
				{	
					if ($('checkbox0') != null)
					{
						if ($('checkbox0').checked)
						{
							var address = $('hid_' + obj);
							if(address != null)
							{
								address = (address.value).replace( /%%NN%%/g, '\r\n' );
								var arr = address.split('\n');
							
								for (i = 0; i < 5 ; i++)
								{
									if (arr[i] != null)
									{
										font = getFlashVar('swf_step2_postcardflash','nombre_txt');
										setFlashVar('swf_step2_postcardflash', 'texto_0' + (i+1), '<FONT FACE="'+font+'">'+ arr[i].replace('\r','').replace('\n','') + '</FONT>');
									}
									else
									{
										setFlashVar('swf_step2_postcardflash', 'texto_0' + (i+1), '');
									}
								}
								if (arr[5] != null)
								{
									document.getElementById('country').value = arr[5];
								}
							}
							$('checkbox0').click();
						}
					}
				}
				else
				{
					if ($('checkbox'+ x) != null)
					{
						if ($('checkbox'+ x).checked)
						{
							var address = $('hid_' + obj);
							if(address != null)
							{
								address = (address.value).replace( /%%NN%%/g, '\r\n' );
								var arr = address.split('\n');
														
								for (i = 0; i < 5 ; i++)
								{
									if (arr[i] != null)
									{
										font = getFlashVar('swf_step2_postcardflash'+x,'nombre_txt');
										setFlashVar('swf_step2_postcardflash'+x, 'texto_0' + (i+1),'<FONT FACE="'+font+'">'+ arr[i].replace('\r','').replace('\n','') + '</FONT>');
									}
									else
									{
										setFlashVar('swf_step2_postcardflash'+x, 'texto_0' + (i+1), '');
									}
								}
								if (arr[5] != null)
								{
									//el problema es que el combo de country no arranca llamandose country0,country1, ...etc sino country, country0
									//entonces a x le resto 1 en el caso que es 0 es contemplado antes.
									if($('country'+ x))
										$('country'+ x).value = arr[5];
								}
							}
							$('checkbox'+ x).click();
						}
					}
					
					if (unica == true && $('swf_step2_postcardflash'+x))
					{
						var address = $('hid_' + obj);
						if(address != null)
						{
							address = (address.value).replace( /%%NN%%/g, '\r\n' );
							var arr = address.split('\n');
													
							for (i = 0; i < 5 ; i++)
							{
								if (arr[i] != null)
								{
									font = getFlashVar('swf_step2_postcardflash'+x,'nombre_txt');
									setFlashVar('swf_step2_postcardflash'+x, 'texto_0' + (i+1),'<FONT FACE="'+font+'">'+ arr[i].replace('\r','').replace('\n','') + '</FONT>');
								}
								else
								{
									setFlashVar('swf_step2_postcardflash'+x, 'texto_0' + (i+1), '');
								}
							}
							if (arr[5] != null)
							{
								document.getElementById('country'+ x).value = arr[5];
							}
						}
					}
				}
			}
			
		}
		else
		{
			var address = $('hid_' + obj);
			if(address != null)
			{
				address = (address.value).replace( /%%NN%%/g, '\r\n' );
				var arr = address.split('\n');
				
				for (i = 0; i < 5 ; i++)
				{
					if (arr[i] != null)
					{
						font = getFlashVar('swf_step2_postcardflash','nombre_txt');
						setFlashVar('swf_step2_postcardflash', 'texto_0' + (i+1),'<FONT FACE="'+font+'"><P ALIGN="LEFT">'+ arr[i].replace('\r','').replace('\n','') + '</FONT></P>');
					}
					else
					{
						setFlashVar('swf_step2_postcardflash', 'texto_0' + (i+1), '');
					}
				}
				if (arr[5] != null)
				{
					document.getElementById('country').value = arr[5];
				}
			}
		}
		hide();
	}
	else
	{
		alert($('erroraddressbook').value);
	}
	
	
}

function show(val)
{
	var obj = $('img_' + val);
	
	if (obj.src.indexOf('images/etc/view.gif') >= 0)
	{
		$('tr_' + val).style.display = '';
		obj.src = 'images/etc/hide.gif';
		$('td_' + val).style.fontWeight = 'bold';
	}
	else
	{
		obj.src = 'images/etc/view.gif';
		$('tr_' + val).style.display = 'none';
		$('td_' + val).style.fontWeight = 'normal';
	}
}
function hide()
{
	$('layerDiv').style.display='none';
	$('boxed').style.display='none';
	
	/*if (isIE)
	{
		for (i = 1; i < (backsidesCount + 1); i++)
		{
			$('ddlCountries' + i).style.display= 'block';
		}
	}

	for (var i = 0; i < document.getElementsByName('select').length; i++)
	{
		if (document.getElementsByName('select')[i].checked)
		{
			document.getElementsByName('select')[i].checked = false;
		}
	}*/
	
	$('boxed').scrollTop = 0;
	
	if ($('swf_step2_postcardflash'))
		$('swf_step2_postcardflash').style.visibility = 'visible';

	if (totalpostcards >0)
	{
		for (x =1;x<=totalpostcards;x++)
		{
			if ($('swf_step2_postcardflash'+ x ) != null)
			{
				$('swf_step2_postcardflash' + x).style.visibility = 'visible';
			}
		}
	}
		
	if ($('country'))
		$('country').style.visibility = 'visible';
		
	if ($('boxed3'))
	{
		$('boxed3').style.display = 'none';
	} 
	
}

function hide2()
{
	$('layerDiv2').style.display='none';
	$('boxed2').style.display='none';
	
	$('boxed2').scrollTop = 0;
	
	if ($('swf_step2_postcardflash'))
		$('swf_step2_postcardflash').style.visibility = 'visible';
	
	if (totalpostcards >0)
	{
		for (x =1;x<=totalpostcards;x++)
		{
			if ($('swf_step2_postcardflash'+ x ) != null)
			{
				$('swf_step2_postcardflash' + x).style.visibility = 'visible';
			}
		}
	}
	
	if ($('country'))
		$('country').style.visibility = 'visible';
	
}

function hide3()
{
	$('layerDiv').style.display='none';
	$('boxed').style.display='none';
	
	/*if (isIE)
	{
		for (i = 1; i < (backsidesCount + 1); i++)
		{
			$('ddlCountries' + i).style.display= 'block';
		}
	}

	for (var i = 0; i < document.getElementsByName('select').length; i++)
	{
		if (document.getElementsByName('select')[i].checked)
		{
			document.getElementsByName('select')[i].checked = false;
		}
	}*/
	
	$('boxed').scrollTop = 0;
	
	if ($('home_flash'))
		$('home_flash').style.visibility = 'visible';
}

function hide4()
{
	$('layerDiv').style.display='none';
	$('boxed').style.display='none';
	
	/*if (isIE)
	{
		for (i = 1; i < (backsidesCount + 1); i++)
		{
			$('ddlCountries' + i).style.display= 'block';
		}
	}

	for (var i = 0; i < document.getElementsByName('select').length; i++)
	{
		if (document.getElementsByName('select')[i].checked)
		{
			document.getElementsByName('select')[i].checked = false;
		}
	}*/
	
	$('boxed').scrollTop = 0;
	
	if ($('swf_step2_postcardflash'))
		$('swf_step2_postcardflash').style.visibility = 'visible';

		if (totalpostcards >0)
	{
		for (x =1;x<=totalpostcards;x++)
		{
			if ($('swf_step2_postcardflash'+ x ) != null)
			{
				$('swf_step2_postcardflash' + x).style.visibility = 'visible';
			}
		}
	}
		
	if ($('country'))
		$('country').style.visibility = 'visible';
	
}

function UseImg(obj)
{
	for (i = 0; i < photos.length; i++)
	{
		if (obj == photos[i]['Id'])
		{
			var wo = window.opener;
			
			index = wo.findItemIndexByIdPostcard(wo.selectedCartItem);
			
			if (index != null)
			{
				wo.cart[index]['imageUrl'] = photos[i]['ImgUrl'];
				wo.cart[index]['externalId'] = photos[i]['Id'];
				wo.loadNewCartItem();
				window.close();
			}
		}
	}
}

function popChangePhoto()
{
	openWindow('photoselectionpopup.php', 780, 600, true, false);
}

//function RotateImage()
//{
//	var step = $('optRot').value;
//	
//	var tmpindex = findItemIndexByIdPostcard(selectedCartItem);
//	
//	$('imgPostcard').src = '/rotateimg.php?imageurl=' + 
//							cart[tmpindex]['rotateurl'] +
//							'&step=' + step;
//}

function GetDateTimeUid()
{
	var now = new Date();
	return Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds());
}

function pop()
{
	if ($('swf_step2_postcardflash'))
		$('swf_step2_postcardflash').style.visibility = 'hidden';
	if ($('country'))
		$('country').style.visibility = 'hidden';
	
	if (totalpostcards >0)
	{
		for (x =1;x<=totalpostcards;x++)
		{
			if ($('swf_step2_postcardflash'+ x ) != null)
			{
				$('swf_step2_postcardflash' + x).style.visibility = 'hidden';
			}
		}
	}
	padd = document.documentElement.scrollTop;
	$('layerDiv').style.display = 'block';
	$('layerDiv').style.height = screen.height + 10 + 'px';
	$('layerDiv').style.width  = screen.width;
	$('boxed').style.display='block';
	$('boxed').style.top = (padd + 40) + 'px';
	$('boxed').style.left = parseInt((screen.width - 524) / 2) + 'px';
	asyncGetAddressPopUp();
}
/*
function popCsv()
{

	if ($('swf_step2_postcardflash'))
		$('swf_step2_postcardflash').style.visibility = 'hidden';
	if ($('country'))
		$('country').style.visibility = 'hidden';
	
	if (totalpostcards >0)
	{
		for (x =1;x<=totalpostcards;x++)
		{
			if ($('swf_step2_postcardflash'+ x ) != null)
			{
				$('swf_step2_postcardflash' + x).style.visibility = 'hidden';
			}
		}
	}
	
	padd = document.documentElement.scrollTop;
	$('layerDiv2').style.display = 'block';
	$('layerDiv2').style.height = screen.height + 10 + 'px';
	$('layerDiv2').style.width  = screen.width;
	$('boxed2').style.display='block';
//	if (navigator.userAgent.indexOf('MSIE 6') >= 0)
//	{
//		$('boxed').style.position = 'absolute';
//	}
	$('boxed2').style.top = (padd + 40) + 'px';
	$('boxed2').style.left = parseInt((screen.width - 524) / 2) + 'px';
	asyncGetCsvPopUp();
}
*/
function scrollPop()
{
	if($('layerDiv').style.display == 'block')
	{
		padd = document.documentElement.scrollTop + 50;
		
		$('boxed').style.top = padd + 'px';
	}
}

function moveLeft()
{
	$('boxed').style.left = parseInt((screen.width - 524) / 2) + 'px';
}

function selCartItem(id)
{
	updateCartCurrentItem();
	$('tdSelectedCartItem' + selectedCartItem.toString()).className = '';
	$('tdSelectedCartItem' + id.toString()).className = 'sel';
	selectedCartItem = id;
	loadNewCartItem();
}

function findItemIndexByIdPostcard(idPostcard)
{
	for (var i = 0; i < cart.length; i++)
	{
		if (cart[i]['idPostcard'] == idPostcard)
		{
			return i;
		}
	}
	return null;
}

function updateCartCurrentItem()
{
	index = findItemIndexByIdPostcard(selectedCartItem);
	
	if (index != null)
	{
		cart[index]['body'] = getFlashText('swf_edit');
		cart[index]['stretched'] = $('optStretch').checked;
		cart[index]['backgroundColor'] = spyColor();
		cart[index]['address'] = getAddressValue();
		cart[index]['idCountry'] = DdlGetSelectedValue($('ddlCountries1'));
		cart[index]['rotatestep'] = $('optRot').value;
	}
}

function loadNewCartItem()
{
	index = findItemIndexByIdPostcard(selectedCartItem);
	
	if (index != null)
	{
		$('tdSelectedCartItem' + selectedCartItem).childNodes[0].childNodes[0].src = cart[index]['imageUrl'];
		
		$('optRot').value = (cart[index]['rotatestep']);
		RotateImage();
		
		if (cart[index]['hasfree'])
		{
			$('texthasfree').style.display = '';
		}
		else
		{
			$('texthasfree').style.display = 'none';
		}
		
		if (cart[index]['stretched'])
		{
			$('optStretch').checked = true;
			$('optStretch').click();
		}
		else
		{
			$('optFit').checked = true;
			$('optFit').click();
		}
		changeColor('#' + cart[index]['backgroundColor']);
		if (cart[index]['body'] != null)
		{
			setFlashText('swf_edit', cart[index]['body']);
			setFlashFont('swf_edit', getFontFromBody(cart[index]['body']));
		}
		else
		{
			setFlashText('swf_edit', '');
		}
		if (cart[index]['address'] != null)
		{
			setAddressValue('swf_edit',cart[index]['address']);
		}
		else
		{
			clearAddressValue();
		}
		DdlSelectByValue($('ddlCountries1'), cart[index]['idCountry']);

	}
}

function getAddressValue()
{
	var i = 0;
	var e = $('addressField_' + i.toString() + '_1');
	var d = new Array();
	while (e)
	{
		d.push(e.value);
		i++;
		e = $('addressField_' + i.toString() + '_1');
	}
	return d.join('\r\n');
}

function pausecomp(millis)
{
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); }
	while(curDate-date < millis);
} 

function setAddressValue(id,v, fontname)
{
	v = base64_decode(v);

	pieces = v.split("\n"); 

	for	(var i = 0; i < 5; i++)
	{
		pieces[i] = str_replace("\r","",pieces[i]);
		if (pieces[i] == undefined)
		{
			pieces[i] = '';
		}
		
		if (strcmp(pieces[i],'"<') == 0)
		{
				pieces[i] = '';
		}
	
		if (pieces[i] != '')
		{
			setFlashVar(id, 'texto_0' + (i+1), '<p><font ' + str_replace("'",'"',fontname) + '>' + pieces[i]+ '</font></p>');
		}
		else
		{
			setFlashVar(id, 'texto_0' + (i+1), '<p><font FACE="Arial">' + pieces[i]+ '</font></p>');
		}
	}
		
}

function clearAddressValue()
{
	var i = 0;
	var e = $('addressField_' + i.toString() + '_1');
	while (e)
	{
		e.value = '';
		i++;
		e = $('addressField_' + i.toString() + '_1');
	}
}

function Checkout()
{
	if(!$('chkAgree').checked)
	{
		CheckAgree($('chkAgree'));
	}
	else
	{
		UpdateCartHidden();
		__doPostBack('Checkout');
	}
}

function CheckoutFreePostcard(id)
{
	location.href = '/freecheckout.php?id=' + id;
}

function AddNewPostcard()
{
	UpdateCartHidden();
	__doPostBack('AddNewPostcard');
}

function NewRecipients()
{
	var count=0;
	var arrDatos = document.getElementsByName('select');
	for (var i = 0; i < arrDatos.length; i++)
	{
		if (arrDatos[i].checked)
			count++;
	}
	if(count>0)
	{
		masssending = 0;
		unica = false;
		if (document.getElementById("moreaddresses"))
		{
			var cell = document.getElementById("moreaddresses");
		
			if ( cell.hasChildNodes() )
			{
			    while ( cell.childNodes.length >= 1 )
			    {
			        cell.removeChild( cell.firstChild );       
			    } 
			}
			$('columnamasssending').style.display = 'none';
		}

		$('cantidadaddresses').value = 0;
		totaladdresses = 0;
		
		
		var text = '',font='Arial';
		
		if($('swf_step2_postcardflash'))
		{
			font = getFlashVar('swf_step2_postcardflash','nombre_txt');
			text = getFlashText('swf_step2_postcardflash');
		}
		else
		{
			for(i=0;i<totalpostcards + 1;i++)
			{
				if($('swf_step2_postcardflash' + i))
				{
					font = getFlashVar('swf_step2_postcardflash' + i,'nombre_txt');
					text = getFlashText('swf_step2_postcardflash' + i);
				}
			}
		}
		
		//preguntar porque getFlashText no recupera bien desde el cuerpor el tipo de fuente y su tamao
		
		newFont = 'FACE="' + font + '"';
		text = text.replace( /FACE="Arial"/g, newFont);
		//text = text.replace( /SIZE="13"/g, 'SIZE="15"');
		text = text.replace( /\"/g, '\\"' );
		//el text recuperado no trae la fuente correcta entonces se la cambio
		//alert(text);
		
		var filledFirst = false;
		for (var j = 0; j < arrDatos.length; j++)
		{
			if (arrDatos[j].checked)
			{
				if(cantidadpostcards == 1)
					primero = 1;
				else
					primero = 0;
				
				var obj = (arrDatos[j].id.substring(4));
				var address = $('hid_' + obj).value;
				address = (address).replace( /%%NN%%/g, '%NN%' );
				partes = address.split('%NN%');
				var codCountry = partes[partes.length - 1];
			
				//cuando la primera postacard no tiene texto se completa con el primer destinatario.
				if(primero && text == '' && !filledFirst)
				{
					filledFirst = true;
					if($('swf_step2_postcardflash'))
					{
						for (i = 0; i < 5 ; i++)
						{
							if (partes[i] != null)
							{
								font = getFlashVar('swf_step2_postcardflash','nombre_txt');
								setFlashVar('swf_step2_postcardflash', 'texto_0' + (i+1), '<FONT FACE="'+font+'">'+ partes[i] + '</FONT>');
							}
							else
							{
								setFlashVar('swf_step2_postcardflash', 'texto_0' + (i+1), '');
							}
						}
						if (partes[5] != null)
						{
							document.getElementById('country').value = partes[5];
						}
					}
					else
					{
						for(x=0;x<totalpostcards + 1;x++)
						{
							if($('swf_step2_postcardflash' + x))
							{
								for (i = 0; i < 5 ; i++)
								{
									if (partes[i] != null)
									{
										font = getFlashVar('swf_step2_postcardflash'+x,'nombre_txt');
										setFlashVar('swf_step2_postcardflash' + x, 'texto_0' + (i+1), '<FONT FACE="'+font+'">'+ partes[i] + '</FONT>');
									}
									else
									{
										setFlashVar('swf_step2_postcardflash'+x, 'texto_0' + (i+1), '');
									}
								}
								if (partes[5] != null)
								{
									if($('country'+ x))
										$('country'+ x).value = partes[5];
								}
							}
							
						}
					}
					
				}
				else
				{
					if($('chk_SendSameMessage').checked == true)
						asyncNewrecipient(text,codCountry,address,font);
					else
						asyncNewrecipient('',codCountry,address,font);
					cantidadpostcards++;
					totalpostcards++;
				}
			}
		}
		
		hide();
	}
	else
	{
		aviso();
	}
		
}

function updateNroCards(chk)
{
	var nroCards = $('nroCards').innerHTML;
	
	if(chk.checked)
		nroCards++;
	else
		nroCards--;
	
	$('nroCards').innerHTML = nroCards;
}

function addDestinatarios()
{
	scroll(0,0);
	
	if ($('swf_step2_postcardflash'))
	{
		setFlashVar('swf_step2_postcardflash', 'tapa','0' );
	}
	
	if ($('swf_step2_postcardflash'))
		$('swf_step2_postcardflash').style.visibility = 'hidden';
	if ($('country'))
		$('country').style.visibility = 'hidden';
	
	if (totalpostcards >0)
	{
		for (x =1;x<=totalpostcards;x++)
		{
			if ($('swf_step2_postcardflash'+ x ) != null)
			{
				$('swf_step2_postcardflash' + x).style.visibility = 'hidden';
			}
		}
	}
	padd = document.documentElement.scrollTop;
	$('layerDiv').style.display = 'block';
	$('layerDiv').style.height = document.body.clientHeight + 250 + 'px'; //screen.height + 10 + 'px';
	$('layerDiv').style.width  = screen.width;
	$('boxed').style.display='block';
	$('boxed').style.top = (padd + 40) + 'px';
	$('boxed').style.left = parseInt((screen.width - 524) / 2) + 'px';
	
	asyncAddDestinatarios();
}

function TaparEditor(modo)
{
	setFlashVar('swf_step2_postcardflash', 'tapa',modo );
}

function Deleterecipient()
{
	cantidadpostcards= 0;
	
	for (x=0;x<totalpostcards+1;x++)
	{
		if ($('checkbox'+x))
		{
			if ($('checkbox'+x).checked == false)
			{
				cantidadpostcards++;
			}
		}
	}
	
	if (cantidadpostcards == 1)
	{
		for (x=0;x<totalpostcards+1;x++)
		{
			if ($('checkbox'+x))
			{
				if ($('checkbox'+x).checked == false)
				{
					$('checkboxpostcard'+ x).removeChild($('checkbox'+ x));
					$('botondelete').removeChild($('deleterecipient'));
					cardprimera = x;
				}
			}

		}

	}
	
	for (x=0;x<=totalpostcards;x++)
	{
		if ($('checkbox'+x))
		{
			if ($('checkbox'+x).checked == true)
			{
				postales++
			}
		}
	}
	
	asyncDeleteRecipient();
}
function ValidarCsv()
{
	$('cajacsv').innerHTML = '';
	asyncValidarCsv();	
}

function UpdateCartHidden()
{
	updateCartCurrentItem();
	$('hdCart').value = YAHOO.lang.JSON.stringify(cart);
	$('hdDeleteAddress').value = YAHOO.lang.JSON.stringify(addressesToDelete);
}

function DeleteItem(i)
{
	UpdateCartHidden();
	$('hdDelete').value = i;
	__doPostBack('DeleteItem');
}

function DeleteSelected()
{
	UpdateCartHidden();
	__doPostBack('DeleteSelected');
}

function CheckAgree(chk)
{
	$('divPleaseAgree').style.display = chk.checked ? 'none' : 'block';
}

function changeSource(sr)
{
	if (sr == 'IMAP ')
	{
		$('btn_signup').style.display = '';
		$('linkleftdiv').style.cursor = '';
		$('header').style.background = 'url(../images/header/bkg_header_imap.gif) no-repeat 0px 0px';
		linkleftopen = '';
		$('text_login_username').style.display = 'none';
		$('text_login_email').style.display = 'inline';
		var searchupload = $('searchupload');
		if (searchupload && searchuploadcont)
		{
			searchupload.innerHTML = searchuploadcont;
		}
	}
	if (sr == 'FOT')
	{
		$('btn_signup').style.display = 'none';
		$('linkleftdiv').style.cursor = 'pointer';
		$('header').style.background = 'url(../images/header/bkg_header_fot.gif) no-repeat 0px 0px';
		linkleftopen = 'http://www.fotolog.com/';		
		$('text_login_username').style.display = 'inline';
		$('text_login_email').style.display = 'none';
		$('searchupload').innerHTML = searchuploadcontalt;
	}
}
function createNew(v)
{
	$('hdSelected').value = v;
	__doPostBack('Create');
}

function clonePostcard(v)
{
	$('hdSelected').value = v;
	UpdateCartHidden();
	__doPostBack('ClonePostcard');
}

function linkleftwin(link)
{
	if (link != '')
	{
		window.open(link);
	}
}

function gostep(step)
{
	var urls = new Array('javascript:gohome()', 'javascript:gostep1("/Photo_Selection")', 'javascript:gostep2("/Write_Postcards")', 'javascript:gocart()', '/PurchaseCredits');
	
	if (step > 0 && step <= 5)
		location.href = urls[(step - 1)];
}

function deleteAddress(id, row)
{
	$('rad_' + row).checked = false;
	$('addressrow_' + row).style.display = 'none';
	$('tr_' + row).style.display = 'none';
	
	asyncDeleteAddress(id);
}

function deleteCsvAddress(row)
{
	$('rad_' + row).checked = false;
	$('addressrow_' + row).style.display = 'none';
	$('tr_' + row).style.display = 'none';
}

function step1_bolderize(which)
{
	$('step1_text_library').style.fontWeight = "";
	$('step1_text_fotolog').style.fontWeight = "";
	$('step1_text_upload').style.fontWeight = "";
	$('step1_text_recent').style.fontWeight = "";
	$('step1_text_lonelyplanet').style.fontWeight = "";
	
	$('step1_text_' + which).style.fontWeight = "bold";
}

function step2_bolderize(which)
{
	$('step1_text_fit').style.fontWeight = "";
	$('step1_text_stretch').style.fontWeight = "";
	
	$('step1_text_' + which).style.fontWeight = "bold";
}

function step2_address()
{
	
	var addrecipient = false;
	
    var	ischecked = false;
	
	if (totalpostcards > 0)
	{
		addrecipient = true;
	
		for (x = 0 ; x<= totalpostcards; x++)
		{
			if ($('checkbox'+x))
			{
				if ($('checkbox'+x).checked == true)
				{
					ischecked = true;
				}
			}
		}
	}
	
	if ((addrecipient && !ischecked) && unica == false)
	{
		alert($('erroraddecipient').value);
	}
	else
	{
		pop();
	}
}


function step2_address_import_step1()
{
	asyncGetCsvPopUp(1);
}

function step2_address_import_step2()
{
	asyncGetCsvPopUp(2);
}
function step2_address_import_step3()
{
	asyncGetCsvPopUp(3);
}

function step2_address_import_step4()
{
	asyncGetCsvPopUp(4);
}

function step2_address_import_step5()
{
	asyncGetCsvPopUp(5);
}

function step2_address_import_step6()
{
	asyncGetCsvPopUp(6);
}

function checkAllImport()
{
	var boxinside = $('boxedinside');
	var address = boxinside.getElementsByTagName('input');
	
	for (var i = 0; i < address.length; i++)
	{
		if(address[i].type == 'checkbox' && address[i].name.split('_')[0] == 'rad')
			address[i].checked = !address[i].checked; 
	}
}

function step2_masssendingbox()
{
	$('tab1').removeChild($('postcards'));
	postcard = document.createElement('div');
	postcard.id = 'postcards';
	$('tab1').appendChild(postcard);
	$('columnamasssending').style.display = '';
	TaparEditor(1);
	
	if ($('checkboxpostcard0').hasChildNodes() )
	{
		$('checkboxpostcard0').removeChild($('checkboxpostcard0').firstChild);
	}
	
	if ($('deleterecipient'))
	{
		$('deleterecipient').style.display = 'none';
	}
	
	recipient = 1;
	anteriorrecipient = 1;
	totalpostcards = 0;
	cantidadpostcards = 1;
	postales=0;
	idpostcard = 0;
	primero = 1;
	ultimo = 0;
	ultimo2 =0;
	cardprimera = 0;
	arrrecipients = new Array();	
}

function step2_help()
{
	if ($('swf_step2_postcardflash'))
		$('swf_step2_postcardflash').style.visibility = 'hidden';
	if ($('country'))
		$('country').style.visibility = 'hidden';
	
	padd = document.documentElement.scrollTop;
	$('layerDiv').style.display = 'block';
	$('layerDiv').style.height = screen.height + 10 + 'px';
	$('layerDiv').style.width = screen.width;
	$('layerDiv').style.position = 'fixed';
	
	$('boxed2').style.display='block';
	$('boxed2').style.top = (padd + 40) + 'px';
	$('boxed2').style.left = parseInt((screen.width - 524) / 2) + 'px';
	asyncGetAddressPopUp();
}

function step1_selectLibrary()
{
	step1_bolderize('library');
	asyncImageLibrary();
}

function step1_selectFotolog()
{
	step1_bolderize('fotolog');
	asyncFotolog();
}

function step1_selectFacebook()
{
	step1_bolderize('fotolog');
	asyncFacebook();
}

function step1_selectRecent()
{
	step1_bolderize('recent');
	asyncRecent();
}

function step1_selectUpload()
{
	step1_bolderize('upload');
	asyncUploadForm();
}

function step1_selectLonelyPlanet()
{
	step1_bolderize('lonelyplanet');
	asyncLonelyPlanetForm();
}

//function step1_selectStretch()
//{
//	step2_bolderize('stretch');
//	step1_ImageSize('stretch',0);
//	
//	$('step1_colorselector').style.display = 'none'
//	$('frametitle').style.paddingTop = '0px';
//	$('step1_topbubble').className = 'step1_topbubble_s';
//}

function step1_selectFit()
{
	step2_bolderize('fit');
	step1_ImageSize('fit',0);
	$('frametitle').style.paddingTop = '15px';
	$('step1_colorselector').style.display = 'block'
	$('step1_topbubble').className = 'step1_topbubble';
}


function step1_selectRotateRight()
{
	$('pleaseWaitPage').style.visibility = 'visible';
	$('photoCropToolPlace').style.visibility = 'hidden';
	
	if (step1_RotateStep <= 0)
	{
		step1_RotateStep = 3;
	}
	else
	{
		step1_RotateStep--;
	}
	
	var showurl = ('/rotateimg.php?imageurl='+step1_selectedphotourl.Base64Encode()+'&step='+step1_RotateStep + '&pdf=1');
	if (contest == 0)
	{
		$('yourphoto2').src = showurl;
	}
	else
	{
		$('yourphoto').src = showurl;
	}
	asyncResamplePhoto(showurl);
	asyncPageCroptool();
}

function step1_selectRotateLeft()
{
	$('pleaseWaitPage').style.visibility = 'visible';
	$('photoCropToolPlace').style.visibility = 'hidden';
	
	if (step1_RotateStep >= 3)
	{
		step1_RotateStep = 0;
	}
	else
	{
		step1_RotateStep++;
	}
	
	var showurl = ('/rotateimg.php?imageurl='+step1_selectedphotourl.Base64Encode()+'&step='+step1_RotateStep + '&pdf=1');
	
	if (contest == 0)
	{
		$('yourphoto2').src = showurl;
	}
	else
	{
		$('yourphoto').src = showurl;
	}

	asyncResamplePhoto(showurl);
	asyncPageCroptool();
}


function step1_selectGalleryPhoto(id)
{
	var url = '/uploaded/' + id + '.jpg';
	
	if (contest == 1)
	{
		$('yourphoto').src = url;
	}
	else
	{
		$('yourphoto2').src = url;
	}
	
	step1_selectedphotourl = url;
	asyncPageCroptool();
}

function step1_rotateToStep(step)
{
	step1_RotateStep = step;
	
	var showurl = ('/rotateimg.php?imageurl='+step1_selectedphotourl.Base64Encode()+'&step='+step);
	if (contest == 1){
		$('yourphoto').src = showurl;
	}
	else
	{
		$('yourphoto2').src = showurl;
	}
	asyncResamplePhoto(showurl);
}

function step1_selectUrlPhoto(url)
{	
	if (contest== 1)
	{
		$('yourphoto').style.display = 'none';	
		$('yourphoto').src = url;
	}
	else
	{
		$('yourphoto2').style.display = 'none';	
		$('yourphoto2').src = url;
	}
		
	if(create_1 == true || create_2 == true || create_3 == true)
	{
		alert(url);return;
		$('yourphoto1').style.display = 'none';
		$('yourphoto1').src = url;
		$('yourphoto2').style.display = 'none';
		$('yourphoto2').src = url;
		$('yourphoto3').style.display = 'none';
		$('yourphoto3').src = url;
	}
	
	step1_selectedphotourl = url;
	
	$('yourphoto2').style.width = currentWidth + 'px';
	$('yourphoto2').style.height = currentHeight + 'px';
					
	step1_RotateStep = 0;
	
	asyncResamplePhoto(url);
}

function step1_selectUrlPhotoFotolog(url)
{
	asyncSelectFotologPhoto(url);
}

function step1_submitupload()
{
	if(contest == 0)
	{
		$('fondo2').style.marginLeft = '3px';
		$('yourphoto2').style.margin = '0px';
		
		$('yourphoto2').style.width = imageSizeDefaultWidth;
		$('yourphoto2').style.height = imageSizeDefaultHeight;
		
		step1_selectedphotourl = false;
		
		$('yourphoto2').src = '/images/'+ currentlanguage +'/step1yourphoto2wait.gif';
	}
	else if(contest == 1)
	{
		step1_selectedphotourl = false;
		$('yourphoto').src = '/images/'+ currentlanguage +'/step1yourphoto2wait.gif';
		$('yourphoto').style.margin = '0px';
		$('yourphoto').style.width = '315px';
		$('yourphoto').style.height = '250px';
	}
	
	asyncSubmitUploadForm();
}

function seemorelibrary()
{
	padd = document.documentElement.scrollTop;
	$('layerDiv').style.display = 'block';
	$('layerDiv').style.height = screen.height + 10 + 'px';
	$('layerDiv').style.width = screen.width 
	$('boxed').style.display='block';
	$('boxed').style.top = (padd + 40) + 'px';
	$('boxed').style.left = parseInt((screen.width - 524) / 2) + 'px';
	asyncGetLibraryPopUp();
}

function seemorerecent()
{
	padd = document.documentElement.scrollTop;
	$('layerDiv').style.display = 'block';
	$('layerDiv').style.height = screen.height + 10 + 'px';
	$('layerDiv').style.width = screen.width 
	$('boxed').style.display='block';
	$('boxed').style.top = (padd + 40) + 'px';
	$('boxed').style.left = parseInt((screen.width - 524) / 2) + 'px';
	asyncGetRecentPopUp();
}
function seeprices()
{
	if ($('home_flash'))
		$('home_flash').style.visibility = 'hidden';

	padd = document.documentElement.scrollTop;
	$('layerDiv').style.display = 'block';
	$('layerDiv').style.height = screen.height + 10 + 'px';
	$('layerDiv').style.width = screen.width 
	$('boxed').style.display='block';
	$('boxed').style.top = (padd + 40) + 'px';
	$('boxed').style.left = parseInt((screen.width - 524) / 2) + 'px';
	asyncListPrices();
}

function seemorefotolog()
{
	padd = document.documentElement.scrollTop;
	$('layerDiv').style.display = 'block';
	$('layerDiv').style.height = screen.height + 10 + 'px';
	$('layerDiv').style.width = screen.width 
	$('boxed').style.display='block';
	$('boxed').style.top = (padd + 40) + 'px';
	$('boxed').style.left = parseInt((screen.width - 524) / 2) + 'px';
	asyncGetFotologPopUp();
}

function step1_submitlogin()
{
	asyncSubmitLoginForm('selectorrecent');
}

function step2_submitlogin_addressBook()
{
	asyncSubmitLoginFormAddress(true);
}
function step2_submitlogin_addDestinatarios()
{
	asyncSubmitLoginFormAddress(false);
}



/*
function step2_submitloginmasssending(csv)
{
	asyncSubmitLoginMassSendingFormAddress(csv);
}
*/

function aviso()
{
	switch (currentlanguage)
	{
		case 'en' : message = 'At least you must select  one address'; break;
		case 'es' : message = 'Debe seleccionar al menos una direccion'; break;
		case 'br' : message = 'Necessario selecionar pelo menos um endereco'; break;
		case 'it' : message = 'Devi selezionare almeno un indirizzo'; break;
		case 'fr' : message = 'Vous devez s�lectionner au moins une adresse'; break;
		case 'de' : message = 'Bitte w�hlen Sie mindestens eine Adresse aus'; break;
	}
	alert(message);
}

function checkout_submitlogin()
{
	asyncSubmitLoginFormCheckout();
}

function step1_submitloginfot()
{
	asyncSubmitLoginForm('selectorfotolog');
}

function step1_formatimage()
{
	if (!step1_selectedphotourl)
	{
		alert($('nophotomessage').value);
	}
	else
	{
		if ($('fromgalleries').value == "true")
		{
			gostep2();return;
		}

		$('step1_bottombubble_format').style.display =  'block';
		$('step1_bottombubble').style.display =  'none';
		
		$('step1_bubble_buttom').style.display = 'none';
		$('step1_bubble_top').style.display = 'none';
		
		$('step1_bubble_top_format').style.display = 'block';
		$('step1_bubble_buttom_format').style.display = 'block';
		
		$('step1_bigbutton_formatimage').style.display = 'none';
		$('step1_bigbutton_changeimage').style.display = 'block';
		$('step1_bigbutton_writemessage').style.display = 'block';

		$('step1_sourcebubble').style.display = 'none';
		$('step1_sources').style.display = 'none';
		
		$('step1_format').style.display = 'block';
		$('fotolog').style.display = 'none';
		
		$('yui_img').src = str_replace(array('.jpg','.png'),'_t',step1_selectedphotourl);
		
		asyncPageCroptool();
	}
}


function step1_formatimageContest()
{
	if (!step1_selectedphotourl)
	{
		alert($('nophotomessage').value);
	}
	else
	{
		
		$('step1_bottombubble_format').style.display =  'none';
		$('step1_bottombubble').style.display =  'none';
		
		$('step1_bubble_buttom').style.display = 'none';
		$('step1_bubble_top').style.display = 'none';
		
		$('step1_bigbutton_formatimage').style.display = 'none';
		$('step1_bigbutton_changeimage').style.display = 'block';
		$('step1_bigbutton_writemessage').style.display = 'block';

		$('step1_sourcebubble').style.display = 'none';
		$('step1_sources').style.display = 'none';
		$('step1_format').style.display = 'block';
		$('fotolog').style.display = 'none';
		
		if (step1_ImageFormat == 'stretch')
		{
			$('step1_topbubble').className = 'step1_topbubble_s';
			$('step1_bottombubble').className = 'step1_bottombubble_s';
		}
		else
		{
			$('step1_colorselector').style.display = 'block';
		}
	}
}

function step1_changeimage()
{
	$('pleaseWaitPage').style.visibility = 'visible';
	$('photoCropToolPlace').style.visibility = 'hidden';
	
	if (contest == 0)
	{
		$('step1_sources').style.display = '';
	}
	else
	{
		$('fotolog').style.display = '';
	}
		$('step1_bottombubble_format').style.display =  'none';
		$('step1_bottombubble').style.display =  'block';
		
		$('step1_sourcebubble').style.display = 'block';
		$('step1_sources').style.display = 'block';
		
		$('step1_bigbutton_formatimage').style.display = 'block';
		$('step1_bigbutton_changeimage').style.display = 'none';
		$('step1_bigbutton_writemessage').style.display = 'none';
		
		$('step1_bubble_top').style.display = 'block';
		$('step1_bubble_top_format').style.display = 'none';
		
		$('step1_bubble_buttom').style.display = 'block';
		$('step1_bubble_buttom_format').style.display = 'none';
		
		$('step1_format').style.display = 'none';
		
		$('step1_topbubble').className = 'step1_topbubble';
		$('step1_bottombubble').className = 'step1_bottombubble';
		$('photoCropToolPlace').innerHTML = '<p><img id=\"yui_img\"></p>';
		
		$('yourphoto2').style.top = '0px';
		$('yourphoto2').style.left = '0px';
		
		$('yourphoto2').style.width = '422px';
		$('yourphoto2').style.height = '310px';
}

function step1_save(returnuri)
{
	if (!$('top') || !$('left') || !$('width') || !$('height'))
	{
		regionsquare = array(null,null,null,null);
	}
	else
	{
		regionsquare = array($('top').value,$('left').value,$('width').value,$('height').value);
	}
	
	asyncUpdateCurrentPostcardImage(
								step1_type,
								step1_selectedphotourl, 
								step1_ImageFormat,
								step1_backgroundcolor,
								step1_RotateStep,
								returnuri,
								step1_frame,
								regionsquare);
}

function step2_save(returnuri)
{	
	var primerpostcard = -1;
	var y = 0;
	
	if (contest == 0)
	{
		for(x=0;x<=totalpostcards;x++)
		{
			if (x == 0)
			{
				if ($('swf_step2_postcardflash'))
				{
					ultimo = x;
					primerpostcard = x;
				}
			}
			else 
			{
				if ($('swf_step2_postcardflash'+x) != null)
				{
					ultimo = x;
					if (primerpostcard == -1)
					{
						primerpostcard = x;
					}
				}
			}
		}
	
		var postcards = new Array();
	
		for	(x=0;x<=totalpostcards;x++)
		{
			if (x == 0)
			{
				if ($('swf_step2_postcardflash'))
				{
					font= getFlashVar('swf_step2_postcardflash','nombre_txt');
										r= { 'body':str_replace('&','%NN%',getFlashText('swf_step2_postcardflash')),
										 'address' : (str_replace('&','%NN%',(strip_tags(getFlashVar('swf_step2_postcardflash', 'texto_01'))) + '\r\n' +
												  (strip_tags(getFlashVar('swf_step2_postcardflash', 'texto_02'))) + '\r\n' +
												  (strip_tags(getFlashVar('swf_step2_postcardflash', 'texto_03'))) + '\r\n' +
												  (strip_tags(getFlashVar('swf_step2_postcardflash', 'texto_04'))) + '\r\n' +
												  strip_tags(getFlashVar('swf_step2_postcardflash', 'texto_05')))),
										'country' : $('country').value,
										'font' : font,
										'id': y,
										'posicion':x,
										'primerpostcard' : primerpostcard,
										'returnuri' : returnuri
									}
					postcards[y] =  r;	
					y++;
				}
				
			}
			else
			{
				if ($('swf_step2_postcardflash'+x) != null)
				{
					font= getFlashVar('swf_step2_postcardflash' + x,'nombre_txt');
				
									z= { 'body':(str_replace('&','%NN%',getFlashText('swf_step2_postcardflash'+x))),
										 'address' : (str_replace('&','%NN%',(strip_tags(getFlashVar('swf_step2_postcardflash'+x, 'texto_01'))) + '\r\n' +
												  (strip_tags(getFlashVar('swf_step2_postcardflash'+x, 'texto_02'))) + '\r\n' +
												  (strip_tags(getFlashVar('swf_step2_postcardflash'+x, 'texto_03'))) + '\r\n' +
												  (strip_tags(getFlashVar('swf_step2_postcardflash'+x, 'texto_04'))) + '\r\n' +
												  strip_tags(getFlashVar('swf_step2_postcardflash'+x, 'texto_05')))),
										'country' : $('country'+ x).value,
										'font' : font,
										'id': y,
										'posicion':x,
										'primerpostcard' : primerpostcard,
										'returnuri' : returnuri
										//al x se le resta 1 en country porque las postcards que se agregan comienzan a llamarse desde country0..pero el contenedor desde 1 por ejemplo
										//la primera postcard agregada "newcart1"..en lugar de tener un country1 como lo dira el sentido comun tiene country0...por eso este hack (es una negrada)
									}
					postcards[y] =  z;		
					y++;
				}
			}
			
		}
		asyncUpdateCurrentPostcardMessage(YAHOO.lang.JSON.stringify(postcards),primerpostcard);
	}
	else
	{
		var postcards = new Array();
		
		font= null;
		
		z= { 'body': $('txtCaption') ?  $('txtCaption').value : '',
			'address' : '"',
			'country' : $('ddlCountry').value,
			'font' : font,
			'id': y,
			'posicion':'0',
			'primerpostcard' : primerpostcard,
			'returnuri' : returnuri,
			'name' : $('txtName').value + ' ' + $('txtLastName').value,
			'email' : $('txtEmail').value,
			'password': $('txtPasswd').value,
			'agree': $('chkAgree').checked
			}
			
		postcards[y] =  z;
		asyncUpdateCurrentPostcardMessage(YAHOO.lang.JSON.stringify(postcards),primerpostcard);
	}
	
}

function addtocart()
{
	var valido1 = true;
	var valido2 = true;
	var valido3 = true;
	var valido4 = true;
	var valido5 = true;
	var valido6 = true;
	var valido7 = true;
	var aviso = true;
	var validacion = true;
	
	for (x= 0;x<=totalpostcards;x++)
	{
		if (x == 0)
		{	
			if ($('swf_step2_postcardflash'))
			{
				if ($('moreaddresses'))
				{
					for (x = 1 ; x<=totaladdresses;x++)
					{
						if ($('address'+x))
						{
							masssending = 1;
						}
					}
				}
				
				if (contest == 0)
				{
					if(strip_tags(getFlashVar('swf_step2_postcardflash', 'texto_01')) == '')
					{
						 valido1 = false;
					}
					
					if(strip_tags(getFlashVar('swf_step2_postcardflash', 'texto_02')) == '')
					{
						 valido2 = false;
					}
					
					if(strip_tags(getFlashVar('swf_step2_postcardflash', 'texto_03')) == '')
					{
						 valido3 = false;
					}
					
					if(strip_tags(getFlashVar('swf_step2_postcardflash', 'texto_04')) == '')
					{
						 valido4 = false;
					}
					
					if(strip_tags(getFlashVar('swf_step2_postcardflash', 'texto_05')) == '')
					{
						 valido5 = false;
					}
				}
				
				if (contest == 1)
				{
					if($('txtName').value == '' || $('txtLastName').value == '' || $('txtEmail').value == '')
					{
						valido6 = false;
					}
					
					if($('chkAgree').checked == false)
					{
						valido7 = false;
					}
				}

				if ((!valido1 && !valido2 && !valido3 && !valido4 && !valido5) && masssending == 0)
				{
					var message = '';
					switch(currentlanguage)
					{
						case 'en' : message = 'You must enter a real address'; break;
						case 'es' : message = 'Usted debe ingresar una direcci�n'; break;
						case 'br' : message = 'Voc� deve incorporar um endere�o do enviamento real'; break;
						case 'it' : message = 'Devi inserire un indirizzo esistente'; break;
						case 'fr' : message = 'Vous devez entrer une vraie adresse'; break;
						case 'de' : message = 'Bitte geben Sie eine reale Adresse ein'; break;
					}
					aviso = false;
					
				}
				else if(!valido6)
				{
					var message = '';
					switch(currentlanguage)
					{
						case 'en' : message = 'You must enter a name and an email'; break;
						case 'es' : message = 'Usted debe ingresar su nombre e email'; break;
						case 'br' : message = 'Voc� deve incorporar um endere�o do enviamento real'; break;
						case 'it' : message = 'Devi inserire nome e email'; break;
						case 'fr' : message = 'Vous devez entrer un nom et un email'; break;
						case 'de' : message = 'Bitte geben Sie einen Namen und eine E-Mail Adresse ein'; break;
					}
					aviso = false;
				}
				else if(!valido7)
				{
					var message = '';
					switch(currentlanguage)
					{
						case 'en' : message = 'Please read and agree to the Contest Rules'; break;
						case 'es' : message = 'Please read and agree to the Contest Rules'; break;
						case 'br' : message = 'Please read and agree to the Contest Rules'; break;
						case 'it' : message = 'Please read and agree to the Contest Rules'; break;
						case 'fr' : message = 'Please read and agree to the Contest Rules'; break;
						case 'de' : message = 'Please read and agree to the Contest Rules'; break;
					}
					aviso = false;
				}
				
				else
				{
					if (contest == 0)
					{
						if ((getFlashText('swf_step2_postcardflash') == '<font face=\'Arial\'></font>')
								 ||(getFlashText('swf_step2_postcardflash') == ''))
						 {
						 	var message = '';
							switch(currentlanguage)
							{
								case 'en' : message = 'You must enter a message'; break;
								case 'es' : message = 'Usted debe ingresar un mensaje'; break;
								case 'br' : message = 'Voc� deve incorporar um mensagem'; break;
								case 'it' : message = 'Devi Inserire un messaggio'; break;
								case 'fr' : message = 'Vous devez entrer un message'; break;
								case 'de' : message = 'Bitte geben Sie eine Nachricht ein'; break;
							}
							aviso = false;
						 }
						 else
						 {
							 if ($('swf_step2_postcardflash'))
								{
									if ((getFlashVar('swf_step2_postcardflash','validacion')) == 1)
									{
										validacion = false;				
									}
								}
						 
							
								if (validacion  == false)
								{
									var message = '';
									switch(currentlanguage)
									{
										case 'en' : message = 'The message is too long.'; break;
										case 'es' : message = 'El mensaje es muy largo.'; break;
										case 'br' : message = 'A mensagem � demasiado longa.'; break;
										case 'it' : message = 'il messaggio e\' troppo lungo'; break;
										case 'fr' : message = 'Le message est trop long'; break;
										case 'de' : message = 'Die Nachricht ist zu lang'; break;
									}
									aviso = false;
								}
						 }
					}
				}
				
				valido1= true;
				valido2= true;
				valido3= true;
				valido4= true;
				valido5= true;
			}
		}
//		Si hay mas de una postcard
		else
		{
			if ($('swf_step2_postcardflash' + x))
			{
				if(strip_tags(getFlashVar('swf_step2_postcardflash'+ x, 'texto_01')) == '')
				{
					 valido1 = false;
				}
							
				if(strip_tags(getFlashVar('swf_step2_postcardflash'+ x, 'texto_02')) == '')
				{
					 valido2 = false;
				}
				
				if(strip_tags(getFlashVar('swf_step2_postcardflash'+ x, 'texto_03')) == '')
				{
					 valido3 = false;
				}
				
				if(strip_tags(getFlashVar('swf_step2_postcardflash'+ x, 'texto_04')) == '')
				{
					 valido4 = false;
				}
				
				if(strip_tags(getFlashVar('swf_step2_postcardflash'+ x, 'texto_05')) == '')
				{
					 valido5 = false;
				}
			
				if (!valido1 && !valido2 && !valido3 && !valido4 && !valido5)
				{
					var message = '';
					switch(currentlanguage)
					{
						case 'en' : message = 'You must enter a real address'; break;
						case 'es' : message = 'Usted debe ingresar una direcci�n'; break;
						case 'br' : message = 'Voc� deve incorporar um endere�o do enviamento real'; break;
						case 'it' : message = 'Devi inserire un indirizzo esistente'; break;
						case 'fr' : message = 'Vous devez entrer une vraie adresse'; break;
						case 'de' : message = 'Bitte geben Sie eine reale Adresse ein'; break;
					}
					aviso = false;
				}
				else
				{
					if ((getFlashText('swf_step2_postcardflash'  + x) == '<font face=\'Arial\'></font>')
					 ||(getFlashText('swf_step2_postcardflash'  + x) == ''))
					 {
					 	var message = '';
						switch(currentlanguage)
						{
							case 'en' : message = 'You must enter a message'; break;
							case 'es' : message = 'Usted debe ingresar un mensaje'; break;
							case 'br' : message = 'Voc� deve incorporar um mensagem'; break;
							case 'it' : message = 'Devi Inserire un messaggio'; break;
							case 'fr' : message = 'Vous devez entrer un message'; break;
							case 'de' : message = 'Bitte geben Sie eine Nachricht ein'; break;
						}
						aviso = false;
					 }
					 else
					 {
					 	if ($('swf_step2_postcardflash'+ x))
						{
							if ((getFlashVar('swf_step2_postcardflash'+ x,'validacion')) == 1)
							{
								validacion = false;				
							}
						}
						
						if (validacion  == false)
						{
							var message = '';
							switch(currentlanguage)
							{
								case 'en' : message = 'The message is too long.'; break;
								case 'es' : message = 'El mensaje es muy largo.'; break;
								case 'br' : message = 'A mensagem � demasiado longa.'; break;
								case 'it' : message = 'il messaggio e\' troppo lungo'; break;
								case 'fr' : message = 'Le message est trop long'; break;
								case 'de' : message = 'Die Nachricht ist zu lang'; break;
							}
							aviso = false;
						}
					 }
				}
				valido1= true;
				valido2= true;
				valido3= true;
				valido4= true;
				valido5= true;
			}
		}
	}

	if (aviso == true)
 	{
 		step2_save('javascript:step2_checksessioncomplete()');
 	}
 	else
 	{
 		alert(message);
 		return;
 	}
}

function step2_checksessioncomplete()
{
	var y = 0;
	var	primerpostcard = -1;
	
	if (totalpostcards == 0)
	{
		asyncCheckSessionComplete(contest);
	}
	else
	{
		for(x=0;x<=totalpostcards;x++)
		{
			if (x == 0)
			{
				if ($('swf_step2_postcardflash'))
				{
					ultimo2 = x;
					primerpostcard = x;
				}
			}
			else 
			{
				if ($('swf_step2_postcardflash'+x) != null)
				{
					ultimo2 = x;
					if (primerpostcard == -1)
					{
						primerpostcard = x;
					}
				}
			}
		}
			
		for (x =0;x<=totalpostcards;x++)
		{
			if (x==0)
			{
				if ($('swf_step2_postcardflash'))
				{
					asyncCheckSessionComplete(contest,y,idpostcard,x);
					y++;
				}
			}
			else
			{
				if ($('swf_step2_postcardflash'+x))
				{
					asyncCheckSessionComplete(contest,y,0,x);
					y++;
				}
			}
		}
	}
}

function gostep1(uri)
{
	validacion = true;
	
	if ($('step2') != null)
	{
		for (x =0; x<=totalpostcards;x++)
		{
			if (x == 0)
			{
				if ($('swf_step2_postcardflash'))
				{
					if (contest == 0)
					{
						if ((getFlashVar('swf_step2_postcardflash','validacion')) == 1)
						{
							var message = '';
							switch(currentlanguage)
							{
								case 'en' : message = 'The message is too long.'; break;
								case 'es' : message = 'El mensaje es muy largo.'; break;
								case 'br' : message = 'A mensagem � demasiado longa.'; break;
								case 'it' : message = 'il messaggio e\' troppo lungo'; break;
								case 'fr' : message = 'Le message est trop long'; break;
								case 'de' : message = 'Die Nachricht ist zu lang'; break;
							}
							validacion = false;				
						}
					}
				}
			}
			else
			{
				if ($('swf_step2_postcardflash'+x))
				{
					if ((getFlashVar('swf_step2_postcardflash'+x,'validacion')) == 1)
					{
						var message = '';
						switch(currentlanguage)
						{
							case 'en' : message = 'The message is too long.'; break;
							case 'es' : message = 'El mensaje es muy largo.'; break;
							case 'br' : message = 'A mensagem � demasiado longa.'; break;
							case 'it' : message = 'il messaggio e\' troppo lungo'; break;
							case 'fr' : message = 'Le message est trop long'; break;
							case 'de' : message = 'Die Nachricht ist zu lang'; break;
						}
						validacion = false;				
					}
				}
			}
		}
		
		if (validacion)
		{
			step2_save(uri);
		}
		else
		{
			alert(message);
			return;
		}
	}
	else if ($('home_flash'))
	{
		location.href = uri;
	}
	else if($('step4'))
	{
		clearAllTransaction(uri);
	}
	else 
	{
		asyncDeleteCurrentPostcard();
	}
}

function gostep2()
{
	if (contest == 0)
	{
		if ($('step1'))
		{
			step1_save('/Write_Postcards');
		}
		else if($('step4'))
		{
			clearAllTransaction('/Write_Postcards');
		}
		else
		{
			location.href = '/Write_Postcards';
		}
	}
	else
	{
		if ($('step1'))
		{
			step1_save('/Submission');
		}
		else if($('step4'))
		{
			clearAllTransaction('/Submission');
		}
		else
		{
			location.href = '/Submission';
		}		
	}
		
}

function gocart()
{
	if ($('step1'))
	{
		step1_save('/Cart');
	}
	else if($('step4'))
	{
		clearAllTransaction('/Cart');
	}
	else
	{
		if ($('step2'))
		{
			step2_save('/Cart');
		}
		else
		{
			location.href = '/Cart';
		}
	}
}

function checkout()
{
	if ($('step1'))
	{
		step1_save('/checkout.php');
	}
	else
	{
		if ($('step2'))
		{
			step2_save('/checkout.php');
		}
		else
		{
			if (($('confirmtos')) && (!($('confirmtos').checked)))
			{
				alert($('tosmessage').value);
			}
			else
			{
				if ($('contest'))
				{
					location.href = '/contest.php'
				}
				else
				{
					location.href = '/checkout.php';
				}
			}
		}
	}
}

function gohome()
{
	if ($('step1'))
	{
		step1_save('/Index');
	}
	else if($('step4'))
	{
		clearAllTransaction('/Index');
	}
	else
	{
		if ($('step2'))
		{
			step2_save('/Index');
		}
		else
		{
			location.href = '/Index';
		}
	}
}

//function step1_selectColor (color)
//{
//	step1_backgroundcolor = color;
//	if (contest == 1)
//	{
//		$('fondo').style.backgroundColor = '#' + color;
//	}
//	else
//	{
//		$('fondo2').style.backgroundColor = '#' + color;
//	}
//}

function goback_removecontest()
{
	location.href= '/Cart?removeall=1';
}


function cart_remove(id)
{
	location.href = '/Cart?remove='+id;
}

function cart_removereal(realid, id)
{
	var message = '';
	switch(currentlanguage)
	{
		case 'en' : message = 'Do you really want to delete this postcard?'; break;
		case 'es' : message = '�Est� seguro de querer eliminar esta postal?'; break;
		case 'br' : message = '�Voc� quer realmente suprimir este cart�o?'; break;
		case 'it' : message = 'Sei sicuro che vuoi cancellare questa cartolina?'; break;
		case 'fr' : message = 'Voulez-vous vraiment supprimer cette carte ?'; break;
		case 'de' : message = 'L�schen? Sind Sie sicher?'; break;
	}
	
	if (confirm(message))
	{
		location.href = '/Cart?remove='+id+'&realid='+realid;
	}
}

function cart_edit(id)
{
	location.href = '/Cart?edit='+id;
}

//--------------------------

function step2_selectUrlPhoto(url,step)
{	
	step1_selectedphotourl = url;
	step1_RotateStep = step;
	$('yourphoto').src = '/photopostcardresize.php?key=0&postcard=1';
}

function step2_selectColor (color)
{
	step1_backgroundcolor = color;
	$('step1_picture').style.background = '#' + color;
}

//---------------------------
function insertShowFlash(id, body)
{

	var flashvars = {};
	var params = {};
	var attributes = {};
	
	var s = new swfobject();
	s.embedSWF("/editor/show.swf", "swf_" + id, "172", "156", "7","", flashvars, params, attributes);

//	var s = new SWFObject("/editor/show.swf","swf_"+id,"172","156","7");
	s.addVariable("txt_text",body);
	s.write(id);
}

function insertEditFlash(id,body,font)
{
	if (contest == 0)
	{
		var tera = body.replace( /"/g, '\'' );
		
		//s.addVariable("txt_text",body.replace( /"/g, '\'' ));
		if (body)
		{
			if (strpos(body,"SIZE='12'") || strpos(body,'SIZE="12"'))
			{
				font = str_replace(font,font + ' Small',font);
			}
			
			flashvars =  font;
		}
		else
		{
			flashvars = "Arial";
		}
		//logoeditor='/archivos/programawards/logo_thumb16.jpg?id=1';
		swfobject.embedSWF("/editor/edit.swf?lang="+ currentlanguage+"&fuenteInicial="+flashvars + "&tapa=0" + '&logoExterno='+ logoeditor + '&photographer=' + photographername + '&logoGallery=' + logogallery,"swf_"+id,"540","370","7","/scripts/expressInstall.swf",flashvars);

		if (body)
		{
			setTimeout("setFlashText(\"swf_"+id+"\",\""+tera+"\")",5000);//era 5000
		}
	}
	else
	{
		var tera = body.replace( /"/g, '\'' );
		//s.addVariable("txt_text",body.replace( /"/g, '\'' ));
		if (body)
		{
			flashvars =  font;
		}
		else
		{
			flashvars = "Arial";
		}
		
		swfobject.embedSWF("/editor/form2.swf?lang="+ currentlanguage,"swf_"+id,"540","368","7","false","Arial");
		
		if (body)
		{
			setTimeout("setFlashText(\"swf_"+id+"\",\""+tera+"\")",3000);//era 3000
		}
	}
}

function sendContest(id)
{
	asyncContest(id);
}

function cart_removecontest(id)
{
	asyncContestcart(id);
}

function gobackwithcontest()
{
	var key = $('key').value;

	if (isNaN(key))
	{
		location.href = '/Cart';
	}
	else
	{
		location.href = '/Cart?remove='+ key +'';
	}
	
}

function continuewhithoutlogin()
{
	asyncWhithoutLogin();
}

function clearContest()
{
	asyncClearContest();
}

function clearPartners()
{
	asyncClearPartners();
}

function cart_rotateToStep(key,postcard,step)
{
	if (postcard)
	{
		param = '?idpostcard='+key;
	}
	else
	{
		param = '?key='+key;
	}
	
	step1_RotateStep = step;

	$('yourphoto'+ key ).src = '/photopostcardresize.php' + param;
}

function cart_selectUrlPhoto(url,key)
{	
	step1_selectedphotourl = url;
	step1_RotateStep = 0;
	cart_selectColor(($('color'+key)).value,key);
	step1_ImageFormat = ($('format'+key)).value;
}

function cart_selectColor (color,key)
{
	$('step1_picture'+key).style.background = '#' + color;
}

function cart_ImageSize(what,key)
{
	var img = $('yourphoto'+key);
	var spFill = $('step1_picture'+key);

		switch(what)
		{
			case 'stretch':
				img.style.width = currentWidth + 'px';
				img.style.height = currentHeight + 'px';
				img.style.marginLeft = '0px';
				img.style.marginTop = '0px';
				step1_ImageFormat = what;
				break;
			case 'fit':
				img.style.width = step1_IdealWidth + 'px';
				img.style.height = step1_IdealHeight + 'px';
				img.style.marginLeft = parseInt((currentWidth - step1_IdealWidth) / 2, 10).toString() + 'px';
				img.style.marginTop = parseInt((currentHeight - step1_IdealHeight) / 2, 10).toString() + 'px';
				step1_ImageFormat = what;
				break;
		}

}

function gotopartner()
{
	location.href = '../registrationpartner.php';
	
}

function clearWithoutlogin()
{
	asyncClearWithoutlogin();
}

function clearRegistration()
{
	asyncClearRegistration();
}

function cambiarIdioma(script,language)
{
	asyncCambiarIdioma(script,language);
}

function nombre(bool)
{
	
	if (bool == 'si')
	{
		document.getElementById('name').innerHTML = document.getElementById('mail').value;
	}
	else
	{
		document.getElementById('name').innerHTML = document.getElementById('user').value;
	}
}

function registration()
{
	var cont =0;
	var error = false;
	var array_errores = Array();
	
	$('txterrorcontract').innerHTML = '';
	$('txterroremail').innerHTML = '';
	$('txterrorpass').innerHTML = '';
	$('txterrorfilebanner').innerHTML = '';
	
	if ($('txterrorfilelogo'))
	{
		$('txterrorfilelogo').innerHTML = '';	
	}
	
	if(($('txtName')).value == '' ||  $('txtName').value == $('erroroname').value)
	{
		$('txterrorname').innerHTML = $('erroroname').value;

		error = true;
	
		$('txtName').style.background = fondoaffiliate;
	}
	
	if(($('txtEmail')).value == '' ||  $('txtEmail').value == $('erroremail').value)
	{
		$('txterroremail').innerHTML = $('erroremail').value;
		error = true;
		$('txtEmail').style.background = fondoaffiliate;
		
	}
	
	if(($('txtPass')).value == '')
	{
		error = true;
		$('txtPass').style.background = fondoaffiliate;
		$('txterrorpass').innerHTML = $('errorpass').value;
		
	}
	
	if(($('txtPassConfirm')).value == '')
	{
		error = true;
		$('txtPassConfirm').style.background = fondoaffiliate;
		$('txterrorpassconfirm').innerHTML = $('errorpassconfir').value;
		
	}
	
	if(($('txtPersonName')).value == '' || $('txtPersonName').value ==$('errorpname').value)
	{
		$('txterrorpersoname').innerHTML = $('errorpname').value;
		error = true;
		$('txtPersonName').style.background = fondoaffiliate;
	}
	
	if(($('txtAddress')).value == '' || $('txtAddress').value == $('erroraddress').value)
	{
		$('txterroraddress').innerHTML = $('erroraddress').value;
		error = true;
		$('txtAddress').style.background = fondoaffiliate;
		
	}
	
	if(($('txtState')).value == '' || $('txtState').value == $('errorstate').value)
	{
		$('txterrorstate').innerHTML = $('errorstate').value;
		error = true;
		$('txtState').style.background = fondoaffiliate;
	}
	
	if(($('txtZip')).value == '' ||  $('txtZip').value == $('errorzip').value)
	{
		$('txterrorzip').innerHTML = $('errorzip').value;
		error = true;
		$('txtZip').style.background = fondoaffiliate;
		
	}
	
	if(($('txtWebSiteName')).value == '' ||  $('txtWebSiteName').value == $('errorwebname').value)
	{
		$('txterrorwebname').innerHTML  = $('errorwebname').value;
		error = true;
		$('txtWebSiteName').style.background = fondoaffiliate;
	}
	
	if(($('txtWebSiteUrls')).value == '' ||  $('txtWebSiteUrls').value == $('errorweburl').value)
	{
		$('txterrorweburl').innerHTML = $('errorweburl').value;
		error = true;
		$('txtWebSiteUrls').style.background = fondoaffiliate;
	}
	
	if(($('txtSiteDescription')).value == '' ||  $('txtSiteDescription').value == $('errorsitedes').value)
	{
		$('txterrordescription').innerHTML = $('errorsitedes').value;
		error = true;
		$('txtSiteDescription').style.background = fondoaffiliate;
	}
	
	if(($('filePayPal')).value == '' && ($('txtMethod1').checked == true))
	{
		error = true;
		$('filePayPal').style.background = fondoaffiliate;
		$('txterrorfilebanner').innerHTML = $('errorpayment').value;
		
	}

	if(($('contract')).checked == false)
	{
		error = true;
		$('txterrorcontract').innerHTML = $('errorcontract').value;
	}

	if($('txtUrlName').value == '' ||  $('txtUrlName').value == $('errourlname').value || $('txtUrlName').value == $('errourlnameexists').value)
	{
		error = true;
		$('txtUrlName').style.background = fondoaffiliate;
		$('txterrorurlname').innerHTML = $('errourlname').value;
	}
	
	if (error == true)
	{
		$('completefields').style.display = '';
		$('linetop').style.display ='';
	}
	else
	{
		asyncPartnerRegistro();
	}
}

function borrar(id,error)
{
	
	if (document.getElementById(id).style.background == 'rgb(255, 253, 228) none repeat scroll 0% 0%')
	{
		document.getElementById(error).innerHTML = '';
		document.getElementById(id).style.background = 'white';
		
	}
}

function step1_contest(iscontest)
{
	
	$('step1_bigbutton_formatimage').style.display = '';
	$('step1_bigbutton_changeimage').style.display = 'none';
	$('step1_bigbutton_writemessage').style.display = 'none';
	
	$('step1_sourcebubble').style.display = '';
//	$('step1_colorselector').style.display = 'none';
	
	$('step1_sources').style.display = 'block';
	$('step1_format').style.display = 'none';
	
	
	if (iscontest == 1)
	{
		$('step1_sources').style.display = 'none';
		$('fotolog').style.display = '';
		$('step2_picture').style.display = 'none';
		$('step1_picture').style.display = '';
		
		contest = 1;
		$('title').style.display = 'none';
		$('barra').style.display='';
		$('textodescripcion').style.display = '';
		salircontest();
		
	}
	else
	{
		$('title').style.display = '';
	}
		
}

function salircontest()
{
		var divlogout = document.createElement('div');
		divlogout.className = 'contestlogout';
		var link = document.createElement('a');
		link.setAttribute('href', '/logout.php');
		link.style.color = 'yellow';
		link.style.fontWeight = 'bold';
		var txt = document.createTextNode($('contestlogout').value);
		link.appendChild(txt); 
		divlogout.appendChild(link);
		document.getElementById('hello2').appendChild(divlogout);
}

function step2_contest(iscontest)
{
	if (iscontest == 1)
	{
		salircontest();
		$('cartbutton').style.display = 'none';
		contest = 1;
		$('barra').style.display='';
		$('textodescripcion').style.display='';
		$('cartbuttoncontest').style.display = '';
		$('tab1').style.display = 'none';
		$('tabContest').style.display = '';
	}
	else
	{
		$('addrecipient').style.display = '';
		$('cartbuttoncontest').style.display = 'none';
		$('step2_addressbookbubble').style.display = '';
		//$('buttoncsv').style.display = '';

		if ($('buttonmasssending'))
		{
			$('buttonmasssending').style.display = '';
		}
		$('cartbutton').style.display = '';
	}
}

function step2_contestnombre(name,font)
{
	setFlashVar('swf_step2_postcardflash', 'texto_06', '<font face="'+font+'">' + name + '</font>');
}

function step2_contestemail(email,font)
{
	setFlashVar('swf_step2_postcardflash', 'texto_07', '<font face="'+font+'">' + email + '</font>');
}

function step2_contestname(name)
{
	setFlashVar('swf_step2_postcardflash', 'txtNombre', '<font face="Arial">' + name + '</font>');
}

function step2_contestmail(email)
{
	setFlashVar('swf_step2_postcardflash', 'txtEmail', '<font face="Arial">' + email + '</font>');
}

function step2_contesttexto(texto)
{
	texto = texto.replace(/-f/g,'\n')
	setFlashVar('swf_step2_postcardflash', 'texto_01', '<font face="Arial">' + texto + '</font>');
}



function error()
{
	alert($('invpartner').value);
}

function resetpartner(id,lan)
{
	$('user').value = '';
	$('DtpFechaDesde_day').value = '';
	$('DtpFechaDesde_month').value = '';
	$('DtpFechaDesde_year').value = '';
	$('DtpFechaHasta_day').value = '';
	$('DtpFechaHasta_month').value = '';
	$('DtpFechaHasta_year').value = '';
	$('Countries').value = '';
	
	user = null;
	fechadesde = null;
	fechahasta = null;
	country = null;
	filtropartner(id,1,lan,true);
}

function saveVarsAndValidation(id,pagina,lan)
{
	var valido;
	valido = true;
	
	var fechadesdevalido = true;
	
	if (lan == 'es')
	{
		if ($('DtpFechaDesde_day').value != '')
		{
			var dia = $('DtpFechaDesde_day').value;
			if (dia <32 && dia> 0)
			{
				dia = dia.toString().substring(0,2);	
			}
			else
			{
				valido = false
				fechadesdevalido = false;
			}
			
		}
		else
		{
			fechadesdevalido = false;
		}
		
		
		if  ($('DtpFechaDesde_month').value != '')
		{
			var mes = $('DtpFechaDesde_month').value;
			if (mes < 13 && mes >0)
			{
				mes = mes.toString().substring(0,2);
			}
			else
			{
				valido = false
				fechadesdevalido = false;
			}
		}
			else
		{
			fechadesdevalido = false;
		}
	
		
		if ($('DtpFechaDesde_year').value != '')
		{
			if ($('DtpFechaDesde_year').value < 999)
			{
				valido = false
				fechadesdevalido = false;
			}
			else
			{
				year = $('DtpFechaDesde_year').value ;
			}
		}
			else
		{
			fechadesdevalido = false;
		}
		
	}
	else
	{
		if ($('DtpFechaDesde_month').value != '')
		{
			var mes = $('DtpFechaDesde_month').value;
			
			if (mes < 13 && mes >0)
			{
				mes = mes.toString().substring(0,2);
			}
			else
			{
				valido = false
				fechadesdevalido = false;
			}
		}
			else
		{
			fechadesdevalido = false;
		}
		
		
		if  ($('DtpFechaDesde_day').value != '')
		{
			var dia = $('DtpFechaDesde_day').value;
			if (dia <32 && dia> 0)
			{
				dia = dia.toString().substring(0,2);
			}
			else
			{
				valido = false
				fechadesdevalido = false;
			}
		}
			else
		{
			fechadesdevalido = false;
		}
	
		
		if ($('DtpFechaDesde_year').value != '')
		{
			if ($('DtpFechaDesde_year').value < 999)
			{
				valido = false
				fechadesdevalido = false;
			}
			else
			{
				var year = $('DtpFechaDesde_year').value ;
			}
		}
			else
		{
			fechadesdevalido = false;
		}
		
	}
	
		
	var fechahastavalido = true;
	
	if (lan == 'es')
	{
		if ($('DtpFechaHasta_day').value != '')
		{
			var diahasta = $('DtpFechaHasta_day').value;
			if (diahasta <32 && diahasta> 0)
			{
				diahasta = diahasta.toString().substring(0,2);	
			}
			else
			{
				valido = false
				fechahastavalido = false;
			}
			
		}
		else
		{
			fechahastavalido = false;
		}
		
		
		if  ($('DtpFechaHasta_month').value != '')
		{
			var meshasta = $('DtpFechaHasta_month').value;
			if (meshasta < 13 && meshasta >0)
			{
				meshasta = meshasta.toString().substring(0,2);
			}
			else
			{
				valido = false
				fechahastavalido = false;
			}
		}
			else
		{
			fechahastavalido = false;
		}
		
		if ($('DtpFechaHasta_year').value != '')
		{
			if ($('DtpFechaHasta_year').value < 999)
			{
				valido = false
				fechahastavalido = false;
			}
			else
			{
				yearhasta = $('DtpFechaHasta_year').value ;			
			}
		}
		else
		{
			fechahastavalido = false;
		}
		
	}
	else
	{
		if ($('DtpFechaHasta_month').value != '')
		{
			var meshasta = $('DtpFechaHasta_month').value;
			
			if (meshasta < 13 && meshasta >0)
			{
				meshasta = meshasta.toString().substring(0,2);
			}
			else
			{
				valido = false
				fechahastavalido = false;
			}
		}
			else
		{
			fechahastavalido = false;
		}
	
		
		if  ($('DtpFechaHasta_day').value != '')
		{
			var diahasta = $('DtpFechaHasta_day').value;
			if (diahasta <32 && diahasta> 0)
			{
				diahasta = diahasta.toString().substring(0,2);
			}
			else
			{
				valido = false
				fechahastavalido = false;
			}
		}
			else
		{
			fechahastavalido = false;
		}
		
		
		if ($('DtpFechaHasta_year').value != '')
		{
			if ($('DtpFechaHasta_year').value < 999)
			{
				valido = false
				fechahastavalido = false;
			}
			else
			{
				yearhasta = $('DtpFechaHasta_year').value ;
			}
		}
		else
		{
			fechahastavalido = false;
		}
		
	}
	
	if ($('Countries').value != '')
	{
		country= $('Countries').value;
	}
	else
	{
		 country = null;
	}
		
	if ($('user').value != '')
	{
	     user =	$('user').value;
	  
	}
	else
	{
		user = null;
	}
	
	if (valido == true)
	{
		
		if (fechadesdevalido == true)
		{
			fechadesde = mes + '/' + dia + '/'+ year;
			
			if (fechahastavalido == false)
			{
				var now = new Date()
				var meshasta = now.getMonth() + 1;
				var diahasta = now.getDate();
				var yearhasta = now.getFullYear();
				
			}
				
			fechahasta = meshasta + '/' + diahasta + '/' + yearhasta; 
		}
		else
		{
			fechadesde = null;
			fechahasta = null;
		}
		filtropartner(id,pagina,lan,valido)
	}
	else
	{
		
	}
	
	
}

function filtropartner(id,pagina,lan,valido)
{
	
	if (valido == true)
	{
		asyncFiltroPartner(id,pagina,fechadesde,fechahasta,country,user);	
	}
	else
	{
		alert('datos incorrectos')
	}
}

function paginador(pag,id)
{		
	anterior= $('pagina').value;
	$('pagina'+ anterior).style.fontWeight = "";
	$('pagina').value = pag;
	$('pagina'+ pag).style.fontWeight = "bold";
	anterior= pag;
	asyncPaginador(pag,id);
}

function validarNum(e)
{
    tecla = (document.all) ? e.keyCode : e.which;
 	
    if (tecla == 8) return true;
    patron = /\d/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}

function isNumericPasteTextBox(str, e, floatValue)
{
	var element;

	if (floatValue)
	{
		if (e.srcElement) element = e.srcElement;
		else if (e.target) element = e.target;
		else return true;

		return str.match(/^[\d\.]+$/) != null && 
			(str.indexOf(".") == -1 || element.value.lastIndexOf(".") == -1) && 
			str.indexOf(".") == str.lastIndexOf(".");
	}
	else
	{
		return str.match(/^[\d]+$/) != null;
	}
}

function isNumericTextBox(e, floatValue)
{
	var key, element;
	
	if (window.event) key = e.keyCode;
	else if(e.which) key = e.which;
	else return true;

	if (e.srcElement) element = e.srcElement;
	else if (e.target) element = e.target;
	else return true;

	if (key == 46)
	{
		return (floatValue && element.value.indexOf(".") == -1);
	}

	return (key > 47 && key < 58) || key == 8;
}

function openPopup()
{
	 popup = window.open('print.php?','800x600','toolbar=no,status=no,scrolling=no,scrollbars=yes,type=fullWindow,fullscreen,location=no,menubar=no,directories=no,resizable=yes,width=auto,height=auto');
}

function UseCsv(name)
{
//	var arrDatos = document.getElementsByName(name);
//	for (var i = 0; i < arrDatos.length; i++)
//	{
//		if (arrDatos[i].checked)
//		{
//			var obj[] = (arrDatos[i].id.substring(4));
//			arrDatos[i].checked = false;
//		}
//	}
//	var address = $('hid_' + obj);
//	if(address != null)
//	{
//		address = (address.value).replace( /%%NN%%/g, '\r\n' );
//		var arr = address.split('\n');
//		
//		for (i = 0; i < 5 ; i++)
//		{
//			if (arr[i] != null)
//			{
//				setFlashVar('swf_step2_postcardflash', 'texto_0' + (i+1), arr[i].replace('\r','').replace('\n',''));
//			}
//			else
//			{
//				setFlashVar('swf_step2_postcardflash', 'texto_0' + (i+1), '');
//			}
//		}
//		hide();
//	}
	if ($('cantidad').value != '0')
	{
		asyncClonarPostcards(name);
		
	}
	else
	{
		var message = '';
		switch(currentlanguage)
		{
			case 'en' : message = 'You must enter CSV file'; break;
			case 'es' : message = 'Usted debe ingresar un archivo CSV'; break;
			case 'br' : message = 'Entre arquivo CSV'; break;
			case 'it' : message = 'Inserisci un file csv'; break;
			case 'fr' : message = 'Vous devez entrer un fichier CSV'; break;
			case 'de' : message = 'Bitte geben Sie eine CSV Datei ein'; break;
		}
		alert(message);
	}
		


}

function isset(variable_name) {
    try {
         if (typeof(eval(variable_name)) != 'undefined')
         if (eval(variable_name) != null)
         return true;
     } catch(e) { }
    return false;
   } 
   
function EnviarMail(id,body)
{
	document.getElementById(id).setAttribute('href','mailto:'+ body);
}

function EnterFotolog()
{
	$('selectorfotolog').checked = 'ON';
	$('selectorfotolog').click();
	step1_selectFotolog();
}


var marcotestimonial = 0; //0 para que notenga marco (borde)
var fondotestimonial = ''; //color de fondo del cuadro
var pausillatestimonial = 2000; //tiempo de la pausa en milisegundos (2000 = 2 segundos)
var destinotestimonial = "_blank"; //target en donde se quiera que se carguen los enlaces, en caso de usarlos.
var cursortestimonial = "default;" ; //cursor que se quiera sobre el cuadro
var colEnlacetestimonial = '#006699'; //color del texto del enlace
var fuentetestimonial = "arial"; //fuente para los textos 
var tamEnlacetestimonial = '28'; // tamao de la fuente del enlace 
var negritatestimonial = true; //si se quiere o no negrita en el texto del enlace

function noticia(texto)
	{
	this.texto = texto;
	
	}

var det = false;

function escribe(id){

if (id == 3)
{
	var anchotestimonial = 140; //anchura del cuadro
	var altotestimonial = 77; //altura del cuadro
}
else if (id == 2)
{
	var anchotestimonial = 140; //anchura del cuadro
	var altotestimonial = 77; //altura del cuadro
}
else if (id == 1)
{
	var anchotestimonial = 120; //anchura del cuadro
	var altotestimonial = 77; //altura del cuadro
}
else
{
	var anchotestimonial = 240; //anchura del cuadro
	var altotestimonial = 77; //altura del cuadro
}

document.write ('<div id="mami" style="width:' + 305 + 'px; height:' + altotestimonial + 'px; overflow:hidden; position: relative;margin-top:56px;">');
document.write('<table bgcolor="' + fondotestimonial + '" border="' + marcotestimonial + '" width="' + anchotestimonial + '" height="100%"><tr><td valign="top">');
document.write ('<div id="uno" style="top:' + altotestimonial +'px; width:' + anchotestimonial + 'px; height:' + altotestimonial + 'px; position: absolute;">');

document.write ('<span ');

document.write ('style="color:white;">' + noticias[0].texto + '</span>');

document.write ('</div><br>');
document.write ('<div id="dos" style="top:' + (altotestimonial*2) +'px; width:' + anchotestimonial + 'px; height:' + altotestimonial + 'px; position: absolute;">');


document.write ('<span ');
document.write (noticias[1].texto);
document.write ('" style="color:white;">'+ noticias[1].texto + '</a>');

document.write ('</div>');
document.write('</td></tr></table>');
document.write ('</div>');
if(navigator.appName == "Netscape")
{altoUno = document.getElementById('uno').offsetHeight;}
else
{altoUno = document.getElementById('uno').clientHeight;}
document.getElementById('uno').onmouseover =function(){
	det = true;
	clearTimeout(tiempotestimonial);
	}
document.getElementById('uno').onmouseout =function(){
	det = false;
	clearTimeout(tiempotestimonial);
	escrolea(id);
	}

document.getElementById('dos').onmouseover =function(){
	det = true;
	clearTimeout(tiempotestimonial);
	}
document.getElementById('dos').onmouseout =function(){
	det = false;
	clearTimeout(tiempotestimonial);
	 escrolea(id);
	 
	}
}
desp = 1;
var conta = 1;
var pos,pos2;
function escrolea(id){

if (id == 3)
{
	var anchotestimonial = 140; //anchura del cuadro
	var altotestimonial = 77; //altura del cuadro
}
else if (id == 2)
{
	var anchotestimonial = 140; //anchura del cuadro
	var altotestimonial = 77; //altura del cuadro
}
else if (id == 1)
{
	var anchotestimonial = 120; //anchura del cuadro
	var altotestimonial = 77; //altura del cuadro
}
else
{
	var anchotestimonial = 240; //anchura del cuadro
	var altotestimonial = 77; //altura del cuadro
}

pos = document.getElementById('uno').style.top;
pos = pos.replace(/px/,"");
pos = pos.replace(/pt/,"");
pos = new Number(pos);
pos2 = document.getElementById('dos').style.top;
pos2 = pos2.replace(/px/,"");
pos2 = pos2.replace(/pt/,"");
pos2 = new Number(pos2);
pos -= desp;
pos2 -= desp;
//alert(pos + ' ' + desp);
//alert(pos2 + ' ' + desp);
if (pos == desp){
	var contenidos = "";
	document.getElementById('dos').style.top = altotestimonial + 'px';
	document.getElementById('dos').childNodes[0].firstChild.nodeValue  = noticias[conta].texto;
	document.getElementById('dos').childNodes[0].href = noticias[conta].enlace ;
	document.getElementById('uno').style.top = 0;
	if(conta == noticias.length-1)
		{conta=0}
	else{
		conta++
		}
	pausa(id);
	return false;
	}
else{

	if (pos2 == desp){
		var contenidos = "";
		document.getElementById('uno').style.top = altotestimonial + 'px';
		document.getElementById('uno').childNodes[0].firstChild.nodeValue  = noticias[conta].texto;
		document.getElementById('uno').childNodes[0].href  = noticias[conta].enlace;
		document.getElementById('dos').style.top = 0;
		if(conta == noticias.length-1)
		{conta=0}
	else{
		conta++;
		}
		pausa(id);
		return false;
		}
	else{
		document.getElementById('uno').style.top = pos + 'px';
		document.getElementById('dos').style.top = pos2 + 'px';
		}
	}
tiempotestimonial = window.setTimeout('escrolea('+id+')',50);
}
var tiempotestimonial;
function pausa(id)
{
clearTimeout(tiempotestimonial);
if (det == false){
	tiempotestimonial = setTimeout ('continuar('+id+')',2000);
	}
}
function continuar(id)
{
if(det == false)
	{escrolea(id);}
}

function getAlbum()
{
	asyncGetAlbumFacebook();
}

function getPhoto(id1,id2)
{
	asyncGetPhotoFacebook(id1.toString()+id2.toString());
}

function NuevoAlbum()
{
	asyncNuevoAlbumFacebook();
}

function CrearAlbum()
{
	asyncCrearAlbumFacebook();
}

function UploadPhotos()
{
	asyncUploadPhotos();	
}

function formCargarImagen()
{
	asyncCargarImagen();
}

function formSubir()
{
	asyncSubirImagen();
}

function insertartextomodificada(texto,font)
{
	insertEditFlash('step2_postcardflash' + recipient,texto,font/*getFontFromBody(texto)*/);
}

function setfont(address,anterior)
{
	if ($("swf_step2_postcardflash" + anterior))
	{
		font = 'FACE=\"'+getFlashVar("swf_step2_postcardflash" + anterior,'nombre_txt')+ '\"';
	
		if (strpos(font,'Arial Small') || strpos(font,'Verdana Small'))
		{
			font = font + ' SIZE=\"12\"';
			font = str_replace(" Small","",font);
		}
	}
	if (font == undefined)
	{
		font = 'FACE=\"Arial\"';
	}
	
	address = str_replace( "%NN%", "\r\n",address);

	setTimeout("setAddressValue(\"swf_step2_postcardflash"+ anterior+"\",\""+ base64_encode(address)+"\",\""+addslashes(font)+"\")",1);

}

function insertaraddressmodificada(address,anterior)
{
	setTimeout("setfont(\'"+address+"\',"+anterior+");",2000);//era 2000
}

function clearEditProfile()
{
	$('name').value = '';
	$('email').value = '';
	$('password').value = '';
	$('passwordconf').value = '';
	$('drpCountry').value = $('hidcountry').value;
	$('drpGender').value = '1';
	$('drpAgeDay').value = '1';
	$('drpAgeMonth').value = '1';
	$('drpAgeYear').value = '1';
	$('msgerror').innerHTML = '';
}

function ModificacionUsuario()
{
	errorpass = false
	errorpassconf = false;
	if ($('password').value != '' && $('passwordconf').value == '')
	{
		errorpass = true;
	}
	
	if ($('password').value == '' && $('passwordconf').value != '')
	{
		errorpassconf = true;
	}
	
	if (errorpass ^ errorpassconf)
	{
		$('msgerror').innerHTML = $('hpassword').value;
	}
	else if ($('password').value != $('passwordconf').value)
	{
		$('msgerror').innerHTML = $('hpasswordnomatch').value;
	}
	else
	{
		$('msgerror').innerHTML  = '';
		asyncModificarDatos();
	}
}

function pressroomfiltro(page)
{
	$('hiddenvalue').value = page;
	__doPostBack('pager');
}


function changemethod(id)
{
	asyncAffiliateMethod(id);
}

function ChooseMethod(idmethod)
{
	asyncPaymentMethod(idmethod);
}

function popaddress()
{
	asyncPopAddress();
}


function validateAddresses()
{
	error1 = true;
	error2 = true;
	error3 = true;
	error4 = true;
	error5 = true;
	
	if ($('txtaddress1').value == '')
	{
		error1 = false;
	}

	if ($('txtaddress2').value == '')
	{
		error2 = false;
	}
	
	if ($('txtaddress3').value == '')
	{
		error3 = false;
	}
	
	if ($('txtaddress4').value == '')
	{
		error4 = false;
	}
	
	if ($('txtaddress5').value == '')
	{
		error5 = false;
	}
	
	if (!error1 && !error2 && !error3 && !error4 && !error5)
	{
		message = '';
		switch(currentlanguage)
		{
			case 'en' : message = 'You must complete all fields'; break;
			case 'es' : message = 'Debes completar todos los campos'; break;
			case 'br' : message = 'You must complete all fields'; break;
			case 'it' : message = 'You must complete all fields'; break;
			case 'fr' : message = 'You must complete all fields'; break;
			case 'de' : message = 'You must complete all fields'; break;
		}
		alert(message);
		return false;
	}
	else
	{
		return true;
	}
	
}

function addaddress()
{
	if(validateAddresses())
	{
		asyncAddAddress();
	}
}

function forgetpassword(url)
{
	error = false;
	$('txterror').innerHTML = '';
	if ($('txtemail').value == '')
	{
		error = true;
	}
	
	if (error)
	{
		message = '';
		switch(currentlanguage)
		{
			case 'en' : message = 'Enter a valid e-mail address'; break;
			case 'es' : message = 'Ingrese una direcci�n de e-mail v�lida'; break;
			case 'br' : message = 'Entre com um endere�o de email v�lido'; break;
			case 'it' : message = 'Inserisci un valido indirizzo e-mail'; break;
			case 'fr' : message = 'Entrez une adresse e-mail valide'; break;
			case 'de' : message = 'G�ltige E-Mail Adresse eingeben'; break;
		}
		alert(message);
		return;
	}
	else
	{
		asynRestorePassword(url);
	}
}

function windowforgetpass()
{
	asyncWindowForgetPassword()
}


function windowforgetpassphotoselection()
{
	asyncWindowForgetPasswordPhotoselection()
}

function updatepassword(url)
{
	error1 = false;
	error2 = false;
	$('txterror').innerHTML = '';
	if ($('txtpassword1').value == '')
	{
		error1 = true;
	}
	
	if ($('txtpassword2').value == '')
	{
		error2 = true;
	}
	
	if (error1 || error2)
	{
		message = '';
		switch(currentlanguage)
		{
			case 'en' : message = 'Enter a valid password and it\'s confirmation.'; break;
			case 'es' : message = 'Ingrese una contrase�a y su confirmacion'; break;
			case 'br' : message = 'Entre com a senha'; break;
			case 'it' : message = 'Inserisci la password '; break;
			case 'fr' : message = 'Entrez un mot de passe'; break;
			case 'de' : message = 'G�ltiges  Passwort and Best�tigung des Passworts eingeben '; break;
		}
		alert(message);
		return;
	}
	else
	{
		if ($('txtpassword1').value == $('txtpassword2').value)
		{
			asyncUpdatePassword(url);
		}
		else
		{
			message = '';
			switch(currentlanguage)
			{
				case 'en' : message = 'The password must match with a Confirm Password'; break;
				case 'es' : message = 'El Password debe coincidir con la Confirmaci�n de Password'; break;
				case 'br' : message = 'A senha deve conferir com a senha previamente confirmada '; break;
				case 'it' : message = 'La password deve coincidere con la password di conferma'; break;
				case 'fr' : message = 'Le mot de passe doit �tre identique � la confirmation du mot de passe'; break;
				case 'de' : message = 'Das Passwort muss mit der Best�tigung des Passworts �bereinstimmen'; break;
			}
			alert(message);
			return;
		}
	}
}



function test()
{
	asyncTest();
}

function changeMask(nro)
{
	step1_frame = nro;
	
	if (contest == 1)
	{
		$('marco_'+marcoanterior).style.visibility = 'hidden';
		
		$('marco'+nro).style.visibility = 'visible';
		$('marco_'+nro).style.height = '312px';
	}
	else
	{
		if ($('marco_'+ marcoanterior))
		{
			$('marco_'+ marcoanterior).style.visibility = 'hidden';
		}
		
		if($('marco_'+nro))
		{
			$('marco_'+nro).style.visibility = 'visible';
			$('marco_'+nro).style.height = '312px';
			marcoanterior = step1_frame;
		}
		
	}
	
}

function clearMask()
{
	if ($('marco_'+ marcoanterior))
	{
		$('marco_'+ marcoanterior).style.visibility = 'hidden';
	}
	
	marcoanterior = 0;
	step1_frame = 0;
}

function step2_selectframe(nro)
{
	if (nro != 0)
	{
		$('marco'+ nro).style.display = 'block';
	}
	else
	{
		$('cajaframes').style.display = 'none';
	}
}

function borraraddresses()
{
	$('txtaddress1').value = '';
	$('txtaddress2').value = '';
	$('txtaddress3').value = '';
	$('txtaddress4').value = '';
	$('txtaddress5').value = '';
	$('txtaddress5').value = '';
	$('drpCountry').value = $('idcountry').value;
}

function clearTransaction(transaction)
{
	asyncClearTransaction(transaction);
}

function clearAllTransaction(uri)
{
	asyncClearAllTransaction(uri);
}

function gotogallery()
{
	asyncGotoGallery();
}

function ChooseMethodHazelBucks(idmethod)
{
	asyncPaymentMethodForHazelBucks(idmethod);
}

function buycredits(idhazelbulktype)
{
	location.href = '/PayCredits/'+idhazelbulktype;
}

function hideshowformMediaHighLights(value,id)
{
	if (value == true)
	{
		$('sharehiddenmedia'+idmediaanterior).style.display = 'none';
		$('textsharemedia'+ idmediaanterior).innerHTML = '<a href="javascript:hideshowformMediaHighLights(true,'+idmediaanterior+');" class="sharetextoff"><img src="images/share/show.jpg"  > Share</a>';
		$('textsharemedia'+idmediaanterior).style.textDecoration = 'none';
		
		$('sharehiddenmedia'+id).style.display = '';
		$('textsharemedia' + id).innerHTML = '<a href="javascript:hideshowformMediaHighLights(false,'+id+');" class="sharetextoff"><img src="images/share/hide.jpg"  > Share</a>';
		$('textsharemedia'+id).style.textDecoration = 'underline';
		
	}
	else 
	{
		$('sharehiddenmedia'+id).style.display = 'none';
		$('textsharemedia'+ id).innerHTML = '<a href="javascript:hideshowformMediaHighLights(true,'+id+');" class="sharetextoff"><img src="images/share/show.jpg"  > Share</a>';
		$('textsharemedia'+id).style.textDecoration = 'none';
	}
	idmediaanterior = id;
	
}

function hideshowformPressReleases(value,id)
{
	if (value == true)
	{
		$('sharehiddenpress'+idshareanterior).style.display = 'none';
		$('textsharepress'+ idshareanterior).innerHTML = '<a href="javascript:hideshowformPressReleases(true,'+idshareanterior+');" class="sharetextoff"><img src="images/share/show.jpg"  > Share</a>';		
		$('textsharepress'+idshareanterior).style.textDecoration = 'none';
		
		$('sharehiddenpress'+id).style.display = '';
		$('textsharepress' + id).innerHTML = '<a href="javascript:hideshowformPressReleases(false,'+id+');" class="sharetextoff"><img src="images/share/hide.jpg"  > Share</a>';
		$('textsharepress'+id).style.textDecoration = 'underline';
	}
	else 
	{
		$('sharehiddenpress'+id).style.display = 'none';
		$('textsharepress'+ id).innerHTML = '<a href="javascript:hideshowformPressReleases(true,'+id+');" class="sharetextoff"><img src="images/share/show.jpg"  > Share</a>';
		$('textsharepress'+id).style.textDecoration = 'none';
	}
	idshareanterior = id;
}


function changeselector(v1, v2, v3)
{
	if(v1 == 1)
	{
		create_1 = true;
		create_2 = false;
		create_3 = false;
		$('leftyourphoto').style.display = 'none';
	}
	
	if(v1 == 2)
	{
		create_2 = true;
		create_1 = false;
		create_3 = false;
		$('leftyourphoto').style.display = '';
	}
	
	if(v1 == 3)
	{
		create_3 = true;
		create_2 = false;
		create_1 = false;
		$('leftyourphoto').style.display = 'none';
	}
	
	$('yourphoto'+v1).style.display = 'inline';
	$('yourphoto'+v2).style.display = 'none';
	$('yourphoto'+v3).style.display = 'none';
}


function fbs_click(url,title)
{
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(title),'sharer','toolbar=0,status=0,width=626,height=436,resizable=1');
	return false;
}

function Linkedin(url,title,summary,source)
{
	window.open('http://www.linkedin.com/shareArticle?mini=true&url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'&summary='+encodeURIComponent(summary)+ '&source='+encodeURIComponent(source),'sharer','toolbar=0,status=0,width=626,height=436,resizable=1');
	return false;
}

function Mixx(url,title,description,tags,partner)
{
	window.open('http://mini.mixx.com/submit/story?page_url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'&description='+encodeURIComponent(description)+'&tags='+encodeURIComponent(tags)+'&partner='+encodeURIComponent(partner),'sharer');
	return false;
}


function Myspace()
{
	u=location.href;
	t=document.title;
	window.open('http://www.linkedin.com/shareArticle?mini=true&url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t)+'&summary=','sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function gotowriteaddress()
{
	$('writeaddressbutton').style.display = 'none';
	$('cartbutton').style.display = 'block';
	$('botomchangetext').style.display = 'block';
	$('cajaEditorAddress').style.display = 'block';	
	$('cajaEditorWriteText').style.display = 'none';
}

function gotochangetext()
{
	$('writeaddressbutton').style.display = 'block';
	$('cartbutton').style.display = 'none';
	$('botomchangetext').style.display = 'none';
	$('botomBack').style.display = 'block';
	$('cajaEditorWriteText').style.display = 'block';
	$('cajaEditorAddress').style.display = 'none';	
}


function massiveshow(val)
{
	var obj = $('img_' + val);
	
	if (obj.src.indexOf('images/etc/view.gif') >= 0)
	{
		$('cajaAddresses_'+ val).style.display = '';
		obj.src = 'images/etc/hide.gif';
		$('cajaNombre_' + val).style.fontWeight = 'bold';
	}
	else
	{
		obj.src = 'images/etc/view.gif';
		$('cajaAddresses_'+ val).style.display =  'none';
		$('cajaNombre_' + val).style.fontWeight = 'normal';
	}
}

function deleteAddressFromMassiveSend(id)
{
	cajaNombre = $('cajaNombre_'+ id);
	cajaAddress = $('cajaAddresses_'+ id);
	
	$('trNombre_'+ id).removeChild(cajaNombre);
	$('trAddresses_'+ id).removeChild(cajaAddress);
	
	hiddenaddress =	$('address'+ id);
	hiddencountry =	$('country'+ id);
	
	$('tdhidden_'+id).removeChild(hiddencountry);
	$('tdhidden_'+id).removeChild(hiddenaddress);
	
	$('cantidadaddresses').value = parseInt($('cantidadaddresses').value) - 1;
	
	if (parseInt($('cantidadaddresses').value) == 0)
	{
		table = $('moreaddresses');
		body = document.getElementById("massbody");
		table.removeChild(body);
	}
	
	asyncdeleteAddressFromMassiveSend(id);
}

function importfromcsv()
{
	$('errormasscsv').innerHTML = '';
	uploadCsvAddress();
}

function importfromAddreesBook()
{
	if ($('swf_step2_postcardflash'))
		$('swf_step2_postcardflash').style.visibility = 'hidden';
	if ($('country'))
		$('country').style.visibility = 'hidden';
	
	if (totalpostcards >0)
	{
		for (x =1;x<=totalpostcards;x++)
		{
			if ($('swf_step2_postcardflash'+ x ) != null)
			{
				$('swf_step2_postcardflash' + x).style.visibility = 'hidden';
			}
		}
	}
	
	padd = document.documentElement.scrollTop;
	$('layerDiv').style.display = 'block';
	$('layerDiv').style.height = screen.height + 200 + 'px';
	$('layerDiv').style.width  = screen.width;
	$('boxed').style.display='block';
	$('boxed').style.top = (padd + 40) + 'px';
	$('boxed').style.left = parseInt((screen.width - 524) / 2) + 'px';
	asyncGetAddressPopUpMassSending();
}

function UseAddressForMassSending()
{
	var checkboxselect = document.getElementsByName('select');
	var cantidadmassaddresses = document.getElementById('cantidadaddresses').value;
	var nro = 0;
	var item;
	var totaladdressbook = parseInt(checkboxselect.length)
	
	for (x=0;x<=totaladdressbook;x++)
	{
		if (document.getElementById('rad_'+x))
		{
			var selectedcheckbox = document.getElementById('rad_'+x);
			nro++;

		    if (selectedcheckbox.checked)
			{
				
				if (cantidadmassaddresses == 0)
				{
					var body = document.createElement("tbody"); 
					body.id = "massbody";
				}
				else
				{
					var body = document.getElementById("massbody");
				}
				
				totaladdresses++;
				hiddenaddress = $('hid_'+nro).value;
				
				address = $('addresstext_'+nro).innerHTML;
				
				partes = split('%%NN%%',hiddenaddress);
				fulladdress = partes[0] + ',' + partes[1] + ',' + partes[2] + ',' + partes[3] + ',' + partes[4];
				idcountry = partes[5];
				cantidadmassaddresses++; 
				
		        trNombre = document.createElement("tr");
		        trNombre.id = "trNombre_"+totaladdresses;
		        
				tdCajaNombre = document.createElement("td");
				tdCajaNombre.className = "cajaNombre";
				tdCajaNombre.id = "cajaNombre_"+totaladdresses;
				tdCajaNombre.style.widht = "200px";
				tdCajaNombre.innerHTML ='<a onclick=\"massiveshow('+totaladdresses+');\" style=\"cursor: pointer;\"><img src=\"images/etc/view.gif\" id=\"img_'+totaladdresses+'\" style=\"float:left;\"/></a><div class="cajaNombreTexto">'+partes[0]+'</div><div><a onclick="deleteAddressFromMassiveSend('+totaladdresses+');" style=\"cursor: pointer;\"><img src=\"images/etc/close.gif\"/></a></div>';
				trNombre.appendChild(tdCajaNombre);
		        
				trAddresses = document.createElement("tr");
		        trAddresses.id = "trAddresses_"+totaladdresses;
	
		        tdCajaAddresses = document.createElement("td");
				tdCajaAddresses.className = "cajaAddresses";
				tdCajaAddresses.id = "cajaAddresses_"+totaladdresses;
				tdCajaAddresses.style.display = "none";
		
				tdCajaAddresses.innerHTML = '<div class="cajaAddresses">'+address+'</div>';
				trAddresses.appendChild(tdCajaAddresses);
					
				trHidden = document.createElement("tr");
	
		        tdCajaHidden = document.createElement("td");
				tdCajaHidden.id = "tdhidden_"+totaladdresses;
				
				tdCajaHidden.innerHTML = '<input id="address'+totaladdresses+'" type="hidden" value="'+fulladdress+'"><input id="country'+totaladdresses+'" type="hidden" value="'+idcountry+'">';
				
				trHidden.appendChild(tdCajaHidden);
				
				body.appendChild(trNombre);
				body.appendChild(trAddresses);
				body.appendChild(trHidden);
	
				$('moreaddresses').appendChild(body);
			}
		}
	}
	
	document.getElementById('cantidadaddresses').value = cantidadmassaddresses;
	hide();
}

function deleteRealPostcardFromMassSending(idpostcard)
{
	asyncdeleteRealPostcardFromMassSending(idpostcard);
}

function CerrarMassSending()
{
	masssending = 0;
	
	if (document.getElementById("moreaddresses"))
	{
		var cell = document.getElementById("moreaddresses");
	
		if ( cell.hasChildNodes() )
		{
		    while ( cell.childNodes.length >= 1 )
		    {
		        cell.removeChild( cell.firstChild );       
		    } 
		}
		$('columnamasssending').style.display = 'none';
	}

	$('cantidadaddresses').value = 0;
	totaladdresses = 0;
}

function getAddressEdit(id)
{
	asyncEditAddress(id);
}

function editAddress(id)
{
	if(validateAddresses())
		asyncEditAddressById(id);
}

function openWindowPressroom(url)
{
	var w = window.open(url,"scrollbars=yes, menubar=no, titlebar=no, resizable=yes");
}

function showfaq(id,img)
{
	if ($(id).style.display == 'none')
	{
		$(id).style.display = '';
		$(img).src = '/images/layout/btn_less.gif';
	}
	else
	{
		$(id).style.display = 'none';
		$(img).src = '/images/layout/btn_plus.gif';
	}
}

function changeTheme()
{
	asyncChangeThemeCombo($('drpThemes').value);
}

function cambiarIphoneImageUp()
{
	$('iphoneImage'+ iphonevar).style.display = 'none';
	
	if (iphonevar == 5)
	{
		iphonevar = 0;
	}
	
	iphonevar++;
	$('iphoneImage'+ iphonevar).style.display = 'block';

}

function cambiarIphoneImageDown()
{
	$('iphoneImage'+ iphonevar).style.display = 'none';

	if (iphonevar == 1)
	{
		iphonevar = 6;
	}

	iphonevar--;
	$('iphoneImage'+ iphonevar).style.display = 'block';
	
}

function facebookLogin()
{
	facebookId = FB.Facebook.get_sessionState().result.uid;
	asyncFacebookLogin(facebookId);
}

function updateUI() {
        var user = FB.Facebook.apiClient.get_session() ? FB.Facebook.apiClient.get_session().uid : null;
        var singleton=FB.Connect._singleton;
        var nextUrl=FBIntern.Uri.addQueryParameters(FB.XdComm.Server.singleton.get_receiverUrl(),'fb_login&fname=_parent&session=loggedout')
        singleton._ensureLoginHandler();
        singleton._logoutCallback="http://www.hazelmail.com";
        logoutUrl=FBIntern.Utility.getFacebookUrl('www')+'logout.php?app_key='+FB.Facebook.apiKey+'&session_key='+encodeURIComponent(FB.Facebook.apiClient.get_session().session_key)+'&next='+encodeURIComponent(nextUrl);
        FB.Facebook.apiClient.set_session(null);
        singleton.set__userInfo(null);
        singleton._logoutIframe=FB.XdComm.Server.singleton.createNamedHiddenIFrame('fbLogout',logoutUrl,'fb_logout',null);
   }
   
function changeAwardCombo()
{
	if($('drpAwardProgram').value != '')
	{
		$('trtxtProgramAwardMember').style.display = '';
	}
	else
	{
		$('trtxtProgramAwardMember').style.display = 'none';
	}
}

function PopCheckout(text)
{
	$('textoError').innerHTML = text;
	$('flotantCheckout').style.display = 'block';
	$('layerDiv').style.display = 'block';
	$('layerDiv').style.height = screen.height + 10 + 'px';
	$('layerDiv').style.width  = screen.width;
}

function HideCheckout()
{
	$('layerDiv').style.display = 'none';
	$('flotantCheckout').style.display = 'none';
}

function LoginWithProgramAward()
{
	asyncLoginWithProgramAward();
}

function MoveFramesToLeft()
{
	asyncMoveFramesToLeft();
}

function MoveFramesToRight()
{
	asyncMoveFramesToRight();
}

function SendCkbOpt()
{
	location.href = backcheckout;
}

function changeGalleryCategories(combo)
{
	asyncChangeGalleryCategories(combo);
}

function removeAllChilds(id)
{
	var holder = document.getElementById(id);
	while(holder.hasChildNodes()){
   		holder.removeChild(holder.lastChild);
	}
}
	
function GetPopPartnersGalleries()
{
	category = $('cboCategories').value;
	subcategory = $('cboSubCategory').value;
	subcategory2 = $('cboSubCategory2').value;
	$('picturedescription').innerHTML = '';
	
	if (category)
	{
		padd = document.documentElement.scrollTop;
		$('layerDiv').style.display = 'block';
		$('layerDiv').style.height = screen.height + 10 + 'px';
		$('layerDiv').style.width = screen.width 
		$('boxed3').style.display='block';
		$('boxed3').style.top = (padd + 40) + 'px';
		$('boxed3').style.left = parseInt((screen.width - 524) / 2) + 'px';
		asyncSetPopPartnersGalleries();
	}
}
	
function openPopImage(idphoto)
{
	asyncOpenPopImage(idphoto);
}

function selectGalleryImage()
{
	asyncSelectGalleryImage();
}

function hideBoxed3()
{
	$('layerDiv').style.display = 'none';
	$('boxed3').style.display='none';
}

function SetNewPrice()
{
	if ($('numbercode').value != '')
	{
		$('errorMessage').innerHTML = '';
		asyncSetNewPrice();
	}
}

function SetNewPriceHazelBucks()
{
	if ($('numbercode').value != '')
	{
		$('promoMessage').innerHTML = '&nbsp;';
		asyncSetNewPriceHazelBucks();
	}
}

function checkEnter(e,evento)
{
	var characterCode;

	if(e && e.which)
	{
		try{
			e = e;
			characterCode = e.which;
		}
		catch(err)
		{
		}
	}
	else
	{
		try{
		e = event;
		characterCode = e.keyCode;
		}
		catch(err)
		{
		}
		
	}
	
	if(characterCode == 13)
	{
		eval(evento)();
		return false;
	}
	else{
		return true;
	}

}

function changeHazelBucksPromo()
{
	$('promoMessage').innerHTML = '&nbsp;';
	$('numbercode').value = '';
	asyncChangeHazelBucksPromo();
} 

function completeTransactionFree(idtransaction,idpromocampaign)
{
	asyncCompleteTransactionFree(idtransaction,idpromocampaign);
}
			
function getFontFromBody(body)
{
	if (!body || strcmp(body,"<p align='left'></p>") == 0 )
	{
		return 'Arial';
	}

	var tmp = body.replace( /\'/g, '"' );
	return (tmp.replace( /.*face="([^"]*)".*/i, "$1"));
}

String.prototype.Base64Encode = function()
{
	var input = this;
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;

	do {
		chr1 = input.charCodeAt(i++);
		chr2 = input.charCodeAt(i++);
		chr3 = input.charCodeAt(i++);

		enc1 = chr1 >> 2;
		enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
		enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
		enc4 = chr3 & 63;

		if (isNaN(chr2))
		{
			enc3 = enc4 = 64;
		}
		else if (isNaN(chr3))
		{
			enc4 = 64;
		}

		output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
			keyStr.charAt(enc3) + keyStr.charAt(enc4);
	} while (i < input.length);

	return output;
}

String.prototype.Base64Decode = function()
{
	var input = this;
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;

	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	do
	{
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = keyStr.indexOf(input.charAt(i++));

		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;

		output = output + String.fromCharCode(chr1);

		if (enc3 != 64)
		{
			output = output + String.fromCharCode(chr2);
		}
		
		if (enc4 != 64)
		{
			output = output + String.fromCharCode(chr3);
		}
	} while (i < input.length);
	
	return output;
}