$(document).ready(function(){
	
        
       ///alert('dddd');
        
        
      
        
        
    
        /// remember me? dontput background . 
        if (!$('#small_loginUser').attr('value'))
        {
            $('#small_loginUser').css('background-image',"url("+base+"css/img/username_bg.jpg)");
        }
        if (!$('#small_loginPassword').attr('value'))
        {
            $('#small_loginPassword').css('background-image',"url("+base+"css/img/pass_bg.jpg)");
        }
    
      
      ///clean the backgroenn n case theres is a usernam    
    
        
    
      $(".download_free_publication").click(function (){
        
                   
                    var  myidentifier = this.id;
                    
                    
                        myidentifier=myidentifier.split("_");
                    var myidentifier_int= myidentifier[1];
                    var loaderimg = base+'img/ajax-loader.gif';
                    //$('#').src= base+'img/'+'ajax-loader.gif';
                     $('#btn_add_to_briefcase').attr('src',loaderimg);
                     
                    
                    	 $.ajax({
		   type: "GET",
		   url: this.href,
		  evalJS:true,
		   success: function(msg){
		      
                            
                        updateLogged();      
              
              
              
              
			  $('#publicationlink_'+myidentifier_int).html(msg);
                    
                       $("#btn_briefcase_gry").hover(function(){
        
        
       //alert(this.id);
       this.src = base+'img/'+this.id+'_r.gif';
       
    },function(){
        
       this.src = base+'img/'+this.id+'.gif';
       
    });
                    
                    
		   }
		 });
                    
            return false;        
                    
            
        
      });
      
      function updateLogged()
      {
        
        var reff = site+'/research/updateloggedmenu/'; 
        //alert(reff);
           $.ajax({
		   type: "GET",
		   url: reff,
		  evalJS:true,
		   success: function(msg){
		      
              $('#loggedmenu').html(msg);
              
		   }
                
            });
                
          
          
      }
    
      function addtobriefcase(id)
      {
        
        
        
      }
    
    
    
    
     $(".hover_me").hover(function(){
        
        
       //alert(this.id);
       this.src = base+'img/'+this.id+'_r.gif';
       
    },function(){
        
       this.src = base+'img/'+this.id+'.gif';
       
    });
    
    
    
    $('#country_selector').change(function (){
            //alert('canefsdsddf');
            var selected_country = this.value;
            var serve_states = site+'/resources/serve_states/'+selected_country;
            //prompt(serve,serve);
         var  options=''; 
        
         
            	 $.ajax({
		   type: 'GET',
		   url: serve_states,
		
            dataType: "xml",
           error:function (){},
		   success: function(xml){
		      //alert('success');
              
               $(xml).find('state').each(function(){
       
                 var item_text = $(this).text();
                 var key = $(this).attr('key');
                 //alert(item_text+key);
                 options += '<option value="' + key + '">' +item_text + '</option>';
        
    });
              if (options.length>0)
		      $("#state_selector").html(options);
              else
              $("#state_selector").html('<option value="-1">Not applicable</option>');
                //alert(data);
			 	
		   }
		 });
      }
    );
    //remove the log in  images on click
    $('#small_loginUser').focus(function (){
        //alert('hello');
        
        
        $('#small_loginUser').css('background-image','none');
        
    });
    
    $('#small_loginUser').blur(function (){
        //alert('hello');
        val = $('#small_loginUser').attr('value');
        if (val.length==0)
        {
              $('#small_loginUser').css('background-image','url('+base+'css/img/username_bg.jpg)');
        }
        
    });
    
    $('#small_loginPassword').blur(function (){
        //alert('hello');
        val = $('#small_loginPassword').attr('value');
        if (val.length==0)
        {
              $('#small_loginPassword').css('background-image','url('+base+'css/img/pass_bg.jpg)');
        }
        
    });
    $('#small_loginPassword').focus(function (){
       // alert('hello');
        $('#small_loginPassword').css('background-image','none');
        
    })
    
    
    //force news to open on selected 
    $('#open_news').click(function(){
        
        //alert(this.href);
        //open(this.href);
        //return false;
    });
    
     
     var main_content_height = Math.max( $('.col2').height(),$('.col1').height());
    $('#line_briefcase, .grey_line_left,.grey_line_border,.grey_border_line').css('min-height',(main_content_height+25)+'px').css('overflow','hidden').css('margin-top','0');
    /*blog left line*/
    
    
    var content_height = $('#news_container').height();
    //alert(content_height);
    $('#blog_border_left').css('min-height',(content_height-50)+'px');
    
    
    
    var content_height = $('#news_container').height();
    //alert(content_height);
    $('#border_left_news').css('min-height',(content_height-50)+'px');
    
    
    $('#captcha_refresh').click(
    
    function (){
          var rnd=Math.floor(Math.random()*10000);
        //prompt(site+'/resources/captcha',site+'/resources/captcha');
        var image_path = base+'response.php'+'?r='+rnd;
      
        $('#captcha_image').attr('src',image_path);
        
        //prompt(image_path,image_path);
        //$('#captcha_image').css('border','1px solid red');
        
        return false;
        
    }
    
    );
    
    
    
    
    $("#login_image, #access_login").hover(function(){
       
       this.src = base+'img/btn_login_r.gif';
       
    },function(){
        
       this.src = base+'img/btn_login.gif';
       
    });
    
    
    
    
     $(".in_briefcase_btn").hover(function(){
       
       this.src = base+'img/btn_briefcase_gry_r.gif';
       
    },function(){
        
       this.src = base+'img/btn_briefcase_gry.gif';
       
    });
    
    
    
    
      $("#submit_account_data_save").hover(function(){
       
    
        
       this.src = base+'img/btn_save_r.gif';
       
    },function(){
        
       this.src = base+'img/btn_save.gif';
       
    });
    
     $("#submit_account_data").hover(function(){
       
    
        
       this.src = base+'img/btn_signup_r.gif';
       
    },function(){
        
       this.src = base+'img/btn_signup.gif';
       
    });
    
    
     $(".btn_view_full").hover(function(){
       
      // alert('vpber');
       this.src = base+'img/btn_view_article_r.gif';
       
    },function(){
        
       this.src = base+'img/btn_view_article.gif';
       
    });
    
     $(".backtotop").hover(function(){
       
       this.src = base+'img/btn_back_to_top_r.gif';
       
    },function(){
        
       this.src = base+'img/btn_back_to_top.gif';
       
    });
    
    
    $('.anchor_backtotop').click(function (){
        
        
        scroll(0,0);
       // alert('Hello ');
        return false;
        
    });
    
    $('.btn_download_publication').hover(function(){
        
        this.src = base + 'img/btn_download_publication_r.gif';
    },function(){
        
        this.src = base + 'img/btn_download_publication.gif';
    });
    
    
     $('.btn_purchase_publication').hover(function(){
        
        this.src = base + 'img/btn_purchase_publication_r.gif';
    },function(){
        
        this.src = base + 'img/btn_purchase_publication.gif';
    });
    
    
    
    $("#login_button").click(function(){
        
        $("#login_form").submit();
           
     });
    
	$(".procontact a").click(function () { 	
		$(".contact").show();
		$("#main").redrawShadow();
		return false;
	});	
	
	$(".contactclose a").click(function () { 	
		$(".contact").hide();
		$("#main").redrawShadow();
		return false;
	});	
    
    
    $(".thanks a").click(function () { 	
		$(".contact").hide();
		$("#main").redrawShadow();
		return false;
	});	
    
		
	$(".col1 a.selected").click(function(){
			return false;							 
	});


	
    
    
    //----maniel pass upadate
    
    /*
    $(".changePass a").click(function () {
		$("#changePasswordContent").show();
		$("#contentFormPassword").css("height","180px");
		$("#contentFormPassword").css("width","425px");
		document.getElementById("changePassword").reset();
		$("#thanksPass").css("display","none");
		$("#linkdisplaypassword").css("display","none");
		$("#main").redrawShadow();
		
		return false;
	});
		
	$(".passclose a").click(function () {
		$("#changePasswordContent").hide();
		$("#contentFormPassword").css("height","10px");
		$("#contentFormPassword").css("width","425px");
		document.getElementById("changePassword").reset();
		$("#linkdisplaypassword").css("display","block");
		$("#main").redrawShadow();
		return false;
	});
	*/
	
	
	/*    BUTTON TO Change password   */    
	
	$('#sendpass').click(function (){
		var myForm=document.getElementById("changePassword");

		var SS= Spry.Widget.Form.validate(myForm);

		if (SS==false){
			return ;	
		}else{
			if(SS==true){
				
				var strUrl = site + '/AjaxRequests/changepassword/';
				var str = $('#changePassword').serialize();
				$.ajax({
					type: "POST",
					url: strUrl,
					data: str,
					success: function(msg){
						$("#msgResponse").css('font-size','13px');
						$("#msgResponse").fadeIn().animate({opacity: 1.0}, 3000).css('font-weight','bold');/*#3A659E*/
						$("#msgResponse").html(msg);
						
						if(msg == "Your password has been updated."){
							/*$("#password_form_container").html('&nbsp;<input type="button" id="returnmyaccount" name="sendpass" tabindex="1" style="background-image:url({base}img/btn_save.gif);height:30px;width:80px;border:0;cursor:pointer;" onclick="location.href=\'/myaccount\'"  />');*/	
							$("#password_form_container").html('&nbsp;<a href="' + site + '/resources/myaccount" >Return My Account</a>');	
							
						}
						
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						$("#msgResponse").css('font-size','13px');
						$("#msgResponse").fadeIn().animate({opacity: 1.0}, 3000).css('font-weight','bold');/*#3A659E*/
						$("#msgResponse").html("Error: " + errorThrown);
						$("#password_form_container").css('display','none');
					}
				});
				
				$("#main").redrawShadow();
				return false;
 			}
		}
	});
	
	/*end manuel change password*/

    							  
	//----
	////// Print page 
	$("#links a.print").click(function () { 
		window.print()
		return false;
	});	
	
	
	
	// Shadow

	
    
    ddsmoothmenu.init({
		mainmenuid: "smoothmenu1",
		orientation: 'h'
	})
	
	// Contact
	//$("#procontact").submit();
	
	
	// Email this page		
	$("#links a.email").click(function () { 
		$("#emailthis").slideDown("normal", function () {
	  		$("#main").redrawShadow();
	  	});		
		return false;					  
	});	
	
	/*found ya*/
	$("#emailthis .close").click(function () { 
		$("#emailthis").slideUp("normal", function () {
	  		$("#main").redrawShadow();
	  	});		
		return false;
	});		
	
	
	
		
	$("#emailthis form").submit(function() {
	   
       //alert('evento submit');  
       
          var myForm=document.getElementById("form_email_this");
          
          //alert($('#form_email_this').serialize());
          
	   var SS= Spry.Widget.Form.validate(myForm);
		
      //  alert(SS);
        
        
	if (SS==false)
	{
	
		
		return ;	
	}
	else 
	if(SS==true){
	       var curr_url = document.location.href;
           
           //alert(document.URL );
           var  str_ = $(this).serialize()+ "&url="+document.URL; 
           
           var  post_url = site + "/resources/emailthis";
           //alert(post_url);
           //alert(str_);
		 $.ajax({
		   type: "POST",
		   url: post_url,
		   data: str_,
		   success: function(msg){
			
             $("#emailsent").fadeIn();
//              $("#emailsent").fadeOut();
            
            /* $("#emailthis").fadeOut();
			 $("#emailsent").fadeIn()*/
			 	
		   }
		 });
         
         
         $("#emailthis").slideUp("normal", function () {
	  		$("#main").redrawShadow();
	  	});
		 return false;  
        
	   }
        
      $("#emailthis").slideUp("normal", function () {
	  		$("#main").redrawShadow();
	  	});
		
	 });
	
	$("#emailsent a.close").click(function () { 	
		$("#emailsent").hide();
		return false;
	});	
	
	// IMG ROLLOVER
	$("img.rollover").hover(
		 function()
		 {
		  	this.src = base+"img/kh_services_whatwedo_p1R.gif";
		 },
		 function()
		 {
		  	this.src = base+"img/kh_services_whatwedo_p1.gif";
		 }
		);
	
        
	
    
/*    BUTTON TO SEND THE EMAIL TO THE PROFESSIONAL   */    
  
    
	$(".send_rollover").click(function(){
	   
        
      //  alert("Testing Safari"); //return false;
        
        
        var myForm=document.getElementById("procontact");
	   var SS= Spry.Widget.Form.validate(myForm);
	
	if (SS==false)
	{
		//alert('false');
		
		return ;	
	}
	else 
	if(SS==true){
	   
       
     //  alert('true');
       /*  ssssssssssssssss */
       
       
      
	   
       
       //alert("AQUIE ESTAMOS LLEGANDO ...");
		 var str = $('#procontact').serialize();
         
         //alert(str);
         
		 $.ajax({
		   type: "POST",
		   url: site+'/resources/procontact/',
		   data: str,
		   success: function(msg){
			 $(".contact").fadeOut();
              $(".thanks").fadeIn().animate({opacity: 1.0}, 3000).css('color','#3A659E');
             
             //$(".thanks").fadeIn().animate({opacity: 1.0}, 3000).css('color','#3A659E');
             
                          
             
			 //$(".thanks").fadeIn().animate({opacity: 1.0}, 3000).fadeOut();
			 
		   }
		 });
         
        //$("#main").dropShadow({left: 0, top: 0, blur: 2, opacity: 0.5});
        
        /*[WARING] [dropShadow][main]if I don t put the following code  A BLACK SHADOW REMAINS BECAUSE THE FORM WAS EXTENDED*/
        
           
            
           	$(".contact").hide();
		$("#main").redrawShadow();
         
		 return false;
	                     
       
       /************************/              
       
       
                                   
      // alert("la forma se submitira");
	//myForm.submit();
	}
        
        
       
		//document.form1.submit();									
	});
	
	$("img.clear_rollover").hover(
		 function()
		 {
		  	this.src = base+"img/btn_clear_r.gif";
		 },
		 function()
		 {
		  	this.src = base+"img/btn_clear.gif";
		 }
	);
		
	$("img.clear_rollover").click(function(){				
		document.form1.reset();
	});	
	
	
	$("img.send_rollover2").click(function(){
		var email = $("input.email").val();	
		var message = $("textarea.message").val();	
		
			
			if (email==null||email=="")
			{				
				jAlert('Please enter an email', 'Error');
				$(".email").focus();
				return false;				
			}
			
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) == false)
			{
				jAlert('Please enter a valid email', 'Error');
				$(".email").focus();
				return false;				
			}
			
			
			if (!message)
			{				
				jAlert('Please enter am essage', 'Error');
				$(".message").focus();
				return false;
			}
		
		});
        
        
    $('.closecontact2 a').click(function(){
        /*alert("close this ");*/ 
        $('.thanks').fadeOut();
    });
    
    
    $('input.send_rollover').hover(function (){
        //alert('clear');
        this.src =base+ "img/btn_send_r.gif";
        
    });
      
	     $('input.send_rollover').mouseout(function (){
        //alert('clear');
        this.src = base+"img/btn_send.gif";
        
    });
	
});

$(document).ready(function (){
    
    $("#main").dropShadow({left: 0, top: 0, blur: 2, opacity: 0.5});
})
//-----------------------------  careers.php validation --------------------------




function do_spryvalidation()
{
       var myForm=document.getElementById("careers");   
	   var SS= Spry.Widget.Form.validate(myForm);
		
       //alert(SS);
        
        
	 if (SS==false)
	 {
	
        scroll(0,0);		
		return ;	
	 }
	else 
	if(SS==true){
	   
        //alert($('#careers').serialize());
        
        myForm.submit();
        return false;
   }
}
$(document).ready(function (){
     
     
     //mask for the careers    
     initFileUploads();  
     //alert('password for the small login');  
       
     var val1 = $('#small_loginPassword').attr('value');
     if (val1.length==0)
     {
              $('#small_loginPassword').css('background-image','url('+base+'css/img/pass_bg.jpg)');
     }
     else
              $('#small_loginPassword').css('background-image','none');
    
     var val2 = $('#small_loginUser').attr('value');
     if (val2.length==0)
     {
              $('#small_loginUser').css('background-image','url('+base+'css/img/username_bg.jpg)');
     }
     else
              $('#small_loginUser').css('background-image','none');
              
              
              
     // file upload 
     //alrt('file upload');
           
    
});

$(document).ready(function (){
   
    
    
});



function calculateHeigth(){
	var bar = document.getElementById("lineArchives");
	var yheight = 450;/*
	if(bar != null){
		if (window.innerHeight){
		   //navegadores basados en mozilla
		   //yheight = window.innerHeight;
		   yheight = document.body.scrollHeight - 500;
		}else{
		   if (document.body.clientHeight){
			  //Navegadores basados en IExplorer, es que no tengo innerheight
			   //yheight = document.body.clientHeight;
			   yheight = document.body.scrollHeight - 500;
		   }
		} 		
		alert(yheight + " screen: " + screen.height + " body: " + document.body.offsetHeight + " scroll: " + document.body.scrollHeight + " outer" + 	window.outerHeight + " cli: " + document.body.clientHeight);
		*/
		bar.style.height = yheight + "px";
	//}
}

window.onload = function (){ calculateHeigth();}
