
function str_replace (search, replace, subject)
{
	var result = "";
	var oldi = 0;
	for (i = subject.indexOf (search); i > -1; i = subject.indexOf (search, i))
	{
		result += subject.substring (oldi, i);
		result += replace;
		i += search.length;
		oldi = i;
	}
	return result + subject.substring (oldi, subject.length);
}
function mover( id )
{
  var obj = document.getElementById( id );
  obj.style.borderColor = "black";
}
function mout( id )
{
  var obj = document.getElementById( id );
  obj.style.borderColor = "white";
}
function selectColor( color )
{
  document.getElementById( "color" ).value = color;
}
function hover( color )
{
  document.getElementById( "hoverColor" ).innerHTML = color;
}
function calclargura( )
{
  var altura = document.getElementById("altura").value;
  document.getElementById( "largura" ).innerHTML = Math.round((149/155)*altura);
}
function escolhaCor(){
	if(document.formularioEmail.listaCidades.options.length >= 11)
	{
		alert("Selecione apenas 10 cidades!");
	}else{
		
		var objCidades  = document.getElementById("listaCidades");
		var cor         = document.getElementById("color").value;
		var objFrame    = document.getElementById("selodemo");
		var cidades     = objCidades.innerHTML.replace("                                      ","");
		cidades         = str_replace("</option>",",",cidades);
		cidades         = str_replace("<option value=\"1\">","",cidades);
		cidades         = str_replace("</OPTION>",",",cidades);
		cidades         = str_replace("<OPTION value=1 selected>","",cidades);
		cidades         = str_replace("<OPTION selected value=1>","",cidades);
		var altura      = document.getElementById("altura").value;
		var largura     = Math.round((149/155)*altura);
		var linkhtml    = "http://tempoagora.uol.com.br/selos/custom/selo_3dias.php?cid="+cidades+"&height="+altura+"&cor="+cor;
		objFrame.src    = linkhtml;
		objFrame.height = altura;
		objFrame.width  = largura;
	
		document.getElementById( "debug" ).value = "<!-- Inicio Banner Tempo Agora - http://www.tempoagora.com.br -->\n"+
		"<iframe src=\"" + linkhtml + "\" name=\"tempoagora_custom_3dias\" width=\""+largura+"\" marginwidth=\"0\" height=\""+altura+"\" marginheight=\"0\" scrolling=\"No\" frameborder=\"0\" id=\"tempoagora_custom_3dias\"></iframe>\n"+
		"<!--Fim Banner Tempo Agora - http://www.tempoagora.com.br -->";
	
	}	
}

function addCidade()
{
if(document.formularioEmail.listaCidades.options.length >= 11)
	{
		alert("Selecione apenas 10 cidades!");
	}else{
		var indice = document.formularioEmail.cidades.selectedIndex;
		document.formularioEmail.listaCidades.options.add( new Option(document.formularioEmail.cidades.options[indice].text,document.formularioEmail.cidades.options[indice].value));
		for(x=0;x<document.formularioEmail.listaCidades.options.length;x++)
		{
			document.formularioEmail.listaCidades[x].selected = true;
		}
	}
}
function limpaCidades()
{
	        while (document.formularioEmail.listaCidades.options.length > 0)
			        {
					           document.formularioEmail.listaCidades.options[0] = null;
						           }
				// document.formularioEmail.lstCidades.options.add(new Option("Cidades Escolhidas:",0));
}
var lprod = "";
/*function itemTostring(field,div,rexp) 
{
re = (rexp==null|rexp=='') ? 'ô' : rexp; //no regex then match all
if (field.length!=0)
{ 
for(i=0 ; i <= field.options.length-1 ; i++){
t = field.options[i].value;
if(!t.match(re)) lprod += t + div;
}
document.formularioEmail.listaCidadesFinal.value = lprod.substr( 0, lprod.length-1 );
return lprod;

} else return "";
}*/
