function openDedicateDiv(album,song)
{
	try{(new Image).src = "http://dir.guruji.com/images/dedicate/vday&rand="+(Math.random());}
	catch(e){}
	document.getElementById('pupDiv').style.display='inline';
	document.getElementById("formDiv").style.display="block";
	document.getElementById('songTitle').innerHTML=song;
	document.getElementById("actionDiv").style.display="none";
	document.getElementById('albumTitle').innerHTML=album;
	document.dedicateForm.song.value=song;
	document.dedicateForm.album.value=album;
}

function GetXmlHttpObject()
{
	// code for IE7+, Firefox, Chrome, Opera, Safari
	if (window.XMLHttpRequest){
		return new XMLHttpRequest();
	}
	// code for IE6, IE5
	if (window.ActiveXObject)
	{
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (E) {	xmlhttp = false;}
		}
		return xmlhttp;
	}
	return null;
}

var fader;
var invalid = "";
function validateEmail(email)
{
	invalid = "";
  if (!email)
    invalid = "Invalid E-mail id.";
  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 == "") {    return true;  }
  else {    return false;  }
  
}
var field_num=0;
function addMoreFields() 
{
		var ni = document.getElementById('myDiv');
	var numi = document.getElementById('theValue');
	var num = (document.getElementById("theValue").value -1)+ 2;
	numi.value = num;var str="";
	var divIdName = "my"+num+"Div";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	for(var field_num=1;field_num<5;field_num++){
	str  += '<table style="color:#F46B20; font-size: 10pt;"><tr><td width="60" align="right"><strong>Name '+(field_num+1)+':</strong></td><td width="220" align="center"><input type="text" tabindex="'+(5+field_num)+'" style="border: 1px solid rgb(204, 204, 204); width: 200px;" name="dfname['+field_num+']" id="dfname"/></td><td width="60" align="right"><strong>E-Mail '+(field_num+1)+':</strong></td><td width="220" align="center"><input type="text"  MAXLENGTH="35" tabindex="'+(5+field_num)+'" style="border: 1px solid rgb(204, 204, 204); width: 200px;" name="dfemail['+field_num+']" id="dfemail"/></td></tr></table>';
	ni.appendChild(newdiv);
	}
	newdiv.innerHTML = str;
	document.getElementById('addmore').style.display="none";
}
function dedicateSong()
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url = "/scripts/clients/dedicateSong.php";
	var url_string ="?";
	var str="";
	var theForm = document.forms[0];
	for(i=0; i<theForm.elements.length; i++){
		str+=theForm.elements[i].name+'='+theForm.elements[i].value+"&";
	}
	var email = theForm.demail.value;
	var femail = theForm.elements[6].value;
	if(!validateEmail(email) || !validateEmail(femail))
	{
		document.getElementById('errId').style.display="inline";
		document.getElementById('errId').innerHTML = invalid;
		return false;
	}
	url_string+=str;url_string=url_string.substr(0,url_string.length-11);
	//document.getElementById('errMsg').innerHTML = "";
	
	//document.getElementById('errId').style.display="none";
	data = url_string;
	for(i=7; i<theForm.elements.length; i++){
		if(theForm.elements[i].name.match('dfemail')){
			var email = theForm.elements[i].value;
			if(email !="" && !validateEmail(email)){
				document.getElementById('errId').style.display="inline";
				document.getElementById('errId').innerHTML = invalid;
				return false;
			}
		}
	}
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("formDiv").style.display="none";
			document.getElementById('errId').style.display="none";
			document.getElementById("actionDiv").style.display="inline";
			document.getElementById("actionDiv").innerHTML=xmlhttp.responseText;
			fader = setInterval("fadeOut2('pupDiv')", 8000);
		}
	};
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(data);
}

function fadeOut(div_id){
	sleep(10000);
	document.getElementById(div_id).style.display="none";
}
function cl(div)
{
	document.getElementById(div).style.display='none';
	var main_node = document.getElementById('mainContent');
}
function fadeOut2(div)
{
	 $('#'+div).hide("slow");
 	 clearInterval(fader);
}

