﻿// JScript File
var content ;
var contentcontainer ;
var position = 1;
var rot_position = 0;
var rot_timer;
var maxY,wd, maxX, ready, slideDur=600, destX=0, destY=0, distY, distX, per, sliding, slideStart, aniTimer, startX, startY, xcoordinate, ycoordinate,url_path_rotation;

function load(cntId,rot_value,url_path)
{

	var tabname = document.getElementById("table-content");
	var tdcount = tabname.getElementsByTagName("td");
//	var zval = tdcount.length / 3;
//	alert (zval);
//	alert ("Number of TD : "+tdcount.length);
//	alert ("Calculated Table Width : "+tdcount.length*210);
	var tdwidth = tdcount.length*140+"px"; 
	var showwidth =	document.getElementById('table-content').clientWidth;
	showwidth = tdwidth;
//	alert (showwidth = tdwidth);
	document.getElementById('table-content').style.width = showwidth;
	
	position = 1;
	url_path_rotation = url_path;
	if(!document.getElementById)
		return;

	content = document.getElementById("content");
	contentcontainer = document.getElementById("content-container"); 
   
	content.visibility="hidden";
	content.style.top=0;
	content.style.left=0;
	xcoordinate=0;
	ycoordinate=0;
	maxY=(content.offsetHeight-contentcontainer.offsetHeight>0)?content.offsetHeight-contentcontainer.offsetHeight:0;
	wd=cntId?document.getElementById(cntId).offsetWidth:content.offsetWidth;
	maxX=(wd-contentcontainer.offsetWidth>0)?wd-contentcontainer.offsetWidth:0;
	content.style.visibility="visible";
	ready=true;
     
//	document.getElementById("slide-links").style.visibility="visible";
	document.getElementById("slideprevious").style.visibility="visible";
	document.getElementById("slidenext").style.visibility="visible";
     
	rot_timer = setInterval("do_rotation()",rot_value);

	disableAnchor(document.getElementById("slidenext"),true);
	document.getElementById("image_next").src = url_path_rotation + "next-disable.gif";
    
	disableAnchor(document.getElementById("slideprevious"),true);
	document.getElementById("image_previous").src = url_path_rotation + "prev-disable.gif";

 }

function glideTo(MstartX, MstartY)
{
	content = document.getElementById("content"); 
	contentcontainer = document.getElementById("content-container");
	startX = parseInt(content.style.left);
	if(startX == "")
	{
		startX = 0;
	}
	startY = parseInt(content.style.top);
	destX = -Math.max(Math.min(MstartX, maxX), 0);
	destY = -Math.max(Math.min(MstartY, maxY), 0);
	distY = destY - startY;
	distX =  destX - startX;
	per = Math.PI/(2 * slideDur);
	sliding = false;
	slideStart = (new Date()).getTime();
	aniTimer = setInterval("doSlide()",10);
	on_slide_start(startX, startY);
  }



function doSlide() 
{
	var elapsed = (new Date()).getTime() - slideStart;
	if (elapsed < slideDur) 
	{
		var x = startX + distX * Math.sin(per*elapsed);
		var y = startY + distY * Math.sin(per*elapsed);
		shiftTo(x, y);
		on_slide(x, y);
	} 
	else
	{	// if time's up
		clearInterval(aniTimer);
		sliding = false;
		shiftTo(destX, destY);
		//content = null;
		on_slide_end(destX, destY);
	}
}

function shiftTo(x,y)
{
	 if(typeof(x) == "number")
	 {
		content.style.left=x+"px";
		content.style.top=y+"px";
	 }
}

on_slide_start = function() {}
on_slide = function() {}
on_slide_end = function() {}


function next_previous(str,img_url)
{
	clearInterval(rot_timer);

//	alert ("Start position value: "+position);

	if(str == "previous")
	{
		
		if(document.getElementById("slidenext").href == "")
		{
			disableAnchor(document.getElementById("slidenext"),false);
			document.getElementById("image_next").src = url_path_rotation + "next.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}		
		
		//change made her position < 6
		var tabname = document.getElementById("table-content");
	    var tdcount = tabname.getElementsByTagName("td");
		if(position < tdcount.length-1)
		{
			position++;
			glideTo(eval(position-1) * 320,0);
			disableAnchor(document.getElementById("slideprevious"),false);
			document.getElementById("image_previous").src = url_path_rotation + "prev.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		//change made her position == 6
		if(position == tdcount.length-1)
		{
			disableAnchor(document.getElementById("slideprevious"),true);
			document.getElementById("image_previous").src = url_path_rotation + "prev-disable.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		
	}

	if(str == "next")
	{
		if(document.getElementById("slideprevious").href == "")
		{
			disableAnchor(document.getElementById("slideprevious"),false);
			document.getElementById("image_previous").src = url_path_rotation + "prev.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		if(position > 1)
		{
			position--;
			glideTo(eval(position-1) * 320,0);
			disableAnchor(document.getElementById("slidenext"),false);
			document.getElementById("image_next").src = url_path_rotation + "next.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		if(position == 1)
		{
			disableAnchor(document.getElementById("slidenext"),true);
			document.getElementById("image_next").src = url_path_rotation + "next-disable.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}

	}
	rot_timer = setInterval("do_rotation()",6000);
}

function do_rotation()
{
    var tabname = document.getElementById("table-content");
	var tdcount = tabname.getElementsByTagName("td");
	//alert ("Show Position :"+position+" - start rotation");
	if(position < tdcount.length-1)
	{
		position++;
		glideTo(eval(position-1) * 320,0);
		disableAnchor(document.getElementById("slideprevious"),false);
		document.getElementById("image_previous").src = url_path_rotation + "prev.gif";
		disableAnchor(document.getElementById("slidenext"),false);
		document.getElementById("image_next").src = url_path_rotation + "next.gif";
	}
	else
	{
		position = 1;
		content.style.left="0px";
		content.style.top="0px";
		disableAnchor(document.getElementById("slideprevious"),false);
		document.getElementById("image_previous").src = url_path_rotation + "prev-disable.gif";
		disableAnchor(document.getElementById("slidenext"),false);
		document.getElementById("image_next").src = url_path_rotation + "next-disable.gif";
	}

}

function disableAnchor(obj, disable)
{
	if(disable)
	{
		var href = obj.getAttribute("href");
		obj.removeAttribute('href');
	}
	else
	{
		if(obj.id == "slidenext")
		{
			obj.setAttribute('href',"javascript:next_previous('next','" + url_path_rotation + "')");
		}
		if(obj.id == "slideprevious")
		{
			obj.setAttribute('href',"javascript:next_previous('previous','" + url_path_rotation + "')");
		}
	}
}

//window.onLoad = function()
//{


//}
//function GetPath(obj)
//{
// var srcVal = document.getElementById(obj);
////      alert(srcVal.src);
//        alert(obj);
//        var strPath = srcVal.src;
//        var srcValue = '<%=txtImages.ClientID%>';
//        document.getElementById(srcValue).value = strPath;
//        alert(document.getElementById(srcValue).value);
//}

function showhide (id) {
	var d = document.getElementById(id);
		for (var i=1; i<=3; i++) {
			if (document.getElementById('reporttab0'+i)) {
				document.getElementById('reporttab0'+i).style.display='none';
				document.getElementById('reporttab0'+i+'img').src="/images/new/product-lp/reporttab0"+i+"-off.gif";
			}
		}
	if (d) {
			document.getElementById(d.id+'img').src="/images/new/product-lp/"+d.id+"-on.gif";
			d.style.display='block';
		}
}

//scripting for testimonial in reports landing page starts here

plusval = 1;

function testimonial(btnval) {

	var getdivname = document.getElementById("report-testimonialdesc");
	var noofdiv = getdivname.getElementsByTagName("div").length;

	document.getElementById("nextlink").style.display="block";

	if (btnval=="home") {
		document.getElementById("componentfrm").style.display="block";
		document.getElementById("report-testimonial").style.display="block";
	}

	if (btnval=="home" && noofdiv<=1) //condition which check if the number of testimony is less than one 
	{
		document.getElementById("nextlink").style.display="none";
	}

	if (btnval=="next") { //condition which runs when next link is clicked
		plusval++;
		for (var i=1; i<=noofdiv; i++) {
		document.getElementById('testimonial'+i).style.display='none';
//		alert ("testimonial"+i);
//		alert (noofdiv);
		//alert ("Show Next Div value "+plusval+" total number of divs "+noofdiv);
		document.getElementById('testimonial'+plusval).style.display='block';
		}
		if (plusval==noofdiv) {
			document.getElementById("nextlink").style.display="none";
			document.getElementById("prevlink").style.display="block";
		}
		else if (plusval<noofdiv && plusval > 1) {
			document.getElementById("nextlink").style.display="block";
			document.getElementById("prevlink").style.display="block";
		}
		else {
			document.getElementById("nextlink").style.display="none";
		}
	}

	if (btnval=="prev") { //condition which runs when previous link is clicked
		plusval--;
		for (var i=1; i<=noofdiv; i++) {
		document.getElementById('testimonial'+i).style.display='none';
		//alert ("testimonial"+i);
		document.getElementById('testimonial'+plusval).style.display='block';
		///alert ("Show Div value "+plusval+" total number of divs "+noofdiv);
		}
		if (plusval>1) {
			document.getElementById("nextlink").style.display="block";
		}
		else {
			document.getElementById("prevlink").style.display="none";
		}
	}

}

//scripting for testimonial in reports landing page ends here


//scripting for component values validation starts here
function componentvalidation () {
		
		var showfrmdiv = document.getElementById('myprofile');
		var selval = showfrmdiv.getElementsByTagName('select');
		
		for (var i=0; i<selval.length; i++){
			
			var selindex = document.getElementById(selval[i].id);

//			alert (selval[i].id);

			if (selindex.selectedIndex == 0){
				alert ("Please select appropriate option.");
				selindex.focus();
				return false;
			}
		}

	return true;
}
//scripting for component values validation starts here
