// JavaScript Document
function check_add()
{
	if(document.getElementById('menu_title').value=="")
	{
		alert("Please Enter Menu Title");
		document.getElementById('menu_title').focus();
		return false;
		}
	if(document.getElementById('menu_url').value=="")
	{
		alert("Please Enter Menu URL");
		document.getElementById('menu_url').focus();
		return false;
		}	
	if(document.getElementById('menu_status').value=="")
	{
		alert("Please Select Menu Status");
		document.getElementById('menu_status').focus();
		return false;
		}
	if(document.getElementById('menu_order').value=="")
	{
		alert("Please Select Menu Order");
		document.getElementById('menu_order').focus();
		return false;
		}
	}
	


//end

function check_add_courses_cat()
{
	if(document.getElementById('cat_name').value=="")
	{
		alert("Please Enter Category Name");
		document.getElementById('cat_name').focus();
		return false;
		}
	if(document.getElementById('cat_status').value=="")
	{
		alert("Please Select Category Status");
		document.getElementById('cat_status').focus();
		return false;
		}
	/*if(document.getElementById('page_url').value=="")
	{
		alert("Please Enter Page URL");
		document.getElementById('page_url').focus();
		return false;
		}*/
	}



// for adding a course content
function check_add_course()
{
	if(document.getElementById('cat_id').value=="")
	{
		alert("Please Select Category Name");
		document.getElementById('cat_id').focus();
		return false;
		}
	if(document.getElementById('course_title').value=="")
	{
		alert("Please Enter Course Content Title");
		document.getElementById('course_title').focus();
		return false;
		}
	if(document.getElementById('course_status').value=="")
	{
		alert("Please Select Course Status");
		document.getElementById('course_status').focus();
		return false;
		}
	/*if(document.getElementById('course_content').value=="")
	{
		alert("Please Enter Course Content");
		//document.getElementById('cat_status').focus();
		return false;
		}*/


	}



// for delete a record

function confirm_del($url)
{
	if(confirm("do you want to delete"))
	window.location = $url;
	}


/// for adding a newsletter -  start

function check_add_news_cat()
{
	if(document.getElementById('cat_name').value=="")
	{
		alert("Please Enter Category Name");
		document.getElementById('cat_name').focus();
		return false;
		}
	if(document.getElementById('cat_status').value=="")
	{
		alert("Please Select Category Status");
		document.getElementById('cat_status').focus();
		return false;
		}
	}

//end
// for adding a course content
function check_add_news()
{
	if(document.getElementById('cat_name').value=="")
	{
		alert("Please Select Category Name");
		document.getElementById('cat_name').focus();
		return false;
		}
	if(document.getElementById('news_title').value=="")
	{
		alert("Please Enter News Content Title");
		document.getElementById('news_title').focus();
		return false;
		}
	if(document.getElementById('news_status').value=="")
	{
		alert("Please Select News Status");
		document.getElementById('news_status').focus();
		return false;
		}
	/*if(document.getElementById('course_content').value=="")
	{
		alert("Please Enter Course Content");
		//document.getElementById('cat_status').focus();
		return false;
		}*/
	}


// for course booking
function check_booking()
{
	if(document.getElementById('name').value=="")
	{
		alert("Please Enter Your Name");
		document.getElementById('name').focus();
		return false;
		}
	if(document.getElementById('company').value=="")
	{
		alert("Please Enter Company name");
		document.getElementById('company').focus();
		return false;
		}
	if(document.getElementById('email').value=="")
	{
		alert("Please Enter Email");
		document.getElementById('email').focus();
		return false;
		}else
		{
			if(!is_email(document.getElementById('email').value))
			{
				alert("Please Enter Valid Email");
				document.getElementById('email').focus();
				return false;
				}
			}
	if(document.getElementById('phone').value=="")
	{
		alert("Please Enter Phone");
		document.getElementById('phone').focus();
		return false;
		}
	if(document.getElementById('word').value=="")
	{
		alert("Please Enter Captcha Code");
		document.getElementById('word').focus();
		return false;
		}

	/*if(document.getElementById('course_title').value=="")
	{
		alert("Please Select Course");
		document.getElementById('course_title').focus();
		return false;
		}*/

}

//end


/// Email Validation function
function is_email(email)
	{
		if(!email.match(/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/))
			return false;
		return true;
	}

// for adding a course content
function check_contact()
{
	if(document.getElementById('name').value=="")
	{
		alert("Please Enter Name");
		document.getElementById('name').focus();
		return false;
		}
	if(document.getElementById('surname').value=="")
	{
		alert("Please Enter Surname/Last Name");
		document.getElementById('surname').focus();
		return false;
		}
	if(document.getElementById('company').value=="")
	{
		alert("Please Enter Company Name");
		document.getElementById('company').focus();
		return false;
		}
	if(document.getElementById('email').value=="")
	{
		alert("Please Enter Email Address");
		document.getElementById('email').focus();
		return false;
		}else{
			if(!is_email(document.getElementById('email').value))
			{
				alert("Please Enter Valid Email Address");
				document.getElementById('email').focus();
				return false;
				}
			}
if(document.getElementById('comments').value=="")
	{
		alert("Please Enter Your Query");
		document.getElementById('comments').focus();
		return false;
		}

if(document.getElementById('word').value=="")
	{
		alert("Please Enter Captcha Code");
		document.getElementById('word').focus();
		return false;
		}

	
	}


// for newsletter section
function check_newsletter()
{

	if(document.getElementById('company').value=="")
	{
		alert("Please Enter Company Name");
		document.getElementById('company').focus();
		return false;
		}
if(document.getElementById('name').value=="")
	{
		alert("Please Enter Name");
		document.getElementById('name').focus();
		return false;
		}
	if(document.getElementById('surname').value=="")
	{
		alert("Please Enter Surname/Last Name");
		document.getElementById('surname').focus();
		return false;
		}

	if(document.getElementById('street').value=="")
	{
		alert("Please Enter Street");
		document.getElementById('street').focus();
		return false;
		}
	if(document.getElementById('postcode').value=="")
	{
		alert("Please Enter Postcode");
		document.getElementById('postcode').focus();
		return false;
		}
	if(document.getElementById('town').value=="")
	{
		alert("Please Enter Town");
		document.getElementById('town').focus();
		return false;
		}		
	if(document.getElementById('email').value=="")
	{
		alert("Please Enter Email Address");
		document.getElementById('email').focus();
		return false;
		}else{
			if(!is_email(document.getElementById('email').value))
			{
				alert("Please Enter Valid Email Address");
				document.getElementById('email').focus();
				return false;
				}
			}
	
	if(document.getElementById('word').value=="")
	{
		alert("Please Enter Captcha Code");
		document.getElementById('word').focus();
		return false;
		}		

	
	}


function courseData()
{
	var cat_name1=document.getElementById("course_cat").value;
	//alert(cat_name);
	var strSubmit = "action=list_course_title&cat_name="+cat_name1;
	var strURL = "ajax_value.php";
	var strResultFunc="course_details";
	//alert(strSubmit);
	xmlhttpPost(strURL, strSubmit, strResultFunc);
}

function course_details(result)
{
	document.getElementById("course_title1").innerHTML=result;
}

function locData()
{
	var course_id=document.getElementById("course_title").value;
	//alert(cat_name);
	var strSubmit = "action=list_loc&course_id="+course_id;
	var strURL = "ajax_value.php";
	var strResultFunc="loc_details";
	//alert(strSubmit);
	xmlhttpPost(strURL, strSubmit, strResultFunc);
}

function loc_details(result)
{
	document.getElementById("course_loc").innerHTML=result;
}


function dateData()
{
	var course_id=document.getElementById("course_title").value;
	var loc_id=document.getElementById("location").value;
	//alert(loc_id);
	var strSubmit = "action=date_loc&course_id="+course_id+"&loc_id="+loc_id;
	var strURL = "ajax_value.php";
	var strResultFunc="date_details";
	//alert(strSubmit);
	xmlhttpPost(strURL, strSubmit, strResultFunc);
}

function date_details(result)
{
	document.getElementById("course_date").innerHTML=result;
}



function check_edit_static()
{
	if(document.getElementById('page_title').value=="")
	{
		alert("Please Enter Page Title");
		document.getElementById('page_title').focus();
		return false;
		}
	}


function check_add_articles_cat()
{
	if(document.getElementById('cat_name').value=="")
	{
		alert("Please Enter Category");
		document.getElementById('cat_name').focus();
		return false;
		}
	if(document.getElementById('cat_status').value=="")
	{
		alert("Please Select Category Status");
		document.getElementById('cat_status').focus();
		return false;
		}

}

function check_add_articles()
{
	if(document.getElementById('cat_name').value=="")
	{
		alert("Please Select Category Name");
		document.getElementById('cat_name').focus();
		return false;
		}
	if(document.getElementById('articles_title').value=="")
	{
		alert("Please Enter Article Title");
		document.getElementById('articles_title').focus();
		return false;
		}
	if(document.getElementById('articles_status').value=="")
	{
		alert("Please Select Articles Status");
		document.getElementById('articles_status').focus();
		return false;
		}
	}


function check_search()
{
	if(document.getElementById('search_text').value=="")
	{
		alert("Please Enter Keyword for search");
		document.getElementById('search_text').focus();
		return false;
		}
	
	}

function search_courses()
{
	if(document.getElementById('search_type').value=="")
	{
		alert("Please Select Search Type");
		document.getElementById('search_type').focus();
		return false;
		}
	if(document.getElementById('keyword').value=="")
	{
		alert("Please Enter Keyword for Search");
		document.getElementById('keyword').focus();
		return false;
		}


	}

// this is for generating captcha code
function new_freecap()
{
	// loads new freeCap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("freecap").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Sorry, cannot autoreload freeCap image\nSubmit the form and a new freeCap will be loaded");
	}
}


// this is for location assignment
function check_assign_location()
{
	if(document.getElementById('course_cat').value=="")
	{
		alert("Please Select Course Category");
		document.getElementById('course_cat').focus();
		return false;
		}
		
	if(document.getElementById('course_title[]').value=="")
	{
		alert("Please Select Atleast One Course");
		document.getElementById('course_title[]').focus();
		return false;
		}

	if(document.getElementById('locID[]').value=="")
	{
		alert("Please Select Atleast One Location");
		document.getElementById('locID[]').focus();
		return false;
		}

	for(var i=0; i<20; i++)
	{
		//alert(document.getElementById('date'+i).value);
		if(document.getElementById('date'+i).value!="dd/mm/yy")
		var sel = '1';
		
	}

	if(sel!='1')
		{
			alert("Please Enter Alteast One Date");
			return false;
			}else
			{
				
				for(var i=0; i<20; i++)
				{
					for(var j=0; j<20; j++)
					{
						if(i!=j)
						{
							if(document.getElementById('date'+i).value!='' && document.getElementById('date'+j).value!='' && document.getElementById('date'+i).value==document.getElementById('date'+j).value)
							{
								alert("Duplicate dates selected");
								return false;
								}
							}
						
						}
					}
				}
			
}

function check_add_location()
{
	if(document.getElementById('locName').value=="")
	{
		alert("Please Enter Location Name");
		document.getElementById('locName').focus();
		return false;
		}
	if(document.getElementById('locStatus').value=="")
	{
		alert("Please Select Location Status");
		document.getElementById('locStatus').focus();
		return false;
		}


	}

