var FONTSIZE;
function input2div(){
	if(document.motion_editor.motion_title.value.length>15){
		FONTSIZE=75/document.motion_editor.motion_title.value.length;
	} else FONTSIZE='5';
	document.motion_editor.motion_title_fontsize.value=FONTSIZE;


	if (document.motion_editor.motion_title.value.length > 50)	document.motion_editor.motion_title.value = document.motion_editor.motion_title.value.substring(0, 30);
	if (document.motion_editor.motion_desc.value.length > 130)	document.motion_editor.motion_desc.value = document.motion_editor.motion_desc.value.substring(0, 130);
	if (document.motion_editor.motion_name.value.length > 30)	document.motion_editor.motion_name.value = document.motion_editor.motion_name.value.substring(0, 30);

	var desc = document.motion_editor.motion_desc.value;
	desc = desc.replace(/\n/g, "<br />");
	var title = document.motion_editor.motion_title.value;
	title = title.replace(/\n/g, "<br />");

	document.getElementById('motion_t').innerHTML = title;
	document.getElementById('motion_tt').innerHTML = desc;
	/*document.getElementById('motion_tt').innerHTML = document.motion_editor.motion_desc.value;*/
}
function fontSize(direction,inputObj){
	/*FONTSIZE = document.motion_editor.font_tt_size.value;*/
	var size = eval ("document.motion_editor." + inputObj + ".value");
	size = parseFloat(size);
	size = roundPlus(size,1);
	if(direction=='+') size += 0.1;
	if(direction=='-') size -= 0.1;
	form = eval ("document.motion_editor." + inputObj);
	form.value=size;
}
function onliner(){

	document.getElementById('copyright').style.color=document.getElementById('motion_t').style.color;	
	document.getElementById('motion_t').style.fontSize=document.motion_editor.motion_title_fontsize.value+"em";	
	document.getElementById('motion_tt').style.fontSize=document.motion_editor.motion_desc_fontsize.value+"em";	
	document.motion_editor.motion_copyright.value=document.getElementById('copyright').innerHTML;
	/*Установка размеров*/
	document.motion_editor.img_main_w.value=document.getElementById('motion_a').clientWidth;
	document.motion_editor.img_main_h.value=document.getElementById('motion_a').clientHeight;

	document.motion_editor.img_border_w.value=document.getElementById('motion_b').clientWidth;
	document.motion_editor.img_border_h.value=document.getElementById('motion_b').clientHeight;

	document.motion_editor.img_bg_w.value=document.getElementById('motion_c').clientWidth;
	document.motion_editor.img_bg_h.value=document.getElementById('motion_c').clientHeight;

	document.motion_editor.img_img_w.value=document.getElementById('motion_img').clientWidth;
	document.motion_editor.img_img_h.value=document.getElementById('motion_img').clientHeight;

	/*document.getElementById('motion_a').style.width=70+"px";*/
	/*alert(document.getElementById('motion_a').clientWidth)*/;

/*	document.getElementById('motion_t').innerHTML = document.motion_editor.motion_title.value;
	document.getElementById('motion_tt').innerHTML = document.motion_editor.motion_desc.value;*/

	if(document.motion_editor.copyrightbox.checked==true) {
		document.motion_editor.motion_name.disabled=false;
		if(document.motion_editor.motion_name.value!=""){
			document.getElementById('copyright').innerHTML='made by '+document.motion_editor.motion_name.value+' on picshot.ru';
		} else document.getElementById('copyright').innerHTML="picshot.ru";
	}

	if(document.motion_editor.copyrightbox.checked==false){
		document.motion_editor.motion_name.disabled=true;
		document.getElementById('copyright').innerHTML="";
	}
	
	/*/Установка размеров*/
	setTimeout("onliner()",100);
}
function clearing(id){
	if(document.getElementById(id).clearing!="1"){
		document.getElementById(id).value="";
		document.getElementById(id).clearing="1";
	}
}
function check2submit(){
	if(document.motion_loader.SubmitRules.checked==false) document.motion_loader.submit_load.disabled=true;
		else document.motion_loader.submit_load.disabled=false;
}
function checkCheckbox(){
	if(document.motion_editor.copyrightbox.checked==true) {
		document.motion_editor.motion_name.disabled=false;
		if(document.motion_editor.motion_name.value!=""){
			document.getElementById('copyright').innerHTML='made by '+document.motion_editor.motion_name.value+' on picshot.ru';
		} else document.getElementById('copyright').innerHTML="picshot.ru";
	}

	if(document.motion_editor.copyrightbox.checked==false){
		document.motion_editor.motion_name.disabled=true;
		document.getElementById('copyright').innerHTML="";
	}

}
function checkFile(){
	if(document.motion_loader.userfile.value==false){
		alert("Пожалуйста, выберите изображение!");
	    document.motion_loader.userfile.focus();
		return false;
	} else document.motion_loader.submit();
}
function checkNullInput(){
	if(document.motion_editor.motion_title.value==false){
		alert("Вы должны заполнить как минимум заголовок");
	    //document.motion_editor.motion_title.focus();
		return false;
	} else document.motion_editor.submit();
}
function changeFont(whereId,inputId,hiddenName,direction){
	defaultFont = eval("document.motion_editor."+hiddenName+".value");
	if(direction=="back"){
		switch (defaultFont)
		{
		case "Verdana":
			defaultFont="Times New Roman";
			break;
		case "Times New Roman":
			defaultFont="Tahoma";
			break;
		case "Tahoma":
			defaultFont="MS Sans Serif";
			break;
		case "MS Sans Serif":
			defaultFont="Lucida Console";
			break;
		case "Lucida Console":
			defaultFont="Courier New";
			break;
		case "Courier New":
			defaultFont="Comic Sans MS";
			break;
		case "Comic Sans MS":
			defaultFont="Arial";
			break;
		case "Arial":
			defaultFont="Visitor_Rus";
			break;
		case "Visitor_Rus":
			defaultFont="Verdana";
			break;
		}
	}
	if(direction=="forward"){
		switch (defaultFont)
		{
		case "Verdana":
			defaultFont="Visitor_Rus";
			break;
		case "Visitor_Rus":
			defaultFont="Arial";
			break;
		case "Arial":
			defaultFont="Comic Sans MS";
			break;
		case "Comic Sans MS":
			defaultFont="Courier New";
			break;
		case "Courier New":
			defaultFont="Lucida Console";
			break;
		case "Lucida Console":
			defaultFont="MS Sans Serif";
			break;
		case "MS Sans Serif":
			defaultFont="Tahoma";
			break;
		case "Tahoma":
			defaultFont="Times New Roman";
			break;
		case "Times New Roman":
			defaultFont="Verdana";
			break;
		}
	}
document.getElementById(inputId).innerHTML=defaultFont;
document.getElementById(whereId).style.fontFamily=defaultFont;
//eval("document.motion_editor."+hiddenName+".value="+defaultFont);
if(hiddenName=='motion_title_font') document.motion_editor.motion_title_font.value=defaultFont;
if(hiddenName=='motion_desc_font') document.motion_editor.motion_desc_font.value=defaultFont;
}
function roundPlus(x, n) { //x - число, n - количество знаков 
  if(isNaN(x) || isNaN(n)) return false;
  var m = Math.pow(10,n);
  return Math.round(x*m)/m;
}
function rotate(direction,name,url){
	var img0 = "http://" + url + "/upload/tmp/0_" + name;
	var img90 = "http://" + url + "/upload/tmp/90_" + name;
	var img180 = "http://" + url + "/upload/tmp/180_" + name;
	var img270 = "http://" + url + "/upload/tmp/270_" + name;
	
	if(direction=="left"){
		switch (document.getElementById('motion_img').src)
			{
			case img0:
				img=img90;
				degrees=90;
				break;
			case img90:
				img=img180;
				degrees=180;
				break;
			case img180:
				img=img270;
				degrees=270;
				break;
			case img270:
				img=img0;
				degrees=0;
				break;
			}
	}
	if(direction=="right"){
		switch (document.getElementById('motion_img').src)
			{
			case img0:
				img=img270;
				degrees=270;
				break;
			case img90:
				img=img0;
				degrees=0;
				break;
			case img180:
				img=img90;
				degrees=90;
				break;
			case img270:
				img=img180;
				degrees=180;
				break;
			}
	}
	document.getElementById('motion_img').src = img;
	document.motion_editor.imgname.value=degrees + "_" + name;
}

function setType(id,val){
	document.getElementById('pajax').src="/lib/pajax.php?do=moderate&what=type&id=" + id + "&how=" + val;
}
function setCat(id,val){
	document.getElementById('pajax').src="/lib/pajax.php?do=moderate&what=cat&id=" + id + "&how=" + val;
}
function setMod(id,val){
	document.getElementById('pajax').src="/lib/pajax.php?do=moderate&what=moderation&id=" + id + "&how=" + val;
}
function setCom(id,val){
	document.getElementById('pajax').src="/lib/pajax.php?do=moderate&what=comments&id=" + id + "&how=" + val;
}
function show(id,val){
	if(!val){
		var val=document.getElementById(id).style.display;
		if(val=="" || val=="none") document.getElementById(id).style.display="block"; else
		if(val=="block") document.getElementById(id).style.display="none";
	} else document.getElementById(id).style.display=val;
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setCookie( name, value, expire ) {
 time = new Date();
 time.setTime( time.getTime() + expire );
 document.cookie = name + "=" + value + "; expires=" + time.toGMTString();
 return true;
}

function getCookie( name ) {
 var cSIndex = document.cookie.indexOf( name );
 if (cSIndex == -1) return false;
 cSIndex = document.cookie.indexOf( name + "=" )
 if (cSIndex == -1) return false;
 var cEIndex = document.cookie.indexOf( ";", cSIndex + ( name + "=" ).length );
 if (cEIndex == -1) cEIndex = document.cookie.length;
 return document.cookie.substring( cSIndex + ( name + "=" ).length, cEIndex );
}

function delCookie( name ) {
 if ( getCookie( name )) 
  document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function setCenz(){
	if(document.profile.cenzCheckbox.checked==true) {
		if (confirm('Снимая ограничение на цензуру, Вы подтверждаете что являетесь совершеннолетним в соответствии с законом вашей страны и полностью осознаете все возможные последствия.')) {createCookie('cenz','1',360);
		} else document.profile.cenzCheckbox.checked=false;
	}
	else createCookie('cenz','0',360);
}
function setLimit(){
	lmt = document.profile.limit.value;
	createCookie('STDLIMIT',lmt,360);
}
function selectAll(obj) {
  obj.focus();
  obj.select();
};
function zoom(img,type){
	var scroll=document.documentElement.scrollTop;
	scroll=scroll+10;
	document.getElementById('zoom').style.opacity='10%';
	document.getElementById('zoom').style.display="block";
	document.getElementById('zoom').style.position="absolute";
	document.getElementById('zoom').style.left="50%";
	document.getElementById('zoom').style.top=scroll+"px";
	document.getElementById('zoom').style.marginLeft="-300px";
	document.getElementById('zoom').style.padding="10px";
	document.getElementById('zoom').style.border="solid 4px #000";
	document.getElementById('zoom').style.backgroundColor="#FFFEE9";
	document.getElementById('zoom').style.zIndex=9999;
	var arrow = "<div id='zoomArrow'><span class='left'><a onClick=\"sPNI('"+img+"','prev','"+type+"')\"><img src='/img/arlt.gif'></a></span><span class='right'><a onClick=\"sPNI('"+img+"','next','"+type+"')\"><img src='/img/arrt.gif'></a></span></div>";
	document.getElementById('zoom').innerHTML=arrow+"<img onClick='show(\"zoom\",\"none\")' src='/upload/600/"+img+"'/>"+arrow;
}
function pause(ms)
{
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < ms);
}
function sPNI(img,dest,type){
	/*searchPrevNextImg*/
	document.getElementById('pajax').src="/lib/pajax.php?do=search&what=img&img="+img+"&dest="+dest+"&type="+type;
}
