function Validate(frm){
	var returnValue = false;
	if( frm.user.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
			alert("Please enter your User Name.");
    	frm.user.focus();
	} else if( frm.pass.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	alert("Please enter a your Password.");
    	frm.pass.focus();
  } else {
  		returnValue = true;
  }
  return returnValue;
}

function checkall(form, match) {
 	var re = new RegExp(match);
	for(var x=0;x<((c = document.forms[form].elements).length);x++){
		if(c[x].type=='checkbox' && re.test(c[x].id))
			c[x].checked=true;
	}
}

function uncheckall(form, match) {
 	var re = new RegExp(match);
	for(var x=0;x<((c = document.forms[form].elements).length);x++){
		if(c[x].type=='checkbox' && re.test(c[x].id))
			c[x].checked=false;
	}
}

function show_hide(e,target) {
	if(e.checked==true){
		document.getElementById(target).style.display = 'block';
	}else{
		document.getElementById(target).style.display = 'none';
	}	
}

function conf(item,yeslink,extra) {
	var str = '';
	if(extra!=null)
		str = extra;

	Dialog.confirm("Are you sure you want to delete this "+item+"?<br />"+str, {
		windowParameters: {className:"alphacube",width:400},
		okLabel: "Yes",
        buttonClass: "button",
       	cancel:function(win) {return true;},
    	ok:function(win) {window.location.href=yeslink; return true;}
	});
}

function info(message) {
	Dialog.alert(message, {
		windowParameters: {className:"alphacube_msg",width:400},
		okLabel: "Close",
        buttonClass: "button",
    	ok:function(win) {return true;}
	});
}

function error(message) {
	Dialog.alert(message, {
		windowParameters: {className:"alphacube_error",width:400},
		okLabel: "Close",
        buttonClass: "button",
    	ok:function(win) {return true;}
	});
	
}

function error1(message,fld) {
	Dialog.alert(message, {
		windowParameters: {className:"alphacube_error",width:400,destroyOnClose:true,onClose:function(){set_focus(fld);}},
		okLabel: "Close",
        buttonClass: "button",
    	ok:function(win) {return true;}
	});
	
}

function set_focus(fld){
    document.getElementById(fld).focus();
}

function openwindow(link){
    window.open(link,"","resizeable=yes,width=600,height=600,status=no");
}

function ValidEmail(strValue){
    var valid = true;
    var regExp = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
    var regExp2 = /(\s+)|(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;

    if ( (strValue.search(regExp)) == -1 || strValue.search(regExp2) != -1)
            valid = false;

    return valid;
}


function editsection(id,cid) {
    var theoptions = 'resizable=yes,scrollbars=yes,width=600,height=700,status=no';
    window.open('content.php?op=edit&ID='+id+'&CID='+cid,'',theoptions);
}

function addsection(id) {
    var theoptions = 'resizable=yes,scrollbars=yes,width=600,height=700,status=no';
    window.open('content.php?op=new&ID='+id,'',theoptions);
}

function preview(id,cid) {
    var theoptions = 'resizable=yes,scrollbars=yes,width=600,height=600,status=no';
    window.open('content.php?op=preview&ID='+id+'&CID='+cid,'',theoptions);
}

function publish(id,cid) {
    var theoptions = 'resizable=yes,scrollbars=yes,width=600,height=600,status=no';
    window.open('content.php?op=publish&ID='+id+'&CID='+cid,'',theoptions);
}

function updateclick(what, theid, filename){
    var options = {method : 'post',onComplete : function(request) {} };
    new Ajax.Request('updater.php?ID='+what+'&fld='+theid+'&file='+filename, options);
    info('Property was updated.');
}

function showLoad() {
	document.getElementById('load').style.display = 'block';
}

function hideLoad() {
	document.getElementById('load').style.display = 'none';
}

function showit(thid) {
	document.getElementById(thid).style.display = '';
}

function hideit(thid) {
	document.getElementById(thid).style.display = 'none';
}

function determine_state(thevalue) {
	if(thevalue=='United States' || thevalue=='Canada') {
		showit('state');
	} else {
		hideit('state');
	}
}
function toggleit(a,theid){
  var elem=document.getElementById(a);
  var thediv=document.getElementById(theid);
  if(!elem)return true;
  if(elem.style.display=="none"){
    elem.style.display="block";
    thediv.innerHTML="-Hide Details";
  } else {
    elem.style.display="none";
    thediv.innerHTML="+Show Details";
  }
  return true;
}

function checkfuture(theval) {
 	var elem = document.getElementById('hideme');
	if(theval.checked==true && theval.value==1) {
		elem.style.display="";
		theval.checked=true;
	} else {
		elem.style.display="none";
		theval.checked=true;
	}
}
function checkother(theval) {
 	var elem = document.getElementById('hideother');
	if(theval.checked==true) {
		elem.style.display='';
	} else {
		elem.style.display='none';
		theval.checked=false;
	}
}

function check_log_form(frm){
	var returnValue = false;
	if( frm.message.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
		error1("Please enter a message.","message");
	} else {
  		returnValue = true;
  	}
  	return returnValue;
}

function check_co_form(frm){
	var returnValue = false;
	if( frm.company.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
		error1("Please enter a company name.","company");
    	//frm.company.focus();
	} else if( frm.address_1.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please enter an address.","address_1");
    	//frm.address_1.focus();
	} else if( frm.city.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please enter a city.","city");
    	//frm.city.focus();
	} else if( frm.state.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 && (frm.country.value=='United States' || frm.country.value=='Canada')){
    	error1("Please pick a state.","state");
    	//frm.state.focus();
	} else if( frm.zip.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please enter a zip code.","zip");
    	//frm.zip.focus();
	} else if( frm.country.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please pick a country.","country");
    	//frm.country.focus();
  	} else {
  		returnValue = true;
  	}
  	return returnValue;
}


function check_lead_form(frm){
	var returnValue = false;

	
	if( frm.first_name.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please enter a first name.","first_name");

	} else if( frm.last_name.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please enter a last name.","last_name");
    	
	} else if( frm.company.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please enter a company name.","company");

	} else if( frm.address_1.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please enter an address.","address_1");
    	    	
	} else if( frm.city.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please enter a city.","city");

	} else if( frm.country.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please pick a country.","country");
    	
    } else if( frm.phone_office.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please enter a phone number.","phone_office");
  	} else {
  		returnValue = true;
  	}
  	return returnValue;
}

function check_program_form(frm){
	
	temp = frm.getElementsByTagName('input')
	foundService = 0
	for(i = 0; i< temp.length;i++)
	{
		if(temp[i].type=='checkbox' && temp[i].name=='services[]' && temp[i].checked==true)
			foundService++;
	}

	var returnValue = false;
	if( frm.program_name.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
		error1("Please enter a program name.","program_name");
		
	} else if( frm.lead.value.replace(/(^\s+)|(\s+$)/g, '').length < 1 ){
    	error1("Please enter a client.","lead");
    			
	} else if( frm.start_date.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please enter a start date.","start_date");
    	
	} else if( frm.end_date.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	error1("Please enter an end date.","end_date");
    	
	} else if( frm.attendees.value.replace(/(^\s+)|(\s+$)/g, '').length < 1 ){
    	error1("Please enter number of attendees.","attendees");
	
	
	}
	else if( foundService < 1){
    	error1("Please select at least one service.","attendees");

	
	} else if( frm.wonlost.value.replace(/(^\s+)|(\s+$)/g, '').length < 1 ){
    	error1("Please choose the status.","wonlost");

	} else if( frm.future.value.replace(/(^\s+)|(\s+$)/g, '').length < 1 ){
    	error1("Please choose yes or no for future programs.","future");
    	    	    	
	
	
  	}/* else if( checkdates(frm)==false){
    	returnValue = false;
    	
  	}*/ else {
  		returnValue = true;
  	}
  	return returnValue;
}

function check_lesserprogram_form(frm){
	var returnValue = false;
	if( frm.program_name.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
		error1("Please enter a program name.","program_name");

  	} else {
  		returnValue = true;
  	}
  	return returnValue;
}




function check_form(frm){
	var formname=frm.name;
	var returnValue = false;
	alert(formname);
	if(formname=='forgot') {	
		if(frm.login_email.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
			error1("Please enter an email address.","login_email");
		} else {
			returnValue = true;
		}
	} else if(formname=='login') {
		if(frm.login_username.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
			error1("Please enter user name.","login_username");
		} else if(frm.login_password.value.replace(/(^\s+)|(\s+$)/g, '').length < 1 ){
			error1("Please enter a password.","login_password");
		} else {
			returnValue = true;
		}
	}
  	return returnValue;
}




function checkdates(frm)
{
    //var reg     = /\d{4}\-\d{2}\-\d{2}/;
    var reg     = /\d{2}\/\d{2}\/\d{4}/;

    var start = document.frm.start_date.value.value;
    var end = document.frm.end_date.value.value;
    //startdate   = frm.startdate.value;
    //enddate     = frm.enddate.value;
    var startdet = start.split('/');
    var enddet = end.split('/');

    if (start!='') {
        if (!reg.test(start)) {
            error1("Start date format is wrong.","start_date");
        }
    }
    if (end!='') {
        if (!reg.test(end)) {
            error1("End date format is wrong.","end_date");
        }
    }

    if (end!='' && start!='') {
        if (end < start) {
            error1("End date is before start date.","end_date");
        }
    }
/*
    today = new Date();
    day = today.getDate();
    if (day < 10) {
        day = "0"+day;
    }

    month = today.getMonth() + 1;
    if(month < 10) {
        month = "0"+month;
    }

    year = today.getFullYear();
    //today = year+"-"+month+"-"+day;
    today = month+"/"+day+"/"+year;
    if ((startdet[2] == year || enddet[2] == year) && (startdet[2] <= year || enddet[2] <= year)) {
        if(start > today || end > today) {
            alert("Date is after today");
            return false;
        }
    }
    */
    //return true;
}


function checkBox(that,target)
{
    target = document.getElementById(target)
    if(that.checked==true)
        target.style.display="";
    else
        target.style.display="none";
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function showCreate()
{
var alert = Dialog.alert($('forum-new').innerHTML, {className:"alphacube", width:400, 
				okLabel: "cancel"
				});
}
function showReply()
{
var alert = Dialog.alert($('forum-new').innerHTML, {className:"alphacube", width:400, 
				okLabel: "cancel"
				});
}