function zoom(magnitude)	{	
	izoom=window.frames['img_scroll'].document.getElementById('zoom').value*magnitude	
	if(izoom>=0.25 && izoom<=8)	{
		document.getElementById('zoom').value=izoom		
		imode=document.getElementById('img_mode').value
		if(parent.document.getElementById('get_img_zoom'))	{
			window.frames['img_scroll'].document.getElementById('img_full_cenx').value=document.getElementById('img_x').value
			window.frames['img_scroll'].document.getElementById('img_full_ceny').value=document.getElementById('img_y').value
			document.getElementById('img_full_cenx').value=document.getElementById('img_x').value
			document.getElementById('img_full_ceny').value=document.getElementById('img_y').value			
			window.frames['img_scroll'].execAjaxImgZoom('get_img_zoom','img_x,img_y,img_full_cenx,img_full_ceny,img_mode','innerHTML','load_img_zoom')
		}
		ifull_cenx=window.frames['img_scroll'].document.getElementById('img_full_cenx').value
		ifull_ceny=window.frames['img_scroll'].document.getElementById('img_full_ceny').value
		window.frames['img_scroll'].location.href="include/start/img_scroll.php?img_mode="+imode+"&img_full_cenx="+ifull_cenx+"&img_full_ceny="+ifull_ceny+"&zoom="+izoom;		
	}
}
function beginOnClick()	{
	document.location.href="register"
}
function modeOnChange()	{
	if(window.frames['img_scroll'].document.getElementById('img_mode').value==1)	{
		window.frames['img_scroll'].document.getElementById('img_mode').value=2
		document.getElementById('img_mode').value=2
	}
	else	{
		window.frames['img_scroll'].document.getElementById('img_mode').value=1	
		document.getElementById('img_mode').value=1
	}
	window.frames['img_scroll'].execAjaxImgFull('get_img_full','get_img_full','img_full_cenx,img_full_ceny,img_mode','src','load_img_full')
	if(document.getElementById('get_img_zoom'))
		execAjaxImgZoom('get_img_zoom','img_x,img_y,img_full_cenx,img_full_ceny,img_mode','innerHTML','load_img_zoom')
}

function loginOnClick()	{
	document.getElementById('info1').innerHTML=document.getElementById('js_message_please_wait').value
	execAjaxRequest('check_user_login','info1','login,password','innerHTML')
}

function registerOnClick()	{
	document.getElementById('info1').innerHTML=document.getElementById('js_message_please_wait').value
	execAjaxRequest('register_user','info1','login,password,rpassword,color,link,descript,verify','innerHTML')
}

function homeLocOnClick()	{
	document.getElementById('info2').innerHTML=document.getElementById('js_message_please_wait').value
	execAjaxRequest('change_home_location','info2','img_x,img_y','innerHTML')
}

function profileOnClick()	{
	document.getElementById('info1').innerHTML=document.getElementById('js_message_please_wait').value
	execAjaxRequest('change_user_data','info1','link,descript,dat','innerHTML')
}

function changePwdOnClick()	{
	document.getElementById('info1').innerHTML=document.getElementById('js_message_please_wait').value
	execAjaxRequest('change_user_data','info1','password,new_password,rnew_password,pwd','innerHTML')
}

function changeVisibility(action)	{	
	document.getElementById('pixel_info').style.visibility=action	
}

function pwdOnKeyDown(e)	{
	if(e.keyCode==13) loginOnClick()
}

function bodyOnLoad()	{
	/*
	zoomx=document.getElementById('zoom').value
	fX=250-(12*zoomx)
	fY=250-(12*zoomx)
	window.frames['img_scroll'].document.getElementById('frame').style.left=fX+'px'
	window.frames['img_scroll'].document.getElementById('frame').style.top=fY+'px'
	if(document.getElementById('get_img_zoom'))
		window.frames['img_scroll'].document.getElementById('frame').style.visibility='visible'
	*/
}

function simgOnLoad()	{
	if(document.getElementById('get_img_full'))	{
		zoomx=document.getElementById('zoom').value
		document.getElementById('get_img_full').style.left='0px'
		document.getElementById('get_img_full').style.top='0px'		
		fX=findPosX(document.getElementById('frame'))
		fY=findPosY(document.getElementById('frame'))
		if(!fX || !fY)	{
			fX=335-(12*zoomx)
			fY=290-(12*zoomx)
		}
		document.getElementById('frame').style.left=fX+'px'
		document.getElementById('frame').style.top=fY+'px'
		if(parent.document.getElementById('get_img_zoom'))
			document.getElementById('frame').style.visibility='visible'
	}
	if(document.getElementById('load_img_full'))	{
		document.getElementById('load_img_full').style.visibility='hidden'
		document.getElementById('loading').value=0
	}
	//document.getElementById('img_scroll').style.zIndex=0;
}

function simgOnMouseOut(e,im_max_x,im_max_y,sf_max_x,sf_max_y)	{
	if(document.getElementById('sdraw').value==1)
		simgOnMouseUp(e,im_max_x,im_max_y,sf_max_x,sf_max_y)
}

function simgOnMouseOver()	{	
	changeVisibility('hidden')
	document.getElementById('glass').style.cursor='pointer'
}

function simgOnMouseDown(e)	{	
	if(document.getElementById('loading').value==0)	{
		mx=e.clientX
		my=e.clientY
		mx2=e.clientX-findPosX(document.getElementById('frame'))
		my2=e.clientY-findPosY(document.getElementById('frame'))
		document.getElementById('sdraw').value=1	
	}
}

function simgOnMouseUp(e,im_max_x,im_max_y,sf_max_x,sf_max_y)	{
	if(document.getElementById('loading').value==0)	{
		zoomx=document.getElementById('zoom').value
		document.getElementById('sdraw').value=0
		cX=findPosX(document.getElementById('get_img_full'))
		cY=findPosY(document.getElementById('get_img_full'))
			
		if(cX!=0 && cY!=0)	{		
			document.getElementById('img_full_cenx').value=parseInt(document.getElementById('img_full_cenx').value)-cX/zoomx
			document.getElementById('img_full_ceny').value=parseInt(document.getElementById('img_full_ceny').value)-cY/zoomx
			parent.document.getElementById('img_full_cenx').value=Math.round(document.getElementById('img_full_cenx').value)
			parent.document.getElementById('img_full_ceny').value=Math.round(document.getElementById('img_full_ceny').value)
			if(document.getElementById('img_full_cenx').value<0) {
				parent.document.getElementById('img_full_cenx').value=0
				document.getElementById('img_full_cenx').value=0
			}
			if(document.getElementById('img_full_ceny').value<0) {
				parent.document.getElementById('img_full_ceny').value=0
				document.getElementById('img_full_ceny').value=0
			}
			if(document.getElementById('img_full_cenx').value>sf_max_x) {
				parent.document.getElementById('img_full_cenx').value=sf_max_x
				document.getElementById('img_full_cenx').value=sf_max_x
			}
			if(document.getElementById('img_full_ceny').value>sf_max_y) {
				parent.document.getElementById('img_full_ceny').value=sf_max_y
				document.getElementById('img_full_ceny').value=sf_max_y
			}		
			document.getElementById('load_img_full').style.left='250px'
			document.getElementById('load_img_full').style.top='0px'		
			execAjaxImgFull('get_img_full','get_img_full','img_full_cenx,img_full_ceny,img_mode','src')
			document.getElementById('load_img_full').style.visibility='visible';
			document.getElementById('loading').value=1
		}	
		else	{
			document.getElementById('img_x').value=parent.document.getElementById('img_full_posx').value
			document.getElementById('img_y').value=parent.document.getElementById('img_full_posy').value	
			if(parent.document.getElementById('get_img_zoom'))	{
				var x,y;
				x=e.clientX-(12*zoomx)
				y=e.clientY-(12*zoomx)			
				parent.document.getElementById('img_x').value=parent.document.getElementById('img_full_posx').value
				parent.document.getElementById('img_y').value=parent.document.getElementById('img_full_posy').value								
				parent.execAjaxImgZoom('get_img_zoom','img_x,img_y,img_full_cenx,img_full_ceny,img_mode','innerHTML','load_img_zoom')
				imgX=parent.document.getElementById('img_x').value
				imgY=parent.document.getElementById('img_y').value		
				imgMinX=parseInt(document.getElementById('img_full_cenx').value)-(im_max_x/2)
				imgMinY=parseInt(document.getElementById('img_full_ceny').value)-(im_max_y/2)
				imgMaxX=im_max_x+parseInt(document.getElementById('img_full_cenx').value)-(im_max_x/2)
				imgMaxY=im_max_y+parseInt(document.getElementById('img_full_ceny').value)-(im_max_y/2)
				if(imgX>imgMinX && imgY>imgMinY && imgX<imgMaxX && imgY<imgMaxY)	{
					document.getElementById('frame').style.left=x+'px'
					document.getElementById('frame').style.top=y+'px'
				}
				document.getElementById('frame').style.visibility='visible';
			}
			if(document.body.scrollLeft)	{
				document.getElementById('pixel_info').style.left=(e.clientX+12+document.body.scrollLeft)+'px'
				document.getElementById('pixel_info').style.top=(e.clientY-12+document.body.scrollLeft)+'px'
			}
			else	{
				document.getElementById('pixel_info').style.left=(e.clientX+12+document.documentElement.scrollLeft)+'px'
				document.getElementById('pixel_info').style.top=(e.clientY-12+document.documentElement.scrollTop)+'px'		
			}		
			parent.execAjaxPixelInfo('pixel_info','img_full_posx,img_full_posy','innerHTML')
			setTimeout("changeVisibility('visible')",1)	
		}
	}
}

function simgOnMouseMove(obj,e,sf_max_x,sf_max_y,im_max_x,im_max_y) {
	
		zoomx=document.getElementById('zoom').value
		document.getElementById('glass').style.cursor='pointer'
		if(document.getElementById('sdraw').value==1)	{
			if(document.getElementById('loading').value==0)	{		
				document.getElementById('get_img_full').style.left=(e.clientX-mx)+'px'
				document.getElementById('get_img_full').style.top=(e.clientY-my)+'px'
				document.getElementById('frame').style.left=(e.clientX-mx2)+'px'
				document.getElementById('frame').style.top=(e.clientY-my2)+'px'				
				document.getElementById('pixel_info').style.visibility='hidden'		
			}
		}	
		else	{			
			coordX=Math.round(parseInt(parent.document.getElementById('img_full_cenx').value)+(e.clientX/zoomx)-(im_max_x/(2)))
			coordY=Math.round(parseInt(parent.document.getElementById('img_full_ceny').value)+(e.clientY/zoomx)-(im_max_y/(2)))
			if(coordX>0 && coordX<=sf_max_x && coordY>0 && coordY<=sf_max_y)	{		
				parent.document.getElementById('img_full_posx').value=Math.round(coordX)
				parent.document.getElementById('img_full_posy').value=Math.round(coordY)
			}				
		}	
}

function simgOnClick(e,im_max_x,im_max_y)	{
	if(document.getElementById('loading').value==0)	{
		document.getElementById('pixel_info').innerHTML='<div><img src="../../template/free_pixels/graphics/loading_free_pixels.gif"/><br/>'+document.getElementById('js_message_please_wait').value+'</div>'
	}
}

function findPosX(obj)	{
	var posX = 0
	if (obj && obj.offsetParent) {
		posX = obj.offsetLeft
		while (obj = obj.offsetParent) {
			posX += obj.offsetLeft
		}
	}
	return posX
}

function findPosY(obj)	{
	var posY = 0
	if (obj && obj.offsetParent) {
		posY = obj.offsetTop
		while (obj = obj.offsetParent) {
			posY += obj.offsetTop
		}
	}
	return posY
}

function navigate(x,y,im_max_x,im_max_y,sf_max_x,sf_max_y,type)	{
	zoomx=document.getElementById('zoom').value
	window.frames['img_scroll'].document.getElementById('loading').value=1
	window.frames['img_scroll'].document.getElementById('frame').style.visibility='visible'	
	iX=parseInt(document.getElementById('img_full_cenx').value)+x
	iY=parseInt(document.getElementById('img_full_ceny').value)+y	
	if(type==1)	{
		iX=parseInt(document.getElementById('img_x').value)+x
		iY=parseInt(document.getElementById('img_y').value)+y		
	}		
	if(iX>=0 && iY>=0 && iX<=sf_max_x && iY<=sf_max_y)	{
		document.getElementById('img_full_cenx').value=iX
		document.getElementById('img_full_ceny').value=iY
		document.getElementById('img_x').value=parseInt(document.getElementById('img_x').value)+x
		document.getElementById('img_y').value=parseInt(document.getElementById('img_y').value)+y
		window.frames['img_scroll'].document.getElementById('img_x').value=iX
		window.frames['img_scroll'].document.getElementById('img_y').value=iY
		window.frames['img_scroll'].document.getElementById('img_full_cenx').value=iX
		window.frames['img_scroll'].document.getElementById('img_full_ceny').value=iY
		execAjaxImgZoom('get_img_zoom','img_x,img_y,img_full_cenx,img_full_ceny,img_mode,ccolor','innerHTML','load_img_zoom')
		window.frames['img_scroll'].execAjaxImgFull('get_img_full','get_img_full','img_full_cenx,img_full_ceny,img_mode','src')
		if(type==1)	{
			window.frames['img_scroll'].document.getElementById('frame').style.left=(335-(12*zoomx))+'px'
			window.frames['img_scroll'].document.getElementById('frame').style.top=(290-(12*zoomx))+'px'
		}		
	}
}

function pixelOnMouseDown()	{
	document.getElementById('draw').value=1
}
function pixelOnMouseUp()	{
	document.getElementById('draw').value=0
}
function pixelOnMouseOver(obj,x,y,color,id_user)	{
	parent.document.getElementById('img_full_posx').value=x
	parent.document.getElementById('img_full_posy').value=y
	if(document.getElementById('draw').value==1)
		pixelDraw(obj,x,y,color,id_user)
}
function pixelOnMouseClick(obj,x,y,color,id_user)	{	
		pixelDraw(obj,x,y,color,id_user)
}

function pixelDraw(obj,x,y,color,id_user)	{
	document.getElementById('pixel_x').value=x
	document.getElementById('pixel_y').value=y	
	 if(id_user && document.getElementById('add_pixels').checked==true)	{	
		if(document.getElementById('pixel_'+x+'_'+y+'').value==0)	{	//add pixel			
			if(document.getElementById('free_pixels').value>0)	{
				if(document.getElementById('img_mode').value==1) obj.style.backgroundColor=color;
				else obj.style.backgroundColor='#'+document.getElementById('ccolor').value
				document.getElementById('pixel_'+x+'_'+y+'').value=id_user
				document.getElementById('free_pixels').value=parseInt(document.getElementById('free_pixels').value)-1;
				window.frames['img_scroll'].execAjaxImgFull('get_img_full','get_img_full','pixel_x,pixel_y,img_full_cenx,img_full_ceny,img_mode,ccolor,add','src','load_img_full')
				inf='P('+x+','+y+') '+document.getElementById('js_message_imz1').value
			}
			else	{
				inf=document.getElementById('js_message_imz2').value			
			}
		}
		else if(document.getElementById('pixel_'+x+'_'+y+'').value==id_user)	{ //change pixel		
			if(document.getElementById('img_mode').value==1) obj.style.backgroundColor=color;
			else obj.style.backgroundColor='#'+document.getElementById('ccolor').value
			window.frames['img_scroll'].execAjaxImgFull('get_img_full','get_img_full','pixel_x,pixel_y,img_full_cenx,img_full_ceny,img_mode,ccolor,change','src','load_img_full')
			inf='P('+x+','+y+') '+document.getElementById('js_message_imz5').value+' #'+document.getElementById('ccolor').value
		}
		else inf='P('+x+','+y+') '+document.getElementById('js_message_imz4').value
	}
	if(id_user && document.getElementById('rem_pixels').checked==true)	{	//remove pixel	
		if(document.getElementById('pixel_'+x+'_'+y+'').value==id_user)	{
			obj.style.backgroundColor='#eeeeee' 
			document.getElementById('pixel_'+x+'_'+y+'').value=0
			document.getElementById('free_pixels').value=parseInt(document.getElementById('free_pixels').value)+1;
			window.frames['img_scroll'].execAjaxImgFull('get_img_full','get_img_full','pixel_x,pixel_y,img_full_cenx,img_full_ceny,img_mode,remove','src','load_img_full')
			inf='P('+x+','+y+') '+document.getElementById('js_message_imz3').value
		}	
		else inf='P('+x+','+y+') '+document.getElementById('js_message_imz4').value
	}
	document.getElementById('info2').innerHTML=inf		
}

function paletteOnClick(color)	{
	document.getElementById('ccolor_box').style.backgroundColor='#'+color
	document.getElementById('ccolor').value=color
	execAjaxRequest('change_color','ccolor','ccolor','value')
}

function txtValidate(e,el)	{
	ck=e.keyCode;		
	if((ck>=65 && ck<=90) || ck==32 || ck==109 || ck==8 || ck==46)
		return true;
	else		{
		e.returnValue=false 
		e.cancelBubble = true
		if(e.preventDefault)	{
			e.stopPropagation()
			e.preventDefault()
		}
	}
}

function numtxtValidate(e)	{
	ck=e.keyCode;		
	if((ck>=65 && ck<=90) || (ck>=48 && ck<=57) || ck==32 || ck==109 || ck==8 || ck==46)
		return true;
	else		{
		e.returnValue=false; 
		e.cancelBubble = true
		if(e.preventDefault)	{
			e.stopPropagation()
			e.preventDefault()
		}
	}
}

function numValidate(e)	{
	ck=e.keyCode;		
	if((ck>=48 && ck<=57) || ck==8 || ck==46)
		return true;
	else		{
		e.returnValue=false 
		e.cancelBubble = true
		if(e.preventDefault)	{
			e.stopPropagation()
			e.preventDefault()
		}
	}
}

function showHideContent(el)	{
	if(document.all)
		if(document.all[''+el].style.display=="none")
			document.all[''+el].style.display="block";
		else
			document.all[''+el].style.display="none";
	else	{
		if(document.getElementById(el).style.display=="none")
			document.getElementById(el).style.display="block";
		else
			document.getElementById(el).style.display="none";			
	}		
}
