var _$ = document; 
function $(element) {
    return ((typeof(element) == 'string')?_$.getElementById(element):element);
}

/* Glider code start */
function glider(middleContainerOfGlider,currentShown,intervals,glidingTime){
	this.gliderCodeRunning = 0;
	this.noOfInterval = (typeof(intervals) == 'undefined')?10:intervals;
	this.timeForGliding = (typeof(glidingTime) == 'undefined')?500:glidingTime;
    try
    {
        var arrayOfChildNodes = this.getFirstLevelChilds(middleContainerOfGlider);
        var widthOfSingleDiv = arrayOfChildNodes[0].offsetWidth;
        middleContainerOfGlider.parentNode.style.width = widthOfSingleDiv+'px';
        for(var i=0;i<arrayOfChildNodes.length;i++){
            arrayOfChildNodes[i].style.width = widthOfSingleDiv+'px';
            arrayOfChildNodes[i].innerHTML += '&nbsp;';
            if(i == currentShown){
                this.changeFirstDivChild(arrayOfChildNodes[i],'');
            }else{
                this.changeFirstDivChild(arrayOfChildNodes[i],'none');
            }
        }
        middleContainerOfGlider.style.width = ((arrayOfChildNodes.length*widthOfSingleDiv)+50) + 'px';
        middleContainerOfGlider.style.left = (Number(currentShown)*Number(widthOfSingleDiv)*(-1)) + 'px';
    }
    catch(e)
    {
    }
	return;
}
glider.prototype.setWidthOfParentDiv = function (parentDivEle,widthOfSingleDiv,noOfDivsAppended){
	var arrayOfChilds = this.getFirstLevelChilds(parentDivEle);
	parentDivEle.style.width = (((arrayOfChilds.length+noOfDivsAppended)*widthOfSingleDiv)+50)+'px';
	return;
}
glider.prototype.setLeftPosition = function(parentDivEle,incrementBy,noOfDivsAppended,widthOfSingleDiv){
	if((incrementBy < 0) && (noOfDivsAppended < 0)){
		parentDivEle.style.left = (noOfDivsAppended*widthOfSingleDiv)+'px';
	}
	if((incrementBy > 0) && (noOfDivsAppended < 0)){
		parentDivEle.style.left = (-(parentDivEle.offsetWidth - widthOfSingleDiv -50))+'px';
	}
	return;
}
glider.prototype.checkLimits = function (parentDivEle,incrementBy,widthOfSingleDiv){
	var flagForLimits = false;
	if(((this.getNumVal(parentDivEle.style.width)-50) == Math.abs(this.getNumVal(parentDivEle.style.left)-Number(widthOfSingleDiv))) && (incrementBy > 0)){
		flagForLimits = 'upper';
	}else if((this.getNumVal(parentDivEle.style.left) == 0) && (incrementBy < 0)){
		flagForLimits = 'lower';
	}
	return flagForLimits;
}
glider.prototype.getNumVal = function (value1){
	return Number(value1.substring(0,(value1.length - 2)));
}
//noOfDivsAppended should be less than zero if divs are appended before and vice versa.
glider.prototype.slideIt = function (idOfParentEle,incrementBy,rotateIt,noOfDivsAppended){
	if(this.gliderCodeRunning ==1){
		return false;
	}
	var parentDivEle = $(idOfParentEle);
	var noOfDivsAppended = (typeof(noOfDivsAppended) == 'undefined')?0:noOfDivsAppended;
	var arrayOfChilds = this.getFirstLevelChilds(parentDivEle);
	var widthOfSingleDiv = arrayOfChilds[0].offsetWidth;
	this.setLeftPosition(parentDivEle,incrementBy,noOfDivsAppended,widthOfSingleDiv);		
	var currentShownDiv = parentDivEle.getAttribute('currentShownDiv');
	var previousShownDivEle = $(idOfParentEle+currentShownDiv);
	currentShownDiv = parseInt(currentShownDiv) + incrementBy;
	var limitCheck = this.checkLimits(parentDivEle,incrementBy,widthOfSingleDiv);
	if(limitCheck != false){
		if(!rotateIt){
			return false;
		}else{
			if(limitCheck == 'upper'){
				this.changeFirstDivChild(arrayOfChilds[0],'');
				parentDivEle.style.left='0px';
				this.changeFirstDivChild(arrayOfChilds[arrayOfChilds.length-1],'none');
				var divNumber = arrayOfChilds[0].getAttribute('divNumber');
			}else{
				this.changeFirstDivChild(arrayOfChilds[arrayOfChilds.length-1],'');
				parentDivEle.style.left= - (gliderObject.getNumVal(parentDivEle.style.width)-widthOfSingleDiv-50)+'px';
				this.changeFirstDivChild(arrayOfChilds[0],'none');
				var divNumber = arrayOfChilds[arrayOfChilds.length-1].getAttribute('divNumber');
			}
			parentDivEle.setAttribute('currentShownDiv',divNumber);
			return false;
		}
	}
	parentDivEle.setAttribute('currentShownDiv',currentShownDiv);
	this.changeFirstDivChild($(idOfParentEle+currentShownDiv),'');
	this.gliderCodeRunning = 1;
	this.alterWithInterval(parentDivEle,previousShownDivEle,incrementBy);
	return;
}
glider.prototype.changeFirstDivChild = function (Object1,property){
	Object1.getElementsByTagName("div")[0].style.display = property;
	return;
}
glider.prototype.alterWithInterval = function (parentDivEle,Object1,typeOfInterval){
	var width1 = this.getNumVal(Object1.style.width);
	var interval = (width1/this.noOfInterval)*typeOfInterval;
	var leftPosition = this.getNumVal(parentDivEle.style.left);
	var finalLeftValue = leftPosition - (width1*typeOfInterval);
	var thisObject = this;
	var count = 0;
	var intervalHadle = setInterval(function (){
		leftPosition = leftPosition - interval;
		parentDivEle.style.left = (leftPosition)+'px';
		count++;
		if(count >= thisObject.noOfInterval){parentDivEle.style.left = (finalLeftValue)+'px'; clearInterval(intervalHadle); thisObject.gliderCodeRunning = 0;  thisObject.changeFirstDivChild(Object1,'none'); }
	},(thisObject.timeForGliding/thisObject.noOfInterval));
	return;
} 

glider.prototype.getFirstLevelChilds = function (Object1){
	var immediateChilds = Object1.childNodes;
	var parentDivEleId = Object1.id;
	var children = new Array();
	for(var i=0;i<immediateChilds.length;i++){
		if((immediateChilds[i].nodeType == 1) && (immediateChilds[i].id.indexOf(parentDivEleId) != -1)){
			children.push(immediateChilds[i])
		}
	}
	return children;	
}
/* Glider code end */


/* ScrollImage Change As per Scroll */
jCount = 2;
function changeScrollImage(parDiv, imageName, increaseNo){
	var par =document.getElementById(parDiv);
	var childs=par.getElementsByTagName('img');
	if(jCount>childs.length){
		jCount=1;
	}
	var imgName = imageName+jCount;	
	for(var i=0; i<childs.length; i++)
	{
		if (childs[i].id == imgName)
		{
			childs[i].src = "images/fillSqr.gif";
		}
		else
		{
			childs[i].src = "images/blankSqr.gif";
		}
	}
	jCount = jCount+increaseNo;
}

QnA = 2;
function changeScrollImageQnA(parDiv, imageName, increaseNo){
	var par =document.getElementById(parDiv);
	var childs=par.getElementsByTagName('img');
	if(QnA>childs.length){
		QnA=1;
	}
	var imgName = imageName+QnA;	
	for(var i=0; i<childs.length; i++)
	{
		if (childs[i].id == imgName)
		{
			childs[i].src = "images/fillSqr.gif";
		}
		else
		{
			childs[i].src = "images/blankSqr.gif";
		}
	}
	QnA = QnA+increaseNo;
}

/* Carsoual Function 
function changeLeftPos(val){
	objCar = document.getElementById('homepageCar');
	getAttr = document.getElementById('homepageCar').getAttribute('divValue');
	objlImg =  document.getElementById('lftArrow');
	objrImg =  document.getElementById('rftArrow');
	var value;
	if(val==1){
		if(eval(getAttr)==0)
		value = 0;
		else
		value = (eval(getAttr)+875);
		objCar.style.left = value+'px';
		document.getElementById('homepageCar').setAttribute('divValue', value);
	} else {
		if(eval(getAttr)==-3500)
		value = 0;
		else
		value = (eval(getAttr)-875);
		objCar.style.left = value+'px';
		document.getElementById('homepageCar').setAttribute('divValue', value);
	}
	if(value<-1){
		objlImg.src='/images/homepage/carouelLftArwA.gif';
	} else {
		objlImg.src='/images/homepage/carouelLftArw.gif';
	}
}
*/

/* Test Preparation Code */
url="http://www.topcoaching.com/mba";
function testPrepartionData(tab){
	var par =document.getElementById('testPrepTab');
	var childs=par.getElementsByTagName('li');
	var parDiv =document.getElementById('testPrepDataWrapper');
	var childsDiv=parDiv.getElementsByTagName('div');
	var objBtn = document.getElementById('testPrepButton');
	for(i=0; i<childs.length; i++)
	{	
		if (childs[i].id == tab)
		{
			childs[i].className = "active";
			childsDiv[i].style.display = 'block';
			if(tab =="mbaTest"){objBtn.value = "Start Preparation For MBA";objBtn.style.width="200px";url='http://www.topcoaching.com/mba';}
			if(tab =="engineerTest"){objBtn.value = "Start Preparation For Engineer";objBtn.style.width="230px";url="http://www.topcoaching.com/engineerTest";}
			if(tab =="lawTest"){objBtn.value = "Start Preparation For Law";objBtn.style.width="200px";url="http://www.topcoaching.com/lawTest";}
			if(tab =="mcaTest"){objBtn.value = "Start Preparation For MCA";objBtn.style.width="200px";url="http://www.topcoaching.com/mcaTest";}
			if(tab =="bbaTest"){objBtn.value = "Start Preparation For BBA";objBtn.style.width="200px";url="http://www.topcoaching.com/bbaTest";}
		}
		else
		{
			childs[i].className = "";
			childsDiv[i].style.display = 'none';
		}
	}
}
function goToPage(){
	window.location = url;
}
function showMenu(val){
	/* Start MainTab Selection */	
	var par =document.getElementById('mainTab');	
	var childs=par.getElementsByTagName('li');
	var objDD = document.getElementById('ddMenu');
	var objLI = document.getElementById(val);
	var mainDiv = document.getElementById('mainWrapper');
	objDD.innerHTML = '';
	if(objLI.className=="active"){
		objDD.style.display = "none";
		objLI.className = '';
	} else {	
		for(i=0; i<childs.length; i++)
		{
			if (childs[i].id == val)
			{
				childs[i].className = "active";
			}
			else
			{
				childs[i].className = "";
			}
		}
		/* End MainTab Selection */	
		var arr = new Array();
		var menuValue = '';
		var menuWidth ='';
		if(val=='mba'){
			/* 1st value is dropdwnValue and second is drop dwn link */
			arr[0]=["MBA in Managemen", "http://www.topcoaching.com/mim.html"];
			arr[1]=["MBA in Business", "http://www.topcoaching.com/mib.html"];
			arr[2]=["MBA in Technology", "http://www.topcoaching.com/mit.html"];
			arr[3]=["MBA in Finance", "http://www.topcoaching.com/mif.html"];
			menuWidth = 'width:200px';
		} else if(val=='engineering'){
			/* 1st value is dropdwnValue and second is drop dwn link */
			arr[0]=["Engineering in Managemen", "http://www.topcoaching.com/mim.html"];
			arr[1]=["Engineering in Business", "http://www.topcoaching.com/mib.html"];
			arr[2]=["Engineering in Technology", "http://www.topcoaching.com/mit.html"];
			arr[3]=["Engineering in Finance", "http://www.topcoaching.com/mif.html"];
			menuWidth = 'width:220px';
		} else if(val=='courses'){
			/* 1st value is dropdwnValue and second is drop dwn link */
			arr[0]=["Course in Managemen", "http://www.topcoaching.com/mim.html"];
			arr[1]=["Course in Business", "http://www.topcoaching.com/mib.html"];
			arr[2]=["Course in Technology", "http://www.topcoaching.com/mit.html"];
			arr[3]=["Course in Finance", "http://www.topcoaching.com/mif.html"];
			menuWidth = 'width:200px';
		} else if(val=='testprep'){
			/* 1st value is dropdwnValue and second is drop dwn link */
			arr[0]=["Testprep in Managemen", "http://www.topcoaching.com/mim.html"];
			arr[1]=["Testprep in Business", "http://www.topcoaching.com/mib.html"];
			arr[2]=["Testprep in Technology", "http://www.topcoaching.com/mit.html"];
			arr[3]=["Testprep in Finance", "http://www.topcoaching.com/mif.html"];
			menuWidth = 'width:220px';
		} else if(val=='studyabroad'){
			/* 1st value is dropdwnValue and second is drop dwn link */
			arr[0]=["Studyabroad in Managemen", "http://www.topcoaching.com/mim.html"];
			arr[1]=["Studyabroad in Business", "http://www.topcoaching.com/mib.html"];
			arr[2]=["Studyabroad in Technology", "http://www.topcoaching.com/mit.html"];
			arr[3]=["Studyabroad in Finance", "http://www.topcoaching.com/mif.html"];
			menuWidth = 'width:230px';
		}
		menuValue = '<ul id="menuUL">';
		for (i=0;i<arr.length;i++){
			if(arr[i][0]){
				menuValue += '<li style="'+menuWidth+'"><a href="'+arr[i][1]+'">'+arr[i][0]+'</a></li>';
			}
		}
		menuValue += '</ul>';	
		objDD.innerHTML = menuValue;
		objDD.style.display ='';
		if(document.all){
			objDD.style.left = 	objLI.offsetLeft - ((screen.width - mainDiv.offsetWidth)/2)-3+'px';
		} else {
			objDD.style.left = 	objLI.offsetLeft - ((screen.width - mainDiv.offsetWidth)/2)-8+'px';
		}
	}
}
function hideMenu(val){
	var par =document.getElementById('mainTab');	
	var childs=par.getElementsByTagName('li');
	var objDD = document.getElementById('ddMenu');
	for(i=0; i<childs.length; i++)
	{
		if (childs[i].id == val)
		{
			childs[i].className = "";
			//objDD.style.display = "none"; 
		}		
	}
}
function showTabData(parDivName,obj){
	var par =document.getElementById(parDivName);
	var childs=par.getElementsByTagName('li');
	for(i=0; i<childs.length; i++)
	{	
		if (childs[i].id == obj){			
			childs[i].className = "active";
			document.getElementById(childs[i].id+"_open").style.display = "block";
			
		} else {
			childs[i].className = "";
			document.getElementById(childs[i].id+"_open").style.display = "none";
		}
	}
}
function showTabData_1(parDivName,obj){
	var par =document.getElementById(parDivName);
	var childs=par.getElementsByTagName('li');
	for(i=0; i<childs.length; i++)
	{	
		if (childs[i].id == obj){			
			childs[i].className = "selected_1";
			
		} else {
			childs[i].className = "";
		}
	}
}
function showDivAsPerId(obj, objshowHiddenDiv){	
	if(objshowHiddenDiv.style.display =="none"){
		obj.className = "headOpen";
		objshowHiddenDiv.style.display = "block";
	} else {
		obj.className = "headClose";
		objshowHiddenDiv.style.display = "none";
	}
}
function openArea(tID){	
	var pParent = document.getElementById('aaaList');
	var cChild = pParent.getElementsByTagName('p');	
	for(var i=0; i<cChild.length; i++)
	{
		if (cChild[i].id == tID)
		{
			cChild[i].style.display = "";
		}
		else
		{		
			cChild[i].style.display = "none";
		}
	}
}
function cancelAns(tID){
	var tParent = document.getElementById(tID);
	tParent.style.display = "none";	
}




function f_showTab(parDivName,obj,cName){
	var par =document.getElementById(parDivName);
	var childs=par.getElementsByTagName('li');
	for(i=0; i<childs.length; i++)
	{	
		if (childs[i].id == obj){			
			childs[i].className = cName;
			if(document.getElementById(childs[i].id+"_open")){
				document.getElementById(childs[i].id+"_open").style.display = "block";
			}
			
		} else {
			childs[i].className = "";
			if(document.getElementById(childs[i].id+"_open")){
				document.getElementById(childs[i].id+"_open").style.display = "none";
			}
		}
	}
}
