/*-.....................................................................................-*/
// function for show and hide a box. normally the appear fade mode is using here. but it can be change by changing just the mode 
function hide_show_obj(div_to_hide, change_img,path) { 
  $(change_img).src = path + (( $(div_to_hide).visible() ) ?  '/maximize.gif' : '/minimize.gif');
  new Effect.toggle(div_to_hide, 'appear');
  }

function hide_show_obj_left(div_to_hide, change_img,path) { 
  $(change_img).src = path + (( $(div_to_hide).visible() ) ?  '/maximize.gif' : '/minimize.gif');
  new Effect.toggle(div_to_hide, 'appear');
  
  for(i = 0; i < divNames.length; i++) {
	  if( div_to_hide == divNames[i] )i++;
	  $(divNames[i]).style.display = 'none';
	  $('left_obj_img' + divNames[i].substr(9)).src = path + '/maximize.gif' ;
  }
}
/*-.....................................................................................-*/
function show_hide_left(change_img,path) { 
   if ( $('leftcolumn').visible() ) { 
	   $(change_img).src = path+'/show.gif';
	   Element.setStyle($('content'),{background:'url()'});
       $('leftcolumn').style.display = 'none';
       Element.setStyle($('leftcolumn'),{width: '0px'});
	   Element.setStyle($('contentpanel'),{marginLeft: '30px'});
   }
   else { 
	   Element.setStyle($('content'),{background:'url('+path+'/lef-nav-bg.gif) repeat-y'})
	   Element.setStyle($('content'),{overflow:'hidden'})
	   Element.setStyle($('content'),{position:'relative'})
	   Element.setStyle($('content'),{backgroundColor:'#163151'}) // blue - 163151 ; black - 30353B
	   $(change_img).src =  path+'/hide.gif';
       $('leftcolumn').style.display = 'block';
       Element.setStyle($('contentpanel'),{marginLeft: '265px'});
       Element.setStyle($('leftcolumn'),{width: '235px'});
   }
}
/*-.....................................................................................-*/
function CheckAdminLogin(action,destination) { 
  $('loginProcess').setStyle({display:'none'}); 
  if ( $F('name') == '' ) { 
     alert('User Name Required!'); 
	 $('name').focus(); 
	 return false; 
  }
  else if ( $F('password') == '' ) { 
  	 alert('Password Required!'); 
	 $('password').focus(); 
	 return false; 
  }
  $('loginProcess').setStyle({display:'block'}); 
  var parms = 'name='+$F('name')+'&password='+$F('password') + '&btnLogin='+$F('btnLogin');
  new Ajax.Request(action,{method:'post', parameters: parms, onComplete: function(OReq){
						 //alert(OReq.responseText);
						 if (OReq.responseText == 'success') { window.location = destination; }
						 else { $('loginProcess').setStyle({display:'none'}); alert('Login Failed: invalid user name / password'); }
					}
		});
}

function checkUserLogin(formName,destination) { 
  $('loginProcess').setStyle({display:'none'}); 
  if ( $F('email').empty() ) { 
     alert('Email Required!'); 
	 $('email').focus(); 
	 return false; 
  }
  else if ( $F('password').empty() ) { 
  	 alert('Password Required!'); 
	 $('password').focus(); 
	 return false; 
  }
  $('loginProcess').setStyle({display:'block'}); 
  $(formName).request({ onComplete: function(t){
		if( t.responseText == 'success' ){ window.location = destination; }
		else { $('loginProcess').setStyle({display:'none'}); alert(t.responseText); }
		}});
}

/*-........................password restet check..........................................-*/
function checkPasswordReset(destination){
  $('recoveryProcess').setStyle({display:'block'});
  $('btnRecover').style.visibility='hidden';
  $('email').style.visibility='hidden';
  $('passwordRecovery').request({ onSuccess: function(response) { 
		if( response.responseText.search('success') > 0 ){
			$('passwordRecovery').style.display='none';
			$('passwordRecoverFeedback').innerHTML = response.responseText;
			}
		else
			$('passwordRecoverFeedback').innerHTML = response.responseText;
			$('btnRecover').style.visibility='visible';
			$('email').style.visibility='visible';
			$('recoveryProcess').setStyle({display:'none'});
		} });
  return false;
}
/*-.....................................................................................-*/
function CheckAllItem(parent, span) { 
   var parent = $(parent);
   if (!parent) return false;
   var span = $(span);
   var action = (span.innerHTML.toLowerCase() == 'check all') ? 'checked' : ''; 
   Element.getElementsByClassName(parent, 'checkMarkAll').each(function(elm){$(elm).checked = action;});
   if (action == 'checked')
       span.update('Uncheck All');
   else  	   
       span.update('Check All');
}

function ActionWithSeletedItem(parent, location) {
  // check whether any action has been selected to execute
  if (!confirm('Are You Sure to Execute the Selected Operation?')) return false;
  if ($('DoActions').value == '') { 
     alert('No Action was Selected To Execute!!! Choose An Action To Execute.');
	 return false; 
  }
  // check if any item has been selected
   var parent = $(parent);
   if (!parent) return false;
   this.checkedItems = [];
   Element.getElementsByClassName(parent, 'checkMarkAll').each(function(elm){
															if($(elm).checked) {
															  this.checkedItems.push($(elm).id.replace('sitem_',''));
															} // end if
															});
  if (this.checkedItems == '' ) { 
     alert('No Item(s) Were Selected to Execure the Action. Select Any Item(s) and Try Again.');
	 return false; 
  }
  
  
  // delete previous delete
  var p = new RegExp("delete=[\d|,]*", "gi");     // Formal constructor 
  var nloc = document.location.href;
  if ( document.location.href.match(p) ) {
	 var rpat = /delete=[\d|,]*/gi;
	 var rtxt = "";
	 var nloc = document.location.href.replace(rpat,rtxt);
  }
  
  // check if there is any ? mark in the uri
  var pc = new RegExp("start=\d*", "gi");     // Formal constructor 
  if ( nloc.match(pc) ) {
 	 nloc = nloc + '&' + $('DoActions').value + '=' + this.checkedItems;
	 var r = /&&/;
	 var v = "&";
	 nloc = nloc.replace(r,v);
  }
  else {
 	 nloc = nloc + '?' + $('DoActions').value + '=' + this.checkedItems;
	 var r = /\?\?/;
	 var v = "?";
	 nloc = nloc.replace(r,v);
  }
 document.location.href = nloc;
  return 1; 	
}























