function checkEmail(myEmail) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myEmail)){
return (true);
}
return (false);
}

function showTF() {
  var tf = document.getElementById('tellfriend');


  var opacity = 90;

        tf.style.filter = "alpha(style=0,opacity:" + opacity + ")"; // IE
        tf.style.KHTMLOpacity = opacity / 100; // Konqueror
        tf.style.MozOpacity = opacity / 100; // Mozilla (old)
        tf.style.opacity = opacity / 100; // Mozilla (new)


        tf.style.visibility='visible';
        //document.body.style.overflow = 'hidden';

}

function hideTF() {

   var tf = document.getElementById('tellfriend');
   //document.body.style.overflow = 'auto';


   var opacity = 100;

  tf.style.visibility='hidden';

        //tf.style.filter = "alpha(style=0,opacity:" + opacity + ")"; // IE
        tf.style.KHTMLOpacity = opacity / 100; // Konqueror
        tf.style.MozOpacity = opacity / 100; // Mozilla (old)
        tf.style.opacity = opacity / 100; // Mozilla (new)


   //tf.style.visibility='hidden';
   
   
}

var sendHTML = "";

function sendm() {

  var p1=document.getElementById('from').value;
  var p2=document.getElementById('to').value;
  var p3=document.getElementById('msgml').value;

  if(!checkEmail(p1)) {
    alert('Check your own email address!');
  } else if(!checkEmail(p2)) {
    alert('Check your friend\'s email address!');
  } else {


  if (!isWorking && http) {
    http.open("GET", "/sendm.php?p1=" + escape(p1) + "&p2=" + escape(p2) + "&p3=" + escape(p3));
    http.onreadystatechange = handleHttpResponse2;
    isWorking = true;
    http.send(null);
  }


  //sendHTML = document.getElementById('tellfriend').innerHTML;

  //document.getElementById('tellfriend').innerHTML = '<div style="color:#ffffff;font-family:verdana, \'Bitstream Vera Sans\';font-size:18px">message sent!</div>';
  window.setTimeout('hideTF()',500);
  }

}

function cancelm() {

   this.sendHTML = document.getElementById('tellfriend').innerHTML;
   hideTF();

}


var opacity = 0;
var slowly = {
fadein : function (id) {
opacity = 0;
this.fadeLoop(id, opacity);
},
fadeout : function (id)  {
opacity = 98;
this.fadeLoop2(id, opacity);
},
fadeLoop : function (id, opacity) {
var object = document.getElementById(id);
if (opacity <= 100) {
slowly.setOpacity(object, opacity);
opacity += 2;
window.setTimeout("slowly.fadeLoop('" + id + "', " + opacity + ")", 50);
} else {
; //do nothing
}
},
fadeLoop2 : function (id, opacity) {
var object = document.getElementById(id);
if (opacity >= 0) {
slowly.setOpacity(object, opacity);
opacity -= 2;
window.setTimeout("slowly.fadeLoop2('" + id + "', " + opacity + ")", 30);
} else {
document.getElementById(id).style.visibility="hidden";
}
},
setOpacity : function (object, opacity) {
object.style.filter = "alpha(style=0,opacity:" + opacity + ")"; // IE
object.style.KHTMLOpacity = opacity / 100; // Konqueror
object.style.MozOpacity = opacity / 100; // Mozilla (old)
object.style.opacity = opacity / 100; // Mozilla (new)
}
}



function showTip() {
  elTip = document.getElementById('tip');
  elTip.style.visibility="visible";
  slowly.fadein('tip');
  setTimeout("slowly.fadeout('tip');",6000);
  setTimeout("showTip2()",12000);
}

function showTip2() {
  elTip = document.getElementById('tip2');
  elTip.style.visibility="visible";
  slowly.fadein('tip2');
  setTimeout("slowly.fadeout('tip2');",6000);
  setTimeout("showTip3()",12000);
}

function showTip3() {
  elTip = document.getElementById('tip3');
  elTip.style.visibility="visible";
  slowly.fadein('tip3');
  setTimeout("slowly.fadeout('tip3');",6000);
  //setTimeout("showTip()",10000);
}


function getHTTPObject() {
  var xmlhttp;
  /* @cc_on @if (@_jscript_version >= 5)
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (E) {
      xmlhttp = false;
    }
  }
  @else xmlhttp = false;
  @end @ */


  if (!xmlhttp && typeof XMLHttpRequest != 'undefined ') {
    try {
      xmlhttp = new XMLHttpRequest();
    }
    catch (e) {
      xmlhttp = false;
    }
  }

  if(!xmlhttp) {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  return xmlhttp;
}

var http = getHTTPObject(); // We create the HTTP Object

var url = "/vote.php?"; // The server-side script

function handleHttpResponse() {
  //var bar_w = 0;
  if (http.readyState == 4) {
    if (http.responseText.indexOf('invalid') == -1) {
      // Split the comma delimited response into an array
      results = http.responseText.split(",");
      bar_w = parseInt(results[0] / 2);
      document.getElementById(v_id).innerHTML = "<div style='position:absolute;z-index:1;height:18px;width:50px'><table cellpadding='0' border='0' cellspacing='0' width='50' bgcolor='#cc6666'><tr><td rowspan='1' width='50' height='18'><img src='/images/green2.gif' width='" + bar_w +"' height='18'></td></tr></table></div><div style='position:relative;z-index:2;width:50px'><table cellpadding='0' cellspacing='0' border='0' width='50'><tr><td style='color:#ffffff' class='bar' align='center' valign='middle' width='25'>" + results[0] + "</td><td style='color:#ffffff' class='bar' align='center' valign='middle' width='25'><img src='/images/spacer.gif' height='18' width='1'></td></tr></table></div>";
      isWorking = false;
    }
  }
}

function handleHttpResponse2() {
  //var bar_w = 0;
  if (http.readyState == 4) {
    if (http.responseText.indexOf('invalid') == -1) {
      // Split the comma delimited response into an array
      results = http.responseText.split(",");
      isWorking = false;
    }
  }
}

var isWorking = false;
var v_id = "";

function voteThis(id,vote) {

  if(document.getElementById('votetip') && document.getElementById('votetip').style.display=='block') {
    document.getElementById('votetip').style.display='none';
  } 

  cValue = readCookie('usr');  

  if(cValue) {

  r_id = "r_" + id;
  this.v_id = "v_" + id;

  document.getElementById(r_id).style.backgroundColor="#eeeeee";

  if (!isWorking && http) {
    http.open("GET", url + "p1=" + escape(id) + "&p2=" + escape(vote));
    http.onreadystatechange = handleHttpResponse;
    isWorking = true;
    http.send(null);
  }

  }
}

function changeCellColor(id,toColor) {

  elId = "r_" + id;

  document.getElementById(elId).style.backgroundColor=toColor;

}

setInterval("check()",2000);

function check() {
        var a1 = document.forms[0].a1.value;

	if(a1 != '' && !readCookie('usr')) {
		createCookie("usr",a1,365);
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
