﻿//
// Browser Detection
//
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
IE7 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)? true : false;


// JScript File

function initgallery()
{
	tOffset = 0;
	thumbLength = 3040;
	scrollLength = 190;
	isscroll = false;
	index = 1;
	current_direction = "";
}

function scrollingLeft() 
{	
	if (tOffset == 0)
	{
		document.getElementById("scroller").style.marginLeft = tOffset + "px";
		isscroll = false;
		return false;
	}
	else if (tOffset % 120 == 0 && isscroll)
	{
		document.getElementById("scroller").style.marginLeft = tOffset + "px";
		isscroll = false;
		clearTimeout(doscroll);
	}
	else
	{
		if (tOffset % 120 == 0)
			Fade("left");
			
		isscroll = true;
		tOffset = tOffset + 10;
		document.getElementById("scroller").style.marginLeft = tOffset + "px";
		doscroll = setTimeout("scrollingLeft()", 20);
	}
}

function scrollingRight(MaxRight) {

	if (tOffset <= MaxRight)
	{
		document.getElementById("scroller").style.marginLeft = tOffset + "px";
		isscroll = false;
		return false;
	}
	else if (tOffset % 120 == 0 && isscroll)
	{
		document.getElementById("scroller").style.marginLeft = tOffset + "px";
		isscroll = false;
		clearTimeout(doscroll);
		
		if (tOffset < -1140)
		{
			isscroll = false;
		}
	}
	else
	{
		if (tOffset % 120 == 0)
			Fade("right");
			
		isscroll = true;
		document.getElementById("scroller").style.marginLeft = tOffset + "px";
		tOffset = tOffset - 10;
		doscroll = setTimeout("scrollingRight(" + MaxRight + ")", 20);
	}
}

function Fade(direction)
{
	if (current_direction != direction && current_direction != "")
	{
		if (direction == "right")
			index = index + 1;	
		else
			index = index - 1;
	}

	if (direction == "right")
	{
		$("#t" + index).fadeTo('slow', 0.01);
		$("#t" + (index+5)).fadeTo('slow', 1);

		current_direction = "right";
		
		index = index + 1;		
	}
	else
	{
		$("#t" + index).fadeTo('slow', 1);
		$("#t" + (index+5)).fadeTo('slow', 0.01);

		current_direction = "left";
		
		if (index > 0)
			index = index - 1;		
	}
}	

function changeimage(imgurl, caption, name, index, count)
{
	//alert(" inhere");
	$("#mainphoto").toggle();
	$('#mainphoto').html('<img src=\"'+imgurl+'\" alt=\"'+name+'\" title=\"'+name+'\" class=\"feature noborder\" />');
	$('#mainphoto').fadeIn('slow');
	
	$('#photodesc').html('<h2>' + name + '</h2>' + caption + '<div class="pagenum"> ' + index + ' / ' + count + '</div>');

}
function getObj( id )
{
	if (document.getElementById)
	{
		this.obj = document.getElementById( id );
		this.style = document.getElementById( id ).style;
	}
	else if (document.all)
	{
		this.obj = document.all[ id ];
		this.style = document.all[ id ].style;
	}
	else if (document.layers)
	{
		this.obj = document.layers[ id ];
		this.style = document.layers[ id ];
	}
	else 
	{
		alert("Can not find the object");
	}
}

function showBubbleBox(obj, id, blind) 
{
	var popin = new getObj(id)
	var intmoveLeft = 0;
	var intmoveTop = 0;
	
	if (id == "SendToFriend")
	{
		intmoveLeft = 60;
		intmoveTop = -170;
	}
	else if (id == "BubbleBox")
	{
		intmoveLeft = 60;
		intmoveTop = -110;
	}
	else if (id == "SendingBox")
	{
		intmoveLeft = 60;
		intmoveTop = -95;
	}

	if (obj && popin.obj)	
	{
		popin.style.top = findPosTop(obj) + intmoveTop + 'px';
		popin.style.left = findPosLeft(obj) + intmoveLeft + 'px';
	}
	
	
	if (blind && !IE6)
		$('#' + id).BlindRight(750);
	else
	{
		popin.style.display = "block";
		popin.style.visibility = "visible";
	}
}

function hideBubbleBox(id)
{
	if (!IE6)
		$('#' + id).BlindLeft(750);
	else
	{
		var popin = new getObj(id)

		popin.style.display = "none";
		popin.style.visibility = "hidden";
	}
}

//This function 
function send_emailtofriend(){
	var friend_email = new getObj('friend_email');
	var email = new getObj('email');
	if(check_email(friend_email.obj.value)&&check_email(email.obj.value)){
		alert("This function need to be completed in backend to send the page's id");
	} else {
		alert("This function need to be completed in backend to send the page's id");
	}
}

function ValidateForm(groupname)
{
	var FailedArray = new Array();
	var Page_IsValid = true;
	
    for (var i = 0; i < Page_Validators.length; i++) 
    {
		var passed = true;
		
		for (var j=0;j<FailedArray.length;j++)
		{
			if (FailedArray[j] == Page_Validators[i].controltovalidate)
			{	
				passed = false;
				continue;
			}
		}
		
		if (passed == false)
			continue;
		
		ValidatorValidate(Page_Validators[i], groupname, null);
		
		if (!Page_Validators[i].isvalid && Page_Validators[i].validationGroup == groupname)
		{
			FailedArray.push(Page_Validators[i].controltovalidate);
			IndicateInput($get(Page_Validators[i].controltovalidate));
			Page_IsValid = false;
		}
		else if (Page_Validators[i].isvalid && Page_Validators[i].validationGroup == groupname)
		{
			ClearIndicator($get(Page_Validators[i].controltovalidate));
		}
    }
		
	return Page_IsValid;
}

/******** Form raise error function *****/
function ClearIndicator(forminput) {
	if (forminput == null) return;
	forminput.style.background 	= '#FFFFFF';
	forminput.style.border 		= 'solid 1px #799dc1';
	//document.getElementById("errMsg").innerHTML = "";
}

function IndicateInput(forminput) {
	if (forminput == null) return;
	forminput.style.background 	= '#fcfbcf';
	forminput.style.border 		= 'solid 1px #FF0000';
	forminput.focus();
}


//findPosLeft and findPosTop are two helper function for ShowOverLayerContentCentralized_1
function findPosLeft(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosTop(obj) {
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}