
function validarEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
  //alert("La dirección de email" + valor + "es correcta.");
  return true
  } else {
    return false;
  }
}


function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function Navegador() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'firefox';
if (agt.indexOf("safari") != -1) return 'safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'ie';
if (agt.indexOf("netscape") != -1) return 'netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

//saca el width de la resolucion
function getWidth(){
    var viewportwidth;


 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth
 }

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth
 }

 // older versions of IE

 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth
 }
//document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
return viewportwidth;
//-->

}

function getHeight(){
 var viewportheight;

 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

 if (typeof window.innerWidth != 'undefined')
 {

      viewportheight = window.innerHeight
 }

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {

       viewportheight = document.documentElement.clientHeight
 }

 // older versions of IE

 else
 {

       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
//document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
return viewportheight;
//-->

}

function checkVersion()
{
  var msg = "You're not using Internet Explorer.";
  var ver = getInternetExplorerVersion();

/*  if ( ver > -1 )
  {
    if ( ver >= 8.0 )
      msg = "ie8."
    else
      msg = "You should upgrade your copy of Internet Explorer.";
  }
  alert( msg );
*/
return ver;
}

function setFocus(elemento){
    document.getElementById(elemento).focus();
}
/* codigos unicode para los alerts
\u00e1 -> á
\u00b0 -> º
\u00e9 -> é
\u00ed -> í
\u00f3 -> ó
\u00fa -> ú
\u00c1 -> Á
\u00c9 -> É
\u00cd -> Í
\u00d3 -> Ó
\u00da -> Ú
\u00f1 -> ñ
\u00d1 -> Ñ
\u00bf -> ¿
*/

function AddEvents(){
  var page="";
  var datax="";

   $('input[type=button], a').click(function() {
        var id = $(this).attr('id');

        switch(id){
              case "candidatos":
              case "empresas":

                 //$('.sf-menu li a').each(function () {
                 $('#inicio,#candidatos,#empresas,#formacion').each(function () {
                     //alert($(this).attr('id'));
                     if($(this).attr('id')!=id)
                        $(this).removeClass("current");
                     else
                        $(this).addClass("current");

                });


                page="Load.php";
                datax = {
                    'opc':id,
                    'sw':'1'
                };
              break;

              case "btnbuscar":
                page="Load.php";
                datax = {
                    'opc':id,
                    'sw':'1'
                };
              break;

            }

        $.ajax({
               type: "POST",
               url: page,
               dataType: 'json',
               data: datax,
               beforeSend : function(){
                // $.blockUI();
               },

               success: function(res){

                  switch(id){
                        case "candidatos":
                        case "empresas":
                            alert("eppe");
                            $('#buscar').load('http://localhost/camarerosycocteleros/02/login/'+id+'.html');
                        break;
                        case "btnbuscar":
                            $('#buscar').html(res.data);
                        break;
                  }
               },
               complete: function(){
                 //$.unblockUI();
               }
        });

    });

    $('select').change(function() {
        var id = $(this).attr('id');

        switch(id){

              case "cmbprov":
                page="Load.php";
                datax = {
                    'opc':id,
                    'sw':$(this).val()
                };
              break;
            }

        $.ajax({
               type: "POST",
               url: page,
               dataType: 'json',
               data: datax,
               beforeSend : function(){
                // $.blockUI();
               },

               success: function(res){
                  switch(id){
                        case "cmbprov":
                            $('#cmbpob').html(res.data);
                        break;
                  }

               },
               complete: function(){
                 //$.unblockUI();
               }
        });

    });


}


function Redirect(url){
    window.location = url;
}

//quita etiquietas html de un texto
function stripHTML(cadena)
{
    return cadena.replace(/<[^>]+>/g,'');
}

function set_iframe_data(ID,valor) {
        var saf = navigator.userAgent.match(/Safari/i);
        var safver = (saf ? parseFloat(navigator.userAgent.match(/[\d\.]+Safari/i)) : 0);
        var targetif = $(ID);
        var data;

        if (targetif.contentDocument && (!saf || (saf && safver >= 3))) {
                // NS6 & Gecko & Opera & IE7+
                if (!saf || (saf && safver >= 3)) {
                        data=targetif.contentDocument.defaultView.document.body.innerHTML=valor;
                } else {
                        data=targetif.document.body.innerHTML=valor;
                }

        } else if (targetif.contentWindow && !saf) {
                // IE 5.5 & 6.x
                data=targetif.contentWindow.document.body.innerHTML=valor;

        }

        return(data);
}





