function getCurrentLeaf()
{
	if (document.getElementById('whitebg') != null && document.getElementById('whitebg').style.display != 'none') {
		return 'F';
	} else if(document.getElementById('whitebgBack') != null && document.getElementById('whitebgBack').style.display != 'none') {
		return 'B';
	} else if(document.getElementById('calendar') != null && document.getElementById('calendar').style.display != 'none')	{
		return 'C';
	} else {
		return false;
	}

}

// Will find the left and top position of an object for any browser...

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	while(1)
	{
		curleft += obj.offsetLeft;
		if(!obj.offsetParent)
		break;
		obj = obj.offsetParent;
	}
	else if(obj.x)
	curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	while(1)
	{
		curtop += obj.offsetTop;
		if(!obj.offsetParent)
		break;
		obj = obj.offsetParent;
	}
	else if(obj.y)
	curtop += obj.y;
	return curtop;
}


function getPrintPaneCoordinates() {
	var currentLeaf = getCurrentLeaf();
	var IE = document.all?true:false
	if(currentLeaf=='F') {
		var ppane=(IE)?document.all.whitebg:document.getElementById("whitebg");

	} else {
		var ppane=(IE)?document.all.whitebgBack:document.getElementById("whitebgBack");
	}
	var p = new Array();
	var pTop = document.all?65 : 65;
	p['left']	=	findPosX(ppane);
	p['top']	=	findPosY(ppane) + pTop;
	p['right']	=	p['left'] + ppane.offsetWidth;
	p['bottom']	=	findPosY(ppane) + ppane.offsetHeight;
	return p;
}
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function changeLeaf(Leafname) {
	if (Leafname=='F') {
		document.getElementById('front').className='highlight';
		document.getElementById('back').className='deamlight';
		document.getElementById('subscr').className='grey_li';
		document.getElementById('clr').className='deamlight';
		document.getElementById('print').className='deamlight';

		document.getElementById('whitebgMainFront').style.display='block';
		document.getElementById('whitebgMainBack').style.display='none';
		document.getElementById('calenderMain').style.display='none';
		document.getElementById('calendar').style.display='none';

		document.getElementById('whitebg').style.display='block';
		document.getElementById('whitebgBack').style.display='none';



		for (var i=0; i<dhtmlwindow.tobjects.length; i++){
			//	alert(dhtmlwindow.getAttrib(dhtmlwindow.tobjects[i]));
			if (dhtmlwindow.tobjects[i].state !='close') {

				if(dhtmlwindow.tobjects[i].contextType =='F') {

					dhtmlwindow.tobjects[i].style.display='block';
				} else {
					dhtmlwindow.tobjects[i].style.display='none';
				}
			}
		}
	} else if (Leafname=='B') {
		document.getElementById('front').className='deamlight';
		document.getElementById('back').className='highlight';
		document.getElementById('subscr').className='grey_li';
		document.getElementById('clr').className='deamlight';
		document.getElementById('print').className='deamlight';

		document.getElementById('whitebgMainFront').style.display='none';
		document.getElementById('whitebg').style.display='none';
		document.getElementById('whitebgBack').style.display='block';
		document.getElementById('whitebgMainBack').style.display='block';

		document.getElementById('calenderMain').style.display='none';
		document.getElementById('calendar').style.display='none';


		/* detect browser type for IE ..STARTS*/
		var browser=navigator.appName
		var b_version=navigator.appVersion
		var version=parseFloat(b_version)
		//		if ((browser=="Microsoft Internet Explorer") && (version>=4))
		//			document.getElementById('whitebgBack').style.position='absolute';
		/* detect browser type for IE ..ENDS*/

		for (var i=0; i<dhtmlwindow.tobjects.length; i++){
			//	alert(dhtmlwindow.getAttrib(dhtmlwindow.tobjects[i]));
			if (dhtmlwindow.tobjects[i].state !='close') {
				if(dhtmlwindow.tobjects[i].contextType=='B') {
					dhtmlwindow.tobjects[i].style.display='block';
				} else {
					dhtmlwindow.tobjects[i].style.display='none';
				}
			}
		}
	} else	{
		document.getElementById('front').className='deamlight';
		document.getElementById('back').className='deamlight';
		document.getElementById('subscr').className='highlight';
		document.getElementById('clr').className='deamlight';
		document.getElementById('print').className='deamlight';

		document.getElementById('whitebgMainFront').style.display='none';
		document.getElementById('whitebgMainBack').style.display='none';
		document.getElementById('calenderMain').style.display='block';

		document.getElementById('whitebg').style.display='none';
		document.getElementById('whitebgBack').style.display='none';
		document.getElementById('calendar').style.display='block';

		for (var i=0; i<dhtmlwindow.tobjects.length; i++){
			//alert(dhtmlwindow.getAttrib(dhtmlwindow.tobjects[i]));
			if (dhtmlwindow.tobjects[i].state !='close' && dhtmlwindow.tobjects[i].style.display !='none') {
				dhtmlwindow.tobjects[i].style.display='none';
			}
		}
	}
}

var StoreSuccess = 0;
function storeLeaf(contextType)
{
	var query = "";
	// If whitebg is hide means Current Leaf is Back else Front
	query += "leafType="+contextType;
	var w=1;
	for (var i=0; i<dhtmlwindow.tobjects.length; i++){
		if (dhtmlwindow.tobjects[i].state !='close') {
			var objcontext = ltrim(dhtmlwindow.tobjects[i].windowName,"_");
			if (dhtmlwindow.tobjects[i].contextType == contextType ) {
				var wind =  dhtmlwindow.getAttrib(dhtmlwindow.tobjects[i]);
				query += "&window"+w+"="+wind;
				w = w+1;
			}
		}
	}
	query += "&totalWindow="+w;

	//alert(query);

	var xmlhttp = zXmlHttp.createRequest();
	var url = 'store_leaf.php?'+query;
	if (xmlhttp) {

		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					var StoreSuccess=xmlhttp.responseText;
					if (StoreSuccess=='1') {
						//alert("Your leaf has been stored");
						processIndicatorEnd(" Leaf stored ");
					}
				} else {
					alert("AJAX Error : Server connection Problem");
				}
			}
		}
		xmlhttp.send(null);
	}
}
/** Use for save the leaf... */

function saveLeaf(contextType)
{
	var query = "";
	// If whitebg is hide means Current Leaf is Back else Front
	query += "leafType="+contextType;
	var w=1;
	for (var i=0; i<dhtmlwindow.tobjects.length; i++){
		if (dhtmlwindow.tobjects[i].state !='close') {
			var objcontext = ltrim(dhtmlwindow.tobjects[i].windowName,"_");
			if (dhtmlwindow.tobjects[i].contextType == contextType ) {
				var wind =  dhtmlwindow.getAttrib(dhtmlwindow.tobjects[i]);
				query += "&window"+w+"="+wind;
				w = w+1;
			}
		}
	}
	query += "&totalWindow="+w;

	//alert(query);
	//var textProcessing = "Leaf store in process...";
	var xmlhttp = zXmlHttp.createRequest();
	var url = 'save_leaf.php?'+query;
	if (xmlhttp) {
		//processIndicatorStart(textProcessing);
		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					//			processIndicatorEnd(" Your Leaf has been stored ");
				} else {
					alert("AJAX Error : Server connection Problem");
				}
			}
		}
		xmlhttp.send(null);
	}
}

function clear()	{
	/* added by SHAILESH*/
	document.getElementById('front').className='deamlight';
	document.getElementById('back').className='deamlight';
	document.getElementById('subscr').className='grey_li';
	document.getElementById('clr').className='highlight';
	document.getElementById('print').className='deamlight';
}

function printLeaf()
{
	//Will store in to the database

	storeLeaf('F');

	storeLeaf('B');
	var obj = document.getElementById('A_notesText');
	if (typeof obj != 'undefined' && obj != null) {
		var AdultNotes = obj.value;
	}
	var obj = document.getElementById('K_notesText');
	if (typeof obj != 'undefined' && obj != null) {
		var KidsNotes = obj.value;
	}
	
	/* added by SHAILESH*/
	document.getElementById('front').className='deamlight';
	document.getElementById('back').className='deamlight';
	document.getElementById('subscr').className='grey_li';
	document.getElementById('clr').className='deamlight';
	document.getElementById('print').className='highlight';

	/*  added by jignesh */
	var width  = 670;
	var height = 1000;
	var left   = (screen.width  - width)/2;
	var top    = (screen.height - height)/2;
	var params = "width="+width+",height="+height;
	params += ",top="+top+",left="+left;
	params += ",directories=no";
	params += ",location=no";
	params += ",menubar=no";
	params += ",resizable=no";
	params += ",scrollbars=1";
	params += ",status=no";
	params += ",toolbar=no";
	docPrint=window.open("","Print", params);

	//	docPrint=window.open("","Print","width=670,height=1000,resizable=no,scrollbars=1");
	docPrint.document.open();
	docPrint.document.write('<html><head><title>Leafling Print</title>');
	docPrint.document.write('<link rel="stylesheet" type="text/css" href="css/site.css">');
	docPrint.document.write('<link rel="stylesheet" type="text/css" href="css/css.css">');
	docPrint.document.write('<link rel="stylesheet" type="text/css" href="css/dhtmlwindow.css">');
	docPrint.document.write('<link rel="stylesheet" type="text/css" href="css/maze.css">');

	docPrint.document.write('<STYLE type="text/css">');
	docPrint.document.write('		.drag-controls { display:none; }');
	docPrint.document.write('@media print { ');
	docPrint.document.write('		#btnOperations { display:none; }');
	document.all?docPrint.document.write('	#backpage .printfixSpan { border-bottom:1px #000000 solid; border-right:1px #000000 solid;}'):docPrint.document.write('');
	docPrint.document.write('		}');
	docPrint.document.write('</STYLE>');

	docPrint.document.write('<script language="js/solve.js" type="text/javascript">');
	docPrint.document.write('function printThisPage()     {');
	docPrint.document.write('	print(); 	');
	docPrint.document.write('	close();	');
	docPrint.document.write('}');
	docPrint.document.write('</script>');

	docPrint.document.write('</head><body style="background:none; background-color:#FFFFFF; margin-left:2px;" >');
	docPrint.document.write('<div id="btnOperations" style="padding-top:20px; padding-bottom:20px; text-align:center;">');
	docPrint.document.write('<input type="button" id="btnPrint" value="Print" onclick="printThisPage();">');
	docPrint.document.write('<input style="margin-left:20px;" type="button" id="btnCancel" value="Cancel" onclick="javascript: window.close();">');
	docPrint.document.write('</div>');

	//  var x = navigator;
	//	docPrint.document.write("CodeName=" + x.appCodeName);
	//	docPrint.document.write("<br />");
	//	docPrint.document.write("MinorVersion=" + x.appMinorVersion);
	document.all?docPrint.document.write('<div id="whitebg" style="border:none;">'):docPrint.document.write('<div id="whitebg" style="border:none;">');
	docPrint.document.write(document.getElementById("whitebg").innerHTML);
	docPrint.document.write('<div style="float:left;">');
	var contextType=getCurrentLeaf();
	if(contextType=='F') {
		var p=document.getElementById('whitebg');
		//		alert(typeof(p));
	} else {
		var p=document.getElementById('whitebgBack');
	}
	var ppane 			= getPrintPaneCoordinates();
	for (var i=0; i <dhtmlwindow.tobjects.length; i++)
	{
		if (dhtmlwindow.tobjects[i].state !='close' && dhtmlwindow.tobjects[i].contextType == 'F')
		{
			if(dhtmlwindow.tobjects[i].style.display == "none")
			{
				var prevdisplayF = "none";
				dhtmlwindow.tobjects[i].style.display='block';
			}

			/* ---------------------------------------------------------- */
			var objDivTitle = dhtmlwindow.tobjects[i].getElementsByTagName('DIV')[0];
			var InnerHtml = dhtmlwindow.tobjects[i].contentarea.innerHTML;
			var objDiv = dhtmlwindow.tobjects[i].contentarea.getElementsByTagName('DIV')[0];


			var Wname 	= 	dhtmlwindow.tobjects[i].windowName;
			var Tarry 	= 	splitContextName(Wname);
			var tr1		=	ltrim(Tarry.name,"_");
			var Title 	= eval(tr1+'.title')+(typeof Tarry.no=='undefined'?"":' #'+Tarry.no);


			if(Title.indexOf("Maze") != -1)
			{
				var mazeflag = "yes";

				InnerHtml = InnerHtml.replace(/<div class="medium">/gi,"<tr class='medium'>");
				InnerHtml = InnerHtml.replace(/<div class="large">/gi,"<tr class='large'>");
				InnerHtml = InnerHtml.replace(/<div class="mrow">/gi,"<tr class='mrow'>");
				InnerHtml = InnerHtml.replace(/<div class=medium>/gi,"<TR class='medium'>");
				InnerHtml = InnerHtml.replace(/<div class=large>/gi,"<TR class='large'>");
				InnerHtml = InnerHtml.replace(/<div class=mrow>/gi,"<TR class='mrow'>");

				InnerHtml = InnerHtml.replace(/<div class=\"batlarge /gi,'<td style="height:5%; font-size:7px;" class=\"batlarge ');
				InnerHtml = InnerHtml.replace(/<div class=\"gamelarge /gi,'<td style="height:6%; font-size:7px;" class=\"gamelarge ');
				InnerHtml = InnerHtml.replace(/<div class=\"cell /gi,'<td style="height:7%; font-size:7px;" class=\"cell ');
				InnerHtml = InnerHtml.replace(/<\/div><\/div>/gi,'&nbsp;</td></tr>');
				InnerHtml = InnerHtml.replace(/<\/div>/gi,'&nbsp;</td>');
				//alert("New"+InnerHtml);
				//				InnerHtml = "<table style='width:"+(dhtmlwindow.tobjects[i].contentarea.offsetWidth-2)+"px;height:"+(dhtmlwindow.tobjects[i].contentarea.offsetHeight)+"px;' cellpadding='0' cellspacing='0'>"+InnerHtml+"</table>";
				InnerHtml = "<table style='width:"+(dhtmlwindow.tobjects[i].contentarea.offsetWidth-2)+"px;height:"+(dhtmlwindow.tobjects[i].contentarea.offsetHeight)+"px;' cellpadding='0' cellspacing='0'>"+InnerHtml+"</table>";
			} else {
				if (typeof objDiv !='undefined') {
					if(objDiv.firstChild.tagName == 'IMG' && typeof objDiv.firstChild.src != 'undefined') {
						InnerHtml="<IMG style='width:"+(dhtmlwindow.tobjects[i].contentarea.offsetWidth-5)+"px;height:"+(dhtmlwindow.tobjects[i].contentarea.offsetHeight-5)+"px;' src='"+objDiv.firstChild.src+"'>";
					} else {
						InnerHtml=objDiv.innerHTML;
					}
				}
			}


			/* ---------------------------------------------------------- */


			var contLeft 		= dhtmlwindow.tobjects[i].offsetLeft;
			var contTop			= dhtmlwindow.tobjects[i].offsetTop;

			/*var winLeft = document.all?p.offsetParent.offsetParent.offsetLeft + p.offsetParent.offsetLeft : p.offsetLeft;*/

			
			
			var contextPosLeft 	= (contLeft - ppane['left'])+'px';
			var contextPosTop  	= ((contTop - ppane['top'])+66)+'px';
			var width 			= (dhtmlwindow.tobjects[i].offsetWidth)+'px';
			var height 			= (dhtmlwindow.tobjects[i].offsetHeight)+'px';

			docPrint.document.write('<div class="dhtmlwindow" style="width:'+width+'; top:'+contextPosTop+'; left:'+contextPosLeft+'; height:'+height+'; visibility:visible; z-index:'+ dhtmlwindow.tobjects[i].style.zIndex +';" id="'+dhtmlwindow.tobjects[i].windowName+'" >');

			/* ---------------------------------------------------------- */

			if(mazeflag == "yes")
			{

				var Mazecont="";
				Mazecont	+= '<div class="drag-handle" >'+ Title +'</div>';
				Mazecont	+= '<div style="height:'+dhtmlwindow.tobjects[i].offsetHeight+'px;width:'+(dhtmlwindow.tobjects[i].offsetWidth-2)+'px;overflow:visible;" class="drag-contentarea">';
				Mazecont	+= InnerHtml + "</div>";
				docPrint.document.write(Mazecont);
			} else if (dhtmlwindow.tobjects[i].id =='_ch1') {
				var oldInner = dhtmlwindow.tobjects[i].contentarea.innerHTML;
				dhtmlwindow.tobjects[i].contentarea.innerHTML = '<textarea class="notesText" style="color:black;" readonly>'+AdultNotes+"</textarea></div>";
				docPrint.document.write(dhtmlwindow.tobjects[i].innerHTML);
				dhtmlwindow.tobjects[i].contentarea.innerHTML = oldInner;
				dhtmlwindow.tobjects[i].contentarea.getElementsByTagName('TEXTAREA')[0].value=AdultNotes;
			} else if (dhtmlwindow.tobjects[i].id =='_ch2') {
				var oldInner = dhtmlwindow.tobjects[i].contentarea.innerHTML;
				dhtmlwindow.tobjects[i].contentarea.innerHTML = '<textarea class="notesText" style="color:black;" readonly>'+KidsNotes +"</textarea></div>";
				docPrint.document.write(dhtmlwindow.tobjects[i].innerHTML);
				dhtmlwindow.tobjects[i].contentarea.innerHTML = oldInner;
				dhtmlwindow.tobjects[i].contentarea.getElementsByTagName('TEXTAREA')[0].value=KidsNotes;
			} else {
				docPrint.document.write(dhtmlwindow.tobjects[i].innerHTML);
			}
			
			/* ---------------------------------------------------------- */

			docPrint.document.write('</div>');

			if(prevdisplayF == "none")
			{
				dhtmlwindow.tobjects[i].style.display='none';
			}

		}
	}

	docPrint.document.write('</div>');
	docPrint.document.write('</div>');
	/*
	document.all?docPrint.document.write('<div id="whitebg" style="margin-top:125px;">'):docPrint.document.write('<div id="whitebg" style="margin-top:170px;">');
	document.all?docPrint.document.write('<div id="whitebg" style="page-break-before: always; border:none;">'):docPrint.document.write('<div id="whitebg" style="page-break-before: always; border:none;">');
	*/
	document.all?docPrint.document.write('<div id="whitebg" style="border:none; page-break-before: always;">'):docPrint.document.write('<div id="whitebg" style="border:none; page-break-before: always;">');
	docPrint.document.write('<div id="whitebgHead" style="height:1px; visibility:hidden;"></div>');
	docPrint.document.write(document.getElementById("whitebgBack").innerHTML);

	document.all?docPrint.document.write('<div id="backpage">'):docPrint.document.write('<div style="padding-top:-2px; position:relative;">');
	//	document.all?docPrint.document.write('<div>'):docPrint.document.write('<div>');

	for (var i=0; i <dhtmlwindow.tobjects.length; i++)
	{
		if (dhtmlwindow.tobjects[i].state !='close' && dhtmlwindow.tobjects[i].contextType == 'B')
		{
			if(dhtmlwindow.tobjects[i].style.display == "none")
			{
				var prevdisplayB = "none";
				dhtmlwindow.tobjects[i].style.display='block';
			}

			/* ---------------------------------------------------------- */
			var objDivTitle = dhtmlwindow.tobjects[i].getElementsByTagName('DIV')[0];
			var InnerHtml = dhtmlwindow.tobjects[i].contentarea.innerHTML;
			var objDiv = dhtmlwindow.tobjects[i].contentarea.getElementsByTagName('DIV')[0];


			var Wname 	= 	dhtmlwindow.tobjects[i].windowName;
			var Tarry 	= 	splitContextName(Wname);
			var tr1		=	ltrim(Tarry.name,"_");
			var Title 	= eval(tr1+'.title')+(typeof Tarry.no=='undefined'?"":' #'+Tarry.no);


			if(Title.indexOf("Maze") != -1)
			{
				var mazeflagans = "yes";
				InnerHtml = InnerHtml.replace(/<div class="medium">/gi,"<tr class='medium'>");
				InnerHtml = InnerHtml.replace(/<div class="large">/gi,"<tr class='large'>");
				InnerHtml = InnerHtml.replace(/<div class="mrow">/gi,"<tr class='mrow'>");
				InnerHtml = InnerHtml.replace(/<div class=medium>/gi,"<TR class='medium'>");
				InnerHtml = InnerHtml.replace(/<div class=large>/gi,"<TR class='large'>");
				InnerHtml = InnerHtml.replace(/<div class=mrow>/gi,"<TR class='mrow'>");

				InnerHtml = InnerHtml.replace(/<div class=\"batlarge /gi,'<td  style="height:5%; font-size:8px;" class=\"batlarge ');
				InnerHtml = InnerHtml.replace(/<div class=\"gamelarge /gi,'<td  style="height:6%; font-size:8px;" class=\"gamelarge ');
				InnerHtml = InnerHtml.replace(/<div class=\"cell /gi,'<td style="height:7%; font-size:8px;" class=\"cell ');
				InnerHtml = InnerHtml.replace(/<div style/gi,'<td style');
				InnerHtml = InnerHtml.replace(/<\/div><\/div>/gi,'&nbsp;</td></tr>');
				InnerHtml = InnerHtml.replace(/<\/div>/gi,'&nbsp;</td>');

				InnerHtml = "<table style='width:"+(dhtmlwindow.tobjects[i].contentarea.offsetWidth-2)+"px;height:"+(dhtmlwindow.tobjects[i].contentarea.offsetHeight)+"px;' cellpadding='0' cellspacing='0'>"+InnerHtml+"</table>";
			} else {
				if (typeof objDiv !='undefined') {
					if(objDiv.firstChild.tagName == 'IMG' && typeof objDiv.firstChild.src != 'undefined') {
						InnerHtml="<IMG style='width:"+(dhtmlwindow.tobjects[i].contentarea.offsetWidth-5)+"px;height:"+(dhtmlwindow.tobjects[i].contentarea.offsetHeight-5)+"px;' src='"+objDiv.firstChild.src+"'>";
					} else {
						InnerHtml=objDiv.innerHTML;
					}
				}
			}

   
			/* ---------------------------------------------------------- */


			var topMins = document.all?86:66;
			var contLeft 		= dhtmlwindow.tobjects[i].offsetLeft;
			var contTop			= dhtmlwindow.tobjects[i].offsetTop;
			var contextPosLeft 	= (contLeft - ppane['left'])+'px';
			var contextPosTop  	= ((contTop - ppane['top'])+topMins)+'px';
			var width 			= (dhtmlwindow.tobjects[i].offsetWidth)+'px';
			var height 			= (dhtmlwindow.tobjects[i].offsetHeight)+'px';
			
			docPrint.document.write('<div class="dhtmlwindow" style="width:'+width+'; top:'+contextPosTop+'; left:'+contextPosLeft+'; height:'+height+'; visibility:visible; z-index:'+ dhtmlwindow.tobjects[i].style.zIndex +';" id="'+dhtmlwindow.tobjects[i].windowName+'" >');

			/* ---------------------------------------------------------- */
			if(mazeflagans == "yes")
			{
				var Mazecont="";
				Mazecont	+= '<div class="drag-handle">'+ Title +'</div>';
				Mazecont	+= '<div style="height:'+dhtmlwindow.tobjects[i].offsetHeight+'px;width:'+(dhtmlwindow.tobjects[i].offsetWidth-2)+'px;overflow:visible;" class="drag-contentarea">';
				Mazecont	+= InnerHtml + "</div>";

				docPrint.document.write(Mazecont);

			} else if (dhtmlwindow.tobjects[i].id =='_ch1') {
				var oldInner = dhtmlwindow.tobjects[i].contentarea.innerHTML;
				dhtmlwindow.tobjects[i].contentarea.innerHTML = '<textarea class="notesText" style="color:black;">'+AdultNotes+"</textarea></div>";
				docPrint.document.write(dhtmlwindow.tobjects[i].innerHTML);
				dhtmlwindow.tobjects[i].contentarea.innerHTML = oldInner;
				dhtmlwindow.tobjects[i].contentarea.getElementsByTagName('TEXTAREA')[0].value=AdultNotes;
			} else if (dhtmlwindow.tobjects[i].id =='_ch2') {
				var oldInner = dhtmlwindow.tobjects[i].contentarea.innerHTML;
				dhtmlwindow.tobjects[i].contentarea.innerHTML = '<textarea class="notesText" style="color:black;">'+KidsNotes +"</textarea></div>";
				docPrint.document.write(dhtmlwindow.tobjects[i].innerHTML);
				dhtmlwindow.tobjects[i].contentarea.innerHTML = oldInner;
				dhtmlwindow.tobjects[i].contentarea.getElementsByTagName('TEXTAREA')[0].value=KidsNotes;
			} else {
				docPrint.document.write(dhtmlwindow.tobjects[i].innerHTML);
			}
			/* ---------------------------------------------------------- */

			docPrint.document.write('</div>');

			if(prevdisplayB == "none")
			{
				dhtmlwindow.tobjects[i].style.display='none';
			}

		}
	}

	docPrint.document.write('</div>');

	docPrint.document.write('</div>');
	docPrint.document.write('</body></html>');

	docPrint.document.close();

	//	docPrint.close();

}


function storeChecklist(item,type)
{

	var ItemValue = document.getElementById(item).value;
	if (ItemValue=='') {
		return false;
	}
	var query = "item="+document.getElementById(item).value+"&type="+type;
	var xmlhttp = zXmlHttp.createRequest();
	var url = 'store_checklist.php?'+query;

	if (xmlhttp) {
		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if(xmlhttp.responseText == "1")
					{
						getChecklist(type);
					}
				} else {
					alert("AJAX Error : Server connection Problem");
				}
			}
		}
		xmlhttp.send(null);
	}
}
function getChecklist(type)
{
	var query = "type="+type;
	var xmlhttp = zXmlHttp.createRequest();
	var url = 'get_checklist.php?'+query;

	if (xmlhttp) {
		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {

					if(xmlhttp.responseText != "")
					{
						var responseArr =  xmlhttp.responseText.split("-|-");
						var idArr		= responseArr[0].split(",");
						var itemArr		= responseArr[1].split(",");
						if (type == 'A') {
							var OldInnerHTML = '<li id="chk1">'+document.getElementById('chk1').innerHTML+'</li>';
							var NewInnerHTML = '<li><div class="leftnavigation_top"><p></p></div></li>';
							NewInnerHTML += '<li><a  id="cl1" style="cursor:move;">Checklist</a></li>';

							for(i=0;i<itemArr.length;i++)
							{
								NewInnerHTML += '<li style="padding:0 4px 0 4px;"> '+itemArr[i]+' <a id='+idArr[i]+' href="javascript:void(0);" onclick="deleteChecklist('+idArr[i]+');">X</a></li>';
							}
							NewInnerHTML += OldInnerHTML
							;
							document.getElementById('checklist').innerHTML=NewInnerHTML;
							$('cl1').makeDraggable(draggableOptionsTest);
						} else {
							var OldInnerHTML1 = '<li id="kchk1">'+document.getElementById('kchk1').innerHTML+'</li>';
							var NewInnerHTML1 = '<li><div class="leftnavigation_top"><p></p></div></li>';
							NewInnerHTML1 	+= '<li><a  id="kcl1" style="cursor:move;">Checklist</a></li>';

							for(i=0;i<itemArr.length;i++)
							{
								NewInnerHTML1 += '<li style="padding:0 4px 0 4px;"> '+itemArr[i]+' <a id='+idArr[i]+' href="javascript:void(0);" onclick="deleteChecklist('+idArr[i]+');">X</a></li>';
							}
							NewInnerHTML1 += OldInnerHTML1;
							document.getElementById('kchecklist').innerHTML=NewInnerHTML1;
							$('kcl1').makeDraggable(draggableOptionsTest);
						}
					}
					else
					{
						var OldInnerHTML = '<li id="chk1">'+document.getElementById('chk1').innerHTML+'</li>';
						var OldInnerHTML1 = '<li id="kchk1">'+document.getElementById('kchk1').innerHTML+'</li>';

						var NewInnerHTML = '<li><div class="leftnavigation_top"><p></p></div></li>';
						var NewInnerHTML1 = '<li><div class="leftnavigation_top"><p></p></div></li>';

						NewInnerHTML += OldInnerHTML;
						NewInnerHTML1 += OldInnerHTML1;

						document.getElementById('checklist').innerHTML=NewInnerHTML;
						document.getElementById('kchecklist').innerHTML=NewInnerHTML1;
					}
				} else {
					alert("AJAX Error : Server connection Problem");
				}
			}
		}
		xmlhttp.send(null);
	}
}
function deleteChecklist(item)
{
	var query = "id="+item;
	var xmlhttp = zXmlHttp.createRequest();
	var url = 'delete_checklist.php?'+query;

	if (xmlhttp) {
		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if(xmlhttp.responseText == "1")
					{
						getChecklist();
					}

				} else {
					alert("AJAX Error : Server connection Problem");
				}
			}
		}
		xmlhttp.send(null);
	}
}

/** Delete Item from the checklist
*/


function restoreChecklist(){
	document.getElementById('chk1').style.display='block';
	document.getElementById('chk2').style.display='none';
	document.getElementById('chk3').style.display='none';
	document.getElementById('item').value=document.getElementById('s_chk').innerHTML;
}

function storeWeather(cityid)
{
	var xmlhttp = zXmlHttp.createRequest();
	var query = "city="+document.getElementById(cityid).value;
	var url = 'store_weather.php?'+query;
	if (xmlhttp) {
		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if(xmlhttp.responseText != "")
					{
						document.getElementById('div1').style.display='none';
						document.getElementById('div2').style.display='block';
						document.getElementById('div3').style.display='block';
						document.getElementById('aw').innerHTML=xmlhttp.responseText;
					}
					else
					{
						document.getElementById('div1').style.display='none';
						document.getElementById('div2').style.display='block';
						document.getElementById('div3').style.display='block';
						document.getElementById('aw').innerHTML=document.getElementById(cityid).value;

					}
				} else {
					alert("AJAX Error : Server connection Problem");
				}
			}
		}
		xmlhttp.send(null);
	}
}
function getWeather()
{
	var query = "";
	var xmlhttp = zXmlHttp.createRequest();
	var url = 'get_weather.php?'+query;

	if (xmlhttp) {
		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {

					if(xmlhttp.responseText != "")
					{
						document.getElementById('div1').style.display='none';
						document.getElementById('div2').style.display='block';
						document.getElementById('div3').style.display='block';
						document.getElementById('aw').innerHTML=xmlhttp.responseText;
					}
					else
					{
						document.getElementById('div1').style.display='block';
						document.getElementById('div2').style.display='none';
						document.getElementById('div3').style.display='none';
					}

				} else {
					alert("AJAX Error : Server connection Problem");
				}
			}
		}
		xmlhttp.send(null);
	}
}
function restoreWeather(){
	document.getElementById('div1').style.display='block';
	document.getElementById('div2').style.display='none';
	document.getElementById('div3').style.display='none';
	document.getElementById('city').value=document.getElementById('aw').innerHTML;
}

function storeDate()
{
	var startDate = document.getElementById('startDate').value;
	var option = document.getElementById('option').value;
	if(startDate == '') {
		document.getElementById('successId').innerHTML="";
		document.getElementById('startdateErrorId').innerHTML="<img src='images/error.gif'>Please select date";
		return false;
	}
	if(option == '' ||option == '0') {
		document.getElementById('optionErrorId').innerHTML="<img src='images/error.gif'>Please select an option";
		return false;
	}
	var operation ="&operation=add";
	var sdateArray=startDate.split('-');
	var sdate=sdateArray[2]+'-'+sdateArray[0]+'-'+sdateArray[1];
	var query = "startdate="+sdate+"&option="+option;
	var xmlhttp = zXmlHttp.createRequest();
	var url = 'calender.php?'+query+operation;

	if (xmlhttp) {
		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if(xmlhttp.responseText == "1")
					{
						document.getElementById('startdateErrorId').innerHTML="";
						document.getElementById('optionErrorId').innerHTML="";
						document.getElementById('successId').innerHTML="Subscription confirmed. You will now receive your Leaf through email.";
					}

				} else {
					alert("AJAX Error : Server connection Problem");
				}
			}
		}
		xmlhttp.send(null);
	}
	return false;
}
/*function hideProcess1() {
document.getElementById('successId').style.display ='none';
}*/
function showpassword(){
	document.getelementById(pwd).style.display='block';
}
function check(){
	var objcheck = document.getElementById("c1");
	if(document.getElementById("c1").checked == false)
	{
		var p1 = document.getElementById("p1");
		p1.style.display = "block";
		var p2 = document.getElementById("p2");
		p2.style.display = "none";
	}
	else
	{
		document.users.submit();
	}
}


function checkLogin(ObjLoginForm)
{

	if(ObjLoginForm.txtUsername.value=="") {
		document.getElementById("invalidLogin").innerHTML="Please enter username";
		return false;
	}
	if(ObjLoginForm.txtPassword.value=="") {
		document.getElementById("invalidLogin").innerHTML="Please enter password";
		return false;
	}

	return true;

}

Array.prototype.max = function(){
	return Math.max.apply({},this)
}


function saveThisLeaf() {
	storeNotes('A_notesText','A');
	storeNotes('K_notesText','K');
	saveLeaf('F');
	saveLeaf('B');
	alert("Your Leaf has been stored");

}

function inObjectArray(varArrayL,varArrayR,varId) {
	for (var i=0;i<varArrayL.length;i++) {
		if (varArrayL[i].windowName == varId) {
			return true;
		}
	}
	for (var i=0;i<varArrayR.length;i++) {
		if (varArrayR[i].windowName == varId) {
			return true;
		}
	}
}



function splitContextName(contextN){
	var part 	= contextN.split("__");
	var arrPart = new Array();
	if(part.length > 1) {
		arrPart.name = part[0];
		arrPart.no	= part[1];
	} else {
		arrPart.name = contextN;
	}
	return arrPart;
}

function processIndicatorStart(textProcessing) {
	var process = document.getElementById('process');
	if(process == null) {
		var process=document.createElement("div");
		process.id 			= "process";
		process.innerHTML	= textProcessing;
		process.className 	= "ProcessIndi";
		document.getElementById("dhtmlwindowholder").appendChild(process);
	} else {

		process.innerHTML	= textProcessing;
		process.style.display='block';
	}
}
function processIndicatorEnd(textEnding) {
	objProcess = document.getElementById('process');
	objProcess.innerHTML=textEnding;
	clearTimeout(TimeId);
	var TimeId = setTimeout('hideProcess(objProcess)',3000);

}
function hideProcess(objarg) {
	objarg.style.display ='none';
}

function SaveHTML()
{
	var PdfContent ="";
	PdfContent	+=	document.getElementById("whitebg").innerHTML;

	var contextType=getCurrentLeaf();

	if(contextType=='F') {
		var p=document.getElementById('whitebg');
	} else {
		var p=document.getElementById('whitebgBack');
	}

	for (var i=0; i <dhtmlwindow.tobjects.length; i++)
	{
		if (dhtmlwindow.tobjects[i].state !='close' && dhtmlwindow.tobjects[i].contextType == 'F')
		{
			if(dhtmlwindow.tobjects[i].style.display == "none")
			{
				var prevdisplayF = "none";
				dhtmlwindow.tobjects[i].style.display='block';
			}

			var contLeft 		= dhtmlwindow.tobjects[i].offsetLeft;
			var contTop			= dhtmlwindow.tobjects[i].offsetTop;

			//			var winLeft			= p.offsetLeft;
			var winLeft			= 275;
			//			var winTop			= p.offsetTop;
			var winTop			= 207;
			var contextPosLeft = (contLeft - winLeft)+'px';
			var contextPosTop  = (contTop - winTop)+'px';

			PdfContent	+= '<div class="dhtmlwindow" style="width:'+dhtmlwindow.tobjects[i].style.width+'; top:'+contextPosTop+'; left:'+contextPosLeft+'; height:'+dhtmlwindow.tobjects[i].contentarea.style.height+'; visibility:visible; z-index:'+ dhtmlwindow.tobjects[i].style.zIndex +';" id="'+dhtmlwindow.tobjects[i].windowName+'" >';
			PdfContent	+= dhtmlwindow.tobjects[i].innerHTML;
			PdfContent	+= '</div>';
			if(prevdisplayF == "none")
			{
				dhtmlwindow.tobjects[i].style.display='none';
			}

		}

	}


	PdfContent	+=	'</div>';
	PdfContent	+=	'</div>';
	PdfContent	+=	'</body>';
	PdfContent	+=	'</html>';

	var xmlhttp = zXmlHttp.createRequest();
	var url = 'saveasHtml.php';

	if (xmlhttp) {
		//var params = 'pdfcontent=' +PdfContent;
		var params = 'pdfcontent='+escape(PdfContent);
		//		var params = 'pdfcontent=<h1>jaggs</h1>';
		xmlhttp.open('POST',url,true);
		//Send the proper header information along with the//   PdfContent	+=	'jaggsr'; request
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		processIndicatorStart("HTML in process...");
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					processIndicatorEnd("HTML saved");

				} else {
					alert("AJAX Error :"+xmlhttp.statusText);
				}
			}
		}
		xmlhttp.send(params);
	}

}
function getCurrentdate()
{
	var xmlhttp = zXmlHttp.createRequest();
	var url = 'currentDate.php';

	if (xmlhttp) {
		xmlhttp.open('GET',url,false);
		xmlhttp.send(null);

		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				return xmlhttp.responseText
			} else {
				alert("AJAX Error :"+xmlhttp.statusText);
			}
		}
	}
}
function sortFunct(a,b) {
	return (a.style.zIndex - b.style.zIndex);
	//return (a.offsetTop - b.offsetTop);
}

function SavePDF()
{
	var MessageContent = "<DIV id='pdfMessage' style='width:400px;height:150px;display:block;font-size:15px;'><IMG src='include/lightbox/loading.gif'><BR>Please wait while the PDF file is being generated...</DIV>";
	showLightbox(MessageContent,400,150);

	var PdfContent	=	document.getElementById('whitebgHead').innerHTML;
	var contextType=getCurrentLeaf();
	if(contextType=='F') {
		var p=document.getElementById('whitebg');
	} else {
		var p=document.getElementById('whitebgBack');
	}
	var l=0;
	var r=0;
	var LContext	= new Array();
	var RContext	= new Array();
	for (var i=0; i <dhtmlwindow.tobjects.length; i++) {
		if (dhtmlwindow.tobjects[i].state !='close') {
			if (dhtmlwindow.tobjects[i].contextType == 'F') {
				
				//Contains the array of context box that will be show on front pdf...
				LContext[l]=dhtmlwindow.tobjects[i];
				l++;
			} else {
				
				//Contains the array of context box that will be show on back pdf...
				RContext[r]=dhtmlwindow.tobjects[i];
				r++;
			}
		}
	}
	// Sort the conext window according to their Zindex value
	// Means the Zindex value that is lower will start to draw on pdf 1st 
	if (LContext.length != 0) {
		LContext.sort(sortFunct);
	}
	if (RContext.length != 0) {
		RContext.sort(sortFunct);
	}

	var NewPage = false;
	var ppane 	= getPrintPaneCoordinates();
	var curBottom 	= 0;
	var curHeight 	= 0;
	//----------------------------------------------------------------------------------------------
	// Drawing the Context Window on FrontPDf...
	//----------------------------------------------------------------------------------------------
	for (var i=0; i < LContext.length; i++) {
		curBottom = curBottom - 15;
		var divOverflow = '';
		var prevdisplay = false;
		if(LContext[i].style.display == "none") {
			LContext[i].style.display='block';
			prevdisplay = true;
		}
		// Resize every context window for better view in PDF(Print pand and PDF Dimension Problem)
		//dhtmlwindow.resizePdf(LContext[i],'-');
		var New 	= 	LContext[i].style.width;
		var Wname 	= 	LContext[i].windowName;
		var Tarry 	= 	splitContextName(Wname);
		var tr1		=	ltrim(Tarry.name,"_");
		var Title 	= 	eval(tr1+'.title')+(typeof Tarry.no=='undefined'?"":' #'+Tarry.no);
		var ttop	= 	(LContext[i].offsetTop - ppane['top']);
		var orgTop	= 	ttop;
		ttop		= 	(ttop - curBottom)+"px";
		var tleft	= 	(LContext[i].offsetLeft - ppane['left']);
		var objDivTitle = LContext[i].getElementsByTagName('DIV')[0];
		var ContHeight = LContext[i].contentarea.offsetHeight;
		PdfContent	+= '<div class="dhtmlwindow" style="z-index:width:'+New+';margin-left:'+tleft+';padding-top:'+ttop+';" id="'+LContext[i].windowName+'">';
		PdfContent	+= '<div class="drag-handle" style="height:'+(objDivTitle.offsetHeight)+'px;">'+Title+'</div>';
		if (LContext[i].state != 'minimized') {
			PdfContent	+= '<div style="overflow:hidden;height:'+(ContHeight)+'px;width:'+(LContext[i].contentarea.offsetWidth-2)+'px;" class="drag-contentarea">';
			var InnerHtml = LContext[i].contentarea.innerHTML;
			var objTable = LContext[i].contentarea.getElementsByTagName('TABLE')[0];
			
			// Convert Entire Maze game from DIV to TABLE because Div Based Maze Game has problem in PDF
			if(Title.indexOf("Maze") != -1) {
				InnerHtml = InnerHtml.replace(/<div class="medium">/gi,"<TR class='medium'>");
				InnerHtml = InnerHtml.replace(/<div class="large">/gi,"<TR class='large'>");
				InnerHtml = InnerHtml.replace(/<div class="mrow">/gi,"<TR class='mrow'>");
				InnerHtml = InnerHtml.replace(/<div class=medium>/gi,"<TR class='medium'>");
				InnerHtml = InnerHtml.replace(/<div class=large>/gi,"<TR class='large'>");
				InnerHtml = InnerHtml.replace(/<div class=mrow>/gi,"<TR class='mrow'>");
	
				InnerHtml = InnerHtml.replace(/<div class=\"batlarge /gi,'<TD class=\"batlarge ');
				InnerHtml = InnerHtml.replace(/<div class=\"gamelarge /gi,'<TD class=\"gamelarge ');
				InnerHtml = InnerHtml.replace(/<div class=\"cell /gi,'<TD class=\"cell ');
				InnerHtml = InnerHtml.replace(/<\/div><\/div>/gi,'</TD></TR>');
				InnerHtml = InnerHtml.replace(/<\/div>/gi,'</TD>');

				InnerHtml = "<Table style='width:"+(LContext[i].contentarea.offsetWidth)+"px;height:"+(LContext[i].contentarea.offsetHeight)+"px;' cellpadding='0' cellspacing='0'>"+InnerHtml+"</Table>";
			
			} else if(typeof objTable !='undefined' && Title.indexOf("Trivia") == -1) {
				// Need to calculate the kakuro and sudoku table and td width,height
				// for identical view in PDF
				if (Title.indexOf("Kakuro") != -1) {
					var trheight = (Math.round(ContHeight / 10)-2);
				} else {
					var trheight = (Math.round(ContHeight / 9)-2);
				}
				InnerHtml = InnerHtml.replace(/<td /gi,"<td height='"+trheight+"' ");
				InnerHtml = InnerHtml.replace(/height="100%"/gi,"height='"+(ContHeight)+"'");
			} else {
				
				// Set the Image width and height according to context window because in PDF I
				// Image needs to with specific with and height in px
				var objDiv = LContext[i].contentarea.getElementsByTagName('DIV')[0];
				if (typeof objDiv !='undefined') {
					if (objDiv.firstChild.tagName == 'IMG' && typeof objDiv.firstChild.src != 'undefined') {
						InnerHtml="<IMG style='width:"+(LContext[i].contentarea.offsetWidth-5)+"px;height:"+(LContext[i].contentarea.offsetHeight-5)+"px;' src='"+objDiv.firstChild.src+"'>";
					} else {
						InnerHtml=objDiv.innerHTML;
					}
				}
			}
			PdfContent	+= InnerHtml;
			PdfContent	+= '</div>';
		}
		PdfContent	+= '</div>';
		curHeight	= (parseInt(orgTop) + LContext[i].offsetHeight);
		if ( curHeight > curBottom) {
			curBottom	=	curHeight
		}
		// Now Make the Context window as it is...
		//dhtmlwindow.resizePdf(LContext[i],'+');
		if (prevdisplay) {
			LContext[i].style.display='none';
		}
	}
	//----------------------------------------------------------------------------------------------
	// Drawing the Context Window on BackPDf...
	//----------------------------------------------------------------------------------------------
	
	PdfContent += "<BR><DIV style='page-break-before: always'>"+document.getElementById('whitebgBack').innerHTML;
	var curBottom 	= 0;
	var curHeight 	= 0;	
	for (var i=0; i < RContext.length; i++) {
		curBottom = curBottom - 15;
		var prevdisplay = false;
		if(RContext[i].style.display == "none") {
			RContext[i].style.display='block';
			prevdisplay = true;
		}
		// Resize every context window for better view in PDF(Print pand and PDF Dimension Problem)
		//dhtmlwindow.resizePdf(RContext[i],'-');
		var New 	= 	RContext[i].style.width;
		var Wname 	= 	RContext[i].windowName;
		var Tarry 	= 	splitContextName(Wname);
		var tr1		=	ltrim(Tarry.name,"_");
		var Title 	= eval(tr1+'.title')+(typeof Tarry.no=='undefined'?"":' #'+Tarry.no);
		
		var ttop	= 	(RContext[i].offsetTop - ppane['top']);
		
		var orgTop	= 	ttop;
		ttop		= 	(ttop - curBottom)+"px";
		
		var tleft	= 	(RContext[i].offsetLeft - ppane['left']);
		var objDivTitle = RContext[i].getElementsByTagName('DIV')[0];
		
		var ContHeight = RContext[i].contentarea.offsetHeight;
		PdfContent	+= '<div class="dhtmlwindow" style="width:'+New+';padding-left:'+tleft+';padding-top:'+ttop+';" id="'+RContext[i].windowName+'">';
		PdfContent	+= '<div class="drag-handle" style="height:'+(objDivTitle.offsetHeight-10)+'px;">'+Title+'</div>';
		if (RContext[i].state != 'minimized') {
			PdfContent	+= '<div style="height:'+(ContHeight)+'px;width:'+(RContext[i].contentarea.offsetWidth-2)+'px;overflow:hidden;" class="drag-contentarea">';
			var InnerHtml = RContext[i].contentarea.innerHTML;
			var objDiv = RContext[i].contentarea.getElementsByTagName('DIV')[0];
			var objTable = RContext[i].contentarea.getElementsByTagName('TABLE')[0];
			// Convert Entire Maze game from DIV to TABLE because Div Based Maze Game has problem in PDF
			if(Title.indexOf("Maze") != -1)
			{
				InnerHtml = InnerHtml.replace(/<div class="medium">/gi,"<TR class='medium'>");
				InnerHtml = InnerHtml.replace(/<div class="large">/gi,"<TR class='large'>");
				InnerHtml = InnerHtml.replace(/<div class="mrow">/gi,"<TR class='mrow'>");
				InnerHtml = InnerHtml.replace(/<div class=medium>/gi,"<TR class='medium'>");
				InnerHtml = InnerHtml.replace(/<div class=large>/gi,"<TR class='large'>");
				InnerHtml = InnerHtml.replace(/<div class=mrow>/gi,"<TR class='mrow'>");
	
				InnerHtml = InnerHtml.replace(/<div class=\"batlarge /gi,'<TD class=\"batlarge ');
				InnerHtml = InnerHtml.replace(/<div class=\"gamelarge /gi,'<TD class=\"gamelarge ');
				InnerHtml = InnerHtml.replace(/<div class=\"cell /gi,'<TD class=\"cell ');
				InnerHtml = InnerHtml.replace(/<div style/gi,'<TD style');
				InnerHtml = InnerHtml.replace(/<\/div><\/div>/gi,'</TD></TR>');
				InnerHtml = InnerHtml.replace(/<\/div>/gi,'</TD>');
				
				InnerHtml = "<Table style='width:"+(RContext[i].contentarea.offsetWidth)+"px;height:"+(RContext[i].contentarea.offsetHeight)+"px;' cellpadding='0' cellspacing='0'>"+InnerHtml+"</Table>";
			} else if(typeof objTable !='undefined') {
				// Need to calculate the kakuro and sudoku table and td width,height
				// for identical view in PDF
				if (Title.indexOf("Kakuro") != -1) {
					var trheight = (Math.round(ContHeight / 10)-2);
				} else {
					var trheight = (Math.round(ContHeight / 9)-2);
				}
				InnerHtml = InnerHtml.replace(/<td /gi,"<td height='"+trheight+"' ");				
				InnerHtml = InnerHtml.replace(/height="100%"/gi,"height='"+(ContHeight)+"'");
			} else {
				// Set the Image width and height according to context window because in PDF I
				// Image needs to with specific with and height in px
				if (typeof objDiv !='undefined') {
					if(objDiv.firstChild.tagName == 'IMG' && typeof objDiv.firstChild.src != 'undefined') {
						InnerHtml="<IMG style='width:"+(RContext[i].contentarea.offsetWidth-5)+"px;height:"+(RContext[i].contentarea.offsetHeight-5)+"px;' src='"+objDiv.firstChild.src+"'>";
					} else {
						InnerHtml=objDiv.innerHTML;
					}
				}
			}
			PdfContent	+= InnerHtml;
			PdfContent	+= '</div>';
		}
		PdfContent	+= '</div>';
		curHeight	= (parseInt(orgTop) + RContext[i].offsetHeight);
		if ( curHeight > curBottom) {
			curBottom	=	curHeight
		}
		// Now Make the Context window as it is...
		//dhtmlwindow.resizePdf(RContext[i],'+');
		if (prevdisplay) {
			RContext[i].style.display='none';
		}
	}

	
	//----------------------------------------------------------------------------------------
	// HTML for PDF is ready Now Generate the PDF...
	//----------------------------------------------------------------------------------------
	var xmlhttp = zXmlHttp.createRequest();
	var url = 'include/pdf/examples.php';
	if (xmlhttp) {
		var params = 'pdfcontent='+escape(PdfContent);
		xmlhttp.open('POST',url,true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if (isUrl(xmlhttp.responseText)) {
						document.getElementById('pdfMessage').innerHTML='Your PDF has been generated.<BR> <A href="'+xmlhttp.responseText+'" onclick="hideLightbox();" target="_blank" >Click here to download </A>';
					} else {
						document.getElementById('pdfMessage').innerHTML='<font style="color:red;font-weight:bold;font-size:12px;">Sorry,Your PDF was not generated.</Font>';
					}
				} else {
					alert("AJAX Error :"+xmlhttp.statusText);
				}
			}
		}
		xmlhttp.send(params);
	}

}
function trimString (str) {
	str = this != window? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function editNotes(objthis) {
	var objNotes 	= document.getElementById('notes');
	var EditNotes 	=   "<DIV id='edit'>";
	EditNotes 		+=  "<textarea id='notesText'>Edit Notes</textarea>";
	EditNotes		+= "</DIV>"

	objNotes.innerHTML = EditNotes;
}

function storeNotes(NotesId,varType)
{
	var obj = document.getElementById(NotesId);
	if (typeof obj == 'undefined' || obj == null) {
		return true;
	}
	var ItemValue = obj.value;
	var query = "notes="+escape(ItemValue);
	var xmlhttp = zXmlHttp.createRequest();
	var url = 'store_notes.php?'+query+'&type='+varType;

	if (xmlhttp) {
		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status != 200) {
					alert("AJAX Error :"+xmlhttp.statusText);
					return false;
				}
			}
		}
		xmlhttp.send(null);
	}
}

function setValue(thisObj) {
	if (thisObj.value=='Type here') {
		thisObj.value='';
		thisObj.style.color='black';
	}
}
function changeValue(thisObj) {
	if (thisObj.value == '' || thisObj.value == 'Type here') {
		thisObj.value='Type here';
		thisObj.style.color='grey';
	}
}

function changecss(theClass,element,value) {
	var cssRules;
	if (document.all) {
		cssRules = 'rules';
	} else if (document.getElementById) {
		cssRules = 'cssRules';
	}
	for (var S = 0; S < document.styleSheets.length; S++) {
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
				
				document.styleSheets[S][cssRules][R].style[element] = value;
			}
		}
	}	
}

function bookMark(thisObj) {
	switch(thisObj.id) {
		case 'bookmark_digg':
			thisObj.href = "http://digg.com/submit?phase=2&url="+escape(window.location.href);
			break;
		case 'bookmark_del':
			thisObj.href = "http://del.icio.us/post?url="+escape(window.location.href)+"&title="+document.title;
			break;	
			
		case 'bookmark_stum':
			thisObj.href = "http://www.stumbleupon.com/submit?url="+escape(window.location.href)+"&title="+document.title;
			break;	
			
		case 'bookmark_red':
			thisObj.href = "http://reddit.com/submit?url="+escape(window.location.href)+"&title="+document.title;
			break;	
			
		case 'bookmark_news':
			thisObj.href = "http://www.newsvine.com/_tools/seed&amp;save?u="+escape(window.location.href)+"&h="+document.title;
			break;	
			
		case 'bookmark_google':
			thisObj.href = "http://www.google.com/bookmarks/mark?op=add&bkmk="+escape(window.location.href)+"&title="+document.title;
			break;	
			
		case 'bookmark_yahoo':
			thisObj.href = "http://myweb2.search.yahoo.com/myresults/bookmarklet?u="+escape(window.location.href)+"&t="+document.title;
			break;	
			
		case 'bookmark_tech':
			thisObj.href = "http://technorati.com/cosmos/search.html?url="+escape(window.location.href);
			break;	
			
		case 'bookmark_facebook':
			thisObj.href = "http://www.facebook.com/sharer.php?u="+encodeURI(window.location.href)+"&t="+encodeURIComponent(document.title);
			break;	
			
			
	}
}

/*<ul class='bookmark'>
     			<li class="bookmark_link"><a id="bookmark_digg" onmouseover="bookMark(this);" href="http://digg.com/submit" rel="nofollow" class="bookmark_link"><img src="images/bookmark/digg.png" alt="Digg" /></a></li>
     			<li class="bookmark_link"><a id="bookmark_del" onmouseover="bookMark(this);" href="http://del.icio.us/post?url=--&title=--" title="Bookmark this page on del.icio.us." rel="nofollow" class="bookmark_link"><img src="images/bookmark/delicious.png" alt="Delicious" /></a></li>
  				<li class="bookmark_link"><a id="bookmark_stum" onmouseover="bookMark(this);" href="http://www.stumbleupon.com/submit?url=--&title=--" title="Thumb this up at StumbleUpon." rel="nofollow" class="bookmark_link"><img src="images/bookmark/stumbleit.png" alt="StumbleUpon" /></a></li>
				<li class="bookmark_link"><a id="bookmark_red" onmouseover="bookMark(this);" href="http://reddit.com/submit?url=--&title=--" title="Submit this page on reddit.com." rel="nofollow" class="bookmark_link"><img src="images/bookmark/reddit.png" alt="Reddit" /></a></li>
  				<li class="bookmark_link"><a id="bookmark_news" onmouseover="bookMark(this);" href="http://www.newsvine.com/_tools/seed&amp;save?u=--&h=--" title="Submit this page on newsvine.com." rel="nofollow" class="bookmark_link"><img src="images/bookmark/newsvine.png" alt="Newsvine" /></a></li>
  				<li class="bookmark_link"><a id="bookmark_google" onmouseover="bookMark(this);" href="http://www.google.com/bookmarks/mark?op=add&bkmk=--&title=--" title="Bookmark this page on Google." rel="nofollow" class="bookmark_link"><img src="images/bookmark/google.png" alt="Google" /></a></li>
  				<li class="bookmark_link"><a id="bookmark_yahoo" onmouseover="bookMark(this);" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=--&t=--" title="Bookmark this page on Yahoo." rel="nofollow" class="bookmark_link"><img src="images/bookmark/yahoo.png" alt="Yahoo" /></a></li>
  				<li class="bookmark_link"><a id="bookmark_tech" onmouseover="bookMark(this);" href="http://technorati.com/cosmos/search.html?url=--" title="Search Technorati for links to this page." rel="nofollow" class="bookmark_link"><img src="images/bookmark/technorati.png" alt="Technorati" /></a></li>
  				<li class="bookmark_link"><a id="bookmark_facebook" href="http://www.facebook.com/share.php" onmouseover="bookMark(this);"  target="_blank" style="text-decoration:none;font-size:10px;"><img src="http://static.ak.facebook.com/images/share/facebook_share_icon.gif?55:26981" alt="Facebook" /></a>
  				<li class="bookmark_link"><a href="javascript:void(0);" onclick="SavePDF();" class="sendlink" id="savepdf">Save PDF</a></li>
  				
  			</ul>
				*/



function SavePsPDF()
{
	var contextType	=	getCurrentLeaf();
	if (contextType !='F' && contextType !='B') {
		alert('Please select Front or Back Leaf to generate PDF');
		return false;
	}
	var MessageContent 	= "<DIV id='pdfMessage' style='width:400px;height:150px;display:block;font-size:15px;'><IMG src='include/lightbox/loading.gif'><BR>Please wait while the PDF file is being generated...</DIV>";
	showLightbox(MessageContent,400,150);
	var PdfContent		= '<Div style="display:block;position:relative;height:905px;">';
	PdfContent			+=	document.getElementById('whitebgHead').innerHTML;
	var l=0;
	var r=0;
	var LContext	= new Array();
	var RContext	= new Array();
	for (var i=0; i <dhtmlwindow.tobjects.length; i++) {
		if (dhtmlwindow.tobjects[i].state !='close') {
			if (dhtmlwindow.tobjects[i].contextType == 'F') {
				//Contains the array of context box that will be show on front pdf...
				LContext[l]=dhtmlwindow.tobjects[i];
				l++;
			} else {
				//Contains the array of context box that will be show on back pdf...
				RContext[r]=dhtmlwindow.tobjects[i];
				r++;
			}
		}
	}
	// Sort the conext window according to their Zindex value
	// Means the Zindex value that is lower will start to draw on pdf 1st 
	if (LContext.length != 0) {
		LContext.sort(sortFunct);
	}
	if (RContext.length != 0) {
		RContext.sort(sortFunct);
	}

	var NewPage 	= 	false;
	var ppane 		= 	getPrintPaneCoordinates();
	
	var adultNotesobj = document.getElementById('A_notesText');
	var kidsNotesobj  = document.getElementById('K_notesText');
	
	//----------------------------------------------------------------------------------------------
	// Drawing the Context Window on FrontPDf...
	//----------------------------------------------------------------------------------------------
	for (var i=0; i < LContext.length; i++) {
		if (contextType != 'F') {
			LContext[i].style.display='block';
		}
		var Back 	=	LContext[i].resizearea.style.background;
		LContext[i].resizearea.style.background='none';
		if (LContext[i].id == '_ch1' && typeof adultNotesobj != 'undefined' && adultNotesobj != null) {
			var AdultNotes = adultNotesobj.value;
			var tmpContentarea = LContext[i].contentarea.innerHTML;
			LContext[i].contentarea.innerHTML = '<textarea  class="notesText" style="color: black;">'+AdultNotes+'</textarea>';
			var finalHtml = LContext[i].innerHTML;
			LContext[i].contentarea.innerHTML = tmpContentarea;
			LContext[i].contentarea.getElementsByTagName('TEXTAREA')[0].value=AdultNotes;
		} else if (LContext[i].id == '_ch2' && typeof kidsNotesobj != 'undefined' && kidsNotesobj != null) {
			var KidsNotes = kidsNotesobj.value;
			var tmpContentarea = LContext[i].contentarea.innerHTML;
			LContext[i].contentarea.innerHTML = '<textarea  class="notesText" style="color: black;">'+KidsNotes+'</textarea>';
			var finalHtml = LContext[i].innerHTML;
			LContext[i].contentarea.innerHTML = tmpContentarea;
			LContext[i].contentarea.getElementsByTagName('TEXTAREA')[0].value=KidsNotes;
		} else {	
			var KakuroHeight = LContext[i].contentarea.offsetHeight;			
			if (LContext[i].id.indexOf('ak') != -1 && KakuroHeight > 243 && KakuroHeight < 252 ) {
				LContext[i].contentarea.style.paddingBottom='11px';	
			}
			var finalHtml = LContext[i].innerHTML;
			LContext[i].contentarea.style.paddingBottom='0px';
			
		}
		var width 	= 	(LContext[i].offsetWidth-2)+'px';
		var height 	= 	(LContext[i].offsetHeight-2)+'px';
		var top		= 	((LContext[i].offsetTop - ppane['top'])+65)+'px';
		var left	= 	((LContext[i].offsetLeft - ppane['left']))+'px';
		
		PdfContent	+= '<div id="'+LContext[i].id+'" class="dhtmlwindow" style="display:block; position: absolute; width: '+width+';left: '+left+';top: '+top+';height: '+height+';visibility: visible;z-index:'+LContext[i].style.zIndex+';">';	
		PdfContent	+= finalHtml;
		PdfContent	+= '</div>';
		LContext[i].resizearea.style.background=Back;
		if (contextType != 'F') {
			LContext[i].style.display='none';
		}
	}
	//----------------------------------------------------------------------------------------------
	// Drawing the Context Window on BackPDf...
	//----------------------------------------------------------------------------------------------
	PdfContent += "</div>";

	PdfContent += "<!-- --------- Page Break --------- -->";
	PdfContent += "<div style='page-break-before: always;display:block;position:relative;'><BR style='line-height:2px;'>";
	PdfContent += document.getElementById('whitebgBack').innerHTML;
	
	for (var i=0; i < RContext.length; i++) {
		if (contextType != 'B') {
			RContext[i].style.display='block';
		}
		var Back 	=	RContext[i].resizearea.style.background;
		RContext[i].resizearea.style.background='none';
		if (RContext[i].id == 'ch1' && typeof adultNotesobj != 'undefined' && adultNotesobj != null) {
			var AdultNotes = adultNotesobj.value;
			var tmpContentarea = RContext[i].contentarea.innerHTML;
			RContext[i].contentarea.innerHTML = '<textarea  class="notesText" style="color: black;">'+AdultNotes+'</textarea>';
			var finalHtml = RContext[i].innerHTML;
			RContext[i].contentarea.innerHTML = tmpContentarea;
			RContext[i].contentarea.getElementsByTagName('TEXTAREA')[0].value=AdultNotes;
		} else if (RContext[i].id == 'ch2' && typeof kidsNotesobj != 'undefined' && kidsNotesobj != null) {
			var KidsNotes = kidsNotesobj.value;
			var tmpContentarea = RContext[i].contentarea.innerHTML;
			RContext[i].contentarea.innerHTML = '<textarea  class="notesText" style="color: black;">'+KidsNotes+'</textarea>';
			var finalHtml = RContext[i].innerHTML;
			RContext[i].contentarea.innerHTML = tmpContentarea;
			RContext[i].contentarea.getElementsByTagName('TEXTAREA')[0].value=KidsNotes;
		} else {
			var KakuroHeight = RContext[i].contentarea.offsetHeight;			
			if (RContext[i].id.indexOf('ak') != -1 && KakuroHeight > 243 && KakuroHeight < 252 ) {
				RContext[i].contentarea.style.paddingBottom='11px';	
			}
			var finalHtml = RContext[i].innerHTML;
			LContext[i].contentarea.style.paddingBottom='0px';
		}
		
		var width 	= 	(RContext[i].offsetWidth-2)+'px';
		var height 	= 	(RContext[i].offsetHeight-2)+'px';
		var top		= 	((RContext[i].offsetTop - ppane['top'])+66)+'px';
		var left	= 	((RContext[i].offsetLeft - ppane['left']))+'px';
		PdfContent	+= '<div id="'+RContext[i].id+'" class="dhtmlwindow" style="display:block; position: absolute; width: '+width+';left: '+left+';top: '+top+';height: '+height+';visibility: visible;z-index:'+RContext[i].style.zIndex+'">';	
		PdfContent	+= finalHtml;
		PdfContent	+= '</div>';
		RContext[i].resizearea.style.background=Back;
		if (contextType != 'B') {
			RContext[i].style.display='none';
		}
	}

	PdfContent += "</div>";
	//----------------------------------------------------------------------------------------
	// HTML for PDF is ready Now Generate the PDF...
	//----------------------------------------------------------------------------------------
	var xmlhttp = zXmlHttp.createRequest();
	var url = 'include/html2ps/samples/generatePdf.php';
	if (xmlhttp) {
		var params = 'pdfcontent='+escape(PdfContent);
		xmlhttp.open('POST',url,true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		//xmlhttp.setRequestHeader("Content-length", params.length);
		//xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if (isUrl(xmlhttp.responseText)) {
						document.getElementById('pdfMessage').innerHTML='Your PDF has been generated.<BR> <A href="'+xmlhttp.responseText+'" onclick="hideLightbox();" target="_blank" >Click here to download </A>';
					} else {
						document.getElementById('pdfMessage').innerHTML='<font style="color:red;font-weight:bold;font-size:12px;">Sorry,Your PDF was not generated.</Font>';
						//document.getElementById('pdfMessage').innerHTML=xmlhttp.responseText;
					}
				} else {
					alert("AJAX Error :"+xmlhttp.statusText);
				}
			}
		}
		xmlhttp.send(params);
	}

}