// JavaScript Document

function publish_quote(id){
	if(confirm('Цитата будет опубликована. Хотите редактировать ее?')){
		location.href=url;
	}
}

function sort_status(url,status){
	if((status==0)||(status==1)) url+='&status='+status;
	location.href=url;
	return true;
}

function change_status(url,status, id){
	if((status==0)||(status==1)) url+='&new_status='+status+"&id="+id;
	location.href=url;
	return true;
}

function add_textarea_field(i) {
    var cnt = document.getElementById('text' + i + '_cnt');
    if(!cnt) return;
	var fel = document.createElement('textarea');
	var tarea_label = document.createTextNode("Текст цитаты");
	var tags_label = document.createTextNode("Ключевые слова");
    fel.id = "text["+cnt.value+"]";
    fel.name="text["+cnt.value+"]";
	var tag = document.createElement('input');
    tag.id = "tags["+cnt.value+"]";
    tag.name="tags["+cnt.value+"]";
    //document.getElementById('photo_container').innerHTML+="<br>";
	fel.setAttribute("cols","70");
	fel.setAttribute("rows","8");
	document.getElementById('textarea_container').appendChild(document.createElement('hr'));
	document.getElementById('textarea_container').appendChild(document.createElement('br'));
	document.getElementById('textarea_container').appendChild(tarea_label);
	document.getElementById('textarea_container').appendChild(document.createElement('br'));
	document.getElementById('textarea_container').appendChild(fel);
	document.getElementById('textarea_container').appendChild(document.createElement('br'));
	document.getElementById('textarea_container').appendChild(tags_label);
	document.getElementById('textarea_container').appendChild(tag);
	document.getElementById('textarea_container').appendChild(document.createElement('br'));
	
          //alert(cnt.value);
  	//alert(document.getElementById('textarea_container').innerHTML);
    cnt.value++;
	document.getElementById(fel.id).focus();
}


function refresh_code(){
var cap=document.getElementById('cap');
cap.src='kcaptcha/index.php?s='+Math.random();
return false;
}

function valid_reg_form(){
	if(document.getElementById("user_name").value==""){
		alert("Вы неправильно ввели имя пользователя"); return false;
	}
	if(document.getElementById("pass").value==""){
		alert("Вы неправильно ввели пароль"); return false;
	}
	if(document.getElementById("pass").value!=document.getElementById("retype_pass").value){
		alert("Вы неправильно подтвердили пароль"); return false;
	}
	if(!echeck(document.getElementById('mail').value)) return false;
	return true;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Неверный е-мэйл")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Неверный е-мэйлD")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Неверный е-мэйл")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Неверный е-мэйл")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Неверный е-мэйл")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Неверный е-мэйл")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Неверный е-мэйл")
		    return false
		 }

 		 return true					
	}


