var id=1;
AIM = {

frame : function(c) {

var n = 'f' + Math.floor(Math.random() * 99999);
var d = document.createElement('DIV');
d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
document.body.appendChild(d);

var i = document.getElementById(n);
if (c && typeof(c.onComplete) == 'function') {
i.onComplete = c.onComplete;
}

return n;
},

form : function(f, name) {
f.setAttribute('target', name);
},

submit : function(f, c) {
AIM.form(f, AIM.frame(c));
if (c && typeof(c.onStart) == 'function') {
return c.onStart();
} else {
return true;
}
},

loaded : function(id) {
var i = document.getElementById(id);
if (i.contentDocument) {
var d = i.contentDocument;
} else if (i.contentWindow) {
var d = i.contentWindow.document;
} else {
var d = window.frames[id].document;
}
if (d.location.href == "about:blank") {
return;
}

if (typeof(i.onComplete) == 'function') {
i.onComplete(d.body.innerHTML);
}
}

}

function startCallback() 
{
			if(document.form.image.value=="")
			{
				alert("Please select image to upload");
				validUpload=false;
				document.form.image.focus();
				return false;
			}
			
			if (document.form.image.value != '') 
				{
					 
						strFilePath = document.form.image.value;
						if (strFilePath.indexOf('.') >=0)
						{
							strFileExtension = strFilePath.slice(strFilePath.lastIndexOf('.')+1, strFilePath.length).toLowerCase();
						} else {
							strFileExtension = '';
							}
					 
					 
					   if (strFileExtension != 'jpg' && strFileExtension != 'jpeg' && strFileExtension != 'JPG' && strFileExtension != 'JPEG' && strFileExtension != 'gif' && strFileExtension != 'GIF' && strFileExtension != 'png' && strFileExtension != 'PNG')
						 {  
							validUpload=false;
							alert('Please upload image of type (JPG/GIF/PNG).');  
							document.form.image.focus();							
							return false;
							
						}	
				 }
				return true;
}
function completeCallback(response) 
{
			document.getElementById('background').value=response;
			FAjax('http://emoticonsterra.com/crie_seu_avatar/genera.php','preview','linea1='+document.getElementById('linea1').value+'&linea2='+document.getElementById('linea2').value+'&linea3='+document.getElementById('linea3').value+'&linea4='+document.getElementById('linea4').value+'&linea5='+document.getElementById('linea5').value+'&font='+document.getElementById('font').value+'&color='+document.getElementById('color').value+'&alignment='+document.getElementById('alignment').value+'&fontsize='+document.getElementById('fontsize').value+'&inclination='+document.getElementById('inclination').value+'&background='+document.getElementById('background').value+'&sombra='+document.getElementById('sombra').value,'POST');
			
}
function showPage(stat,e)
{
	if(!e)
	{
		e=window.event;
	}

	//alert(stat);
	//alert(id);
	if(stat=='prev')
	{
		if(id==1)
		{
			e.target.style.color='gray';
		}
		else
		{
			document.getElementById('nexti').style.color='blue';
			id--;
			
		}
	}
	else
	{
		if(id==4)
		{
			e.target.style.color='gray';
			
		}
		else
		{
			document.getElementById('previ').style.color='blue';
			$('#previ').show();
			id++;
			
		}
	}
	
	var options=Array('p1','p2','p3','p4');
	for(i=0; i < options.length; i++)
	{
		if("p"+id==options[i])
		{
			$("#p"+id).show();
		}
		else
		{
			$("#"+options[i]).hide();
		}
	}

}
