/* TL - 06/17/2008 (change in handlerdivIdScrapLayer() function*/

/*************************************************************
/* custom function handling response and other interactive states
*************************************************************/

function handlerdivSubmit(handler) 
{
	if(xmlHttpReq.readyState == 4) 
	{
		if(xmlHttpReq.status == 200)
		{
				if(xmlHttpReq.responseText.indexOf("Oops! You need to login.") >= 0)
				{
					window.location.href = '/z/login/login.php?go=' + encodeURIComponent(window.location);
				}

				document.getElementById("sub"+handler).innerHTML = xmlHttpReq.responseText;
				document.getElementById("post"+handler).style.display = "";
				document.getElementById("img1"+handler).style.display = "";
				document.getElementById("img2"+handler).style.display = "none";
		}
		else
		{
			alert("Error: While trying to fetch records, please try again later");
		}
	}
	else
	{
		document.getElementById(handler).innerHTML = "";
		document.getElementById("sub"+handler).innerHTML = "<span id=\"\" valign=\"middle\" align=\"center\"><img src=\"/zones-ssi/js-css-images/loading.gif\" border=\"0\" alt=\"Loading...\"><span>";
	}
}


function handlerdivReply(handler,totalScrap) 
{
	if(xmlHttpReq.readyState == 4) 
	{
		if(xmlHttpReq.status == 200)
		{
			if(xmlHttpReq.responseText.indexOf("Oops! You need to login.") >= 0)
			{
				window.location.href = '/z/login/login.php?go=' + encodeURIComponent(window.location);
			}

			document.getElementById(handler).innerHTML = xmlHttpReq.responseText;
			if(xmlHttpReq.responseText.indexOf("textarea") >= 0 )
			{
				document.getElementById("post"+handler).style.display = "none";
				document.getElementById("img1"+handler).style.display = "none";
				document.getElementById("img2"+handler).style.display = "";
			}
			for(divCounter = 1 ; divCounter <= totalScrap; divCounter++)
			{
				if(divCounter != handler)
				{
					document.getElementById(divCounter).innerHTML = "";
					if(document.getElementById("post"+divCounter))
					{
						document.getElementById("post"+divCounter).style.display = "";
					}

					if(document.getElementById("img1"+divCounter))
					{
						document.getElementById("img1"+divCounter).style.display = "";
					}
					if(document.getElementById("img1"+divCounter))
					{
						document.getElementById("img2"+divCounter).style.display = "none";
					}
				}
			}
			Quill.init('quillDiv1', 'quillSelect1', 'quillWordCount1');
		}
		else
		{
			alert("Error: While trying to fetch records, please try again later");
		}
	}
	else
	{
				document.getElementById("sub"+handler).innerHTML = "";
				document.getElementById(handler).innerHTML = "<span id=\"\" valign=\"middle\" align=\"center\"><img src=\"/zones-ssi/js-css-images/loading.gif\" width=\"63\" height=\"13\" border=\"0\" alt=\"Loading...\"><span>";
	}
}

function handlerdivMsg(handler)
{
	if(xmlHttpReq.readyState == 4) 
	{
		if(xmlHttpReq.status == 200)
		{
				if(xmlHttpReq.responseText.indexOf("Oops! You need to login.") >= 0)
				{
					window.location.href = '/z/login/login.php?go=' + encodeURIComponent(window.location);
				}

				document.getElementById(handler).innerHTML = xmlHttpReq.responseText;
				document.getElementById ("comment1").value = "";
				document.getElementById ("remLen").value = 500;
		}
		else
		{
			alert("Error: While trying to fetch records, please try again later");
		}
	}
	else
	{
		document.getElementById(handler).innerHTML = "<span id=\"\" valign=\"middle\" align=\"center\"><img src=\"/zones-ssi/js-css-images/loading.gif\" border=\"0\" alt=\"Loading...\"><span>";
	}
}

function handlerdivIdScrapLayer(handler)
{
	// alert(handler);
	if(timeOutView1)
	{
		window.clearTimeout(timeOutView1);
	}

	if(xmlHttpReq.readyState == 4)
	{
		if(xmlHttpReq.status == 200)
		{

			findPos(document.getElementById('last_div'));


			if(xmlHttpReq.responseText.indexOf("<!--error_login-->") != null && xmlHttpReq.responseText.indexOf("<!--error_login-->") != -1)
			{
				/* show the please wait image untill the setTimeout is called */
				document.getElementById(handler).innerHTML = "<div style=\"padding: 10px;\"><img src=\"/zones-ssi/js-css-images/please-wait.gif\" border=\"0\" alt=\"please wait...\" align=\"absmiddle\"></div>";

				window.setTimeout("getLogin('')",5000);
			}
			else
			{
				
				document.getElementById(handler).innerHTML = xmlHttpReq.responseText;
				
				show_layer(handler); 
				findPos(document.getElementById('fade_id'));
				
				putFocus("scrap_comment");
				//clear_n_hide_layer(handler);
				if(xmlHttpReq.responseText.indexOf("<!--success-->") != -1)
				{
					var handlerFun = "clear_n_hide_layer('"+handler+"')";
					if(timeOutView1)
					{
						window.clearTimeout(timeOutView1);
					}
					timeOutView1 = window.setTimeout(handlerFun,5000);
				}



			}

			findPos(document.getElementById('last_div'));


		}
		else
		{
			alert("Error: While trying to fetch records, please try again later");
		}
	}
	else
	{
		display_layer_center(handler);
		
		document.getElementById(handler).innerHTML = "<div style=\"padding: 10px;\"><img src=\"/zones-ssi/js-css-images/please-wait.gif\" border=\"0\" alt=\"please wait...\" align=\"absmiddle\"></div>";
	}
}//EO