var tt, nn;
var update_course_cost = 0;

$(document).ready(
	function(){
		$('#banner_panel').innerfade({
			animationtype: 'fade',
			speed: 'slow',
			timeout: 8000,
			type:'sequence',
			containerheight: '284px'
		});
		$('#testimonial_panel').innerfade({
			animationtype: 'fade',
			speed: 'slow',
			timeout: 5000,
			type:'sequence'
			
		});
		$('#news_panel').innerfade({
			animationtype: 'fade',
			speed: 'slow',
			timeout: 5000,
			type:'sequence'
			
		});		
		$('#sap_solutions_panel').innerfade({
			animationtype: 'fade',
			speed: 'slow',
			timeout: 5000,
			type:'sequence'
			
		});
		$('#support_services_panel').innerfade({
			animationtype: 'fade',
			speed: 'slow',
			timeout: 5000,
			type:'sequence'
			
		});
		$('#training_panel').innerfade({
			animationtype: 'fade',
			speed: 'slow',
			timeout: 5000,
			type:'sequence'
			
		});		
		$('#update_events').innerfade({
			animationtype: 'slide',
			speed: 1000,
			timeout: 2000,
			type:'sequence',
			containerheight: '20px'
		});	
		$("#change_country_panel").fancybox({
			'titleShow'     : false,
			'autoScale'	: true,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
		$("#contact_us_left").fancybox({
			'titleShow'     : false,
			'autoScale'	: false,
			'width'		: 350,
			'height'	: 350,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
		$(".contactblock").fancybox({
			'titleShow'     : false,
			'autoScale'	: false,
			'width'		: 350,
			'height'	: 350,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});		
		$(".schdtl").fancybox({
			'titleShow'     : false,
			'autoScale'	: true,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});			
});

$(function() {
	$("#img_slider").jCarouselLite({
		auto: 800,
		speed: 1000,
		visible: 6
	});       
});

function clear_control(id,val)
{
	if($("#"+id).val()==val || $("#"+id).val()=="")
		$("#"+id).val("");
}

function show_countrydd(id)
{
	var divid = id+'_ddpanel';
	if(typeof(document.getElementById(divid))=='undefined' || document.getElementById(divid)==null)
	{
		var div = document.createElement('div');
		div.id=divid;
		div.className='dd_input';
		div.setAttribute("style",'margin-left:-215px;');
		var parent = document.getElementById(id).parentNode;
		parent.appendChild(div);

		$.get('/dropdown_data.php?param=country', function(data) {
		  $('#'+divid).html(data);
		});
	}
	else
	{
		$('#'+divid).toggle();
	}	
}

function show_categorydd(id)
{
	var divid = id+'_ddpanel';
	if(typeof(document.getElementById(divid))=='undefined' || document.getElementById(divid)==null)
	{
		var div = document.createElement('div');
		div.id=divid;
		div.className='dd_input';
		div.setAttribute("style",'margin-left:-315px;');
		var parent = document.getElementById(id).parentNode;
		parent.appendChild(div);

		$.get('/dropdown_data.php?param=category', function(data) {
		  $('#'+divid).html(data);
		});
	}
	else
	{
		$('#'+divid).toggle();
	}	
}


function country_dd_done(id)
{
	var obj = document.getElementById(id);
	var panelid = obj.parentNode.id;
	$('#'+panelid).toggle();
}

function clearAllChkByClass(id,NoVal)
{
	var sel_class = id;
	var selected=0;
	with(document.getElementById("training_search_frm"))
	{
		for(i=0;i<elements.length;i++)
		{
			if(elements[i].type=='checkbox' && elements[i].className==sel_class)
			{
				elements[i].checked=false;
				var parentnode = elements[i].parentNode;
				parentnode.className='select_dd';
			}
		}
	}
	if(document.getElementById(id).parentNode.parentNode.children[0].type=="hidden")
	{
		var hiddenctrol = document.getElementById(id).parentNode.parentNode.children[0].id;
		var mainctrol = document.getElementById(id).parentNode.parentNode.children[1].id;
		$("#"+hiddenctrol).val("");
		$("#"+mainctrol).val(NoVal);
	}	
}

function selectAllChkByClass(id,MulVal)
{
	var sel_class = id;
	if(document.getElementById(id).parentNode.parentNode.children[0].type=="hidden")
	{
		var hiddenctrol = document.getElementById(id).parentNode.parentNode.children[0].id;
		var mainctrol = document.getElementById(id).parentNode.parentNode.children[1].id;
	}
	var selected=0;
	with(document.getElementById("training_search_frm"))
	{
		for(i=0;i<elements.length;i++)
		{
			if(elements[i].type=='checkbox' && elements[i].className==sel_class)
			{
				selected++;
				var update = elements[i].value.split("||");
				elements[i].checked=true;
				var parentnode = elements[i].parentNode;
				parentnode.className='select_dd_hover';
				if(selected>1)
					$("#"+hiddenctrol).val($("#"+hiddenctrol).val()+","+update[0]);
				else
					$("#"+hiddenctrol).val(update[0]);				
			}
		}
	}
	if(selected>1)
	{
		$("#"+mainctrol).val(MulVal);
	}
}

function search_select_country(id,record,data)
{
	var selectaedLabel = "No Country";
	if(id.checked)
	{
		var parentNode = id.parentNode;
		parentNode.className='select_dd_hover';
	}
	else
	{
		var parentNode = id.parentNode;
		parentNode.className='select_dd';	
	}
	var selected=0;
	with(document.getElementById('training_search_frm'))
	{
		for(i=0;i<elements.length;i++)
		{
			if(elements[i].checked && elements[i].type=='checkbox' && elements[i].className=="search_country_panel")
			{
				var update = elements[i].value.split("||");
				selectaedLabel=update[1];
				selected++;
				if(selected>1)
					$("#selected_country").val($("#selected_country").val()+","+update[0]);
				else
					$("#selected_country").val(update[0]);				
			}	
		}	
	}
	if(selected>1)
	{
		$("#sel_country").val("Multiple Countries");
	}
	else
	{
		$("#sel_country").val(selectaedLabel);		
	}	
}

function search_select_category(id,record,data)
{
	var selectaedLabel = "No Category";
	if(id.checked)
	{
		var parentNode = id.parentNode;
		parentNode.className='select_dd_hover';
	}
	else
	{
		var parentNode = id.parentNode;
		parentNode.className='select_dd';	
	}
	var selected=0;
	with(document.getElementById('training_search_frm'))
	{
		for(i=0;i<elements.length;i++)
		{
			if(elements[i].checked && elements[i].type=='checkbox' && elements[i].className=="search_category_panel")
			{
				var update = elements[i].value.split("||");
				selectaedLabel=update[1];
				selected++;
				if(selected>1)
					$("#selected_category").val($("#selected_category").val()+","+update[0]);
				else
					$("#selected_category").val(update[0]);				
			}	
		}	
	}
	if(selected>1)
	{
		$("#sel_category").val("Multiple Categories");
	}
	else
	{
		$("#sel_category").val(selectaedLabel.substr(0,20));		
	}	
}


function choose_country(country,abbr)
{
	$.get("/set_country.php",{q:abbr}, function(data) {
	  $('#top_phone_lbl').html(data);
	  if(update_course_cost==1)
	  {
	  	update_course_sch(abbr);
	  }
	});
	$("#country_title").html(country);
	$('#fancybox-close').trigger('click'); 
}

function show_submenu(ctrl,id)
{
	$(ctrl).addClass("midmenu_hover");
	if($(ctrl).find("a").attr('class')=="main_link_selected" || $(ctrl).find("a").attr('class')=="main_link_selected main_link_sel_text")
	{
		$(ctrl).find("a").addClass("main_link_sel_text");
	}
	else
		$(ctrl).find("a").removeClass("main_link");
	$(ctrl).find("a").addClass("midmenu_hover_a");
	if(id!="") $("#"+id+"_submenu").toggle();
}

function hide_submenu(ctrl,id)
{
	if(id!="") $("#"+id+"_submenu").toggle();
	$(ctrl).removeClass("midmenu_hover");
	$(ctrl).find("a").removeClass("midmenu_hover_a");
	if($(ctrl).find("a").attr('class')=="main_link_selected" || $(ctrl).find("a").attr('class')=="main_link_selected main_link_sel_text")
		$(ctrl).find("a").removeClass("main_link_sel_text");
	else
		$(ctrl).find("a").addClass("main_link");
}

function show_banner(prefix,cnt,total)
{
	clearTimeout(tt);
	clearTimeout(nn);
	var sid = prefix+cnt;
	var hid="";

	for(i=1;i<=total;i++)
	{
		hid=prefix+i;
		$('#'+hid).css('display','none');
	}	
	$('#'+sid).css('display','block');
}

function update_course_sch(val)
{
	course_id = $("#course_id").val();
	$.get('/update_course_sch.php?country='+val + '&course_id='+course_id, function(data) {
		var response=data.split("||");
		$('#course_sch_panel').html(response[0]);	
		$("#countrydd").val(response[1]);		
		$(".schdtl").fancybox({
			'titleShow'     : false,
			'autoScale'	: true,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});		
	});	
}

function showhide_courses(id,imgid,imgpath)
{
	if($("#"+id).is(':visible'))
		$("#"+imgid).attr('src',imgpath + 'images/plus.png');
	else
		$("#"+imgid).attr('src',imgpath + 'images/minus.png');
	
	$("#"+id).toggle();
}
