﻿var carousel;
function showCarousels()
{
	
	carousel = new YAHOO.widget.Carousel("GalleryCarousel", {
		isCircular: true // for a circular Carousel
	});
	carousel.getElementsByClassName("yui-carousel-content","div");
	carousel.set("numVisible", 5);
	carousel.set("animation", { speed: 0.5 });
	carousel.render();
	carousel.show();
	
	var car = document.getElementById("GalleryCarousel");
	car.getElementsByTagName("DIV")[1].style.width = "775px";
	car.style.width = "775px";	
}

function ValidateForm()
{
	var form = document.forms[0];
	if (isnull(form.fullName.value))
	{
		alert("Please fill your name.");
		form.fullName.focus();
		return false;
	}
	
	if (!ValidateEmail(form.email.value))
	{
		alert("The email address is not valid.");
		form.email.focus();
		return false;
	}
	
	if (isnull(form.subject.value))
	{
		alert("The subject/title field is empty.");
		form.subject.focus();
		return false;
	}
	
	if (isnull(form.message.value))
	{
		alert("The message field is empty.");
		form.message.focus();
		return false;
	}
	
	form.submit();
}

function ValidateEmail(email)
{
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
    if (!filter.test(email)) 
	{
		return false;
	}
	else
	    return true;
}

function trim(str)
{
	try {
		return str.replace(/^\s+|\s+$/g,'');
	} catch (e) {
		return str;
	}
}
function isnull(arg)
{
	arg = arg+'';
	return (arg == '' || arg == 'null' || arg == 'undefined');
}

function viewComments(docid)
{
	if (typeof ClickTaleExec == "function") {
		if(docid) {
			ClickTaleExec("viewComments('" + docid + "')");
		}
	}
	
	var commentsDiv = document.getElementById(docid + 'CommentsDiv');
	var img = document.getElementById(docid + "_gif");
	if (isnull(commentsDiv.style.display) || commentsDiv.style.display == 'none') {
		commentsDiv.style.display = 'block';
		img.src = '/Images/Minus.gif';
	}
	else {
		commentsDiv.style.display = 'none';
		img.src = '/Images/Plus.gif';
	}
	
	//Clicktale tag
    if (typeof ClickTaleTag == "function") {
    	ClickTaleTag("OpenClose_Comments");
    }  
}

// logic for the smooth scrolling functionality
// taken from : http://www.itnewb.com/v/Creating-the-Smooth-Scroll-Effect-with-JavaScript
 
function currentYPosition() {
       if (self.pageYOffset)
              return self.pageYOffset;
       if (document.documentElement && document.documentElement.scrollTop)
              return document.documentElement.scrollTop;
       if (document.body.scrollTop)
              return document.body.scrollTop;
       return 0;
}
function elmYPosition(eID) {
       var elm = document.getElementById(eID);
       var y = elm.offsetTop;
       var node = elm;
       while (node.offsetParent && node.offsetParent != document.body) {
              node = node.offsetParent;
              y += node.offsetTop;
       } return y;
}
function smoothScroll(eID) {
       var startY = currentYPosition();
       var stopY = elmYPosition(eID);
       var distance = stopY > startY ? stopY - startY : startY - stopY;
       if (distance < 100) {
              scrollTo(0, stopY); return;
       }
       var speed = Math.round(distance / 100);
       var step = Math.round(distance / 25);
       var leapY = stopY > startY ? startY + step : startY - step;
       var timer = 0;
       if (stopY > startY) {
              for (var i = startY; i < stopY; i += step) {
                     setTimeout("window.scrollTo(0, " + leapY + ")", timer * speed);
                     leapY += step; if (leapY > stopY) leapY = stopY; timer++;
              } return;
       }
       for (var i = startY; i > stopY; i -= step) {
              setTimeout("window.scrollTo(0, " + leapY + ")", timer * speed);
              leapY -= step; if (leapY < stopY) leapY = stopY; timer++;
       }
}

function TogglePostComments(elem)
{
	if (typeof ClickTaleExec == "function") {
		if(rowID) {
			ClickTaleExec("OpenTalkBacks('" + rowID + "')");
		}
	}

    var obj = document.getElementById(rowID);
    var img = document.getElementById(rowID + "_gif");
    if (obj.style.display == "")
    {
        obj.style.display = 'none';
        img.src = '/Images/Minus.gif';
    }
    else if (obj.style.display == "none")
    {
        obj.style.display = 'block';
        img.src = '/Images/Minus.gif';
    }
    else if (obj.style.display == "block")
    {
        obj.style.display = 'none';
        img.src = '/Images/Plus.gif';
    }
    
    //Clicktale tag
    if (typeof ClickTaleTag == "function") {
    	ClickTaleTag("OpenClose_Talkback");
    }    
}
