
function registerSessionOptionType(valor, pagePHP, sessionInicialize){
    var varSendOption;
	
    if(valor =="1"){
        varSendOption = "1";
    }else if(valor =="2"){
        varSendOption = "2";
    }	

	var form = document.createElement("form");
	form.setAttribute("method", "post");
	form.setAttribute("action", pagePHP);
	var hiddenField = document.createElement("input");
	var hiddenFieldSession = document.createElement("input");
	
	hiddenField.setAttribute("type", "hiden");
	hiddenField.setAttribute("name", "registerType");
	hiddenField.setAttribute("value", varSendOption);
	
	hiddenFieldSession.setAttribute("type", "hidden");
	hiddenFieldSession.setAttribute("name", "sessionInicialize");
	hiddenFieldSession.setAttribute("value", sessionInicialize);


	form.appendChild(hiddenField);
	form.appendChild(hiddenFieldSession);
	document.body.appendChild(form);
	$(form).submit();
	/*setTimeout(function (e) {form.submit( function (e){
		 $(window).unbind('beforeunload');												
	});},0); */       
}
/*
 * Muestra el mensaje de Error
 */
function viewMessage(divMessage,Message,viewText){
    if(viewText==1){	
        $(divMessage).html(Message).show();
    }else{
        $(divMessage).hide().html('');
    }
}

/*
 * Muestra el mensaje de Error visibility
 */
function viewMessageVisibility(divMessage,Message,viewText){
    if(viewText==1){
        $(divMessage).html(Message).css('visibility','visible');
    }else{
        $(divMessage).css('visibility','hidden').html('');
    }
}

/*
 * Pasa el focus al campo especificado
 */
function goToError(field,estiloError){
    $('#'+field).focus();
}
/*
 * Validacion de Email
 */

function validateEmailBussiness(fieldEmail){	
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/.test(fieldEmail)){
            if (/^.+@(HOTMAIL\.COM|GMAIL\.COM|YAHOO\.COM|AOL\.COM)$/.test(fieldEmail.toUpperCase())){
                    return false;
            }
       return true;
    }else{
        return false;
    }
}

function validatePassword(value){
	var localValue = $.trim(value);	
	return ( /^[^\s]{6,}/.test(localValue) );
}

function validateEmail(fieldEmail){
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/.test(fieldEmail)){
        return true;
    }else{
        return false;
    }
}

/*
 *valida varios email
 */
function validateVariosEmailExpression(emails){
   arrayEmails = emails.split(",");
   for(i=0;i<arrayEmails.length;i++){
       if(!validateEmail(arrayEmails[i].replace(/^\s*/, ''))){
           return false;
       }
   }
   return true;
}


/*
 * Validar Zip Code
 */
function validateZipCode(value) {
    var RegExPattern = /^([0-9]{2}|[0-9][0-9]|[0-9][0-9])[0-9]{3}$/;
    if ((value.match(RegExPattern)) && (value!='')) {
        return true;
    } else {
        return false;
    }
}
/*
 * Validamos numero telefonico de EEUU
 */


function validatePhone(numero){
    if(numero==""){
            return false;
    }else if (!/^([0-9-])*$/.test(numero)){
            return false;
    }else if(numero.length < 10){
            return false;
    }else{
            return true;
    }
}
/*
 * Limpiamos los espacios en blanco
 */
function clearInputText(objForm){
    $('input[type="text"]:enabled', objForm).each( function (){
         $element = $(this);
         $element.val($.trim($element.val()));
    });
}

/*
 * Validamos la extencion de los archivos
 */
function validateFile(archivo){
    var ext = archivo.split('.').pop().toLowerCase();
    if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) {
        return false;
    }
    return true;

}

function validateFormFields(obj, ruleList){
	
    var returnString = true;
    var $element;
    var id;
    var value;

    //var list = new Array();
	// .filter('[id^="tb"]').
    $(":input", obj).filter(':visible, [type="hidden"]').each( function (i){
																		
        $element = $(this);
        id = $element.attr("id");
        value = $element.val();
		
        //list[i] = id;
		
        if (/^tbl/.test(id)){		
			if ($("#tblcountry_web_register").val() != 223 && id == "tblother_state_web_register"){				
				return true;
			}else if($("#tblcountry_web_register").val() == 223 && id == "tblstate_web_register"){
                                return true;
                        }else{
				value = $.trim(value);
				if(value.length == 0){
					returnString = id;
					return false;
				}
			}
        }else if(/^tbxl/.test(id)){ //para archivos adjuntos
            value = $.trim(value);
            if(value.length == 0){
                returnString = id;
                return false;
            }
        }else if(/^tbP/.test(id)){
            value = $.trim(value);            
            if(value.length == 0){                
                returnString = id;
                return false;
            }
        }else if(/^tbN/.test(id)){
            if (!(/^[0-9]+$/.test(value))){
                returnString = id;
                return false;
            }
        }else if(/^tbxN/.test(id)){
            value = $.trim(value);
            if(value.length != 0){
                if (!(/^[0-9]+$/.test(value))){
                    returnString = id;
                    return false;
                }
            }
        }else if(/^tbE/.test(id)){
            if(!validateEmailBussiness(value)) {
                returnString = id;
                return false;
            }
        }else if(/^tbxE/.test(id)){
            value = $.trim(value);
			if(value.length != 0){
				if(!validateVariosEmailExpression(value)) {
					returnString = id;
					return false;
				}
			}
            
        }

        if( id in ruleList ) {
            returnString = ruleList[id].call(this,value);
            if( returnString === true) {
                return true;
            } else if(returnString === false ) {
                returnString = id;
            }

            return false;
        }

    });

    return returnString;
}

function validatePhoneOffice(string){
   if (/^[\d()\-+\.\s]+$/.test(string)){
        return true;
    }else{
        return false;
    }
}

function validateFormFieldsExcept(obj, ruleList){
    var returnString = true;
    var $element;
    var id;
    var value;

    //var list = new Array();
	// .filter('[id^="tb"]').
    $(":input", obj).filter(':enabled,[type="hidden"]').each( function (i){
        $element = $(this);
        id = $element.attr("id");
        value = $element.val();

        if (/^tbl/.test(id)){
            value = $.trim(value);
            if(value.length == 0){
                returnString = id;
                return false;
            }
        }else if (/^tblN/.test(id)){
            value = $.trim(value);
            if(value.length == 0){
                returnString = id;
                return false;
            }
        }else if(/^tbN/.test(id)){
            if (!(/^[0-9]+$/.test(value))){
                returnString = id;
                return false;
            }
        }else if(/^tbxN/.test(id)){
            value = $.trim(value);
            if(value.length != 0){
                if (!(/^[0-9]+$/.test(value))){
                    returnString = id;
                    return false;
                }
            }
        }else if(/^tbE/.test(id)){
            if(!validateEmail(value)) {
                returnString = id;
                return false;
            }
        }else if(/^tbxE/.test(id)){
            value = $.trim(value);
            if(value.length != 0){
                if(!validateVariosEmailExpression(value)) {
                    returnString = id;
                    return false;
                }
            }
        }
        

        if( id in ruleList ) {
            returnString = ruleList[id].call(this,value);
            if( returnString === true) {
                return true;
            } else if(returnString === false ) {
                returnString = id;
            }

            return false;
        }

    });

    return returnString;
}

function cambiarDisplay(id,ac,idb) {
	
   try
   {
	  if (!document.getElementById)
	  return false;
	  fila = document.getElementById(id);
	  filab= document.getElementById(idb);
	  tipo = ac;
	
	  if (fila.style.display != "none" && tipo=="Hidden_field" ) {
		fila.style.display = "none"; //ocultar fila 
		filab.style.display = "none"; //ocultar fila
		$(":input", fila).attr("disabled", true);
	  }if (fila.style.display == "none" && tipo=="Show_field" ) {
		fila.style.display = ""; //mostrar fila 
		filab.style.display = ""; //ocultar fila
		$(":input", fila).removeAttr("disabled");
	  }
   }catch(error){
	   alert(error+" id -> "+id+" -> "+ac+" -> "+idb);
   }
}


function showHideAlertLogin(action){
    if(action == 1){ // Mostramos el Alert y Ocultamos el login
        var htmlEmail = '<div id="text-register-title-text">User/password combination is incorrect.<div class="btn-close"><a href="javascript:void(0);" onclick="showHideAlertLogin(2);">Close</a></div></div>';
        $('#boxRegister').hide();
        $('#box-alert').show();
        $('#box-alert').html(htmlEmail);
    }else if(action == 2){ // Oculta el Alert y se muestra el login
        $('#box-alert').hide();
        //$('#boxRegister').show();
    }else if(action == 3){ // Oculta el Login y se muestra forgot your password
        $('#boxes-login').hide();
        $('#boxes-forgot').show();
    }else if(action == 4){ // Oculta el forgot your password  y se muestra Login
        $('#boxes-forgot').hide();
        $('#box-alert').hide();
        $('#boxes-login').show();
    }else if(action == 5){ // Oculta el forgot your password  y se muestra el Alert
        var htmlEmail = '<div id="box-register-title-forgot">Invalid Info</div><div id="text-register-title-text">Type an email address</div>';
        //$('#boxForgot').hide();
         $('#boxAlertForgot').hide();
         $('#boxAlertForgotInvalid').hide();
         $('#boxes-forgot').show();       
        $('#textInfo').html(htmlEmail);
    }else if(action == 6){ // Oculta el Alert y se muestra el forgot your password
        $('#boxes-login').hide();
        $('#box-alert').hide();
        $('#boxes-forgot').show();
    }else if(action == 7){ // Oculta el forgot your password  y se muestra el Alert
		//href='javascript:void(0);' onclick='registerSessionOptionType(1, \"../mod_registration/step1.php\", 1);' 
        var htmlEmail = "<div id='text-register-title-text'>This Email Address is not registered. Please try again or register <a href=\"./\" style='color: #fff'> here.</a><div class='btn-close'><a href='javascript:void(0);' onclick='showHideAlertLogin(6);'>Close</a></div></div>";
        $('#boxes-forgot').hide();
        $('#boxes-login').show();
        $('#box-alert').show();
        $('#box-alert').html(htmlEmail);
    }else if(action == 8){ // Oculta el forgot your password  y se muestra el Alert
        var htmlEmail = '<div id="text-register-title-text">A new password has been sent to your account.<div class="btn-close"><a href="javascript:void(0);" onclick="showHideAlertLogin(2);">Close</a></div></div>';
        $('#boxes-forgot').hide();
        $('#boxes-login').show();
        $('#box-alert').show();
        $('#box-alert').html(htmlEmail);
    }else if(action == 9){ // Oculta el forgot your password  y se muestra el Alert	
        var htmlEmail = '<div id="text-register-title-text">User/password combination is incorrect.<div class="btn-close"><a href="javascript:void(0);" onclick="showHideAlertLogin(2);">Close</a></div></div>';
        $('#box-alert').show();
        $('#box-alert').html(htmlEmail);
    }else if(action == 10){ // Oculta el forgot your password  y se muestra el Alert
        $('#boxAlertForgot').hide();
        $('#boxes-forgot').show();		
    }else if(action == 11){ // Oculta el forgot your password  y se muestra el Alert
        var htmlEmail = '<div id="text-register-title-text">User/password combination is incorrect.<div class="btn-close"><a href="javascript:void(0);" onclick="showHideAlertLogin(2);">Close</a></div></div>';
        $('#boxRegister').hide();
        $('#box-alert').show();
		$('#box-alert').html(htmlEmail);
        //$('#textInfoLogin').html(htmlEmail);	
    }
    
}

function validateForgot(){
    try{
     var emailAddressForgot     = document.getElementById('emailAddressForgot');
     $('#btnForgot').attr('disable',true);
     if(!validateEmail(document.getElementById('emailAddressForgot').value)){	 
             $('#btnForgot').attr('disable',false); 
             showHideAlertLogin(5);
             goToError(emailAddressForgot.id,'');
             return false;
     }else{
         $.ajax({
            type: "POST",
            url: "../mod_login/forgot.php.php",
            async: true,
            data: "tbEemailAddressForgot="+$("#emailAddressForgot").val(),
            success: function(msgHtml){			
                if(msgHtml=='0'){
                     showHideAlertLogin(7);
                     goToError(emailAddressForgot.id,'');
                     $("#emailAddressForgot").val("");
                     return false;
                }else{
                    showHideAlertLogin(8);
                    $("#emailAddressForgot").val("");
                    //setTimeout("showHideAlertLogin(8);",2000);
                    return false;
                }
            },
            beforeSend: function(){
              $('#boxes-forgot').hide();			 	  
              $('#loading').show();
            },
            complete: function(){
              $('#loading').hide();
            }
        });
     }
    }catch (e){
        alert(e);
        return false;
    }
}

function validateIfLogin(booleanLogin, nameSession){	
    var fragmentoTexto;
    var url;
    if (booleanLogin==0){
        $.ajax({
            type: "POST",
            url: "../mod_login/login.php.php",
            async: true,
            data: "typeValidate=2",
            success: function(msgHtml){				
                if(msgHtml != 0){
                    $('#boxes-login').hide();
                    $('#boxes-logout').show();
                    fragmentoTexto = msgHtml.split('**');
                    $('#nameRegister').html(fragmentoTexto[0]);					
                    if (fragmentoTexto[1]==1 || fragmentoTexto[1]==2){
                        url = "../mod_registration/summary1.php";                        
                    }else{                        
                        url = "../index.php";
                    }
                    document.location = url;
                    //return false;
                }
            }
        });
    }else{
        $('#boxes-login').hide();
        $('#boxes-logout').show();
        $('#nameRegister').html(nameSession);
        return false;
    }
}

  
function logOutLogin(){
    $.ajax({
        type: "POST",
        url: "../mod_login/login.php.php",
        async: true,
        data: "typeValidate=3",
        success: function(){
            $('#boxes-logout').hide();
            $('#boxes-login').show();
			//document.location = "../mod_registration/";
                        document.location = "../index.php";
            return false;
        },
		beforeSend: function(){
		  $('#boxes-login').hide();
  		  $('#boxes-logout').hide();		  
		  $('#loading').show();
		},
		complete: function(){
		  $('#loading').hide();
		}
    });
}

function activeMenu(idMenu){
    $('#'+idMenu).addClass('selected');
}

function validateLogin(obj){
			
	if ($("#activePage").val()==="true"){
		var r = confirm("Your registration has not been completed. If you decide to leave the Cognizant Community Europe 2011 website now, your information will not be saved and you will need to restart the registration process.");
		if (r == true){
			$("#activePage").val("false");
			validateLogin();	
		}else{
			return;
		}
	}else{
		try{
			
		$(window).unbind('beforeunload');	
			
		 var emailAddress     = document.getElementById('tbEemailLogin');
		 var passwordRegister = document.getElementById('tblpasswordLogin');
		 $('#btnLogin').attr('disable',true);
		 
		if ($("#tbEemailLogin").val()==""){
			showHideAlertLogin(1);
			goToError(emailAddress.id, '');
			return false;
		}else if(!validateEmail(document.getElementById('tbEemailLogin').value) || ($("#tblpasswordLogin").val()=="")){		
			showHideAlertLogin(11);
			goToError(emailAddress.id, '');
			return false;
		 }else{
			 $.ajax({
				type: "POST",
				url: "../mod_login/login.php.php",
				async: true,
				data: "tbEemailAddressForgot="+$("#tbEemailLogin").val()+"&tblpasswordRegister="+$("#tblpasswordLogin").val()+"&typeValidate=1",
				success: function(msgHtml){					
					if(msgHtml==0){
						 showHideAlertLogin(9);
						 $("#tbEemailLogin").val("");
						 $("#tblpasswordLogin").val("");
						 return false;
					}else{
						$('#boxes-login').hide();
						validateIfLogin(0, '');
						$("#tbEemailLogin").val("");
						$("#tblpasswordLogin").val("");
						return false;
					}
				},
				beforeSend: function(){				
				  $('#loading').show();
				},
				complete: function(){
				  $('#loading').hide();
				  $(window).bind('beforeunload');	
				}
			});
		 }
		}catch (e){
			alert(e);
		}
	}
}

function openPopupVideos(idVideo){
    $.openPopupLayer({
        name: "MyForm",
        /*width: 410,*/
        url: "layer"+idVideo+".php",
        cache: false,
        success: function(){
            
             
        }
    });
   
}
