// onload jquery
$(document).ready(function(){
	//$("#d-cert_date").mask("99/99/9999");
	$(".sizer").click(function() { $('#sizer').slideToggle('fast'); });
	$(".togglehint").click(function() { $('#black').slideToggle(1); $(".instruction").fadeToggle("fast"); });
	$(".feedback").click(function() { $('#black').slideToggle(1); $('#feedback').fadeToggle("fast"); });
	$(".lsvtcsupport").click(function() { $('#black').slideToggle(1); $('#lsvtcsupport').fadeToggle("fast"); });
	$(".feedbackswitch").click(function() { $(".instruction").fadeOut("fast"); $('#feedback').fadeToggle("fast"); $('#lsvtcsupport').fadeToggle("fast"); });
	$(".forgotpass").click(function() { $("#forgot").attr('value', '1'); $(".forgotpass").hide(); $(".forgotset").show(); $(".submit").val('Retrieve Password'); });
	$(".forgotcancel").click(function() { $("#forgot").attr('value', '0'); $(".forgotpass").show(); $(".forgotset").hide(); $(".submit").val('Log in.'); });
	$("#updateform .formelem").blur( function() { id=this.id; val=this.value; update(id,val); });
	$("#updateform select").change( function() { id=this.id; val=this.value; update(id,val); });
	$("#c-password_txt").blur( function() { id=this.id; val=this.value; chkPass($("#oldpass").val(),val);  });
	$("#updateform .submit").click( function() { $("#updateform .submit").attr("disabled", "false"); $("#updateform .submit").val('Saving...'); location.href = 'index.php?action=updateprofile'; });
	$("a.larger").click( function(){ $('link[id="largecss"]').attr('href','css/large.css'); $(this).hide(); $("a.smaller").show(); s('largecss','1'); } );
	$("a.smaller").click( function(){ $('link[id="largecss"]').attr('href',''); $(this).hide(); $("a.larger").show(); s('largecss','0'); } );
	$("#noncompete input#d-noncompete_txt").click( function() { id=this.id; val=this.value; update(id,val); $('#noncompete').html('Thank you.'); $('#black').fadeOut("slow");					    $('#noncompete').fadeOut(2000); $('#noncompete').remove(); });
	
	getStates('US');
	
	$("#countryselect").change(function() { getStates(this.value); });
});


jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

}; 



function chkPass(oldpass,newpass) {
	if(oldpass!=newpass){  
		var change = confirm("Are you sure you want to update your password?");
		if (change==true) { update('c-password_txt',newpass); $("#oldpass").val(newpass); }
	}
}

function update(fld,val) {
	//alert(fld+" "+val);
	$.ajax({
	   type: "POST",
	   url: "u.php",
	   cache: false,
	   data: "fld="+fld+"&val="+val,
	   success: function(html){
		   	$(".spanupd").remove();
			$("#res").hide(); $("#res").html(html); $("#res").show(); 
			$("#"+fld).after("<span class='hint spanupd' style='font-size:11px;' id='"+fld+"_upd'>Updated</span>");
			$("#"+fld+"_upd").fadeOut(4000);
			//$("#"+fld+"_upd").remove();
		}

	 });
	
}


function login(u,p,f) {
	 $.ajax({
	   type: "POST",
	   url: "l.php",
	   cache: false,
	   data: "username="+u+"&password="+p+"&forgot="+f,
	   success: function(html){
			$("#res").hide(); $("#res").html(html);
			$("#results p").hide();
			if (html=="1") {
				$("#results p.yes").fadeIn(500,function(){ location.href = 'index.php?action=provider';});
			} else if (html=="0") {
				$("#results p.no").fadeIn();
				$("#loginform").each(function(){ this.reset(); });
			} else if (html=="2") {
				$("strong.emailaddress").html(u);
				$("#results p.forgot").fadeIn();
				$("#loginform").each(function(){ this.reset(); });
			} else if (html=="3") {
				$("#results p.missing").fadeIn();
				
			}
			 
		  }

	 });

}

function s(s,v) {
	 $.ajax({
	   type: "POST",
	   url: "s.php",
	   cache: false,
	   data: "s="+s+"&v="+v
	 });

}

function chkSel(id){
	var field = 'chkbox'+id;
	var box = 'box'+id;
	if (document.getElementById(field).checked) {
		document.getElementById(box).className = 'selBox';
	} else { 
		document.getElementById(box).className = 'box'; 
	}
}

function feedback() {
	$('#black').slideToggle(1);
	$('#feedback').slideToggle('fast');
}

function lsvtcsuport() {
	$('#black').slideToggle(1);
	$('#lsvtcsuport').slideToggle('fast');
}

var min=8; var max=18; var b;
var blocks = new Array("div","p","td","a","h1","h2","h3","h4","span");

function fontSize(dir) {
	
	for (b in blocks) {
		var p = document.getElementsByTagName(blocks[b]);
		for(i=0;i<p.length;i++) {
			if(p[i].style.fontSize) {
				var s = parseInt(p[i].style.fontSize.replace("px",""));
				var t = parseInt(p[i].style.lineHeight.replace("px",""));
			} else {
				var s = 12;
			}
			if(s!=max && dir=="i") { s += 1; }
			if(s!=min && dir=="d") { s -= 1; }
			p[i].style.fontSize = s+"px";
		}
	}
}

function toggle(id) {
	$(".addrcontainer").hide();
	$("#"+id).toggle();
	}

function more(id) {
	
	$('#details_'+id).toggle();
	}

function getStates(c) {
	$.ajax({
	   type: "get",
	   url: "ajax_states.php",
	   cache: false,
	   data: "c="+c,
	   success: function(html){
		   $("#statesselect").html(html);
	   }
	 });
}