$(document).ready(function(){
	$('#newsletter_form .btn-smll').click(function(){
		$.ad.track({ "newsletter": {"signup":true} });		
	});
});

var videoDomain = 'video.foxnews.com';

String.prototype.ucFirst = function () {
    return this.substr(0,1).toUpperCase() +  this.substr(1,this.length);
};

function AuthorPage() {
  $('select.author-page-redirct').each(function(){
      $(this).unbind('change').bind('change',function(change){
    window.location = $(this).attr('value');
      });
  });
  }
/** NEW VIDEO PLAYER FUNCTIONS **/
/*
playShowsVideo();
playShowsVideoAttempt();
setSmoothScroll(); -> setSlideshowVideoItems();
*/

function playShowsVideo(videoId,autoplay) {
  // it plays on page load
  holderElm = $(".video-player-wrapper");
  var id = "videoid:g"+videoId; // g for grab video
  var config = {
    holder: holderElm,
    type: "video",
    id: id,
    cssClass: "video-player-format",
    autoplay: true,
    callbacks: { // define callback functions
      feedLoaded: function(data) { updatePageContent(data); }, // if new feed is loaded
      dataChanged: function(data) { updatePageContent(data); }, // if current data was changed
      videoEnded: function(controls) {
        if (controls) { // html5 controls
          controls.jumpTo(id,0);
          controls.pause(id);
        }
        //playNextSlideshowVideo(videoId);
      }
    }
  }

  $(document).ready(function(){
    videoPlayer.render(config);
    /*
    videoPlayer.getFeed({
      id: id,
      callback: function(data) {
        console.log(data);
      }

    });
    */
  });

}

function playNextSlideshowVideo(id) {
  id = id || false;
  var list = $("ul#accordion .slideshow > ul"),
    items = list.children(),
    first = list.children(":first"),
    selected = list.children(".selected:first"),
    selData = returnItemData(selected.find("a:first"));

  function trigger(target) {
    target = target || false;
    if (target) {
      target = target.next();
      if (target.size()===0) { target = first; } // if no next item, default to first
    } else {
      target = first;
    }

    var data = returnItemData(target.find("a:first"));

    pageVars.videoId = data.videoId;
    pageVars.playlistId = data.playlistId;
    document.location.hash = data.href; // add video link as hash

    items.removeClass("selected");
    target.addClass("selected");
    playShowsVideo(data.videoId,true);
  }

  function findId() {
    var elm = false;
    items.find("a:first").each(function(){
      var data = returnItemData($(this));
      if (data.videoId===id) { elm = $(this); return; }
    });
    trigger(elm);
  }

  if (id && selData.videoId===id) {
    trigger(selected);
  } else if (id && selData.videoId!==id) {
    findId();
  } else {
    trigger(selected);
  }
}

function playNextVideo() {
  var videoId = (pageVars && pageVars.videoId) ? pageVars.videoId : false;
  playNextSlideshowVideo(videoId);
}

function returnItemData(aTag) {
  var href = oFoxVideo.cleanHref(aTag.attr("href"));
  var playlistId = oFoxVideo.extractVideoId(href);
  var videoId = oFoxVideo.extractVideoId(href);

  var obj = {
    href: href,
    playlistId: playlistId,
    videoId: videoId
  };

  return obj;
}

function playShowsVideoAttempt(videoId,autoplay) { // DEPRECATED - video player object in video player prototype
  playShowsVideo(videoId,autoplay);
}

function setSlideshowVideoItems(videoItems) {
  videoItems = videoItems || false;
  if (!videoItems) { return false; }

  videoItems.each(function(i){
    var item = $(this);

    item.find("a:first").each(function(){
      var data = returnItemData($(this));

      if (!item.data("itemVideoId")) { // set this for reference on playNexSlideshowVideo()
        item.data("itemVideoId",data.videoId);
      }
    });


    item.find("a").click(function(){
      var data = returnItemData($(this));

      pageVars.videoId = data.videoId;
      pageVars.playlistId = data.playlistId;

      videoItems.removeClass("selected");
      $('li[class=""]').removeAttr("class");
      item.addClass("selected");
      document.location.hash = data.href;
      playShowsVideo(data.videoId,true);
      return false;

    });

  });

}

function updatePageContent(oVideo) {
  // page elements
  var article = $(".article");
  article.find("h2").html(oVideo.title);
  article.find(".date").html(oVideo.creationDate);
  article.find("p.description").html(oVideo.description);
  $('#embed-input').val('<script type="text/javascript" src="http://' + videoDomain + '/embed.js?id=' + pageVars.videoId + '&w=400&h=249"></script><noscript>Watch the latest video at <a href="http://video.foxnews.com/">FOXNews.com</a></noscript>');

  // share this
  shareInfo.title = oVideo.title;
  shareInfo.summary = oVideo.shortDescription;
  shareInfo.url = 'http://' + videoDomain + '/v/' + pageVars.videoId + '/' + oFoxVideo.cleanTitle(shareInfo.title) + '?playlist_id=' + pageVars.playlistId;
  shareInfo.icon = 'http://' + videoDomain + oFoxVideo.cleanImageUrl(oVideo.thumbnail);
}


/** NEW VIDEO PLAYER FUNCTIONS - END **/

function transcriptUpdateSelect(obj, value) {
  jQuery.ajax({
        type: 'POST',
        url: Drupal.settings.base_url+'/transcript_category/'+value,
        success: function(data){
          jQuery('#latest-transcripts').html(data);
        }
  });
  jQuery('.dropdown.current-value').html($('#transcript-select :selected').text());
  var datedisplayed = new Date('01 '+jQuery('.turn-me-into-datepicker h2').html());
  transcriptUpdateAvailableDays((datedisplayed.asString()).substring(6,10),(datedisplayed.asString()).substring(3,5));
}

function transcriptUpdateAvailableDays(year,month) {
  jQuery.getJSON(Drupal.settings.base_url+'/transcript_exists/'+year+month+'/'+$('#transcript-select').val()+'?callback=?',
    function(data) {
      $('.current-month').addClass('disabled');
      jQuery.each(data, function(i, item) {
        $('.dp-calendar td.current-month').each(
        function() {
          if (Number($(this).text()) == item) {
            $(this).removeClass('disabled');
          }
        });
      });
  });
}

jQuery.fn.exists=function(){return jQuery(this).length>0;}

function createCarouselButtons(obj) {
    var list = []
    for (var x=1;x<=obj.batch.max;x++) {
      list.push('<li><a href="#">&nbsp;&nbsp;&nbsp;</a></li>');
    }
    return list.join('');
}

//for links with hash
function scrollToCarouselItem(id) {
  id = id || false;
  if (!id) { return false; }
  var loop = 100;

  $("#accordion .section-mod").each(function(){
    var carousel = $(this);
    var children = carousel.find("ul:first").children();
    var title = carousel.children().filter("h2.title:first");

    children.each(function(){
      var item = $(this);
      if (item.find("a[href*='/v/"+id+"/']:first").size()>0) {
        children.removeClass("selected");
        var n = 0;
        function trigger() {
          if (carousel.data("isCarouselLoaded")) {
            if (!title.hasClass("active")) { title.trigger("click"); } // trigger accordion if not the opened accordion
            item.trigger("focusCarouselOnItem"); // trigger bind item from carousel
            item.addClass("selected"); // selected
          } else if (n<loop) {
            n++;
            setTimeout(function(){ trigger(); },10);
          }
        }
        trigger();
      }
    });

  });
};

imgCaptions = function(){
  $('#content .transcript').find('img').each( function(){

    var thisImg = $(this);
    var thisImgAlt = thisImg.attr('alt');

    if(thisImgAlt != "" && thisImgAlt != "Quantcast"){

      thisImg.wrap('<div class="hmedia fn" style="width: '+ (thisImg.attr('width')+10)+'px; float:left" >');
      thisImg.after('<p class="fn">' + thisImgAlt + '</p>');
      thisImg.addClass('alignleft');

    }
  });
}

$(document).ready(function(){
  imgCaptions();
  $.ad.init();
  
  /*** External Links ***/
  (function(){
	 var wOpen = function(elm,force) {
	   if (!elm.data("relSet")) {
		  elm.data("relSet",true).click(function(){ 
			 var win = $(window), props = "width="+win.width()+",height="+win.height()+",location=1,resizable=1,scrollbars=1,menubar=1,status=0,titlebar=1,toolbar=1";
			 window.open($(this).attr("href"),"_blank",(force) ? props : null); 
			 return false; 
		  });
	   }
	 };
	
	 // force window open first
	 $("#nav-related a[rel='external']").each(function(){ wOpen($(this),true); });

	 // the rest of the externals
	 $("a[rel='external']").each(function(){ wOpen($(this)); });

  }());
  
  AuthorPage();
  // video player
  if (Drupal.settings.videoplayer) {
    if (document.location.hash!='') {
      pageVars.playlistId = document.location.hash.substring(1).split('playlist_id=')[1];
      pageVars.videoId = document.location.hash.substring(1).split('/')[2];
    }

    var slideshowVideos = $("ul#accordion").find(".slideshow ul").children();
    setSlideshowVideoItems(slideshowVideos);
    slideshowVideos.filter(":first").addClass("selected");

    // clipboard copy app
    if (jQuery('#embed-input').length >= 1) {
      clip = new ZeroClipboard.Client();
      clip.setHandCursor( true );
      clip.glue('embed-but');
      clip.addEventListener( 'mouseDown', function(client) {
        clip.setText($('#embed-input').val());
      });
    }
  }

  /*** Twitter ***/
  if (jQuery('#twitter_module').length >= 1) {
    var url = 'http://twitter.com/status/user_timeline/'+jQuery('#twitter_id').val()+'.json?count=3&callback=?';
    jQuery.getJSON(url,
     function(data){
      var w_names = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
      var m_names = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
      var html = '';
      jQuery.each(data, function(i, item) {
        var profile_picture = '';
        var values = item.created_at.split(" ");
        time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
        var post_date = new Date(Date.parse(time_value));
        post_time = (post_date.getHours() > 12) ? (post_date.getHours()%12)+'PM' : post_date.getHours()+'AM';
        html += '<li><blockquote><p>'+item.text.ucFirst()+'</p></blockquote><p class="time">'+post_time+' '+w_names[post_date.getDay()]+', '+m_names[post_date.getMonth()]+' '+post_date.getDate()+', '+post_date.getFullYear()+'</p></li>';
      });
      jQuery("#twitter_module .content ul").html(html);
      jQuery('#twitter_module .content ul li:first-child').addClass('first');
      jQuery('#twitter_module').show();
     });	 
  }

	// omniture tracking 
	$(document).ready(function(){
		$.loadAttempt({
			maxAttempts: 30, // interval
			timeout: 500, // in ms
			callback: {
				check: function() {
					return (typeof twttr!=="undefined") ? true : false;
				},
				success: function() {
				  	twttr.events.bind('click', function(event){
						$.ad.track({ "twitter": {"click":true} });
				  });
				}
			}
		});		
	})	

  /*** Live Events Schedule ***/
  if (jQuery('#schedule-events').size() >= 1 || jQuery('#block-fox_shows_general-fox_shows_general_streaming').size() >= 1) {
  var parseInfo = window.parseInfo = function(data) {
    data = data || false;
    if (!data) { return false; }

      var channel = data.channel;
      var item = channel.item;
      item = (item instanceof Array) ? item[0] : item;

      var status = item["media-status"]["@attributes"].state;
      var isLive = (status) ? (status.toLowerCase()==="active") ? true : false : false;

      if (!isLive) {
        $("#stream-image").each(function(){
          var imgSrc = $(this).val();
          if (imgSrc) { $("#section-video .video-player-wrapper").html('<img src="'+Drupal.settings.base_url+'/'+imgSrc+'">'); }
        });
      }
    }
    jQuery.getJSON($('#show-feed').val()+'?callback=parseInfo&jsonp=?');
  }

  /*
    jQuery.getJSON($('#show-feed').val()+'?callback=parseInfo',
        function(data) {
        var islive = false;
        if (data != undefined) {
          jQuery.each(data, function(i, item) {
            if (item.show_title == $('#show-title').val()) {
            var Start = new Date(item.now);
            var End = new Date(item.now);
            Start.setMinutes(Start.getMinutes() + 15);
            End.setMinutes(End.getMinutes() - 15);
              if (((new Date(item.episode_start_time)) < Start) && ((new Date(item.episode_end_time)) > End)) {
                islive = true;
              }
            }
          });
        }
        if ($('#show-title').val() && !islive && jQuery('#stream-image').val()) {
          jQuery('#section-video .video-player-wrapper').html('<img src="'+Drupal.settings.base_url+'/'+jQuery('#stream-image').val()+'">');
        }
   });
  */

  /*** IE6 Selector Fix ***/
  //$(".description").after('<div class="br"></div>');
  //$(".br + *").css("paddingTop", "5px");

  /*** List 2 ****/
  $(".list-2,.list-features").each(function(i) {
      var $list = $(this).find(".list");

      $list.wrap('<div class="list-encapsulator"></div>');
  });

  /*** Apps ***/
  $(".apps ul").each(function(){
    var ul = $(this);
    var item = ul.find("li");
    var size = item.size();

    ul.find("li:nth-child(even)").addClass("alt");
    ul.find("li:last").addClass("last-type");

    if (size%2===0) {
      ul.find("li:nth-child(" + (size-1) + ")").addClass("last-type");
    }
  });

  /*** Tabbed Mod ***/
  $(".tabbed-mod,.tabbed-mod2").each(function(i) {
  var item = $(this).find("> .content"), tabs = item.find("> .controller li"), content = item.find("> .section");

  tabs.each(function(i){
    var tab = $(this);
    tab.find("a:first").click(function(){
      toggle(tabs); toggle(content); // hide
      toggle(tab,true); toggle(item.find("> .section:eq("+i+")"),true); // show
      return false;
    });
  });

  function toggle(elm,bool) {
    bool = bool || false;
    elm.toggleClass("active",bool);
  }
  });

  /*** User Options ***/
  $("#content:first").each(function() {
    var $init = $(this);
    var $parentMod = $init.find(".user-options p");
    var $targetText = $init.find(".section-description");
    $targetText.css("font-size","12px");

    $parentMod.each(function(i) {
      $parentMod.find("a").click(function() {
        var $this = $(this);
        var textSize = parseFloat($targetText.css("fontSize").replace("px",""));

        if ($this.is(":nth-child(1)")) {
          if (textSize > 10) {
            $targetText.css("fontSize", textSize - 1 + "px");
          }
        }

        if ($this.is(":nth-child(2)")) {
          if (textSize < 16) {
            $targetText.css("fontSize", textSize + 1 + "px");
          }
        }

        return false;

      });
    });
  });

  /*** Date Picker ***/
  if ($("div").is(".turn-me-into-datepicker")) {
    $('.turn-me-into-datepicker')
    .datePicker({inline:true,startDate: '01/01/2000',endDate: (new Date()).asString()})
    .bind(
      'dateSelected',
      function(e, selectedDate, $td)
      {
        var vocab_id = ($('#transcript-select').length >= 1) ? $('#transcript-select').val() : 1;
        jQuery.ajax({
          type: 'POST',
          url: Drupal.settings.base_url+'/transcript_url/'+((new Date(selectedDate)).asString('yyyymmdd'))+'/'+vocab_id,
          success: function(data){
            window.location = Drupal.settings.base_url+'/'+data;
          }
        });
      }
    );
    transcriptUpdateAvailableDays(((new Date()).asString()).substring(6,10),((new Date()).asString()).substring(3,5));

    $('.turn-me-into-datepicker')
    .datePicker({inline:true})
    .bind(
      'dpMonthChanged',
      function(e, displayedMonth, displayedYear)
      {
        $('.current-month').addClass('disabled');
        var displayedMonth = (++displayedMonth < 10) ? '0'+displayedMonth : displayedMonth;
        transcriptUpdateAvailableDays(displayedYear,displayedMonth);
      }
    );

  }


  /*** Start Attribute ***/
  var count = 1;

  $("ol.list").each(function(i) {
    if (i == 0) {
      count = $("li", this).size() + 1;
    }

    else {
      $(this).attr("start", count);
      count = count + $("li", this).size();
    }
  });

  if ($(".format-1").css("float") == "left") {
    $(".format-1").find(".description").css("margin-left","127px");
  }

  /*** Accordion ***/
  $("#accordion .title").append('<span class="indicator"></span>');

  $("ul[id='accordion']").jfoxAccordion({
    duration: 400,
    speed: "fast",
    activeClass: "active"
  });

  /*** Carousel ***/
	(function(){
		
		var setLinkItems = function(elm,control) {
			elm.each(function(i){
				$(this).click(function(){
               control.stopAutoScroll();
               control.scrollToBatch(i+1);
               return false;
             });
			});
		};
		
		$("#accordion .section-mod, #photo-slide-show .section-mod").each(function(i){
			var carousel = $(this),
				isFancyBox = (carousel.parent().hasClass("photo-slide-mod")) ? true : false;
			
			var config = {
	      	auto: { set:false,speed:3000 }, // auto scroll
	      	slide: 'horizontal', // horizontal or vertical
	      	scroll: 3, // number of items to scroll per event
	      	show: 4, // items shown
	      	speed: "slow", // scroll speed
	      	rotate: true, // rotate back to star if end
	      	eventCallback: function(obj) { // callback function for all carousel events
	        		if (obj.event=='init') {
	          		carousel.data("isCarouselLoaded",true);
	          		$(".content ol:first",carousel).html(createCarouselButtons(obj)); // create the buttons
	          		$(".content ol li:first",carousel).addClass("active"); // set the first one as always active
	          		if (obj.batch.max == 1) { //remove buttons and controls if less than one page
	            		carousel.children('.content').children('.sectioning').remove();
	            		carousel.children('.content').children('.controls').remove();
	          		}
	        		}
					carousel.find("ol.sectioning > li").each(function(i){ // button highlight listener
						var sel = (i+1 === obj.batch.current) ? true : false;
						$(this).toggleClass("active",sel);
					});
	      	},
	      	controlsCallback: function(control) { // callback to set up controls

					setLinkItems(carousel.find("ol > li a"),control);
					
					carousel.find(".prev").click(function(){ // previous link
						control.stopAutoScroll();
						control.slide('prev');
						return false;
					});
					
					carousel.find(".next").click(function(){ // next link
						control.stopAutoScroll();
						control.slide('next');
						return false;
					});
					
	        		// set up event listener - focus
	    			carousel.find("div.slideshow ul:first").children().each(function(i){
	      			$(this).bind("focusCarouselOnItem",function(){
	        				control.stopAutoScroll();
	        				control.scrollToItem(i+1);
	        				return false;
	      			});
	    			});
	      	}
	    	};
	
			// for fancy box slideshows
			if (isFancyBox) {
				config.scroll = 7;
				config.show = 7;
				config.scrollType = "absolute";
				
				var items = carousel.parent().find(".slideshow > ul > li > ul > li a");
				items.attr("rel","s-group-1");
				items.each(function(){
					var href = $(this).attr("href");
					// href = href.replace(".preview.jpg",".gallery.jpg");
					$(this).attr("href",href);
				});
				items.fancybox({
					transitionIn: "none",
					transitionOut: "none",
					centerOnScroll: true,
					autoScale: false,
					onStart: function() {
						
					}
				});
				
			}	
				
			carousel.jfoxCarousel(config);
			
			var listenerConfig = {
				elm: carousel,
				moveSensitivity: 15,
				eventsCallback: {
					touchmoveMoveOnce: function(direction,moveProperties,rawEvent) {
						// move callback - sensitivity
						var directions = direction.join("|");

						if (directions.indexOf("left")>-1) {
							carousel.find(".next").click();
						}

						if (directions.indexOf("right")>-1) {
							carousel.find(".prev").click();
						}
					}
				}
			};

			touchEventListener.append(listenerConfig);
	
		});
		
	}());

	// "iframe" issue workaround
	touchEventListener.reTriggerListener();
  
 // Newsletter signup
  var core_url = Drupal.settings.base_url.substring(0, Drupal.settings.base_url.indexOf("/on-air/"));
  $('#newsletter_form').submit(function(){
      var emailAddress = $('#newsletter_input').val();
      var newsletterSLID = $('#newsletter_slid').val();
     if(echeck(emailAddress)== true){

       $.ajax({
           url: core_url + '/portal/newsalertsubscribe',
           data:'slids='+newsletterSLID+'&email='+ emailAddress,
            contentType:'text/xml',
            dataType:'xml',
            type: "GET",
            success: function(data) {

             $(data).find('list').each(function(){
                if($(this).text() == "ok"){
                    $('#newsletter_form').parent().html('<div class="block_notice"><strong>'+ emailAddress + '</strong> is now registered </div>');
                }else{
                    $('#newsletter_form').parent().html('<div class="block_notice"><strong>'+ emailAddress + '</strong> could not be added at this time.</div>');
                }
              });
            },
            error: function(data,e){

              $('#newsletter_form').parent().html('<div class="block_notice" style="border: 1px solid #ffff00; background-color:#ffffe0"><strong>Address could not be added at this time.</strong></div>');

            }
         });

  } else if ($('.block_notice').length < 1){
      $('#newsletter_form').parent().prepend('<div class="block_notice" style="border: 1px solid #ffff00; background-color:#ffffe0"><strong>Invalid email address. Please click here to try again.</strong></div>');
  }

     return false;
  });


  //blog image captions
  $('.post .content, .node .content').each( function(){
    var content = $(this);
    var imgs = content.find('img');

    imgs.each(function(){

      var thisImg = $(this);
      var thisImgAlt = thisImg.attr('alt');
      var parent = thisImg.parent();

      if(thisImgAlt != "" && thisImgAlt != "Quantcast"){
        if(parent.hasClass('img_link')){

          parent.wrap('<div class="hmedia fn" style="width: '+ (thisImg.attr('width')+10)+'px; float:left" >');
          parent.after('<p>' + thisImgAlt + '</p>');

        }
        else{
          thisImg.wrap('<div class="hmedia fn" style="width: '+ (thisImg.attr('width')+10)+'px;" float:"left" >');
          thisImg.after('<p>' + thisImgAlt + '</p>');
        }
        thisImg.addClass('alignleft');
      }
    });
  });

  /*** Tool Tip ***/
  $("#document:first").each(function(i) {
    var $init = $(this);
    var $tooltip = $init.find(".tooltip");

    $tooltip.hover(function(e) {
      var $this = $(this);
      var title = $this.attr("title");
      var message = '<div class="informative">'+title+'</div>';

      $init.append(message);

      return false;
    },
    function() {
      $("div.informative").remove();
    });

    $tooltip.mousemove(function(e) {
      $("div.informative").css({
        "top" : e.pageY + -40,
        "left" : e.pageX + -310
      });
    });

  });



  /*** Blogs video slider module ***/
    $("#feature-slider").each(function(){
          var target = $(this),
                  controlElm = target.find("> .content > .encap > .controls "),
                  paginationElm = target.find("> .content > .encap > .nums"),
                  sectionElm = target.find("> .content > .slideshow ul"),
                  prev = controlElm.find(".prev"),
                  next = controlElm.find(".next"),
                  currentNumElm = paginationElm.find(".current-num"),
                  maxNumElm = paginationElm.find(".max-num");

          var config = {
                  auto: false, // auto scroll
                  slide: 'horizontal', // horizontal or vertical
                  scroll: 2, // number of items to scroll per event
                  show: 2, // items shown
                  speed: "slow", // scroll speed
                  rotate: false, // rotate back to star if end
                  eventCallback: function(obj) { // callback function for all carousel events
                          if (obj.event==="init") { maxNumElm.html(obj.batch.max); } // set max batch
                          currentNumElm.html(obj.batch.current); // current batch
                          next.toggleClass("inactive-next",(obj.batch.current===obj.batch.max));
                          prev.toggleClass("inactive-prev",(obj.batch.current===1));
                  },
                  controlsCallback: function(control) { // callback to set up controls
                          prev.click(function(){ // previous link
                                  control.stopAutoScroll();
                                  control.slide("prev");
                                  return false;
                          });

                          next.click(function(){ // next link
                                  control.stopAutoScroll();
                                  control.slide("next");
                                  return false;
                          });
                  }
          };

          target.jfoxCarousel(config);
    });

});

function echeck(str) {
  var at="@";
  var dot=".";
  var lat=str.indexOf(at);
  var lstr=str.length;
  var ldot=str.indexOf(dot);
  if (str.indexOf(at)==-1){
    return false;
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     return false;
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    return false;
  }
  if (str.indexOf(at,(lat+1))!=-1){
    return false;
  }
  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    return false;
  }
  if (str.indexOf(dot,(lat+2))==-1){
    return false;
  }
  if (str.indexOf(" ")!=-1){
    return false;
  }

  return true;
}

