function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
	if (use_gebi && document.all) {
			x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
			y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
			}
	else if (use_gebi) {
			var o=document.getElementById(anchorname);
			x=AnchorPosition_getPageOffsetLeft(o);
			y=AnchorPosition_getPageOffsetTop(o);
			}
	else if (use_css) {
			x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
			y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
			}
	else if (use_layers) {
			var found=0;
			for (var i=0; i<document.anchors.length; i++) {
					if (document.anchors[i].name==anchorname) { found=1; break; }
					}
			if (found==0) {
					coordinates.x=0; coordinates.y=0; return coordinates;
					}
			x=document.anchors[i].x;
			y=document.anchors[i].y;
			}
	else {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

function AnchorPosition_getPageOffsetLeft (el) {
		var ol=el.offsetLeft;
		while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
		return ol;
		}

function AnchorPosition_getWindowOffsetLeft (el) {
		return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
		}       

function AnchorPosition_getPageOffsetTop (el) {
		var ot=el.offsetTop;
		while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
		}

function AnchorPosition_getWindowOffsetTop (el) {
		return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
		}

//--------------------------------------------------

function createRequestObject()
         {
            var request_o; //declare the variable to hold the object.
            var browser = navigator.appName; //find the browser name
            if(browser == "Microsoft Internet Explorer")
             {
                request_o = new ActiveXObject("Microsoft.XMLHTTP");
             }
            else
             {
               request_o = new XMLHttpRequest();
             }
            return request_o; //return the object
        }

	var http = createRequestObject(); 
//------------------------------------------------------------------------------------------------------------------

   function DisplayValues()
	   {
		
			if(http.readyState == 4)
			   { 
			     
				var response = http.responseText;
			   	var sugarr   = new Array();
				sugarr		 = response.split('||');
			   	document.getElementById('suggest').innerHTML = sugarr[0];
				if(sugarr[1] != undefined && sugarr[1] != null )
				{
					document.getElementById('rewardsdiv').style.display = "block";
					document.getElementById('rewardsdiv').style.top = "620px";
					document.getElementById('rewardsdiv').style.left = "141px";
					document.getElementById('rewardsdiv').style.visibility = "visible";
					document.getElementById('rewardsdiv').style.zIndex = "1000000";
					document.getElementById('rewardsdiv').innerHTML = sugarr[1];
				}
				//document.getElementById('suggest').innerHTML = response;
				
			 }
	   }
//------------------------------------------------------------------------------------------------------------------
function suggestMovie(sug)
{  
	if(sug == 1)
		var tit = "Suggest a Passionate Movie";
	else if(sug == 2)
		var tit = "Suggest a Romantic Destination";
	else if(sug == 3)
		var tit = "Suggest a Romantic Classics";
	else 
		var tit = "Suggest for a Erotic Art";

	var close = "<div  id ='suggestmovie'><div id =\"headsuggest\" >&nbsp;"+tit+"</div><div id=\"close\"><a href='javascript:void(0)' onclick='closeSuggest("+sug+")' class='amovie1'>X</a>&nbsp;</div><br><br>";
	var frm =close+"<form name='frmsuggest'>" +
		     "&nbsp;&nbsp;&nbsp;<input type='text' id='txtmovie' class='movieinput'>&nbsp;"+
		     "<input type='button' onclick='saveMovie("+sug+")' class='btnRate' value='ADD' ></form><br></div>";
	document.getElementById('suggest').innerHTML =frm;
}
//------------------------------------------------------------------------------------------------------------------
function noCache(url)
{
	var sep = (-1 < url.indexOf("?")) ? "&" : "?"	
	url = url + sep + "__=" + encodeURIComponent((new Date()).getTime());	
	return url;
}

//------------------------------------------------------------------------------------------------------------------
function saveMovie(type)
{
		  movie   = document.getElementById('txtmovie').value;
		  if(movie == "")
			{
			  if(type==1)
				  alert("Please suggest a passionate movie name");
			  else if(type==2)
				  alert("Please suggest a romantic destination");
			  else if(type==3)
				  alert("Please suggest a romantic classic");	
			  else 
				  alert("Please suggest a erotic art");

			  document.getElementById('txtmovie').focus();
			}
		 else
		  {
		    path = getPath();
			url  = path	+"/cafe-passion/suggestmovie/";

			desturl = url+"?movie="+movie+"&cat="+type;
			desturl = noCache(desturl);

			http.open('GET', desturl);

			http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			http.onreadystatechange = DisplayValues; 
			http.send(null);
	      }
}
function getPath()
{
	url		=	document.location.href;
	x		=	url.indexOf(".");
	x		=	url.indexOf("/",x);
	return url.substring(0,x);
}
function closeSuggest(sug)
{
	if(sug == 1)
		var tit = "Do you have a Suggestion for a Passionate Movie?";
	else if(sug == 2)
		var tit = "Do you have a Suggestion for a Romantic Destination?";
	else if(sug == 3)
		var tit = "Do you have a Suggestion for a Romantic Classic?";
	else 
		var tit = "Do you have a Suggestion for Erotic Art?";

	document.getElementById('suggest').innerHTML ="<a href=\"javascript:void(0)\" class=\"amovie\" onclick='suggestMovie("+sug+")'>"+tit+"</a>";
}

function CheckRating(selectedRate,sid,frm)
{
	var flag=0;
	for(var i=0;i<idarr.length;i++)
	{
		if(eval("frm.rate"+idarr[i]+".value == frm."+selectedRate+".value") && idarr[i] != sid && eval("frm."+selectedRate+".value != 0") )
		{	
			if(confirm("Oops! You have chosen this rating already, click 'Ok' to continue otherwise 'Cancel'"))
			{
			//alert("sval: "+eval("frm."+selectedRate+".value")+" arr: "+eval("frm.rate"+idarr[i]+".value"));
				eval("frm.rate"+idarr[i]+".disabled = false");			
				eval("frm.rate"+idarr[i]+".value = 0");
				flag=1;
			}
			else
			{
				eval("frm."+selectedRate+".value = 0");
				flag=2;
			}
		}	
	}

	if(flag==1 || flag==0)
		eval("frm."+selectedRate+".disabled = true");
}
function saveTopten(frm,type)
{
	var ids = ""; 
	for(var i=0;i<idarr.length;i++)
	{
		if(eval("frm.rate"+idarr[i]+".value")==0)
		{
			if(type == 1)
				alert("Select Top 10 passionate movies");
			else if(type == 2)
				alert("Select Top 10 romantic destinations");
			else if(type == 3)
				alert("Select Top 10 romantic classics");
			else 
				alert("Select Top 10 erotic art");
			return false;
		}	
		
		ids += idarr[i]+",";

	}
	frm.iarr.value=ids;
	for(var i=0;i<idarr.length;i++)
		eval("frm.rate"+idarr[i]+".disabled = false");			

	frm.save.value=type;
	frm.submit();
}

function showSynapsis(snapdivname,snaplink)
{
	eval("obj = document.getElementById('"+snapdivname+"')");

	var cord		= eval("getAnchorPosition('"+snaplink+"')");
	cord.y			= cord.y-100;
	cord.x			= cord.x-420;
	obj.style.top	= eval("'"+cord.y+ "px'"); 
	obj.style.left	= eval("'"+cord.x+ "px'"); 

	//alert("Top:"+obj.style.top+" Left:"+obj.style.left);

	obj.style.visibility= "visible";
	obj.style.display	= "block";

	for(i=0;i<10;i++)
	{
		eval("closedivname = 'divsynapsis"+i+"'");
		eval("closelink = 'snapdiv"+i+"'");
		if(snapdivname!=closedivname)
			eval("hideSynapsis('"+closedivname+"')");
	}
}

function hideSynapsis(snapdivname)
{
	eval("obj = document.getElementById('"+snapdivname+"')");
	obj.style.visibility= "hidden";
	obj.style.display	= "none";
}


