
aErrorsTbl = Array();

aPendingAction = {param:'',action:'',hold:false};
aPendingLoginAction = {param:'',action:'',hold:false};

function float_login(sForwardUrl){
	
						var t =  null;
                    	var a = '/profile/login?back_url='+sForwardUrl+'&width=350&height=220';
                    	var g = false;
						tb_show(t,a,g);

}

function collect_href_from_elems(){

	var aElems = []
	
	aDates = $('#showcalendar').datepicker("getDate");
	
	if(aDates instanceof Array){
	
		oDate = aDates[0];
		sDate = oDate.getFullYear()+'-'+(oDate.getMonth()<9?'0':'')
                +(oDate.getMonth()+1)+'-'+(oDate.getDate()<10?'0':'')+oDate.getDate()
    	var sHref = '/week/'+ $('#iroomid').attr('value')+'/'+sDate
    } else {
    
    	oDate = aDates;
    	sDate = oDate.getFullYear()+'-'+(oDate.getMonth()<9?'0':'')
                +(oDate.getMonth()+1)+'-'+(oDate.getDate()<10?'0':'')+oDate.getDate()
        var sHref = '/day/' + sDate        
    }	 
	return sHref;
}

function check_form_id(oField){
	if(oField){
		if($(oField.form).attr('id')==''){
			var  iForms = aErrorsTbl.length;
			$(oField.form).attr('id','form'+iForms);
		}
		//alert(typeof(aErrorsTbl[$(oField.form).attr('id')]))
		if(typeof(aErrorsTbl[$(oField.form).attr('id')])!='object')	aErrorsTbl[$(oField.form).attr('id')] = Array()
	}
}

function system_message(msg){

	alert(unescape(msg))

}

function system_ask(msg){

	return confirm(msg)

}

function trigger_error(msg,oField){
	
	if(oField){
	
		check_form_id(oField)

	
		$(oField).addClass('error');
		//alert($(oField).attr('id'));
		$('#'+$(oField).attr('id')+'_errormsg').remove();
		$(oField).after($("<p>"+msg+"</p>").addClass('formerror').attr('id',oField.id+'_errormsg'));
		aErrorsTbl[$(oField.form).attr('id')][oField.id] = 1;
	}
}

function clear_error(oField){
	if(oField){
		check_form_id(oField)
		aErrorsTbl[$(oField.form).attr('id')][oField.id] = 0;
		$(oField).removeClass('error');
		$('#'+$(oField).attr('id')+'_errormsg').remove();
	}

}

function check_before_submit(oForm)
{


	//	aTmp = oForm.elements;
	
	//$(oForm.elements).each(function(i){alert(this.value)})
	for(var i=0;i<oForm.elements.length;i++){
	
		if($(oForm.elements[i]).attr('type')!='submit')$(oForm.elements[i]).trigger('blur')
		//	console.log(i+' '+aErrorsTbl)
	}
	
	

	if(typeof(aErrorsTbl[$(oForm).attr('id')])=='object'){
			
		for (var i in aErrorsTbl[$(oForm).attr('id')]) { 
		//console.log(i+' '+aErrorsTbl[$(oForm).attr('id')][i])
		   				if(aErrorsTbl[$(oForm).attr('id')][i]==1){
		   				
		   					return false
		   				
		   				}	
		};
		
	}
	return true;
}

function removeElementById(id){
    var oTmp = document.getElementById(id);

    if(oTmp)oTmp.parentNode.removeChild(oTmp);
}



 function isInt(x) {
   var y=parseInt(x);
   if (isNaN(y)) return false;
   return x==y && x.toString()==y.toString();
 } 
 
 


 function is_valid_email (email)
      {

      return /^([a-zA-Z0-9_\.\-\'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);

      }


  function is_num(Field)
    {
   if (Field.value=='')
      {
      return true;
      }
    theNum = parseFloat(Field.value);
    //alert(Field.value)
    if (Field.value != '' + theNum && Field.value != '' + theNum+'.' && Field.value != '')
       {
       //alert();
       return false;
       }
    return true;
    }




