//user validation-----------------------------------------
function CheckAdminUser()
{
	var objform=document.getElementById("f1");
	if(objform.admin_user.value=="")
	{
		alert("Please enter your user name.");
		objform.admin_user.focus();
		return false;
	}

	if(objform.admin_pwd.value=="")
	{
		alert("Please enter your Password.");
		objform.admin_pwd.focus();
		return false;
	}
	return true;
}


//------------------------------------------------------------------------------------
function get_state_list_process(obj,target_obj)
{
  var country=obj.value;
  //alert(country + " " + target_obj);
  univer_value=target_obj;
  if(country=="-1"){return;}
  
  var tbpage="admin/process/get_state_list_process.php";
  
  var data="country=" + escape(country);

   http.open("POST", tbpage, true); 
   http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   http.setRequestHeader("Content-Length", data.length);
   document.getElementById('index_popup_load').style.visibility='visible';
   http.onreadystatechange=get_state_list_process_handle;
   http.send(data);
  

}

function get_state_list_process_handle()
{
  
     if (http.readyState == 4) 
     {
	    if(navigator.appName=="Microsoft Internet Explorer")
	    {
		   if (http.status == 200)  
           {
		     get_state_list_process_content();
		   }
		   else
           { 
		     document.getElementById("index_popup_load").style.visibility="hidden";
             alert("there was an error");
           }
		}
		else
		{
		  get_state_list_process_content();
		}
       
     }//end state
}

function get_state_list_process_content()
{
  document.getElementById("index_popup_load").style.visibility="hidden"; 
  var objform=document.getElementById("f1");
  //alert(http.responseText);
  //return;
  eval("var target=objform."+univer_value+"");
  //alert(target);
  //return;
  var xmlDocument = http.responseXML.documentElement;
  //alert("asas");
  var count=xmlDocument.childNodes.length;
  //alert(count);
  
 // return;
  
  target.length=1;
    
  for(var i=0;i<count;i++)
  {
    var state_id= xmlDocument.getElementsByTagName('state_id').item(i).firstChild.data;
	var state_name= xmlDocument.getElementsByTagName('state_name').item(i).firstChild.data;
	
	var cnt=target.options.length;
	objform.state.options[cnt]=new Option(state_name,state_id,false,false);
  } 
  
}

//------------------------------------------------------------------------------------

//-------------------------------------------------function for state list-----------------------------------//
function get_state_list_process_admin(obj,target_obj)
{
  var country=obj.value;
  //alert(country + " " + target_obj);
  univer_value=target_obj;
  if(country=="-1"){return;}
  
  var tbpage="process/get_state_list_process.php";
  
  var data="country=" + escape(country);

   http.open("POST", tbpage, true); 
   http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   http.setRequestHeader("Content-Length", data.length);
   document.getElementById('index_popup_load').style.visibility='visible';
   http.onreadystatechange=get_state_list_process_handle_admin;
   http.send(data);
  

}

function get_state_list_process_handle_admin()
{
  
     if (http.readyState == 4) 
     {
	    if(navigator.appName=="Microsoft Internet Explorer")
	    {
		   if (http.status == 200)  
           {
		     get_state_list_process_content_admin();
		   }
		   else
           { 
		     document.getElementById("index_popup_load").style.visibility="hidden";
             alert("there was an error");
           }
		}
		else
		{
		  get_state_list_process_content_admin();
		}
       
     }//end state
}

function get_state_list_process_content_admin()
{
  document.getElementById("index_popup_load").style.visibility="hidden"; 
  var objform=document.getElementById("f1");
  //alert(http.responseText);
  //return;
  eval("var target=objform."+univer_value+"");
  //alert(target);
  //return;
  var xmlDocument = http.responseXML.documentElement;
  //alert("asas");
  var count=xmlDocument.childNodes.length;
  //alert(count);
  
 // return;
  
  target.length=1;
    
  for(var i=0;i<count;i++)
  {
    var state_id= xmlDocument.getElementsByTagName('state_id').item(i).firstChild.data;
	var state_name= xmlDocument.getElementsByTagName('state_name').item(i).firstChild.data;
	
	var cnt=target.options.length;
	objform.state.options[cnt]=new Option(state_name,state_id,false,false);
  } 
  
}

//-------------------------------------------End of function------------------------------------------------//


//-------------------------------------------function class date--------------------------------------------//
function get_date_list_admin(obj,target_obj)
{
  var loc_val=document.getElementById("location").value;
  //alert(loc_val);
  var obj_val=obj.value;
  //alert(obj_val + " " + target_obj);
  univer_value=target_obj;
  if(obj_val=="-1"){return;}
  
  var tbpage="process/get_date_time_list.php?loc_id="+loc_val;
  
  var data="cls_day=" + escape(obj_val);

   http.open("POST", tbpage, true); 
   http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   http.setRequestHeader("Content-Length", data.length);
   document.getElementById('index_popup_load').style.visibility='visible';
   http.onreadystatechange=get_date_list_handle_admin;
   http.send(data);
  

}

function get_date_list_handle_admin()
{
  
     if (http.readyState == 4) 
     {
	    if(navigator.appName=="Microsoft Internet Explorer")
	    {
		   if (http.status == 200)  
           {
		     get_date_list_content_admin();
		   }
		   else
           { 
		     document.getElementById("index_popup_load").style.visibility="hidden";
             alert("there was an error");
           }
		}
		else
		{
		  get_date_list_content_admin();
		}
       
     }//end state
}

function get_date_list_content_admin()
{
  document.getElementById("index_popup_load").style.visibility="hidden"; 
  var objform=document.getElementById("f1");
  //alert(http.responseText);
  //return;
  eval("var target=objform."+univer_value+"");
  //alert(target);
  //return;
  var xmlDocument = http.responseXML.documentElement;
  //alert("asas");
  var count=xmlDocument.childNodes.length;
  //alert(count);
  
 // return;
  
  target.length=1;
    
  for(var i=0;i<count;i++)
  {
    var state_id= xmlDocument.getElementsByTagName('state_id').item(i).firstChild.data;
	var state_name= xmlDocument.getElementsByTagName('state_name').item(i).firstChild.data;
	
	var cnt=target.options.length;
	objform.cls_date.options[cnt]=new Option(state_name,state_id,false,false);
  } 
  
}

//------------------------------------------------------------------------------------

//-------------------------------------------function class date--------------------------------------------//
function get_time_list_admin(obj,target_obj)
{
  //alert(loc_val);
  var obj_val=obj.value;
  //alert(obj_val + " " + target_obj);
  univer_value=target_obj;
  if(obj_val=="-1"){return;}
  
  var tbpage="process/get_time_list.php";
  
  var data="tb_cls_id=" + escape(obj_val);

   http.open("POST", tbpage, true); 
   http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   http.setRequestHeader("Content-Length", data.length);
   document.getElementById('index_popup_load').style.visibility='visible';
   http.onreadystatechange=get_time_list_handle_admin;
   http.send(data);
  

}

function get_time_list_handle_admin()
{
  
     if (http.readyState == 4) 
     {
	    if(navigator.appName=="Microsoft Internet Explorer")
	    {
		   if (http.status == 200)  
           {
		     get_time_list_content_admin();
		   }
		   else
           { 
		     document.getElementById("index_popup_load").style.visibility="hidden";
             alert("there was an error");
           }
		}
		else
		{
		  get_time_list_content_admin();
		}
       
     }//end state
}

function get_time_list_content_admin()
{
  document.getElementById("index_popup_load").style.visibility="hidden"; 
  var objform=document.getElementById("f1");
  //alert(http.responseText);
  //return;
  eval("var target=objform."+univer_value+"");
  //alert(target);
  //return;
  var xmlDocument = http.responseXML.documentElement;
  //alert("asas");
  var count=xmlDocument.childNodes.length;
  //alert(count);
  
 // return;
  
  target.length=1;
    
  for(var i=0;i<count;i++)
  {
    var state_id= xmlDocument.getElementsByTagName('state_id').item(i).firstChild.data;
	var state_name= xmlDocument.getElementsByTagName('state_name').item(i).firstChild.data;
	
	var cnt=target.options.length;
	objform.cls_time.options[cnt]=new Option(state_name,state_id,false,false);
  } 
  
}

//-------------------------------------------------------End of function-------------------------------------------//

//-------------------------------------------------function show_class details-------------------------------------//
function show_cls_details(obj)
{
	var cls_id=obj.value;
	ajax_loadContent('cls_details','ajx_cls_details.php?cls_id='+cls_id);	

}

function show_cls_details_pw(obj)
{
	var cls_id=obj.value;
	ajax_loadContent('cls_details','ajx_cls_details_pw.php?cls_id='+cls_id);	

}


//--------------------------------------------------End of function------------------------------------------------//

var ajax;

function ajax_showContent(divId,pathToFile)
{
	//alert(ajax.response);
	if(ajax.response=="")
	{
		alert("We're sorry, that class is already full.\nPlease register in another class.");
		document.getElementById('cls_time').options[0].selected=true;
		//return false;
	}
  	document.getElementById(divId).innerHTML = ajax.response;
   	document.getElementById("index_popup_load").style.visibility="hidden";
 // dynamicContent_ajaxObjects[ajaxIndex] = false;
}

function ajax_loadContent(divId,pathToFile)
{
  //alert(divId);
 
  //document.getElementById(divId).innerHTML = '<table align="center" style="padding-top:100px" width="100%"><tr><td align="center">Loading ...</td></tr></table>';
  document.getElementById("index_popup_load").style.visibility="visible";
  ajax = new sack();
  ajax.requestFile = pathToFile;

  ajax.onCompletion = function(){ ajax_showContent(divId,pathToFile) ;};  

  ajax.runAJAX();  
  
} 

//---------------------------------------make full blank function---------------------------------------------------------//
function make_blank(obj,type)
{
	var val=obj.value;
	if(type==1)
	{
		if(val=="dd/mm/yyyy")
		{
			obj.value="";
			obj.style.color="#000000";
		}
	}
	if(type==2)
	{
		if(val=="DVD")
		{
			obj.value="";
			obj.style.color="#000000";
		}
	}
	//alert("as");
}

function make_full(obj,type)
{
	var val=obj.value;
	if(type==1)
	{
		if(val=="")
		{
			obj.style.color="#7C7C7C";
			obj.value="dd/mm/yyyy";	
		}
	}
	if(type==2)
	{
		if(val=="")
		{
			obj.style.color="#7C7C7C";
			obj.value="DVD";	
		}
	}
	//alert(obj.value);
}

//------------------Set mail llist-----------------------------------//
function set_print_arr(obj,val,id)
{
	//alert(id);
	var objform=document.getElementById("f1");
	var pr_arr=objform.pr_arr.value;
	var str_id=objform.arr_id.value;
	var tot_no=objform.select_no.value;
	var row_no=objform.rw_no.value;
	var arr_id=pr_arr.split('_');
	var cnt_pr_arr="";
	
	if(val=="")
	{
		obj.value=1;
		if(pr_arr=="")
		{
			objform.pr_arr.value="_"+id;
		}
		if(pr_arr!="")
		{
			objform.pr_arr.value=pr_arr+"_"+id;
		}
		objform.select_no.value=parseInt(tot_no)+1;
		//alert(objform.select_no.value);
		//alert(objform.pr_arr.value);
		return true;
	}
	if(val=="1")
	{
		//alert(id);
		obj.value="";
		var no=1;
		while(no<=tot_no)
		{
			if(arr_id[no]!=id)
			{
				cnt_pr_arr+="_"+arr_id[no];
			}
			no++;
		}
		objform.pr_arr.value=cnt_pr_arr;
		objform.select_no.value=parseInt(tot_no)-1;
		return true;
	}
}

function form_check()
{
	var objform=document.getElementById("f1");
 	var str_id=objform.arr_id.value;
	var row_no=objform.rw_no.value;
 	var arr_id=str_id.split('_');
	//alert(arr_id[0]);
	var i=1;
	objform.select_no.value=row_no;
	while(row_no!=0)
	{
			//alert(arr_id[row_no]);
			var ch_box="cbox_"+arr_id[row_no];
			//alert(ch_box);
			eval("document.getElementById('"+ch_box+"').checked=true");
			eval("document.getElementById('"+ch_box+"').value=1");
			objform.pr_arr.value=str_id;
			row_no--;
	}
	document.getElementById('sel_all').style.display='none';
	document.getElementById('can_all').style.display='block';
}

function form_check_cancel()
{
	var objform=document.getElementById("f1");
 	var str_id=objform.arr_id.value;
	var row_no=objform.rw_no.value;
 	var arr_id=str_id.split('_');
	//alert(str_id);
	var i=1;
	objform.select_no.value=0;
	while(row_no!=0)
	{
			//alert(arr_id[row_no]);
			var ch_box="cbox_"+arr_id[row_no];
			//alert(ch_box);
			eval("document.getElementById('"+ch_box+"').checked=false");
			eval("document.getElementById('"+ch_box+"').value=''");
			//objform.pr_arr.value=str_id;
			row_no--;
	}
	document.getElementById('sel_all').style.display='block';
	document.getElementById('can_all').style.display='none';
	objform.pr_arr.value="";
}

//--------------------------------------------------------------//
function get_set_chceck_process(type,obj_id,set_type)
{
  //alert(set_type);
  var tbpage="../admin/process/set_check_process.php?type="+type+"&set_type="+set_type;
  
  var data="obj_id=" + escape(obj_id);

   http.open("POST", tbpage, true); 
   http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   http.setRequestHeader("Content-Length", data.length);
   document.getElementById('index_popup_load').style.visibility='visible';
   http.onreadystatechange=get_set_chceck_process_handle;
   http.send(data);
 
}

function get_set_chceck_process_handle()
{
  
     if (http.readyState == 4) 
     {
	    if(navigator.appName=="Microsoft Internet Explorer")
	    {
		   if (http.status == 200)  
           {
		     get_set_chceck_process_content();
		   }
		   else
           { 
		     document.getElementById("index_popup_load").style.visibility="hidden";
             alert("there was an error");
           }
		}
		else
		{
		  get_set_chceck_process_content();
		}
       
     }//end state
}

function get_set_chceck_process_content()
{
  document.getElementById("index_popup_load").style.visibility="hidden"; 
}

function check_user(reg_type,tb_class_id,erreg_date)
{
	//alert(reg_type);
	if(reg_type==1)
	{
		var obj_height=document.getElementById('last_pix');
		//alert(obj_height);
		var input_div=document.getElementById('reg_code');
		var f_height=getAbsY(obj_height);
		input_div.style.height=f_height+"px";
		input_div.style.display='block';
		document.getElementById("msg_div").innerHTML="";
		document.getElementById('focus_input').focus();
		document.getElementById('focus_input').value=tb_class_id;
 		return false;
	}
	if(reg_type==3)
	{
		//var early_reg_date=document.getElementById('early_reg_code').value;
		//alert(erreg_date);
		var alText="Sorry, early registration not yet begun.\nPlease check back on "+erreg_date+".";
		alert(alText);	
		return false;
	}
	if(reg_type==4)
	{
		alert("We're sorry, that class is already full.\nPlease register in another class.");	
		return false;
	}
	if(reg_type==2)
	{
		window.location.href="registration.php?tb_class_id="+tb_class_id+"&stat=0";
		//alert("You are registering as early registrant !!");	
	}
}
//=================================Start of get X and Y length=====================================//
function getAbsY(obj)
{
   var topOffset=0;
   if (obj.offsetParent)
   {
  while (obj.offsetParent)
  {
    topOffset += obj.offsetTop;
    obj = obj.offsetParent;
  }
   }
   else if (obj.y) // for NN4
   {
  	topOffset = obj.y;
   }
   
   return topOffset;
}

//------------------------------------------------------------------------------------------------//

//-------------------------------------Function code check----------------------------------------//
function check_code_validation()
{
  var input_code_fld=document.getElementById("early_reg_code");
  var tb_class_fld=document.getElementById("focus_input");
  input_code=input_code_fld.value;
  tb_class_id=tb_class_fld.value;
  //alert(tb_class_id);
  var tbpage="admin/process/set_check_code.php";
  
  var data="input_code="+input_code+"&tb_class_id="+tb_class_id;

   http.open("POST", tbpage, true); 
   http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   http.setRequestHeader("Content-Length", data.length);
  // document.getElementById('index_popup_load').style.visibility='visible';
   http.onreadystatechange=check_code_process_handle;
   http.send(data);
 
}

function check_code_process_handle()
{
  
     if (http.readyState == 4) 
     {
	    if(navigator.appName=="Microsoft Internet Explorer")
	    {
		   if (http.status == 200)  
           {
		    check_code_process_content();
		   }
		   else
           { 
		     document.getElementById("index_popup_load").style.visibility="hidden";
             alert("there was an error");
           }
		}
		else
		{
		  check_code_process_content();
		}
       
     }//end state
}

function check_code_process_content()
{
  //document.getElementById("index_popup_load").style.visibility="hidden"; 
  var res_code= http.responseText;
  res_code_arr=res_code.split("~");
  if(res_code_arr[0]==res_code_arr[1])
  {
	  window.location.href="registration.php?tb_class_id="+res_code_arr[2]+"&stat=0";
  }
  else
  {
	  document.getElementById("msg_div").innerHTML="Sorry, only currently registered clients may use early registration.";
	  document.getElementById("msg_div").style.display="block";
  }
  //alert(org_code);
}
//------------------------------------------------------------------------------------------------//

function ajloader_show()
{
	var obj=document.getElementById('last_pix');
	var obj_height=getAbsY(obj);
 	document.getElementById('ajax_loader').style.height=obj_height+"px";
}

//==============================Pay pal function==================================================//
function go_to_pay_pall()
{
	var obj_height=document.getElementById('last_pix');
 	var input_div=document.getElementById('reg_code');
	var f_height=getAbsY(obj_height);
	input_div.style.height=f_height+"px";
	input_div.style.display='block';
	document.getElementById("msg_div").innerHTML="";
	document.getElementById('focus_input').focus();
	var objform=document.getElementById('f1');
 	objform.action='https://www.paypal.com/cgi-bin/webscr';
}

function pay_pall_redirect()
{
	document.getElementById("msg_div").innerHTML="Please wait while re-directing to PayPal.";
	document.getElementById("msg_div").style.display='block';
	
	var country=document.getElementById("country").value;
	var first_name=document.getElementById("first_name").value;
	var address1=document.getElementById("address1").value;
	var city=document.getElementById("city").value;
	var state=document.getElementById("state").value;
	var zip=document.getElementById("zip").value;
	var email=document.getElementById("email").value;
	var child_name=document.getElementById("child_name").value;
	var child_dob=document.getElementById("child_dob").value;
	var chp_name=document.getElementById("chp_name").value;
	var tb_class_id=document.getElementById("tb_class_id").value;
	
	var phone_no=document.getElementById("phone_no").value;
	var mobile_no=document.getElementById("mobile_no").value;
	var single_stat=document.getElementById("single_stat").value;
	//alert(single_stat);
	var stat=document.getElementById("stat").value;
	//alert(stat);
	
	var send_str="country="+escape(country)+"&first_name="+escape(first_name)+"&address="+escape(address1)+"&city="+escape(city);
	send_str+="&state="+escape(state)+"&zip="+escape(zip)+"&email="+escape(email)+"&city="+escape(city);
	send_str+="&child_name="+escape(child_name)+"&child_dob="+escape(child_dob)+"&chp_name="+escape(chp_name)+"&tb_class_id="+escape(tb_class_id);
	send_str+="&phone_no="+escape(phone_no)+"&mobile_no="+escape(mobile_no)+"&single_st="+escape(single_stat)+"&stat="+escape(stat);
	
	//alert(send_str);
	var tbpage="admin/process/user_record_save.php";
	
	var data=send_str;
	
	http.open("POST", tbpage, true); 
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.setRequestHeader("Content-Length", data.length);
 	http.onreadystatechange=pay_pall_redirect_handle;
	http.send(data);
 
}

function pay_pall_redirect_handle()
{
  
     if (http.readyState == 4) 
     {
	    if(navigator.appName=="Microsoft Internet Explorer")
	    {
		   if (http.status == 200)  
           {
		    pay_pall_redirect_content();
		   }
		   else
           { 
		     document.getElementById("index_popup_load").style.visibility="hidden";
             alert("there was an error");
           }
		}
		else
		{
		  pay_pall_redirect_content();
		}
       
     }//end state
}

function pay_pall_redirect_content()
{
   var reg_id= http.responseText;
   
   var return_page=document.getElementById("return").value;
   		document.getElementById("return").value=return_page+"&id="+reg_id;
    var cancel_page=document.getElementById("cancel_return").value;
   		document.getElementById("cancel_return").value=cancel_page+"&id="+reg_id;
    
   if(reg_id)
   {
 		document.getElementById('f1').submit();
   }
}

//------------------------------------------------------------------------------------
function get_class_list_process(obj,target_obj)
{
  var loc_id=obj.value;
  //alert(country + " " + target_obj);
  univer_value=target_obj;
  if(loc_id=="-1"){return;}
  
  var tbpage="process/get_class_list_process.php";
  
  var data="loc_id=" + escape(loc_id);

   http.open("POST", tbpage, true); 
   http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   http.setRequestHeader("Content-Length", data.length);
   document.getElementById('index_popup_load').style.visibility='visible';
   http.onreadystatechange=get_class_list_process_handle;
   http.send(data);
  

}

function get_class_list_process_handle()
{
  
     if (http.readyState == 4) 
     {
	    if(navigator.appName=="Microsoft Internet Explorer")
	    {
		   if (http.status == 200)  
           {
		     get_class_list_process_content();
		   }
		   else
           { 
		     document.getElementById("index_popup_load").style.visibility="hidden";
             alert("there was an error");
           }
		}
		else
		{
		  get_class_list_process_content();
		}
       
     }//end state
}

function get_class_list_process_content()
{
  document.getElementById("index_popup_load").style.visibility="hidden"; 
  var objform=document.getElementById("f1");
  //alert(http.responseText);
  //return;
  eval("var target=objform."+univer_value+"");
  //alert(target);
  //return;
  var xmlDocument = http.responseXML.documentElement;
  //alert("asas");
  var count=xmlDocument.childNodes.length;
  //alert(count);
  
 // return;
  
  target.length=1;
    
  for(var i=0;i<count;i++)
  {
    var class_id= xmlDocument.getElementsByTagName('class_id').item(i).firstChild.data;
	var class_name= xmlDocument.getElementsByTagName('class_name').item(i).firstChild.data;
	
	var cnt=target.options.length;
	objform.cls_time.options[cnt]=new Option(class_name,class_id,false,false);
  } 
  
}

//------------------------------------------------------------------------------------

