// JavaScript Document



// Ready DOM
$(document).ready(function(){
	
	// Focuss on html control
	$("input[type=text],input[type=password],textarea,select").focus(function (){
		$(this).css('background-color','#E0F4FF');
		if($(this).attr('title') == $(this).val() || $(this).val() == '')
			$(this).val('');
	});
	$("input[type=text],input[type=password],textarea,select").blur(function (){
		$(this).css('background-color','#FFFFFF');
		if($(this).attr('title') == $(this).val() || $(this).val() == '')
			$(this).val($(this).attr('title'));
	});
						   
	// Paymement Option
	$(".tabLink").each(function(){
      $(this).click(function(){
        tabeId = $(this).attr('id');
        $(".tabLink").removeClass("activeLink");
        $(this).addClass("activeLink");
        $(".tabcontent").addClass("hide");
        $("#"+tabeId+"-1").removeClass("hide")   
        return false;	  
      });
    });  
						   
	// Tool Tips
	$(".menu a").hover(function() {
		$(this).next("em").animate({opacity: "show", top: "-75"}, "slow");
	}, function() {
		$(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");
	});
	
	$(".comment a").hover(function() {
		$(this).next("em").animate({opacity: "show", top: "-75"}, "slow");
	}, function() {
		$(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");
	});
	
	//For Select Popular Test Packages
	/*$('#chk_1').click(function(){
		if($('#chk_1:checked').size() == 1)
		{
			$('#chk_2').attr("checked",false);
			$('input[id^=chkCDC_]').attr("checked",false);
			$('input[id^=chkIndi_]').attr("checked",false);
			$('input[id^=chkIndi_]').attr("disabled",true);
		}
		else
		{
			$('"input[id^=chkIndi_]').attr("disabled",false);
		}
	});
	$('#chk_2').click(function(){
		
		if($('#chk_2:checked').size() == 1)
		{
			$('#chk_1').attr("checked",false);
			$('input[id^=chkIndi_]').attr("checked",false);
			$('input[id^=chkIndi_]').attr("disabled",true);
		}
		else
		{
			$('input[id^=chkCDC_]').attr("checked",false);
			$('input[id^=chkIndi_]').attr("disabled",false);
		}
		
	});*/
	
	
	$('.totaltest').each(function(){ 
		var tid = this.id.split('_');
		
		$('#chk_'+tid[1]).click(function(){
			if($('#chk_'+tid[1]+':checked').size() == 1)
			{
				$('input[id^=chk_]').attr("checked",false);
				$(this).attr("checked",true);
				$('input[id^=chkCDC_]').attr("checked",false);
				$('input[id^=chkIndi_]').attr("checked",false);
				$('input[id^=chkIndi_]').attr("disabled",true);
			}
			else
			{
				$('"input[id^=chkIndi_]').attr("disabled",false);
			}
		});
		
		$('#chk_'+tid[1]).click(function(){
			var act = '';
			if(this.checked)
				act= 'add';
			else
				act= 'remove';
				
			$.ajax({
				type: "POST",
				url: "pack_cal.php",
				data: "packtype=group&pack_short_name="+this.value+"&act="+act+"&pcat=main",
				beforeSend: function(){
				 // Handle the beforeSend event
					$('#pack_load').css("display","block");
					$('#pack_cal').css("display","none");
				},
				success: function(msg){
				 // Handle the complete event
					$('#pack_load').css("display","none");
					$('#pack_cal').css("display","block");
					$('#pack_cal').html(msg);
				}
			});
		});
		
		
		
	});
	
	
	
	$('input[id^=chkCDC_]').click(function(){
		$('input[id^=chk_]').attr("checked",false);
		$('#chk_2').attr("checked",true);
		$('input[id^=chkIndi_]').attr("checked",false);
		$('input[id^=chkIndi_]').attr("disabled",true);
		
		var act = '';
		if(this.checked){ act= 'add'; }else{ act= 'remove'; }
		var subcat = '';
		if($('input[id^=chkCDC_]:checked').size() == 1){ subcat = this.name.substr(7); } else { subcat = ''; }
		
		$.ajax({
			type: "POST",
			url: "pack_cal.php",
			data: "packtype=group&pack_short_name="+this.value+"&act="+act+"&subcat="+subcat,
			beforeSend: function(){
			 // Handle the beforeSend event
				$('#pack_load').css("display","block");
				$('#pack_cal').css("display","none");
			},
			success: function(msg){
			 // Handle the complete event
			 	$('#pack_load').css("display","none");
				$('#pack_cal').css("display","block");
				$('#pack_cal').html(msg);
			}
		});
	});
	
	
	$('input[id^=chkIndi_]').click(function(){
		$('input[id^=chk_]').attr("checked",false);
		$('"input[id^=chkCDC_]').attr("checked",false);
		
		var act = '';
		if(this.checked)
			act= 'add';
		else
			act= 'remove';
			
		
		$.ajax({
			type: "POST",
			url: "pack_cal.php",
			data: "packtype=indi&pack_short_name="+this.value+"&act="+act,
			beforeSend: function(){
			 // Handle the beforeSend event
				$('#pack_load').css("display","block");
				$('#pack_cal').css("display","none");
			},
			success: function(msg){
			 // Handle the complete event
				$('#pack_load').css("display","none");
				$('#pack_cal').css("display","block");
				$('#pack_cal').html(msg);
			}
		});
	});
});


function checkEnter(e)
{ 
	//e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable
	if(e && e.which)
	{ 	
		//if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13)
	{ 	
		//if generated character code is equal to ascii 13 (if enter key)
		return searchLocations(''); //submit the form
	}
}

function display_order(order_id){
		if(order_id == ''){
			alert("Your order history has been removed.");
		}else {
			$.ajax({
				type: "POST",
				url: "getorderdetail.php",
				data: "order_id="+order_id,
				beforeSend: function(){
				 // Handle the beforeSend event
				 var msg = "<div  style='text-align: center;padding-top:140px' ><img src='images/testloading.gif'></div>";
				 $('#list_placeholder').html(msg);
				},
				success: function(msg){
					// Handle the complete event
					$('#list_placeholder').html(msg);
				}
			});
		}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function numbersonly(evnt)
{	
   var unicode=evnt.charCode? evnt.charCode : evnt.keyCode
   //alert("Hello" + unicode);
	if (unicode <48||unicode>57 || unicode==47){
		if(unicode == 13 || unicode == 46 || unicode == 43 || unicode == 32 || unicode == 8 || unicode == 9 || (unicode >= 37 && unicode <= 40))
			return true;
		else
		{
			return false;
		}
	}
	
}
