$(function(){
  /*IDENTIFY IE6*/ $.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);

  /*HANDLE TRANSPARENT PNGS IN IE6*/
  if($.browser.msie&&($.browser.msie6)) {
    $("#menu ul li").ifixpng();
    $(".panel").ifixpng();
    $("#central h2").ifixpng();
    $("#central ul li").ifixpng();
    $("#willy img").ifixpng();
    $("#headertext img").ifixpng();
    $("#centralbottom").ifixpng();
    $("#footertop").ifixpng();
  }


  /*HANDLE BROWSER-SPECIFIC CSS*/
  /*MOZ*/
  $("#twitter").css("-moz-border-radius","4px");
  $("ul.submenu").css("-moz-border-radius-bottomleft","10px").css("-moz-border-radius-bottomright","10px");
  $("#central").css("-moz-border-radius-bottomleft","6px").css("-moz-border-radius-bottomright","6px");
  $(".panel").css("-moz-border-radius","4px");
  $("#panels .firstpanel").css("-moz-border-radius-topleft","0").css("-moz-border-radius-topright","0");
  $("#central ul.panels").css("-moz-border-radius","10px");
  $("#breadcrumbs").css("-moz-border-radius-bottomleft","4px").css("-moz-border-radius-bottomright","4px");
  $("input.text").css("-moz-border-radius","4px");
  $("span.cms").css("-moz-border-radius","4px");
  /*WEBKIT*/
  $("#twitter").css("-webkit-border-radius","4px");
  $("ul.submenu").css("-webkit-border-bottom-left-radius","10px").css("-webkit-border-bottom-right-radius","10px");
  $("#central").css("-webkit-border-bottom-left-radius","6px").css("-webkit-border-bottom-right-radius","6px");
  $(".panel").css("-webkit-border-radius","4px");
  $("#panels .firstpanel").css("-webkit-border-top-left-radius","0").css("-webkit-border-top-right-radius","0");
  $("#central ul.panels").css("-webkit-border-radius","10px");
  $("#breadcrumbs").css("-webkit-border-bottom-left-radius","4px").css("-webkit-border-bottom-right-radius","4px");
  $("input.text").css("-webkit-border-radius","4px");
  $("span.cms").css("-webkit-border-radius","4px");

  /*HANDLE VALID CSS 3 SYNTAX BROKEN IN VALIDATOR*/
  if(!$.browser.msie) {
    $("#twitter").css("border-color","rgba(94,178,188,0.5)");
    $("#breadcrumbs").css("border-color","rgba(94,178,188,0.3)");
    $("input.text").css("border-color","rgba(94,178,188,0.3)");
    $("span.cms").css("border-color","rgba(94,178,188,0.3)");
  }




   $("#togglecms").click(function(event){
    if($(".cms").is(":visible")) {
      $(".cms").fadeOut();
      $("#togglecms").html("Show CMS Controls");
    } else {
      $(".cms").fadeIn();
      $("#togglecms").html("Hide CMS Controls");
    }
     event.preventDefault();
   });

$("#twitter").getTwitter({
		userName: "ibbyuk",
		numTweets: 1,
		loaderText: "",
		slideIn: false,
    fadeIn: true,
		showHeading: false,
		headingText: "Latest Tweets",
		showProfileLink: false
	});


  $("ul.dropdown li").hover(function(){

        $(this).addClass("hover");
        $('ul:first',this).slideDown();/*css('visibility', 'visible');*/

    }, function(){

        $(this).removeClass("hover");
        $('ul:first',this).slideUp(250);/*css('visibility', 'hidden');*/

    });

  $("a.idodeletesection").click(function(event){
    var response=confirm("Are you sure you want to delete this section?\nYou cannot undo this!");
    if(!response) {
      event.preventDefault();
    }
  });

  $("span.cmscontrol").mouseover(function(event){
    var mousedid=this.id;
    var idlen=mousedid.length;
    var sectionid="#"+mousedid.substring(1,idlen);
    $(sectionid).css("background-color","#f7f0e8");
  });

  $("span.cmscontrol").mouseout(function(event){
    var mousedid=this.id;
    var idlen=mousedid.length;
    var sectionid="#"+mousedid.substring(1,idlen);
    $(sectionid).css("background-color","");
  });

   $("span.cms a.idoeditsectionlocked").click(function(event){
     alert("This is a programmed section. It cannot be edited. Please contact Intexta if you need to make changes to this section.");
     event.preventDefault();
   });

   $("span.cms a.idoclonesectionlocked").click(function(event){
     alert("This is a programmed section. It cannot be cloned. Please contact Intexta if you need to clone this section.");
     event.preventDefault();
   });

   $("span.cms a.idodeletesectionlocked").click(function(event){
     alert("This is a programmed section. It cannot be deleted. Please contact Intexta if you need to delete this section.");
     event.preventDefault();
   });
	 
	 $(".autofocus").focus();
	 
	 /* VALIDATION */
      $("#btnSubmissionFormOK").click(function(event){
				
				  var err="";
          var submit=1;

          if($("#CV").val()=="") {
            err+="Please attach your CV/Resume before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
          if($("#Forename").val()=="") {
            err+="Please enter your First Name (forename, given name) before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
          if($("#Surname").val()=="") {
            err+="Please enter your Last Name (surname, family name) before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
          if($("#Occupation").val()=="") {
            err+="Please enter your Occupation (job title) before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
          if($("#Institution").val()=="") {
            err+="Please enter the name of your Institution (school, university) before clicking the Send Form Now button. If you are not attached to an institution, please enter 'No Institution'.\r\n\r\n";
            submit=0;
          }
          if($("#Address").val()=="") {
            err+="Please enter your Address before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
          if($("#Phone").val()=="") {
            err+="Please enter your Telephone Number before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
          if($("#Email").val()=="") {
            err+="Please enter your E-Mail Address before clicking the Send Form Now button. We will only use your e-mail address to contact you about matters directly related to the congress, and we will not pass it on to any third party.\r\n\r\n";
            submit=0;
          }
          if($("#PaperTitle").val()=="") {
            err+="Please enter the title of your proposed paper before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
					
					var themeid = $("input[@name=Theme]:checked").attr('id');
					if(themeid==undefined) {
						err+="Please click the button corresponding to the broad theme of the congress which your paper addresses.\r\n\r\n";
            submit=0;
					}
					
					var sessionid = $("input[@name=Session]:checked").attr('id');
					if(sessionid==undefined) {
						err+="Please click the button corresponding to the parallel session in which your paper should be included.\r\n\r\n";
            submit=0;
					}					
					
					
					if($("#Summary").val()=="") {
            err+="Please include a 60 word summary in English or Spanish.\r\n\r\n";
            submit=0;
          }
					if($("#Abstract").val()=="") {
            err+="Please include a 500 word abstract in English.\r\n\r\n";
            submit=0;
          }							

          if(submit==0) {
            alert(err);
						return false;
          } else {
            return true;
					}
           


       });
			
			
			
			
			
$("#btnPosterSessionFormOK").click(function(event){
				
				  var err="";
          var submit=1;

          if($("#Forename").val()=="") {
            err+="Please enter your First Name (forename, given name) before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
          if($("#Surname").val()=="") {
            err+="Please enter your Last Name (surname, family name) before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
          if($("#Occupation").val()=="") {
            err+="Please enter your Occupation (job title) before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
          if($("#Institution").val()=="") {
            err+="Please enter the name of your Institution (school, university) before clicking the Send Form Now button. If you are not attached to an institution, please enter 'No Institution'.\r\n\r\n";
            submit=0;
          }
          if($("#Address").val()=="") {
            err+="Please enter your Address before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
          if($("#Phone").val()=="") {
            err+="Please enter your Telephone Number before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
          if($("#Email").val()=="") {
            err+="Please enter your E-Mail Address before clicking the Send Form Now button. We will only use your e-mail address to contact you about matters directly related to the congress, and we will not pass it on to any third party.\r\n\r\n";
            submit=0;
          }
          if($("#PaperTitle").val()=="") {
            err+="Please enter the title of your proposed poster session before clicking the Send Form Now button.\r\n\r\n";
            submit=0;
          }
									
					if($("#Summary").val()=="") {
            err+="Please include a 250 word summary in English.\r\n\r\n";
            submit=0;
          }
					

          if(submit==0) {
            alert(err);
						return false;
          } else {
            return true;
					}
           


       });
	

			
	 

});
