// JavaScript Document
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
function getHashVars()
{
    var vars = [], hash;
    var string = window.location.hash.replace("#","");
	
	string = string.split("&");
	
    for(var i = 0; i < string.length; i++)
    {
        hash = string[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
function openHashTabs()
{
	var vars = getHashVars();
	if(typeof vars.menu == "string")
	{
		onMenuClick(vars.menu);
		if(typeof vars.submenu == "string")
		{
			onMenuClick(vars.submenu);
			if(typeof vars.links == "string")
			{
				onMenuClick(vars.links);
			}
		}
	}
}
function callBackOnClick(id)
{
	var pos = getMenuPosition(id);
	if(pos.id == 'leftMenu' && countSubMenu(id) > 0)
	{
		openSubMenu(id)	
	}
	else
	{
		closeSubMenu();
	}
	if(id=="home")
	{
		document.getElementById("viewPoint").className="viewPointHome";
		document.getElementById("topMenu_home").style.backgroundImage='url("global/page_6/images/backHomeButton.jpg")';
		document.getElementById("topMenu_literature").style.backgroundImage='';
		document.getElementById("topMenu_multimedia").style.backgroundImage='';
		document.getElementById("topMenu_downloads").style.backgroundImage='';
		document.getElementById("topMenu_contactus").style.backgroundImage='';
		
		document.getElementById("applicationWindow").style.backgroundImage = 'url("global/page_6/images/backHomeBG.png")';
		document.getElementById("website").style.backgroundImage='url("global/page_6/images/backHomeBG.png")';
		
	}
	else if(id=="literature")
	{
		document.getElementById("viewPoint").className="viewPointLiterature";
		document.getElementById("topMenu_home").style.backgroundImage='';
		document.getElementById("topMenu_literature").style.backgroundImage='url("global/page_6/images/backLiteratureButton.jpg")';
		document.getElementById("topMenu_multimedia").style.backgroundImage='';
		document.getElementById("topMenu_downloads").style.backgroundImage='';
		document.getElementById("topMenu_contactus").style.backgroundImage='';

		document.getElementById("applicationWindow").style.backgroundImage = 'url("global/page_6/images/backLiteratureBG.png")';
		document.getElementById("website").style.backgroundImage='url("global/page_6/images/backLiteratureBG.png")';
	}
	else if(id=="multimedia")
	{
		document.getElementById("viewPoint").className="viewPointMultimedia";
		document.getElementById("topMenu_home").style.backgroundImage='';
		document.getElementById("topMenu_literature").style.backgroundImage='';
		document.getElementById("topMenu_multimedia").style.backgroundImage='url("global/page_6/images/backMultimediaButton.jpg")';
		document.getElementById("topMenu_downloads").style.backgroundImage='';
		document.getElementById("topMenu_contactus").style.backgroundImage='';
		
		document.getElementById("applicationWindow").style.backgroundImage = 'url("global/page_6/images/backMultimediaBG.png")';
		document.getElementById("website").style.backgroundImage='url("global/page_6/images/backMultimediaBG.png")';
	}
	else if(id=="downloads")
	{
		document.getElementById("viewPoint").className="viewPointDownloads";
		document.getElementById("topMenu_home").style.backgroundImage='';
		document.getElementById("topMenu_literature").style.backgroundImage='';
		document.getElementById("topMenu_multimedia").style.backgroundImage='';
		document.getElementById("topMenu_downloads").style.backgroundImage='url("global/page_6/images/backDownloadButton.jpg")';
		document.getElementById("topMenu_contactus").style.backgroundImage='';
		
		document.getElementById("applicationWindow").style.backgroundImage = 'url("global/page_6/images/backDownloadBG.png")';
		document.getElementById("website").style.backgroundImage='url("global/page_6/images/backDownloadBG.png")';
	}
	else if(id=="contactus")
	{
		document.getElementById("viewPoint").className="viewPointContectus";
		document.getElementById("topMenu_home").style.backgroundImage='';
		document.getElementById("topMenu_literature").style.backgroundImage='';
		document.getElementById("topMenu_multimedia").style.backgroundImage='';
		document.getElementById("topMenu_downloads").style.backgroundImage='';
		document.getElementById("topMenu_contactus").style.backgroundImage='url("global/page_6/images/backContectusButton.jpg")';
		
		document.getElementById("applicationWindow").style.backgroundImage = 'url("global/page_6/images/backContectusBG.png")';
		document.getElementById("website").style.backgroundImage='url("global/page_6/images/backContectusBG.png")';
	}
}

function postLoadData(id)
{
	if(id=="latest" )
	{
			Shadowbox.clearCache(); 
			Shadowbox.setup(); 
			openUstreamPlayer();
			//Shadowbox.init({displayCounter:false});
	}


}
function openSubMenu(id)
{
	if(document.getElementById('subMenuDiv')==null)
	{
		var obj = document.createElement('div');
		obj.id="subMenuDiv";
		obj.className = 'subMenuDiv';
		var dataDiv = document.createElement('div');
		dataDiv.id = 'subMenuData';
		obj.appendChild(dataDiv);
		var closeLink = document.createElement('div');
		closeLink.innerHTML = '<a href="javascript:closeSubMenu()">Close</a>';
		closeLink.style.marginTop="20px";
		//obj.appendChild(closeLink);
		
		document.getElementById('displayDiv').appendChild(obj);
	}
}
function closeSubMenu()
{
	if(document.getElementById('subMenuDiv')!=null)
	{
		document.getElementById('displayDiv').removeChild(document.getElementById('subMenuDiv'));
	}
}
function makeAccordian(obj)
{
	if(obj.id == "booksDownload" || obj.id == "multimediaDownload" || obj.id == "images" )
	{
		$( "#accordianList" ).accordion();
	}

//	alert(obj.id);
}
function openDownloadDetail(id,app,p)
{
	var action="getFilelist";
	if(id=="photoDownloadDetail")
	{
		action="getPhotothumb";
	}
	$.post(applicationPath+"remoteService.php","a=remote&ac="+action+"&id="+app+"&p=remoteAccess",
	function(resp)
	{
		document.getElementById('displayDiv').innerHTML="";
		var obj = document.createElement('div');
		obj.style.margin="10px";
		obj.innerHTML=resp;
		document.getElementById('displayDiv').appendChild(obj);
		$('.scrollbar2').corner();
		$('.roundCorner').corner();
		$('.scrollbar2').shortscroll();
	});
}
function openDownloadSubDetail(app,id)
{
	$.post(applicationPath+"remoteService.php","a=remote&ac=getFilelist&id="+app+"&p=remoteAccess",
	function(resp)
	{
		document.getElementById('displayDiv').innerHTML="";
		var obj = document.createElement('div');
		obj.style.margin="10px";
		obj.innerHTML=resp;
		document.getElementById('displayDiv').appendChild(obj);
		$('.scrollbar2').corner();
		$('.roundCorner').corner();
		$('.scrollbar2').shortscroll();
	});
	//$.blockUI({ message: '<h1><img src="global/page_3/images/busy.gif" /> Just a moment...</h1>' });
}
function createSlideShow()
{
	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 5000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
}

function getcity(obj)
{
//document.write("this is selected")
var statecode = obj.value;
$.post("/global/page_6/php/service.php", "id=getCity&state=" + statecode , 
function(response) { document.getElementById("city").innerHTML = response;		
	});
}

function getaddressData(state, obj)
{
//document.write("this is selected")
var citycode = obj.value;
$.post("/global/page_6/php/service.php", "id=getaddressData&state=" + state + "&city=" + citycode, 
function(response) {  document.getElementById("addressData").innerHTML = response;		
	});
}
function loadUstreamPlayer(id,width,height)
{
	var html='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" name="utv35280" width="'+width+'" height="'+height+'" id="utv35280">                      <param name="flashvars" value="autoplay=false&brand=embed&cid=4683728&locale=en_US"/>                      <param name="allowfullscreen" value="true"/>                      <param name="allowscriptaccess" value="always"/>                      <param name="movie" value="http://www.ustream.tv/flash/live/1/4683728"/>                      <embed flashvars="autoplay=false&brand=embed&cid=4683728&locale=en_US" width="'+width+'" height="'+height+'" allowfullscreen="true" allowscriptaccess="always" id="utv35280" name="utv35280" src="http://www.ustream.tv/flash/live/1/4683728" type="application/x-shockwave-flash" /></embed>                      </embed>                    </object>';
	document.getElementById(id).innerHTML=html;
}

function openUstreamPlayer()
{
	loadUstreamPlayer("ustreamVideoPlayer",200,150);
}
function goPage(obj)
{
	window.open(obj.value);
}
var topStatus="max";
function minimizeTop()
{
	if(topStatus=="max")
	{
		document.getElementById("applicationWindow").style.top="-117px";
		topStatus = "min";
	}
	else
	{
		document.getElementById("applicationWindow").style.top="0px";
		topStatus = "max";		
	}
}
function blockUI()
{
	
	busy("applicationWindow");

}
function unBlockUi()
{
	
	free("applicationWindow");

}
function goToPage2(val)
{
	var w = document.getElementById('word');
	var o = document.getElementById('select2');
	//PageIndex2=document.select2.selectedIndex
	if (o.value != "none")
	{
		window.open("http://literature.awgp.org/search/"+o.value+"/"+val);
	}
} 
function writetous()
{
	var email = document.getElementById("email").value;
	var name = document.getElementById("name").value;
	var to = document.getElementById("destination").value;
	var msg = document.getElementById("message").value;
	
	if(validateEmail(email)==false)
	{
		alert("Please entry a valid email address.");
		return;
	}
	if(name=="")
	{
		alert("Enter your name.");
		return;
	}
	if(msg=="")
	{
		alert("Enter message.");
		return;
	}
	$.post("global/page_6/php/writetous.php?t="+to+"&f="+email+"&n="+name+"&m="+msg,
	function(resp)
	{
		if(resp=="1")
		{
			document.getElementById("email").value="";
			document.getElementById("name").value="";
			document.getElementById("message").value="";
			alert("Mail has been sent to web team.");
		}
		else
		{
			alert(resp);
		}
	});
}

function validateEmail(x)
{
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
  return false;
  }
}

function joinSMSEmail()
{
	var SubEmail = document.getElementById("SubscriptionEmail").value;
	var checkedData = ""
	if (document.getElementById("Thought").checked == true)
	{
		checkedData = "1";		
	}
	if (document.getElementById("WebSwadhyay").checked == true)
	{ 	
		if(checkedData == "")
		{
		checkedData = "2";		
		}
		else 
		{
		checkedData = checkedData + ",2";					
		}
	}
	if (document.getElementById("EmailSubs").checked == true)
	  {
		if(checkedData == "")
		{
		checkedData = "3";		
		}
		else 
		{
		checkedData = checkedData + ",3";					
		}
	  }
	if (document.getElementById("5KJigyasa").checked == true)
	{
		if(checkedData == "")
		{
		checkedData = "4";		
		}
		else 
		{
		checkedData = checkedData + ",4";					
		}
	}
	if (checkedData == "") 
	{
		alert("Please select atleast one checkbox");
		return;
	}
	if(validateEmail(SubEmail)==false)   
	{
		alert("Please entry a valid email address.");
		return;
	}
	$.post("global/page_6/php/joinSMSEmail.php?t="+checkedData+"&s="+SubEmail,
	function(resp)			  
	{ 
		if(resp.length > 0)
		{
			document.getElementById("SubscriptionEmail").value="";
			alert("Mail has been sent to respective team.");
		}
		else
		{
			alert(resp);
		}
	});
		
}
