function checkcontactform(){
	var throw_error=false
	$('r_name').update("");
	$('r_email').update("");
	$('r_comment').update("");
	if ($F('name').blank()){
		throw_error=true;
		$('r_name').update("<br />Name is Required");
	}
	if ($F('email').blank()){
		throw_error=true;
		$('r_email').update("<br />Email is Required");
	}
	if ($F('comment').blank()){
		throw_error=true;
		$('r_comment').update("<br />Inquiry is Required");
	}
	if (throw_error)
	{
		return false;
	}
}
function show_uploadform(id){
		var url2send='users-ajax-main.php?randSID='+Math.random()+'&id='+id+'&action=show_uploadform';
		new Ajax.Updater('update_'+id, url2send);
}

function show_girls_pics(id){
		var url2send='users-ajax-main.php?randSID='+Math.random()+'&id='+id+'&action=show_girls_pics';
		new Ajax.Updater('update_'+id, url2send);
}

function show_updateform(id){
		var url2send='users-ajax-main.php?randSID='+Math.random()+'&id='+id+'&action=show_updateform';
		new Ajax.Updater('update_'+id, url2send);
}

function checkupdateform(id){
	var serialized_form = ($('form2').serialize());
	var url2send = 'users-ajax-main.php?randSID='+Math.random()+'&id='+id+'&action=update_attendant&'+serialized_form;
	new Ajax.Updater('update_'+id, url2send);
	window.setTimeout('clearupdatediv('+id+');',1000);
}

function clearupdatediv(id){
	$('update_'+id).update('');
	show_info('show_attendants','');
	//$('refresh_list').update('<a href="#" onclick="show_info(\'show_attendants\',\'\');">Refresh List</a>');
}

function show_addform(){
	var url2send='users-ajax-main.php?randSID='+Math.random()+'&action=show_addform';
	new Ajax.Updater('addform', url2send);
}

function checkaddform(){
	var serialized_form = ($('form3').serialize());
	var url2send = 'users-ajax-main.php?randSID='+Math.random()+'&action=add_attendant&'+serialized_form;
	//alert (url2send);
	new Ajax.Updater('addform', url2send);
	window.setTimeout('clearadddiv();',1000);
}

function clearadddiv(){
	$('addform').update('');
	show_info('show_attendants','');
	//$('refresh_list').update('<a href="#" onclick="show_info(\'show_attendants\',\'\');">Refresh List</a>');
}

function show_deleteform(id){
	var text2show = 'Are you sure you want to delete Attendant #'+id+'?<br />This will delete her pics, remove her from the schedule, and remove her from this list!<br /><b>CAUTION!!</b><br /><a href="#" onclick="checkdeleteform('+id+');"><img src="images/001_18.gif" border="0" Alt="Yes"></a>&nbsp;&nbsp;Yes&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="clearupdatediv('+id+');"><img src="images/001_19.gif" border="0" Alt="No"></a>&nbsp;&nbsp;No';
	$('update_'+id).update(text2show);
}

function checkdeleteform(id){
	var url2send = 'users-ajax-main.php?randSID='+Math.random()+'&id='+id+'&action=delete_attendant';
	new Ajax.Updater('update_'+id, url2send);
	window.setTimeout('clearupdatediv('+id+');',1000);
}

function delete_image(id,name){
	//alert (id+'-'+name);
	var confirm_res = confirm(name+" is going to be deleted.Are you sure?");
	if (confirm_res == true){	
		var url2send = 'users-ajax-main.php?randSID='+Math.random()+'&id='+id+'&action=delete_image&name='+name;
		new Ajax.Updater(name, url2send);
		window.setTimeout('show_girls_pics('+id+');',1000);
	}else{
		alert("Operation Cancelled");
	}
}

function checkusername(){
	var username=$F('username');
	var url2send='ajax-getusername.php?randSID='+Math.random()+'&username='+username;
	new Ajax.Updater('username_check', url2send);
	$('username_check').show();
}

function show_info(what,extra){
	var url2send='users-ajax-main.php?randSID='+Math.random()+'&action='+what+'&extra='+extra;
	new Ajax.Updater('show_user_stuff', url2send);
}

function getcount()	{
		var totalcount=75;
		var remainingcount=totalcount-$F('1')-$F('2')-$F('3')-$F('4')-$F('5')-$F('6')-$F('7');
		$('remainingcount').update(remainingcount);
	}

function getinnerfromtags1(txt,tag){
		var startstr1=txt.indexOf('<'+tag+'>')+tag.length+2;
		var endtstr1=txt.indexOf('</'+tag+'>');
		var response1=txt.substring(startstr,endtstr);
		return response1;
}

function add_more_upload(){
	var new_total = Math.round($F('TOTAL_FILE')) + 1;
	//document.getElementById('attach_'  + document.Uploader.TOTAL_FILE.value).innerHTML = "<input type='file' size='60' name='theFile[" +  new_total  + "]' /></p><p id='attach_" + new_total  + "'>";
	new Insertion.After('attach', '<p id="attach_' + new_total  + '"><input type="file" size="40" name="theFile[' +  new_total  + ']" /></p>');
	document.Uploader.TOTAL_FILE.value++;
}

function $RF(el, radioGroup) {
    if($(el).type && $(el).type.toLowerCase() == 'radio') 
	{
        var radioGroup = $(el).name;
        var el = $(el).form;
    } 
	else if ($(el).tagName.toLowerCase() != 'form') 
	{
        return false;
    }
 
    var checked = $(el).getInputs('radio', radioGroup).find(
        function(re) {return re.checked;}
    );
    return (checked) ? $F(checked) : null;
}

function prototypetest(){
myArray=$$('input.validate');
myArray.each(function(item) 
{
	alert(item.name);
	// Your code working on item here... 
}); 
}


function checkform_template()
{

	var strFName = "First Name"
	var strLName = "Last Name"
	var strEmail = "E-Mail"
	var strAddy = "Address"
	var strCity = "City"
	var strProv = "Province"
	var strpc = "Postal Code"
	var strPhone = "Phone"
	var strAgree = "You must agree to the terms in the welcome letter"
	var strCountMore = "You do not have enough questions"
	var strCountLess = "You have too many questions"
	var strMsgAdmin=""
	var AdminMsg="[The Following Information is Required] "
	var strUsernameinuse = "Username is already in use. Please choose another."
	var strUsername = "Username"
	var strPassword = "Password"
	var strwhattype = "Type of Submission"
	var strexperience = "Teaching Experience"
	var strgrade = "Grade of Questions"
	var validateAdmin=false

	
	if ( $F('fname').blank() )
	{
		validateAdmin=true;
		strMsgAdmin = strFName+"\n";		
	}

	if ( $F('lname').blank() )
	{
		validateAdmin=true;
		strMsgAdmin += strLName+"\n";
	}
	if ( $F('email').blank() )
	{
		validateAdmin=true;
		strMsgAdmin += strEmail+"\n";
	}
	if ( $F('address').blank() )
	{
		validateAdmin=true;
		strMsgAdmin += strAddy+"\n";
	}
	if ( $F('city').blank() )
	{
		validateAdmin=true;
		strMsgAdmin += strCity+"\n";
	}
	if ( $F('province').blank() )
	{
		validateAdmin=true;
		strMsgAdmin += strProv+"\n";
	}
	if ( $F('pc').blank() )
	{
		validateAdmin=true;
		strMsgAdmin += strpc+"\n";
	}
	if ( $F('phone').blank() )
	{
		validateAdmin=true;
		strMsgAdmin += strPhone+"\n";
	}
	if ( $F('username').blank() )
	{
		validateAdmin=true;
		strMsgAdmin += strUsername+"\n";
	}

	if ( $F('password').blank() )
	{
		validateAdmin=true;
		strMsgAdmin += strPassword+"\n";
	}

	var grade = $RF('grade');
	if ( grade==null )
	{
		validateAdmin=true;
		strMsgAdmin += strgrade+"\n";
	}

	var experience = $RF('experience');
	if ( experience==null )
	{
		validateAdmin=true;
		strMsgAdmin += strexperience+"\n";
	}

	var whattype = $RF('whattype');
	if ( whattype==null )
	{
		validateAdmin=true;
		strMsgAdmin += strwhattype+"\n";
	}

	if ( whattype=="questions" )
	{	
		var totalcount=75;
		var remainingcount=totalcount-$F('1')-$F('2')-$F('3')-$F('4')-$F('5')-$F('6')-$F('7');
		if ( remainingcount>0 )
		{
			validateAdmin=true;
			strMsgAdmin += strCountMore+"\n";
		}
		else if (remainingcount<0)
		{
			validateAdmin=true;
			strMsgAdmin += strCountLess+"\n";
		}
	}

	if (validateAdmin==true)
	{
		// Build Registrant alert message

		strMsgAll="SIGN UP ERROR\n\n"
		strMsgAll += "_____________________________________________________\n\n";
		strMsgAll += "The form was not submitted because of the following error(s).\n";
		strMsgAll += "Please correct these error(s) and re-submit.\n";
		strMsgAll += "_____________________________________________________\n\n";
		if (validateAdmin==true)
		{
			strMsgAll += AdminMsg+"\n"+strMsgAdmin+"\n"
		}
		// display alert message
		alert(strMsgAll);
		//return to page without submitting form
		return false;
	}	
}

function checkloginform(){
	var serialized_form = ($('loginform').serialize());
	var url2send = 'users-ajax-login.php?randSID='+Math.random()+'&action=add_attendant&'+serialized_form;
	// notice the use of a proxy to circumvent the Same Origin Policy.
	new Ajax.Request(url2send, {   
		method: 'get',   
		onSuccess: function(transport) {
		var notice = $('login_error');     
		var result=transport.responseText;
		if (result=="good"){
			notice.update(result).setStyle({ background: 'green' });
			window.location = "users-main.php";
		}else{
			notice.update(result).setStyle({ background: 'red' });
			$('username').clear().focus();
			$('password').clear();
		} 
		} 
		}); 
}

function flashResize(ele, height, width) {
	var uploader = $(ele);
	/*
	if(height != 0)
		uploader.style.height = height+"px";
	
	if(width != 0)
		uploader.style.width = width+"px";
	*/
	if(height != 0){
		uploader.setStyle({
			height: height+'px'
		});
	}
	if(width != 0){
		uploader.setStyle({
			width: width+'px'
		});
	}
}

function canResizeFlash(){
	var ua = navigator.userAgent.toLowerCase();
	var opera = ua.indexOf("opera");
	
	if( document.getElementById ) {
		if(opera == -1) return true;
		else if(parseInt(ua.substr(opera+6, 1)) >= 7) return true;
	}
	
	return false;
}

e = canResizeFlash();