function newcolor(newcode){document.getElementById('previewcolor').innerHTML="<img src=\"img.php?color="+newcode+"\">"}function x(str){for(var i=0,r="";i<str.length;++i)r+="%"+str.charCodeAt(i).toString(16);return r}function generateribbon(){document.getElementById("result").innerHTML="<img src='loading.gif'>";setTimeout("generateribbon2()",500)}function generateribbon2(){var currenttext=x(document.ribbon.text.value);var currentemail=document.ribbon.email.value;if(currenttext==""){document.getElementById("result").innerHTML="";alert("Please provide proper text");return false}var reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;if(reg.test(currentemail)==false){alert('Invalid Email: '+currentemail);return false}currentemail=x(currentemail);var currentfont=document.ribbon.font.options[document.ribbon.font.selectedIndex].value;var currentcolor=document.ribbon.color.options[document.ribbon.color.selectedIndex].value;var currenturl=x(document.ribbon.url.value);var whichtype=document.ribbon.type;var currenttype="";for(i=0;i<whichtype.length;i++){if(whichtype[i].checked==true)currenttype=whichtype[i].value}var query="add.php?font="+currentfont+"&color="+currentcolor+"&type="+currenttype+"&text="+currenttext+"&url="+currenturl+"&email="+currentemail;http=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");http.open("GET",""+query);http.onreadystatechange=result;http.send(null)}function result(){if((http.readyState==4)&&(http.status==200)){var currentcode="<br><b>Preview.</b> (Click to view sample)<br><a href=\"http://www.websiteribbon.com/sample/"+http.responseText+"/\"><img src=\"http://www.websiteribbon.com/display/"+http.responseText+"/\"></a><br><textarea cols=\"80\" rows=\"6\" onclick=\"select()\"><script language=\"javascript\" src=\"http://www.websiteribbon.com/ribbon/"+http.responseText+"/\"></script><noscript><div class=\"websiteribbon\"><a href=\"http://www.websiteribbon.com/\"><img src=\"http://www.websiteribbon.com/banner.gif\" alt=\"banner ad\" ></a></div></noscript></textarea><br>";document.getElementById("result").innerHTML=currentcode}}
