
function get_course_selection(CONTROL)
{
	var strTemp = "";
	var found_ctr = 0;

	for(var i = 0;i < CONTROL.length;i++)
	{
		if(CONTROL.options[i].selected == true)
		{
			found_ctr++;
			strTemp += CONTROL.options[i].value + ",";
		}
	}

	if(found_ctr == 0 || trim(strTemp) == "")
	{
		alert('Please select at least one Course from the list');
	}
	else
	{
		strTemp = strTemp.substring(0,strTemp.lastIndexOf(","));
		document.training_course_form.courses_list_selected.value = strTemp;
		document.training_course_form.step_number.value = "2";
			
	}
}


function show_progress_bar(loading_message)
{
	url = "progress_bar.php?loading_message="+loading_message;

	var name = "progress_bar";
	var width = 300;
	var height = 10;

	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	str += ",menubar=no,toolbar=no,titlebar=no,scrollbars=no,resizable=no,status=no";

	if (window.screen)
  	{
    	var ah = screen.availHeight - 30;
	    var aw = screen.availWidth - 10;

    	var xc = (aw - width) / 2;
	    var yc = (ah - height) / 2;

    	str += ",left=" + xc + ",screenX=" + xc;
	    str += ",top=" + yc + ",screenY=" + yc;
	}

 	var progress_bar_window = window.open(url, name, str);
	progress_bar_window.focus();
	return progress_bar_window;
}

function open_window(url, name, width, height)
{
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	str += ",resizable=1, scrollbars=1, status=1";

	if (window.screen)
  	{
    	var ah = screen.availHeight - 30;
	    var aw = screen.availWidth - 10;

    	var xc = (aw - width) / 2;
	    var yc = (ah - height) / 2;

    	str += ",left=" + xc + ",screenX=" + xc;
	    str += ",top=" + yc + ",screenY=" + yc;
	}

 	var win = window.open(url, name, str);
	win.focus();
}

function trim(inputString)
{
   if (typeof inputString != "string") { return inputString; }
   
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   
   while (ch == " ")
   { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   
   ch = retValue.substring(retValue.length-1, retValue.length);
   
   while (ch == " ")
   { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   

   while (retValue.indexOf("  ") != -1)
   { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function select_all(CONTROL)
{
	var found_ctr = 0;
	for (var i = 0;i < CONTROL.length;i++)
	{
		CONTROL.options[i].selected = true
	}
	get_course_selection(CONTROL);
	document.training_course_form.submit();
}

function clear_selection(CONTROL)
{
	var found_ctr = 0;
	for (var i = 0;i < CONTROL.length;i++)
	{
		if(CONTROL.options[i].selected == true)
		{
			CONTROL.options[i].selected = false
		}
	}
}


function ToExcel()
{ 
	if (window.ActiveXObject)
	{ 
	
		var  xlApp = new ActiveXObject("Excel.Application");  
		var xlBook = xlApp.Workbooks.Add(); 
		
		
		xlBook.worksheets("Sheet1").activate; 
		var XlSheet = xlBook.activeSheet; 
		xlApp.visible = true;  
		
		for(var P = 1; P<= obj.getRowProperty("count"); P++)
		{ 
		
			  for(var Q = 1; Q <= obj.getColumnProperty("count"); Q++)
			  { 
				  if (P==1)
				  { 
					XlSheet.cells(P ,Q).value = obj.getColumnProperty("text",Q-1) 
				  } 
				   
				  XlSheet.cells(P +1,Q).value = obj.getDataText(P-1,Q-1); 
			  } 
		} 
	XlSheet.columns.autofit;  
	} 
}//end function 

function get_checked_schedule()//formname
{
	var strTemp1 = "";
	var strTemp2 = "";
	var files_selected_count = 0;
//	var r ;
//	if(formname=='course_schedule_form'){
//	r = course_schedule_form;
//	}else{r = document.course_schedule_form_OnDemand;}
	var r  = document.course_schedule_form;
	
	var len = r.elements.length;
	
	for (var i = 0; i < len; i++) 
	{
		var e = r.elements[i];
		if ((e.checked) == true)
		{
			files_selected_count++;
			strTemp1 += e.name+",";
			strTemp2 += e.value+",";
		}
	}
		
	if(files_selected_count == 0 || trim(strTemp1) == "" || trim(strTemp2) == "")
	{
		alert('Please select at least one course to register into.');
	}
	else
	{
		strTemp1 = strTemp1.substring(0,strTemp1.lastIndexOf(","));
		strTemp2 = strTemp2.substring(0,strTemp2.lastIndexOf(","));
		
//		if(formname=='course_schedule_form'){
	document.course_schedule_form.selected_courses_name.value = strTemp1;
		document.course_schedule_form.selected_courses_value.value = strTemp2;
		document.course_schedule_form.submit();
//	}else{document.course_schedule_form_OnDemand.selected_courses_name.value = strTemp1;
//		document.course_schedule_form_OnDemand.selected_courses_value.value = strTemp2;
//		document.course_schedule_form_OnDemand.submit();}
	
	
		
		
	}
}

function refresh_step_number()
{
	document.training_course_form.step_number.value = "1";
	document.training_course_form.submit();
	
}

function get_checked_categories()
{
	var strTemp1 = "";
	//var strTemp2 = "";
	var files_selected_count = 0;
	var r = document.recommended_courses_form;
	var len = r.elements.length;
	
	for (var i = 0; i < len; i++) 
	{
		var e = r.elements[i];
		if ((e.checked) == true)
		{
			files_selected_count++;
			strTemp1 += e.value+",";
			//strTemp2 += e.name+",";
		}
	}
		
	//if(files_selected_count == 0 || trim(strTemp1) == "" || trim(strTemp2) == "")
	if(files_selected_count == 0 || trim(strTemp1) == "")
	{
		alert('Please select at least one category to view recommended courses.');
	}
	else
	{
		strTemp1 = strTemp1.substring(0,strTemp1.lastIndexOf(","));
		//strTemp2 = strTemp2.substring(0,strTemp2.lastIndexOf(","));
		document.recommended_courses_form.selected_category_id.value = strTemp1;
		//document.recommended_courses_form.selected_category_name.value = strTemp2;
		document.recommended_courses_form.submit_ok.value = "1";
		document.recommended_courses_form.submit();
	}
}

function clear_checked_items()
{
	var files_selected_count = 0;
	var r = document.recommended_courses_form;
	var len = r.elements.length;
	
	for (var i = 0; i < len; i++) 
	{
		var e = r.elements[i];
		if ((e.checked) == true)
		{
			files_selected_count++;
			e.checked = false;
		}
	}
		
	if(files_selected_count == 0 )
	{
		alert('Please select at least one category to clear.');
	}
	
}

function open_window(url, name, width, height)
{
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	str += ",resizable=1, scrollbars=1, status=1";

	if (window.screen)
  	{
    	var ah = screen.availHeight - 30;
	    var aw = screen.availWidth - 10;

    	var xc = (aw - width) / 2;
	    var yc = (ah - height) / 2;

    	str += ",left=" + xc + ",screenX=" + xc;
	    str += ",top=" + yc + ",screenY=" + yc;
	}

 	var win = window.open(url, name, str);
	win.focus();
}

function validate_register_form()
{
	if (trim(document.online_registration_form.customer_name.value) =='')
	{
		alert('Please register a Name in order to submit the form');
	}
	else if (trim(document.online_registration_form.job_position.value) =='')
	{
		alert('Please enter your Job Position or Job Title');
	}
	else if (trim(document.online_registration_form.organization.value) =='')
	{
		alert('Please enter your Company Name or Organization');
	}
	else if (trim(document.online_registration_form.mail_address.value) =='')
	{
		alert('Please provide a PO Box number or mailing address');
	}
	else if (trim(document.online_registration_form.city.value) =='')
	{
		alert('Please provide the City you stay in');
	}
	else if (trim(document.online_registration_form.country.value) =='')
	{
		alert('Please provide the Country you stay in');
	}
	else if (trim(document.online_registration_form.phone.value) =='')
	{
		alert('Please enter your Phone Number (Landline or Mobile) where you can be contacted');
	}
	else if (trim(document.online_registration_form.fax.value) =='')
	{
		alert('Please enter a Fax Number where we can send you further information');
	}
	else if (trim(document.online_registration_form.email_add.value) =='')
	{
		alert('Please enter your Email Address where we can contact you');
	}
	else
	{
		//Confirm submit and disable all buttons
		//document.online_registration_form.frm_cust_name.value = document.online_registration_form.cust_name.value;
		// Get Payemnt Method value
		var radio_flag = '0';
		for (var i=0; i < document.online_registration_form.payment_method.length; i++)
	   	{
	   		if (document.online_registration_form.payment_method[i].checked)
			{
		  		var payment_val = document.online_registration_form.payment_method[i].value;
				radio_flag = '1';
		  	}
		}
		if (radio_flag != 1)
		{
			alert('Please select either Credit Card or Bank Transfer to pay for the training');
		}
		else
		{
			document.online_registration_form.payment_value.value = payment_val;
			var strEmailAddTemp;
			strEmailAddTemp = document.online_registration_form.email_add.value;
			if (strEmailAddTemp.indexOf("@") < 0 || strEmailAddTemp.indexOf(".") < 0)
			{
				alert('Invalid Email Address, please enter a valid email address');
			}
			else
			{
				document.online_registration_form.submit_ok.value = "1";
				document.online_registration_form.submit();
			}
		}
		radio_flag = '0';
	}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//-------Function: keyCheck  (javascript function)
//-------Purpose:  Checks if the key pressed is numeric
//-------Inputs:   eventObj, obj
//-------Returns:  returns true if keypressed is numeric, otherwise returns false
//-------Remarks:
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function keyCheck(eventObj, obj)
{
	var keyCode
	
	if (document.all)
	{ 
		keyCode=eventObj.keyCode
	}
	else
	{
		keyCode=eventObj.which
	}
	
	var str=obj.value
	
	if(keyCode==46)
	{ 
		if (str.indexOf(".")>0)
		{
			return false
		}
	}
	// Also added backspace in unfiltered entry
	if((keyCode<48 || keyCode >58)   &&   (keyCode != 46) && (keyCode != 8))
	{ // Allow only integers and decimal points
		return false
	}
	
	return true
}

function verify_login()
{
	var radio_flag = '0';
	for (var i=0; i < document.login_form.bot_attack_prevent.length; i++)
	{
		if (document.login_form.bot_attack_prevent[i].checked)
		{
			var bot_attack_val = document.login_form.bot_attack_prevent[i].value;
			if (bot_attack_val == "YES")
			{
				alert('Please select NO in the Bot Attack Prevention radio button');
			}
			else 
			{
				radio_flag = '1';
			}
			
		}
	}
	if (radio_flag != 1)
	{
		alert('Please select NO in the Bot Attack Prevention radio button');
	}
	else
	{
		if (trim(document.login_form.strusername.value) =='')
		{
			alert('Username cannot be blank');
		}
		else if (trim(document.login_form.strpassword.value)=='')
		{
			alert('Password cannot be blank');
		}
		else
		{
			//alert('You made a successful login');
			document.login_form.login_ok.value = "1";
			document.login_form.submit();
		}
	}
	radio_flag = '0';
}
