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 ucwords(string) {
    // Split the string into words if string contains multiple words.
    var x = string.split(/\s+/g);

    for (var i = 0; i < x.length; i++) {

        // Splits the word into two parts. One part being the first letter,
        // second being the rest of the word.
        var parts = x[i].match(/(\w)(\w*)/);

        // Put it back together but uppercase the first letter and
        // lowercase the rest of the word.
        x[i] = parts[1].toUpperCase() + parts[2].toLowerCase();
    }

    // Rejoin the string and return.
    return x.join(' ');
}

function AddFriend(username)
{
	OpenBox("/friends_add.php?username="+username);
}

function Delete()
{
	return confirm('Esti sigur ca vrei sa stergi?')?true:false;
}
function ObjectDelete(obiect,url)
{
	if (Delete())
	{
		$.ajax({
		  type: "GET",
		  url: url
		});
		$("#"+obiect).fadeOut("fast");	 
	}
	return false;	
}


function LoadingBox(id)
{
	$("#"+id).html('<div style="position:relative; height:400px; background-color:#FFF"><img src="/wp-content/themes/lifestyle_30_vara/images/al_loading.gif" style="position:absolute; left:50%; top:50%"></div>');
}


function OpenBoxIframe(url){
	 createBox("box_email");
	 
	$("#box_email").text('');
	$("#box_email").html('<a href="javascript:removeBox(\'box_email\')" style="position:absolute;right:10px;top:10px;">close</a><iframe id="dialogIframe" src="'+url+'" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto" />');
	
	$('#box_email').css('width','600px');
	$('#box_email').css('height','400px');
	$('#box_email').css('display','block');
	
	 
	var ws=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
	var leftContainer=((ws/2)-250); 
	$('#box_email').css('left',leftContainer+'px');
		
	if (window.addEventListener){
		window.addEventListener("resize",resizeBox, false);
	}else if (window.attachEvent){
		window.attachEvent("onresize",resizeBox);
	}else if(window.onresize){
        window.onresize= resizeBox;
    }
	 
	 $('#box_email').css('display','block');	
}

function OpenBoxAvatar(url){
	 createBox("box_email");
		
	 
	$("#box_email").text('');
	$("#box_email").html('<a id="closeiframe" href="javascript:CloseBoxAvatar(\'box_email\')" style="position:absolute;right:10px;top:20px;">close</a><iframe id="dialogIframe" src="'+url+'" width="600" height="320" marginWidth="0" style="border:10px solid #9DC28E;background-color:#FFFFFF;" marginHeight="0" frameBorder="0" scrolling="no" />');
	
	$('#box_email').css('width','600px');
	$('#box_email').css('height','320px');
	$('#box_email').css('display','block');
	$("#dialogIframe").attr("src",url);
	 
	var ws=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
	var leftContainer=((ws/2)-300); 
	$('#box_email').css('left',leftContainer+'px');
	
	
	if (jQuery.browser.msie) {
		if(parseInt(jQuery.browser.version) == 6) {
			$('#box_email').css('width','620px');
			$('#closeiframe').css('right','20px');
		}else{
			var wh=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
			var topContainer=((wh/2)-160); 
			$('#box_email').css('top',topContainer+'px');
		}
	}else{
		var wh=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
		var topContainer=((wh/2)-160); 
		$('#box_email').css('top',topContainer+'px');
	}
	
	
	/*
	if (window.addEventListener){
		window.addEventListener("resize",resizeBox, false);
	}else if (window.attachEvent){
		window.attachEvent("onresize",resizeBox);
	}else if(window.onresize){
        window.onresize= resizeBox;
    }
	*/
	 
	 
}


function CloseBoxAvatar(){
	removeBox("box_email");
	document.location.href = document.location.href;	
}

resizeBox = function(){
	var ws=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
	var leftContainer=((ws/2)-600);
	if(document.getElementById("box_email"))
		document.getElementById("box_email").style.left=leftContainer+"px";	
}
function createBox(name){
	if(document.getElementById(name)){
		//exista
	}else{
		divShare=document.createElement("div");
		divShare.id=name;
		document.body.insertBefore(divShare, document.body.firstChild);
	}
}
function removeBox(name){
	divDestroy = document.getElementById(name);
	if(divDestroy)
	document.body.removeChild(divDestroy);
}



function OpenBox(url){
	 createBox("box_email");
	 
	 $("#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');
} 
