function trim(myString){
 return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}
$(document).ready(function(){
 $('.text').focus(function(){$(this).addClass('focused')});
 $('.text').blur(function(){$(this).removeClass('focused')});
});
function isValidEmail(str) {
  re = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;
  return re.test(str);
}
function isPDF(path){
  return path.toLowerCase().match(/\.(pdf)$/);
}
function showMessage(message){
 alert(message);
}
showError = showMessage;
function change_source(src){
  if(src == 0){
    $("#upload_input").show();;
    $("#pdf_url").hide();
  }
  else{
    $("#upload_input").hide();
    $("#pdf_url").show().val("http://").focus();
  }
  $("#source").val(src);
  if(src == 0){
    $("#lb0").addClass('active');
    $("#lb1").removeClass('active');
  }else{
    $("#lb1").addClass('active');
    $("#lb0").removeClass('active');
  }
}

function upload(){
  var source = $("#source").val();
  
  if($("#pdf").val() == "" && source == 0){
    alert("Please select a file to upload!");
    return false;
  }

  var $pdf_url = $("#pdf_url").val();
  if( ($pdf_url == "" || $pdf_url == "http://") && source == 1){
     alert("Please provide the URL for the Form!");
     return false;
  }

  if( $pdf_url != "" &&  $pdf_url != "http://" && source == 1){
    var $clear_url = 'http://' + trim($pdf_url.replace(/http\:\/\//g,''));
    $("#pdf_url").val($clear_url);
  }

  var filename = $("#pdf" + (source == 1?'_url':'') ).val();

  if(!isPDF(filename)){
    alert("Please select a PDF file!");
    return false;
  }

  document.getElementById('wait_msg').style.display = 'block';
  document.forms[0].action = document.forms[0].action + "?ssl";
  document.forms[0].submit();
  return false;
}
/*function urlUpload(url,t){
 $(t).html('Loading ...<span></span><em></em>');
 alert(url);
 $.get(url,function(data){
  console.log(data);
 });
 $(t).html('Fill On-line<span></span><em></em>');
 return false;
}*/

function areCookiesEnabled() {
var cookieenabled = false;
if (typeof window.navigator.cookieenabled == "undefined") {
    document.cookie = "testcookie=val";
    cookieenabled = (document.cookie.indexOf("testcookie=") != -1);
} else {
    cookieenabled = window.navigator.cookieenabled;
}
return cookieenabled;
}

function safeClose(){}

function showNews(t){
	var prnt = $(t).parent().parent();
	if(prnt.hasClass('mess')){
		prnt.removeClass('mess');
		$('.news_content').show();
		$('.plus').text('-');
	}else{
		prnt.addClass('mess');
		$('.news_content').hide();
		$('.plus').text('+');
	}
}
function FB_login(appId,session){
window.fbAsyncInit = function() {
        FB.init({
          appId   : appId,
          session : session, // don't refetch the session when PHP already has it
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true // parse XFBML
        });

        // whenever the user logs in, we refresh the page
        /*FB.Event.subscribe('auth.login', function() {
          //window.location.reload();
        });*/
      };

      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
      }());

}
function flogout(){
	FB.logout();
	window.location="logout.php";
}
function show_sign_up(){
	$("#sign-up-pdffiller").show();
}
function change_login_box(src){
  if(src == 0){
    $("#show_log").show();;
    $("#show_reg").hide();
  }
  else{
    $("#show_log").hide();
    $("#show_reg").show();
  }
	return false;
}