// JavaScript Document

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function simg(path,con,zone,des,wdth,ht)
{
	
	var winW = 630, winH = 460;
	var imgWidth,imgHeight;
	var origW, origH;
	wdth=wdth+20;
	ht=ht+160;
	imgWidth = wdth;
	imgHeight = ht;
	if (parseInt(navigator.appVersion)>3) 
	{
		if (navigator.appName=="Netscape") 
		{
			winW = window.innerWidth - 16;
			winH = window.innerHeight - 16;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) 
		{
			winW = document.body.offsetWidth - 20;
			winH = f_clientHeight() - 20 ;
		}
	}
	//alert(winH+"-"+ht);
	if(winW<wdth)
	{
		imgWidth=winW - 50;
		imgHeight = imgWidth * ht / wdth;
		//alert (winH);
		if(winH<imgHeight)
		{
			origH=imgHeight;
			imgHeight=winH - 170;	
			imgWidth=imgHeight * imgWidth / origH;
		}
	}
	else if(winH<ht)
	{
		imgHeight=winH - 170;
		imgWidth = imgHeight * wdth / ht;
	}
	document.getElementById('jump').style.display="none";
	document.getElementById('imagelayer').innerHTML ='<table border="0" width="5" cellspacing="0" cellpadding="0" align="center"><tr><td><div onclick="hideImage();">Close X</div></td><td>&nbsp;</td></tr><tr bgcolor="#FFFFFF"><td colspan="2"><table border="0" cellspacing="2" cellpadding="2" align="center" style="border:1px solid #000000;"><tr bgcolor="#FFFFFF"><td colspan="3" align="center"><img id="img" width="'+(imgWidth-20)+'" height="'+(imgHeight-140)+'" src="'+path+'" alt="larger image" border="0" /></td></tr><tr bgcolor="#FFFFFF"><td width="39%" align="left" nowrap><b>Grown by/Contributor</b></td><td width="1%"><b>:</b></td><td align="left" nowrap>&nbsp;'+con+'</td></tr><tr><td align="left" nowrap><b>Zone</b></td><td width="1%"><b>:</b></td><td align="left" nowrap>&nbsp;'+zone+'</td></tr><tr><td align="left"><b>Description</b></td><td width="1%"><b>:</b></td><td align="left">&nbsp;'+des+'</td></tr></table></td></tr></table>';
	
	
	document.getElementById('imagelayer').style.display="block";
	document.getElementById('masklayer1').style.display="block";
	if(parseInt(f_clientWidth())>766)
	document.getElementById('masklayer1').style.width=f_clientWidth()+"px";
	else
	document.getElementById('masklayer1').style.width="766px";
	document.getElementById('imagelayer').style.top = ((parseInt(f_clientHeight())-parseInt(document.getElementById('imagelayer').offsetHeight))/2+parseInt(f_scrollTop()))+"px";
	document.getElementById('imagelayer').style.left = ((parseInt(f_clientWidth())-parseInt(document.getElementById('imagelayer').offsetWidth))/2+parseInt(f_scrollLeft()))+"px";
}
function hideImage() {
	//alert("hello");
	document.getElementById('imagelayer').innerHTML = "";
	document.getElementById('imagelayer').style.display="none";
	document.getElementById('masklayer1').style.display="none";
	document.getElementById('jump').style.display="block";
	
}
function upload()
{

	document.getElementById('imagelayer').innerHTML = '<table border="0" cellspacing="0" cellpadding="0" align="center"><tr><td><div onclick="hideImage();">Close X</div></td><td>&nbsp;</td></tr><tr><td colspan="2"><table border="0" cellspacing="0" cellpadding="0" align="left"  style="border:1px solid #000000;" width="100%"><tr><td width="35%" align="right"><table id="abc" bgcolor="#FFFFFF" border="0" height="150" width="400" cellspacing="0" cellpadding="0"  align="center"><tr style="padding-top:5px;"><td align="right">Grown by/Contributor :</td><td align="left"><input type="text" name="contributor" id="contributor" value=""></td></tr><tr><td align="right">Zone :</td><td align="left"><input type="text" name="zone" id="zone" value=""></td></tr><tr><td align="right">Description :</td><td align="left"><input type="text" name="description" id="description" value=""></td></tr><tr><td align="right">Select Image :</td><td align="left"><input type="file" name="image" id="image"></td></tr><tr><td align="right">Security Code: </td><td align="left"><input type="text" name="securitycode" id="securitycode" value=""><img src="verificationimage.php"></td></tr><tr><td>&nbsp;</td><td align="left"><input type="button" name="Submit" value="Submit" onclick="saveimg();"></td></tr></table></td></tr></table>';
	document.getElementById('imagelayer').style.display="block";
	document.getElementById('masklayer1').style.display="block";
	
	if(parseInt(f_clientWidth())>766)
	document.getElementById('masklayer1').style.width=f_clientWidth()+"px";
	else
	document.getElementById('masklayer1').style.width="766px";
	
	document.getElementById('imagelayer').style.top = ((parseInt(f_clientHeight())-parseInt(document.getElementById('abc').offsetHeight))/2+parseInt(f_scrollTop()))+"px";
	document.getElementById('imagelayer').style.left = ((parseInt(f_clientWidth())-parseInt(document.getElementById('abc').width))/2+parseInt(f_scrollLeft()))+"px";
	
}

function check1()
{
	if(document.getElementById('masklayer1'))
	{
		if(parseInt(f_clientWidth())>766)
			document.getElementById('masklayer1').style.width=f_clientWidth()+"px";
		else
			document.getElementById('masklayer1').style.width="766px";
	}
	if(document.getElementById('img'))
	{
		var winW = 630, winH = 460;
		var imgWidth,imgHeight;
		var origW, origH;
		var wdth = document.getElementById('img').width + 20;
		var ht=document.getElementById('img').height + 80 ;
		imgWidth = wdth;
		imgHeight = ht;
		if (parseInt(navigator.appVersion)>3) 
		{
			if (navigator.appName=="Netscape") 
			{
				winW = window.innerWidth - 16;
				winH = window.innerHeight - 16;
				var margin=500;
			}
			if (navigator.appName.indexOf("Microsoft")!=-1) 
			{
				winW = document.body.offsetWidth - 20;
				winH = f_clientHeight() - 20 ;
				var margin=0;
			}
		}
		
		if(winW<wdth)
		{
			imgWidth=winW - 200;
			imgHeight = imgWidth * ht / wdth;
			
			if(winH<imgHeight)
			{
				origH=imgHeight;
				imgHeight=winH - 200;	
				imgWidth=imgHeight * imgWidth / origH;
			}
		}
		else if(winH<ht)
		{
			imgHeight=winH - 200;
			imgWidth = imgHeight * wdth / ht;
		}
		
		document.getElementById('img').height=imgHeight;
		document.getElementById('img').width=imgWidth;
	}
	if(document.getElementById('img'))
	{
		document.getElementById('imagelayer').style.top = ((parseInt(f_clientHeight())-parseInt(document.getElementById('imagelayer').offsetHeight))/2+parseInt(f_scrollTop()))+"px";
		document.getElementById('imagelayer').style.left = ((parseInt(f_clientWidth())-parseInt(document.getElementById('imagelayer').offsetWidth))/2+parseInt(f_scrollLeft()))+"px";
	}
	
	if(document.getElementById('abc'))
	{
		document.getElementById('imagelayer').style.top = ((parseInt(f_clientHeight())-parseInt(document.getElementById('abc').offsetHeight))/2+parseInt(f_scrollTop()))+"px";
		document.getElementById('imagelayer').style.left = ((parseInt(f_clientWidth())-parseInt(document.getElementById('abc').width))/2+parseInt(f_scrollLeft()))+"px";
	}
	
	if(document.getElementById('loaderimg'))
	{
		document.getElementById('loader').style.top = ((parseInt(f_clientHeight())-parseInt(document.getElementById('loaderimg').height))/2+parseInt(f_scrollTop()))+"px";
		document.getElementById('loader').style.left = ((parseInt(f_clientWidth())-parseInt(document.getElementById('loaderimg').width))/2+parseInt(f_scrollLeft()))+"px";
	}
}
function check()
{
	
	if(document.getElementById('masklayer1'))
	{
		if(parseInt(f_clientWidth())>766)
			document.getElementById('masklayer1').style.width=f_clientWidth()+"px";
		else
			document.getElementById('masklayer1').style.width="766px";
	}
	
	if(document.getElementById('img'))
	{
		document.getElementById('imagelayer').style.top = ((parseInt(f_clientHeight())-parseInt(document.getElementById('imagelayer').offsetHeight))/2+parseInt(f_scrollTop()))+"px";
		document.getElementById('imagelayer').style.left = ((parseInt(f_clientWidth())-parseInt(document.getElementById('imagelayer').offsetWidth))/2+parseInt(f_scrollLeft()))+"px";
	}
	
	if(document.getElementById('abc'))
	{
		document.getElementById('imagelayer').style.top = ((parseInt(f_clientHeight())-parseInt(document.getElementById('abc').offsetHeight))/2+parseInt(f_scrollTop()))+"px";
		document.getElementById('imagelayer').style.left = ((parseInt(f_clientWidth())-parseInt(document.getElementById('abc').width))/2+parseInt(f_scrollLeft()))+"px";
	}
	
	if(document.getElementById('loaderimg'))
	{
		document.getElementById('loader').style.top = ((parseInt(f_clientHeight())-parseInt(document.getElementById('loaderimg').height))/2+parseInt(f_scrollTop()))+"px";
		document.getElementById('loader').style.left = ((parseInt(f_clientWidth())-parseInt(document.getElementById('loaderimg').width))/2+parseInt(f_scrollLeft()))+"px";

	
	}
}
window.onscroll=check;

function saveimg()
{
	if(document.getElementById("contributor").value=="")
	{
		alert("Please enter Contributor Name.");
		document.getElementById("contributor").focus();
		return;
	}
	else if(document.getElementById("zone").value=="")
	{
		alert("Please enter Zone.");
		document.getElementById("zone").focus();
		return;
	}
	else if(document.getElementById("description").value=="")
	{
		alert("Please enter Description.");
		document.getElementById("description").focus();
		return;
	}
	else
	{
		document.getElementById("flag").value=1;
		document.getElementById("contributor1").value=document.getElementById("contributor").value;
		document.getElementById("zone1").value=document.getElementById("zone").value;
		document.getElementById("description1").value=document.getElementById("description").value;
		//document.getElementById("image1").value=document.getElementById("image").value;
		document.form1.submit();
	}
}
function paging()
{
	var pageno=document.getElementById("pageno").value;
	
	document.getElementById('masklayer1').style.display="block";
	document.getElementById('loader').style.display="block";
	if(parseInt(f_clientWidth())>766)
	document.getElementById('masklayer1').style.width=f_clientWidth()+"px";
	else
	document.getElementById('masklayer1').style.width="766px";
	document.getElementById('loader').style.top = ((parseInt(f_clientHeight())-parseInt(document.getElementById('loaderimg').height))/2+parseInt(f_scrollTop()))+"px";
	document.getElementById('loader').style.left = ((parseInt(f_clientWidth())-parseInt(document.getElementById('loaderimg').width))/2+parseInt(f_scrollLeft()))+"px";
	
	myRequest = new ajaxObject('ajax/paging.php');
	myRequest.callback = function(responseText) {
		document.getElementById('masklayer1').style.display="none";
		document.getElementById('loader').style.display="none";
		document.getElementById('maincontent').innerHTML=responseText;
	}
	var sendString="pageno="+pageno;
	myRequest.update(sendString,'POST');
	
}
function order()
{
	if(document.getElementById("oid").value=="")
	{
		alert("Please enter your Order Id.");
		document.getElementById("oid").focus();
		return;
	}
	else
	{
		var orderid=document.getElementById("oid").value;
		document.getElementById('masklayer').style.display="block";
		document.getElementById('loader').style.display="block";
		if(parseInt(f_clientWidth())>766)
		document.getElementById('masklayer').style.width=f_clientWidth()+"px";
		else
		document.getElementById('masklayer').style.width="766px";
		document.getElementById('loader').style.top = ((parseInt(f_clientHeight())-parseInt(document.getElementById('loaderimg').height))/2+parseInt(f_scrollTop()))+"px";
		document.getElementById('loader').style.left = ((parseInt(f_clientWidth())-parseInt(document.getElementById('loaderimg').width))/2+parseInt(f_scrollLeft()))+"px";
		
		myRequest = new ajaxObject('ajax/order.php');
		myRequest.callback = function(responseText) {
			document.getElementById('masklayer').style.display="none";
			document.getElementById('loader').style.display="none";
			document.getElementById('orderdata').innerHTML=responseText;
		}
		var sendString="orderid="+orderid;
		myRequest.update(sendString,'POST');
	}
}