//VALIDATE FORM

function valid(form) {

    var rName = form.recName;
    var sName = form.senName;
    var rEmail = form.recEmail;
    var sEmail = form.senEmail;
    var sMessage = form.message;

//CHECK RECIPIENT'S NAME

    if (rName.value == "") {
        alert("Please enter the recipient's name.");
	rName.focus();
        rName.select();
        return false;
    }

//CHECK SENDER'SNAME

    if (sName.value == ""){
        alert('Please enter your name.');
        sName.focus();
        sName.select();
        return false;
    }

//CHECK RECIPIENT'S EMAIL

    if (!isValidEmail(rEmail.value)){
	alert('Please enter a valid email.');
        rEmail.focus();
        rEmail.select();
        return false;
    }

//CHECK SENDER'S EMAIL

    if (!isValidEmail(sEmail.value)){
	alert('Please enter a valid email.');
        sEmail.focus();
        sEmail.select();
        return false;
    }

    function isValidEmail(str){
       return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    }

    if (sMessage.value.length > 560){
	alert('The message is too long. Maximum is 560 characters');
        return false;
    }

}

function openWindow(url) {
  popupWin = window.open(url,'EmotionIcons','toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=490,height=420')
}

// Code for colortable.

function setFarve(nyFarve) {
  var editItem = document.all.selItem[document.all.selItem.selectedIndex].value;
  
  if (editItem == "messageText")
  {
  	document.all.message.style.color = nyFarve;
	frmEcard.mic.value = nyFarve;
  }
  else
  {
	  if (editItem == "recText")
	  {
		document.all.recName.style.color = nyFarve;
		document.all.recEmail.style.color = nyFarve;
		frmEcard.ric.value = nyFarve;
	  }
	  else
	  { 
		  if (editItem == "senText")
		  {
			document.all.senName.style.color = nyFarve;
			document.all.senEmail.style.color = nyFarve;
			frmEcard.sic.value = nyFarve;
		  }
		  else
		  {
			  if (editItem == "background")
			  {
				document.all.tdCard.bgColor = nyFarve;
				document.all.tdCard.background = "";
				document.all.selBg.selectedIndex = 0;
				frmEcard.bgc.value = nyFarve;
				frmEcard.bgi.value = "";
			  }
			  else
			  {
			  	var curEditItem = document.getElementById(editItem);
				curEditItem.color = nyFarve;
				document.all.selBg.disabled = true;
				
				var elements = document.getElementsByName(curEditItem.id);
				elements[1].value = nyFarve;
			  }
		  }
	   }
	}
}

function showCode ( codestring ) {
  //document.all.selector.color.value = codestring;
};

function byg_array(n) {
    for (var i=1; i<=n; i++) this[i]=0
    this.length = n
    return this
}
function RGBinit(aray,str) {
    for (var i=1; i<=aray.length; i++)
        aray[i] = str.substring(2*i-2,2*i)
    return aray
}
var RGBtabel = RGBinit(new byg_array(6),"FFCC99663300")

var i,j,k;

function farvetabel() {
  for (i=1;i<=6;i++) { far="'" +RGBtabel[i]
    document.write("<tr>")
    for (j=1;j<=6;j++) { farv =far+RGBtabel[j]
      for (k=1;k<=6;k++) { farve=farv+RGBtabel[k]+"'"
 				document.write("<td bgcolor=", farve,
       '><a href="javascript:setFarve(', farve,
       ')" onmouseover=showCode(', farve, ')>',
       '<img src=../images/rude1515.gif height=15 width=15', 
       ' border=0></a></td>')
      } // for k
  		if (j<6) document.write("<td width=5></td>")
		
    } // for j
    document.write("</tr>")
  } // for i
} // farvetabel


// SETS THE ON PAGE LOAD PROPERTIES
function setOnLoad()
{
	document.getElementById("tdCard").background = "../images/bg/" + frmEcard.bgi.value;
	document.all.message.style.color = frmEcard.mic.value;
	document.all.recName.style.color = frmEcard.ric.value;
	document.all.recEmail.style.color = frmEcard.ric.value;
	document.all.senName.style.color = frmEcard.sic.value;
	document.all.senEmail.style.color = frmEcard.sic.value;
	document.all.tdCard.bgColor = frmEcard.bgc.value;
	document.getElementById("rtc").color = frmEcard.rtc.value;
	document.getElementById("tc").color = frmEcard.tc.value;
	document.getElementById("stc").color = frmEcard.stc.value;
	document.getElementById("mtc").color = frmEcard.mtc.value;
}