$(function() {
	$("#accordion").accordion({collapsible: true,active: false});
	setInterval("rotate_simple()",5000);
});

function rotate_simple(){
	curEle = $(".rotate_simple>.current");
	nxtEle = curEle.next();
	if(nxtEle.length == 0) nxtEle = $(".rotate_simple>div:first");
	
	curEle.addClass("previous").removeClass("current").animate({opacity:0},1000);
	nxtEle.animate({opacity:0},0).addClass("current").animate({opacity:1},1000,function(){curEle.removeClass("previous");});
}
// cart.php --------------------------------------
function deletion()
{
con = confirm('Are You Sure You Want To Delete?');
if(con==1)
	return true;
else
	return false;
}
// on click move to a new location:------------------------------------
$(document).ready(function(){
	$("#save_your_hands #authors").click(function(){
		window.location = 'save_your_hands_authors.php';
	});
});
//header.inc.php ---------------------------------------
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}
// banner rotate ------------------------------
$(function() {
	$('.banner_rotate').cycle({fx:'fade', timeout:5000, speed:2000, after:onAfter, pause:1, random:0});//students guide dvd on left sidebar
	$('#story').cycle({fx:'fade', timeout:5000, speed:2000, after:onAfter, pause:1, random:0});
	$('#home_testimonials').cycle({fx:'fade', timeout:15000, speed:2000});
});
function onAfter() {
}
// curvey corner ------------------------------------
$(document).ready(function(){
		$("#home_testimonials p").corner();
		$(".sidebar_box").corner("");
		$("#store table").corner("");
		$(".round_corner").corner("20px");
	});
// popup on hover --------------------------------------------------------
$(document).ready(function(){
	$(".popup").hover(function() {
		$(this).next("div").stop(true, true).animate({opacity: "show", top: "60", left:"50"}, "slow");
		}, 
		function() {
		$(this).next("div").animate({opacity: "hide", top: "70"}, "fast");
		}
	);
});
// therapists.php ---------------
$(function(){
	$('div.edit_your_listing').hide();
	$('a.edit_your_listing').click(function(){
		$('div.edit_your_listing').toggle("explode","slow");
	});
});
function display_details(email,site) {
	var win_url = site + "/therapist_details.php?email=" + email;
	new_window = window.open(win_url,"","height=800,width=500,scrollbars=1");
	new_window.moveTo(0,0);
}
// therapists_form.php -------------------------------
function therapists_form_check(){
	var message = "";
	var therapists_form_backgroundcolor = "#FFFABF";
	var therapists_form_regular_color = "#fff";
	var therapists_form_reset_color = "#EBF4FB";
	var focus_first = "";
	var form_elements = ["therapy_id", "name_first", "name_middle", "name_last", "sex", "email", "password", "password1", "therapy_style", "address_address", "address_county_uk", "address_county", "address_country", "tel_mobile", "tel_land", "qualification", "experience", "company_description", "accrediting_organizations"];
	
	for (i = 0; i < form_elements.length; i++) {
		document.getElementById(form_elements[i]).style.backgroundColor = therapists_form_reset_color;
	}
	
	// radio button Package Selection
	var radio_selected = -1;
	var radio_options = document.therapists_form.therapy_id.length;
	for (var i = 0; i < radio_options; i++) {
		if (document.therapists_form.therapy_id[i].checked) {
			radio_selected = i;
		}
	}
	if (radio_selected == -1) {
		document.getElementById("therapy_id").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Choose Package\n";
	}
	if (document.therapists_form.therapy_id[0].checked) {
		if (document.therapists_form.free_listing_code.value != "CHW") {
			document.getElementById("therapy_id").style.backgroundColor = therapists_form_backgroundcolor;
			message += "The code entered is not correct!\n";
		}
	}
	return therapists_common_elements_2(message,form_elements,therapists_form_backgroundcolor,therapists_form_regular_color,therapists_form_reset_color,focus_first);
}
// therapists_edit.php 
function therapists_edit_check(){
	var message = "";
	var therapists_form_backgroundcolor = "#FFFABF";
	var therapists_form_regular_color = "#fff";
	var therapists_form_reset_color = "#EBF4FB";
	var focus_first = "";
	var form_elements = ["name_first", "name_middle", "name_last", "sex", "email", "password", "password1", "therapy_style", "address_address", "address_county_uk", "address_county", "address_country", "tel_mobile", "tel_land", "qualification", "experience", "company_description", "accrediting_organizations"];
	
	for (i = 0; i < form_elements.length; i++) {
		document.getElementById(form_elements[i]).style.backgroundColor = therapists_form_reset_color;
	}
	return therapists_common_elements_2(message,form_elements,therapists_form_backgroundcolor,therapists_form_regular_color,therapists_form_reset_color,focus_first);
}
//----------------
function therapists_common_elements_2(message,form_elements,therapists_form_backgroundcolor,therapists_form_regular_color,therapists_form_reset_color,focus_first){
	if (document.therapists_form.name_first.value == ""){
		document.getElementById("name_first").style.backgroundColor = therapists_form_backgroundcolor;
		message += "First Name\n";
	}
	if (document.therapists_form.name_last.value == ""){
		document.getElementById("name_last").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Last Name\n";
	}
	
	// radio button Sex
	var radio_selected = -1;
	var radio_options = document.therapists_form.sex.length;
	for (var i=0; i<radio_options; i++){
		if (document.therapists_form.sex[i].checked){
			radio_selected = i;
		}
	}
	if (radio_selected == -1) {
		document.getElementById("sex").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Sex\n";
	}
	
	if (document.therapists_form.email.value == ""){
		document.getElementById("email").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Email\n";
	}
	
	//Passwords
	if (document.therapists_form.password.value == ""){
		document.getElementById("password").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Password\n";
	}
	else if (document.therapists_form.password.value != document.therapists_form.password1.value){
		document.getElementById("password").style.backgroundColor = therapists_form_backgroundcolor;
		document.getElementById("password1").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Passwords do not match. Please enter same password in both fields!\n"
	}
	
	if (document.therapists_form.therapy_style.value == ""){
		document.getElementById("therapy_style").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Therapy Style\n";
	}
	if (document.therapists_form.address_address.value == ""){
		document.getElementById("address_address").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Address\n";
	}
	
	// COUNTRY/COUNTY
	if (document.therapists_form.address_country.value == "UK"){
		if (document.therapists_form.address_county_uk.value == "") {
			document.getElementById("address_county_uk").style.backgroundColor = therapists_form_backgroundcolor;
			document.getElementById("address_county").style.backgroundColor = therapists_form_regular_color;
			message += "UK County(from the drop down list)\n";
		}
	}
	else if (document.therapists_form.address_county.value == "") {
		document.getElementById("address_county").style.backgroundColor = therapists_form_backgroundcolor;
		document.getElementById("address_county_uk").style.backgroundColor = therapists_form_regular_color;
		message += "County/State\n";
	}
	
	// telephone
	if (document.therapists_form.tel_mobile.value == "" && document.therapists_form.tel_land.value == ""){
		document.getElementById("tel_mobile").style.backgroundColor = therapists_form_backgroundcolor;
		document.getElementById("tel_land").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Telephone Mobile/Telephone Land Line\n";
	}
	
	if (document.therapists_form.qualification.value == ""){
		document.getElementById("qualification").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Qualification\n";
	}
	if (document.therapists_form.experience.value == ""){
		document.getElementById("experience").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Experience\n";
	}
	if (document.therapists_form.company_description.value == ""){
		document.getElementById("company_description").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Company Descripton\n";
	}
	if (document.therapists_form.accrediting_organizations.value == ""){
		document.getElementById("accrediting_organizations").style.backgroundColor = therapists_form_backgroundcolor;
		message += "Member of which Accrediting Organisations\n";
	}
	if (document.therapists_form.specialization.value == ""){
		document.getElementById("specialization").style.backgroundColor = therapists_form_backgroundcolor;
		message += "\n";
	}
	if (message != "") {
		alert("Please fill up the following compulsory values:\n" + message);
		return false;
		//return true; // USE FOR TESTING ONLY
	}
	else return true;
}
// save_your_hands image_rotate with AnythingSlider 1.2 --------------------------------------
function formatText(index, panel) {
		  return index + "";
	    }
    
        $(function () {
            $('.anythingSlider').anythingSlider({
                easing: "swing",        // Anything other than "linear" or "swing" requires the easing plugin
                autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
                delay: 5000,                    // How long between slide transitions in AutoPlay mode
                startStopped: false,            // If autoPlay is on, this can force it to start stopped
                animationTime: 600,             // How long the slide transition takes
                hashTags: true,                 // Should links change the hashtag in the URL?
                buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
        		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
        		startText: "Go",             // Start text
		        stopText: "Stop",               // Stop text
		        navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
            });
            
            $("#slide-jump").click(function(){
                $('.anythingSlider').anythingSlider(6);
            });
            
        });
// menu open/hide -------------------------------
$(document).ready(function(){
	$('.accordion .head').click(function() {
		$(this).next().toggle('slow');
		return false;
	}).next().hide();
});
// choice_stockist.php form ---------------------------------
function validForm(){
	var allGood = true;
	
	var firstInvalidTag = "";
	var allTags = document.getElementsByTagName("*");
	for(var i=0; i<allTags.length; i++){
		if(!validTag(allTags[i])){
			allGood = false;
			if(firstInvalidTag == ""){
				firstInvalidTag = allTags[i];
			}
		}
	}
	if(firstInvalidTag != ""){
		firstInvalidTag.focus();
		if(firstInvalidTag.nodeName == "INPUT"){
			firstInvalidTag.select();
		}
		error_announcement("stockist_form"); //id of parent to whose end the error is appended.
	}
	else {
		document.getElementById('valid').value = 1;
	}
	return allGood; //validForm()
	
	function error_announcement(thisid){
		if(!document.getElementById("error_para")){
			var errorPara = document.createElement("p");
			errorPara.setAttribute("id","error_para");
			errorPara.appendChild(document.createTextNode("Please correct the highlighted fields."));
			document.getElementById(thisid).appendChild(errorPara);
			document.getElementById('error_para').style.textAlign = 'center';
			document.getElementById('error_para').style.color = 'red';
		}
	}
}

function validTag(thisTag){
	var isValid = true;
	var thisTagClassesArray = thisTag.className.split(" ");
	var outClass = "";
	for (var i=0; i<thisTagClassesArray.length; i++){
		outClass += validBasedOnClass(thisTagClassesArray[i],thisTag) + " ";
	}
	thisTag.className = outClass;
	if(outClass.indexOf("invalid") > -1){
		isValid = false;
		thisTag.parentNode.setAttribute("class", "invalid");
	}
	return isValid; //validTag()
}

function validBasedOnClass(thisClass,thisTag){
	var returnClass = thisClass;
	switch (thisClass){
		case "":
		case "invalid":
			returnClass = "";
			break;
		case "email":
			if (!validEmail(thisTag.value)) {
				returnClass += " invalid";
			}
			break;
		case "reqd":
			if(thisTag.value==""){
				returnClass += " invalid";
			}
			break;
		case "money":
			if (!thisTag.value.match(/^[0-9]+(\.([0-9]+))?$/)) {
				returnClass += " invalid";
			} 
		break;
	}
	return returnClass;
	
	
	function validEmail(email) {
			var invalidChars = " /:,;";
		
			if (email == "") {
				return false;
			}
			for (var k=0; k<invalidChars.length; k++) {
				var badChar = invalidChars.charAt(k);
				if (email.indexOf(badChar) > -1) {
					return false;
				}
			}
			var atPos = email.indexOf("@",1);
			if (atPos == -1) {
				return false;
			}
			if (email.indexOf("@",atPos+1) != -1) {
				return false;
			}
			var periodPos = email.indexOf(".",atPos);
			if (periodPos == -1) {	
				return false;
			}
			if (periodPos+3 > email.length)	{
				return false;
			}
			return true;
		}
}
// ------------------------------------------------------------------