﻿var site = "./";

function showAllTraks(id)
{
	$("#traks_"+id).load("playlist_all.php@id="+id);
}

function AddFriend(username)
{
	OpenBox("friends_add.php@username="+username);
}

function Delete()
{
	return confirm('Сигурни ли сте, че искате да го изтриете?')?true:false;
}
function ObjectDelete(obiect,url)
{
	if (Delete())
	{
		$.ajax({
		  type: "GET",
		  url: url
		});
		$("#"+obiect).fadeOut("fast");	 
	}
	return false;	
}


function openPlaylist(id)
{
	OpenBox("playlist_add.php@id="+id);
}

function addPlaylist(){
	playlist= $("INPUT[_40name=playlist_item][type='radio']:checked").val() ;
	
	var id_melodie = $("input#id_melodie").val();
	var dataString = 'send=send&id_melodie='+ id_melodie + '&playlist='+ playlist ;

	
	$.ajax({
	  type: "POST",
	  url: "playlist_add.php",
	  data: dataString,
	  success: function(data,text) {
		$("#box_email").html(data);
	  }
	});
}




function LoadingBox(id)
{
	$("#"+id).html('<div style="position:relative; height:400px; background-color:#FFF"><img src="images/common/al_loading.gif" style="position:absolute; left:50%; top:50%"></div>');
}

function addComments(post_id)
{
	$.ajax({
	  type: "POST",
	  url: "wall_comments.php@post_id="+post_id,
	  data: $("#frm_comment_add_"+post_id).serialize(),
	  processData: true,
	  success: function(data,text) {
		$("#msg_"+post_id).html(data);
	  }
	});
	
	 $("#frm_comment_add_"+post_id+" TEXTAREA ").val('');
}
function showComments(post_id)
{
	$("#comments_"+post_id).load("wall_comments.php@post_id="+post_id);
	$("#comments_"+post_id).toggle();
}

function importContacts(){
	
	var email_box = $("input#email_box").val();
	var password_box = $("input#password_box").val();
	var type_contact = $("input#type_contact").val();
	var inv = $("input#inv").val();
	
	
	var dataString = 'step=get_contacts&email_box='+ email_box + '&password_box='+ password_box + '&type_contact='+ type_contact   + '&inv='+ inv;
	
	LoadingBox('box_email');
	
	$.ajax({
	  type: "POST",
	  url: "friends_import.php",
	  data: dataString,
	  success: function(data,text) {
		$("#box_email").html(data);
	  }
	});
}

function sendInvitationEmail()
{

	$.ajax({
	  type: "POST",
	  url: "sendInvitationEmail.php",
	  data: $("#contacts_form").serialize(),
	  processData: true,
	  success: function(data,text) {
		$("#box_email").html(data);
	  }
	});
}

function sendInvitation()
{

	$.ajax({
	  type: "POST",
	  url: "friends_import.php",
	  data: $("#contacts_form").serialize(),
	  processData: true,
	  success: function(data,text) {
		$("#box_email").html(data);
	  }
	});
}

function OpenBox(url){
	 $("#box_email").text('');
	 $("#box_email").load(url);
	 
	ttop=0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		ttop=window.pageYOffset;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		ttop=document.documentElement.scrollTop;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		ttop=document.body.scrollTop;
	}

	l = (myWidth-600)/2;
	t = (myHeight-500)/2+ttop ; 
	
	 $('#box_email').css('left',l+'px');
	 $('#box_email').css('top' , t+'px'); 
	 
	 $('#box_email').css('display','block');
}

function Close(name){
	//$("#box_email").text();
	$('#'+name).css('display','none');
} 

function submit_form(frm){
	try{
		var cr_form;
		if (typeof frm == "object") cr_form = frm;
		else{
			cr_form = document.forms[typeof frm == "undefined" ? 1 : frm];
		}
		if (typeof cr_form.onsubmit == "function"){
			if (cr_form.onsubmit() != false){
				cr_form.submit();
			}
		}else{
			cr_form.submit();
		}
	}catch(e){}
}

function submitEnter(e, frm){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13){
		submit_form(frm);
	}
	return true;
}

function enterSubmit(e, el){
	var targ = whi.events.getSrcElement(e);
	if (targ == el || (targ.tagName.toLowerCase() == 'input')){
		submitEnter(e, el);
	}
}

function clearInputDefaultValue(){
	if (this.value == this.defValue){
		this.value = "";
	}
}

function putInputDefaultValue(){
	if (this.value == ""){
		this.value = this.defValue;
	}
}

function put_search(siteURL, id){
	var a;
	if (a = document.getElementById(id ? id : "top_search")){
		var srch_val = a.value.toString().replace(/[^a-zA-Z0-9]+/g,'-');
		srch_val = srch_val.trim("-");
		if (srch_val != ''){
			window.location.href = siteURL+"cautare/"+srch_val;
		}
	}
}

function put_print_logo(){
	var im = document.createElement("img");
	im.src = site+"/images/common/print-logo.jpg";
	document.getElementById("logo").appendChild(im);
}

var array_validate = [];
array_validate["news_user_email"] = {name:"news_user_email",validate:"check_value:notequal:Твоят имейл|check_email",error:"Въведи имейл!|Имейлът е невалиден!"};




