var httpRequest;
function getHttpRequest() {
 if (window.XMLHttpRequest) {
	           return new XMLHttpRequest();
	 } else if (window.ActiveXObject) {
	   return new ActiveXObject("Microsoft.XMLHTTP");
	 }else {
	   return null;
	 }
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf(";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
  function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0)
    break;
  }
  return null;
}
  function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = "/"; //(argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
  ((expires == null) ? "" : ("; expires=" +
  expires.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}

var emailcookie = GetCookie('email_address');
if (emailcookie == null) {
  emailcookie = ' e-mail address';
}

// New from Dan Tuesday, October 31, 2006
function checkWinGen(winName,winVar,features) {
  if (!features) features = "height=320,width=780,titlebar=no,resizable=yes,scrollbars=yes";
  window[winVar] = window.open('',winName,features);
  if (window[winVar].focus) {
    window[winVar].focus();
  }
}
// End new from Dan

function getFeedback(displayalbum,originalquery) {
  var email= document.getElementById('emailInput').value;
  //var querystring = document.getElementById("q").value;
  invalid = "";
  if (!email)
    invalid = "No email address found!  Try reloading the page then use the 'email a script' feature again.";
  else {
    if ( (email.indexOf("@") == -1) || (email.indexOf(".") == -1) )
   	 invalid = "Invalid E-mail id.";
    if (email.indexOf(" e-mail address") > -1)
     invalid = "Invalid E-mail id.";
    if (email.indexOf("\\") > -1)
     invalid = "Invalid E-mail id.";
    if (email.indexOf("/") > -1)
     invalid = "Invalid E-mail id.";
    if (email.indexOf("'") > -1)
     invalid = "Invalid E-mail id.";
    if (email.indexOf("zaz.com.br") > -1)
     invalid = "Invalid E-mail id.";
    if (email.indexOf("!") > -1)
   	 invalid = "Invalid E-mail id.";
    if ( (email.indexOf(",") > -1) || (email.indexOf(";") > -1) )
     invalid = "Invalid E-mail id.";
    if (email.indexOf("?subject") > -1)
     invalid = "Invalid E-mail id.";
  }
  if (invalid == "") {
    var largeExpDate = new Date();
    largeExpDate.setTime(largeExpDate.getTime() + (31 * 24 * 3600 * 1000));
    SetCookie('email_address', email, largeExpDate);
    document.getElementById("ajax-load").innerHTML = "<div style=\"padding:50px 20px 50px 125px\"> <img src='/images/ajax-loader.gif' border='0' /></div>";
	sendFeedback(email,displayalbum,originalquery);
    return true;
    // New from Dan ends here
  } else {
    document.getElementById('errMsg').innerHTML = invalid;
    return false;
  }
}

function sendFeedback(email,querystring,originalquery){
	
	httpRequest = getHttpRequest();
	var x = RegExp('&#x[a-z0-9]+;');
	originalquery = originalquery.replace(x,"");
	var ignoreCache  = '&ignoreDate='+new Date().getTime();
    var url = '/scripts/clients/up_coming_movies.php?email='+email+'&dq='+ querystring + '&q=' + originalquery + ignoreCache;	
	httpRequest.onreadystatechange=function() {
		 if (httpRequest.readyState == 4) {
			 document.getElementById('ajax-load').innerHTML = "<div style=\"padding:50px 20px 20px 120px;font-size:14pt;font-weight:bold;\">Thank you!</div>";
				setInterval("fadeOut2('feedback-popup')", 3000);
         }
    };	
	httpRequest.open("GET",url,true);
    httpRequest.send(null);

}
function close(popupBox,q,displayalbum,nr,wt){
	 document.getElementById(popupBox).style.display="none";
	var img_node = document.createElement("img");
	img_node.setAttribute("id", "up_coming_movie_close");
	var src = "http://dir.guruji.com/images/music_upcoming_close?q="+q+"&displayalbum="+displayalbum+"&nr="+nr+"&wt="+wt+"&rand="+Math.random();
	img_node.setAttribute("src",src);
	document.body.appendChild(img_node);
	return;
	
}
function fadeOut2(div)
{
 $('#'+div).hide("slow");
}
function Delay()
{
	document.getElementById('ajax-load').innerHTML = "<div style=\"padding:50px 20px 20px 120px;font-size:14pt;font-weight:bold;\">Thank you!</div>";
    setInterval("fadeOut2('feedback-popup')", 3000);

}

