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 tdwidth = tdcount.length*210+"px";
	var showwidth =	document.getElementById('table-content').clientWidth;
	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()",2);
	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 == "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 < 2)
		{
			position++;
			glideTo(eval(position-1) * 210,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 == 2)
		{
			disableAnchor(document.getElementById("slidenext"),true);
			document.getElementById("image_next").src = url_path_rotation + "next-disable.gif";
//			alert ("Next Condition - Clicked 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);
		}
		if(position > 1)
		{
			position--;
			glideTo(eval(position-1) * 210,0);
			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)
		{
			disableAnchor(document.getElementById("slideprevious"),true);
			document.getElementById("image_previous").src = url_path_rotation + "prev-disable.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}

	}
}

function do_rotation()
{
//	alert ("Show Position :"+position+" - start rotation");
	if(position < 2)
	{
		position++;
		glideTo(eval(position-1) * 210,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()
//{


//}

//script for makaan popup tab starts here

function showhide (id) {
	var d = document.getElementById(id);
		for (var i=1; i<=2; 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';
		}
}

//script for makaan popup tab ends here

//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 validating instant online report form 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 validating instant online report form ends here

//scripting for promotional tab at home page starts here

var i=1;
var j=1;
var intervalID;
var selval = 1;

function slideshow (id){

	document.getElementById('slidermenu').style.display='block';
	for(var i=1; i<=2; i++) {
		if (document.getElementById('slider'+i)){
			document.getElementById('slider'+i).style.display='none';
			document.getElementById('showlink'+i).className='showlink';
		}
	}

	document.getElementById('slider'+selval).style.display='block';
	document.getElementById('showlink'+selval).className='showactive';

	if (id=="startslide"){
		//alert ("Main if condition : "+id);
		intervalID = setInterval(startslidefn, 10000);
	}

	else if (id!="startslide" && id!="pause" && id!="play" && id!="next" && id!="prev"){
		
		selval=id;
		for(var i=1; i<=2; i++) {
			if (document.getElementById('slider'+i)){
				document.getElementById('slider'+i).style.display='none';
				document.getElementById('showlink'+i).className='showlink';
			}
		}
		document.getElementById("slider"+id).style.display='block';
		document.getElementById('showlink'+id).className='showactive';
		clearInterval(intervalID)
//		document.getElementById("pause").innerHTML='play';
//		alert ("Else if Condition - Show value of i : "+i+" - Show value of id : "+id);

//		document.slidevalfrm.slideval.value="slider"+id;
		//clearInterval(intervalID)
		intervalID = setInterval(startslidefn, 12000);
	}

	/*else if (id=="next") {
		clearInterval(intervalID)
		selval++;
		for(var i=1; i<=2; i++) {
			if (document.getElementById('slider'+i)){
				document.getElementById('slider'+i).style.display='none';
				document.getElementById('showlink'+i).className='showlink';
			}
		}

		if (selval>2){
			document.getElementById("slider1").style.display='block';
			document.getElementById("showlink1").className='showactive';
			selval=1;
		}
		else {
			selval=selval;
			document.getElementById("slider"+selval).style.display='block';
			document.getElementById("showlink"+selval).className='showactive';
			document.getElementById("pause").innerHTML='play';
		}
	}

	else if (id=="prev") {
		clearInterval(intervalID)
		selval--;
		for(var i=1; i<=2; i++) {
			if (document.getElementById('slider'+i)){
				document.getElementById('slider'+i).style.display='none';
				document.getElementById('showlink'+i).className='showlink';
			}
		}
		if (selval<1){
			document.getElementById("slider2").style.display='block';
			document.getElementById("showlink2").className='showactive';
			selval=2;
		}
		else {
			selval=selval;
			document.getElementById("slider"+selval).style.display='block';
			document.getElementById("showlink"+selval).className='showactive';
			document.getElementById("pause").innerHTML='play';
		}
	}

	else if (btnaction=="pause") {
		//alert ("Second else if condition - btn action : "+btnaction);
		for(var i=1; i<=2; i++) {
			if (document.getElementById('slider'+i)){
				document.getElementById('slider'+i).style.display='none';
				document.getElementById("showlink"+i).className='showlink';
			}
		}
		document.getElementById("slider"+selval).style.display='block';
		document.getElementById("showlink"+selval).className='showactive';
		document.getElementById("pause").innerHTML='play';
		clearInterval(intervalID)
//		alert ("Else if Condition [pause] - Show value of i : "+i+" - Show value of id : "+id);
	}

	else if (btnaction=="play") {
		//alert ("Third else if condition - btn action : "+btnaction);
		intervalID = setInterval(startslidefn, 5000);
		document.getElementById("pause").innerHTML='pause';
	}*/

}

function startslidefn (){

	for(var i=1; i<=2; i++) {
		if (document.getElementById('slider'+i)){
			document.getElementById('slider'+i).style.display='none';
			document.getElementById('showlink'+i).className='showlink';
			//alert(document.getElementById('showlink'+i).className='showlink');
		}
	}

	if (j>=2) {
		document.getElementById('slider1').style.display='block';
		document.getElementById('showlink1').className='showactive';
//		alert ("If condition where "+j+" greater than 2");
		selval='1';
		j=1;
	}

	else {
		j++;
		document.getElementById('slider'+j).style.display='block';
		document.getElementById('showlink'+j).className='showactive';
		selval=j;
//		alert ("Else Condition - Show value of j : "+j);
	}

}

//scripting for promotional tab at home page ends here
