//////////////////////////////////
// Begin MTN Utility Functions  //
//////////////////////////////////
function stoperror(){
return true
}
window.onerror=stoperror


function showhide(div){
	$(div).toggle();
}

// Click on the whole row for search results instead of just the view details link.
function clickRow(theUrl)
  {
  document.location.href = theUrl;
  this.style.cursor='wait';
  }
  
function toggleCountryInput() {
    if ($('#country').val() == "USA") {
        $('#showhidecity').hide();
        $('#showhidezip').show();
    } else {
        $('#showhidezip').hide();
        $('#showhidecity').show();
    }
}

/*function toggleCountryInput() {

	if ( document.frmDetails.getElementById("country").options[document.frmDetails.getElementById("country").options.selectedIndex].value == "USA" ) {
		 document.frmDetails.getElementById('showhidecity').style.display = "none";
		 document.frmDetails.getElementById('showhidezip').style.display = '';
	} else {
		 document.frmDetails.getElementById('showhidecity').style.display = '';
		 document.frmDetails.getElementById('showhidezip').style.display = "none";
	}

}
*/
function getSearchForm(){
	
	 var url = '../../../search_int_world_get.php';
     var target = 'searchagain';
     var myAjax = new Ajax.Updater(target, url, {method: 'get'});
}

function allowForm() {

if ($F('nid') == "%"){
		$('servid').disable();
		$('catid').disable();
		$('scatid').disable();
			if ($F('servid') == "%"){
			$('catid').disable();
			$('scatid').disable();
			}
			if ($F('catid') == "%"){
				$('scatid').disable();
		}
}


/*	if ($F('nid') == "%"){
		$('servid').disable();
		$('catid').disable();
		$('scatid').disable();
		} else {
			$('servid').enable();
			$('catid').disable();
			$('scatid').disable();
		}
		
	if ($F('servid') == "%"){
		$('catid').disable();
		$('scatid').disable();
		} else {
			$('catid').enable();
			$('scatid').disable();
		}
		
	if ($F('catid') == "%"){
		$('scatid').disable();
		} else {
			$('scatid').enable();
		}
*/}


<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='You must fill out all information on the form below down to the Sub-Category level (other than \"All\") in order to post a need for this recipient.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='You must fill out all information on the form below down to the subcategory level in order to post a need for this recipient.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert(errors);
  document.MM_returnValue = (errors == '');
}


function autoIframe(frameId){
try{
frame = document.getElementById(frameId);
innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
objToResize = (frame.style) ? frame.style : frame;
objToResize.height = innerDoc.body.scrollHeight + 150;
}
catch(err){
window.status = err.message;
}
}


//-->


//////////////////////////////////
//  End MTN Utility Functions   //
//////////////////////////////////

//////////////////////////////////
//   ORGANIZATIONAL DASHBOARD   //
//////////////////////////////////
function changeRecipientStatus(id,status){
    $.ajax({
        type:    'POST',
        url:     '../../../ajaxphp/togglerecipientdisplay.php',
        data:    'ID_recipient='+id+'&ToggleDisplay='+status,
        success: function(html) {
            if (status == 1) $('#ID'+id).html('<a href="javascript:;" onclick="changeRecipientStatus('+id+',0)">Active - Click to Deactivate</a>');
            else $('#ID'+id).html('<a href="javascript:;" onclick="changeRecipientStatus('+id+',1)">Inactive - Click to Activate</a>');
        }
    });
}

function orderChanged(){
    new Ajax.Updater('orderChanged', '../../../myaccount/action/ind/reorder.php');
}

function updateOrder(){
    var options = {
        method : 'post',
        parameters : Sortable.serialize('item_list')
    };
    new Ajax.Request('../../../myaccount/action/ind/reorder.php', options);
    $("orderChanged").innerHTML = "<img src='../../../images/loader.gif'  align='absmiddle'/> Updating Order";
    new Ajax.Updater('orderChanged', '../../../myaccount/action/ind/reorder.php', options);
} 

//////////////////////////////////
// END ORGANIZATIONAL DASHBOARD //
//////////////////////////////////


//////////////////////////////////
//            ADMIN             //
//////////////////////////////////
// Begin Organization Functions //
//////////////////////////////////
function activateOrg(id,div,status,type){
	
	var url = '../../../ajaxphp/changeorgstatus.php';
	var pars = 'ID_org='+id+'&status='+status;
    var target = div;
	$(div).innerHTML = "<img src='../../../images/loader.gif'  align='absmiddle'/> Activating Organization";
    var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars});

	var row = 'row_'+id;
	var anySibling = $(row).siblings();
	
	
	
//	$('test').update(anySibling);

	if ((anySibling == '[object HTMLTableRowElement]') || (anySibling == '[object]'))
	{ 
		removeTable.delay(2, id, type,'There are no inactive organizations.');
	} else {
		removeRow.delay(2, id);	
	}
}
function deactivateOrg(id,div,status,type){
	
	var url = '../../../ajaxphp/changeorgstatus.php';
	var pars = 'ID_org='+id+'&status='+status;
    var target = div;
    var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars});

	var row = 'row_'+id;
	var anySibling = $(row).siblings();
	
	
	
//	$('test').update(anySibling);

	if ((anySibling == '[object HTMLTableRowElement]') || (anySibling == '[object]'))
	{ 
		removeTable.delay(2, id, type,'There are no active organizations.');
	} else {
		removeRow.delay(2, id);	
	}
}


////
function changeTeamStatus_NA(id,status){
	
	 var url = '../../../ajaxphp/changeorgstatus.php';
	 var pars = 'ID_org='+id+'&status='+status;
     var target = 'ToggleText';
     var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars});

	var divid = 'link_'+id;
	 if (status == '1'){
		 $(divid).update('<a href="javascript:;" onclick="changeTeamStatus('+id+',0)">Active - Click to Deactivate</a>');
	 } else {
		 $(divid).update('<a href="javascript:;" onclick="changeTeamStatus('+id+',1)">Inactive - Click to Activate</a>');
	 }
}

////

function hideRow(id){
	var row = 'row_'+id;
	$(row).setStyle({display: 'none'});
}

function removeRow(id){
	var row = 'row_'+id;
	$(row).remove();
}

function removeTable(rowID, tableID, text){
		$(tableID).remove();	
		var messagediv = tableID+'Message';
		$(messagediv).update(text);
}
//////////////////////////////////
//  End Organization Functions  //
//////////////////////////////////



////////////////
var checkurl = "../../../myaccount/action/recipients/getCityStateReg.php?param="; // The server-side script

function handleHttpResponse() {

  if (http.readyState == 4) {

    // Split the comma delimited response into an array

    var results = http.responseText;
	
	$('zipmessage').innerHTML = results;


//    document.getElementById("city").value = results[0];
//
//    document.getElementById("state").value = results[1];

  }

}

function checkCityState() {
  var zipValue = document.getElementById("zip_user").value;

  http.open("GET", checkurl + escape(zipValue), true);

  http.onreadystatechange = handleHttpResponse;

  http.send(null);
}


function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object



//////////////////////////////////
//        END ADMIN             //
//////////////////////////////////


//////////////////////////////////
// Begin Shopping Cart Functions//
//////////////////////////////////
function chooseMethod(id, method) {
	$(id).update('<input name="method" type="hidden" id="method" value="'+method+'" />');
}
//////////////////////////////////
//  End Shopping Cart Functions //
//////////////////////////////////
