///////////////////////////////////////

function FiendAction(id, status){
	
	if(status==0){
		
		input_box=confirm("Do you want to invite him/her?");
	}
	if(status==2){
		
		input_box=confirm("Do you want to block her/him?");
	}
	if(status==3){
		
		input_box=confirm("Do you want to cancel her/his request?");
	}
	if(status==12){
		
		input_box=confirm("Do want to unblock her/him?");
	}
	if(status==1){
		
		input_box=confirm("Do You want to be a friend with him/her?");
	}
	
	
	if (input_box == true){
		
		location.href='m_friend_action.php?id='+id+'&status='+status;		
	}
	else{
		
	 	return false;
	}
	
}


function send_message(){
	
	var fishka=0;	
	
	for(var i=1; (i <= document.getElementById("num").value); i++){
			
		if(document.getElementById("ch_" + i).checked == true){
			
			var id = document.getElementById("ch_" + i).value;
			fishka=1;
		}
	}	
	
	if(fishka==1){
		
		window.open('send_message.php?id='+id, '0', 'width=500, height=500, scrollbars=yes, resizable=yes, status=yes');
	}	
	else{
		
		alert("Please select any user");
	}
}

function confirm_delete(){
	
	input_box=confirm("Do you want to delete this item?");
	
	if (input_box == true){
		
		return true;
		//document.edit_form.submit();
	}
	else{
		
	 	return false;
	}
}


function all_check(){
	
	if( document.getElementById("this_ch").checked == true ){ 
		
		for(var i=1; i <= document.getElementById("num").value; i++){
			
			document.getElementById("ch_" + i).checked = true;
		}
	}
	else{
		
		for(var i=1; i <= document.getElementById("num").value; i++){
			
			document.getElementById("ch_" + i).checked = false;
		}
	}	
}

function go_back(){ 
	
	location.href="forum.php";
}

function invite_detect(){

	if (document.invite_form.mail.value==0 || !isEmailAddress(document.invite_form.mail.value)){
		
		alert('Abnormal emal Format');		
		return false;
	}
}


function reg_detect(gif){ 	
	
	if (document.reg_form.name.value.length==0)
	{
		alert('There is no name in your subscription.');
		document.reg_form.name.focus();
		return false;
	}
	
	if (document.reg_form.surname.value.length==0)
	{
		alert('Your Last name please.');
		document.reg_form.surname.focus();
		return false;
	}
		
	if (document.reg_form.b_day.value==0 || document.reg_form.b_month.value==0 || document.reg_form.b_year.value==0)
	{
		alert('Please fill you birth day, month and year.');		
		return false;
	}
				
	if (document.getElementById("sex1").checked == false && document.getElementById("sex2").checked == false)
	{
		alert('Your Sex please.');		
		return false;
	}
	
	if (document.reg_form.country.value==0)
	{
		alert('Your Country Of Location is empty.');
		document.reg_form.country.focus();
		return false;
	}
	
	if (document.reg_form.us_lang.value==0)
	{
		alert('Your Language field is empty.');
		document.reg_form.us_lang.focus();
		return false;
	}
	
	if (document.reg_form.city.value==0)
	{
		alert('Your City detail is empty.');
		document.reg_form.city.focus();
		return false;
	}
	
	if (document.reg_form.mail_admin.value==0 || !isEmailAddress(document.reg_form.mail_admin.value))
	{
		alert('Abnormal email format.');
		document.reg_form.mail_admin.focus();
		return false;
	}
	
	if (document.reg_form.mail_admin_re.value==0 || document.reg_form.mail_admin_re.value!=document.reg_form.mail_admin.value)
	{
		alert('Your confirmation email is not matching.');
		document.reg_form.mail_admin_re.focus();
		return false;
	}
	
	if (document.reg_form.password.value==0)
	{
		alert('Please fill your password.');
		document.reg_form.password.focus();
		return false;
	}
	
	if (document.reg_form.password.value.length<6)
	{
		alert('Your Passwor should be more than 6 symbols.');
		document.reg_form.password.focus();
		return false;
	}
	
	if (document.reg_form.password_re.value==0 || document.reg_form.password_re.value!=document.reg_form.password.value)
	{
		alert('Your condirmation password is wrong.');
		document.reg_form.password_re.focus();
		return false;	
	}
	
	if( document.getElementById("captcha").value=="" ){
		
		alert('Please input security code provided on image.');
		document.reg_form.captcha.focus();
		return false;
	}
	
	return true;
	
}


function isEmailAddress (mail){
	
	var addressPattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	return addressPattern.test(mail);
}


function validChars(e, goods){
	
	var key, keychar;
	key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
	if (key == null) return true;
 
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
 
	if (goods.indexOf(keychar) != -1)
		return true;
 
	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27)
		return true;
 
	return false;
}


function change_mail_detect(){ 	
	
	if (document.change_form.password.value==0){
		
		alert('Please write your password.');
		document.change_form.password.focus();
		return false;
	}
	
	if ( document.change_form.mail_admin.value==0 || !isEmailAddress(document.change_form.mail_admin.value) || document.change_form.mail_admin_re.value==0 || !isEmailAddress(document.change_form.mail_admin_re.value) ){
		
		alert('Wrong mail format.');
		document.change_form.mail_admin.focus();
		return false;
	}
	
	if( document.change_form.mail_admin.value != document.change_form.mail_admin_re.value ){
		
		alert('Different email addresses for email changes.');
		document.change_form.mail_admin.focus();
		return false;
	}

}


function gif_detect(gif){	
	
	if( document.getElementById("captcha")!=gif ){
		
		alert('Your security code is wrong.');
		document.reg_form.captcha.focus();
		return false;
	}
}


function ChangeImageAction(id, num){
	
	document.getElementById("form_" + num).action = "m_images.php?img_edit_type=edit&general";
	document.getElementById("form_" + num).submit();
}

function feedback_form(){	

	if (document.feedback.subject.value.length==0)
	{
		alert('Wrong subject.');
		document.feedback.subject.focus();
		return false;
	}
	
	if (document.feedback.name.value.length==0)
	{
		alert('Please, write your name.');
		document.feedback.name.focus();
		return false;
	}
	
	if (document.feedback.contact.value.length==0)
	{
		alert('Please leave your contact details.');
		document.feedback.contact.focus();
		return false;
	}
	
	if (document.feedback.message.value.length==0)
	{
		alert('Your message is empty.');
		document.feedback.message.focus();
		return false;
	}
			
	return true;	
}



function change_forgot_pass(){ 	
	
	if( document.change_form.pass1.value=="" || document.change_form.pass2.value=="" || (document.change_form.pass1.value != document.change_form.pass2.value) ){
		
		alert('One of your passwords is empty or is not the same.');		
		return false;
	}
	
	if ( document.change_form.pass1.value.length<6 || document.change_form.pass2.value.length<6 ){
		
		alert('Your password should be more than 6 symbols.');		
		return false;
	}
	
	return true;
}