// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function resetOptions() {
  $('notes').value = '';
  $('credit').style.width = '77px';
  $$('input').each(function(e) {
    if(e.type == 'radio') {
      e.checked = false;
    } 
  });
  option_area('none');
  clear_credit_reasons('none');
}

function clear_credit_reasons(except){
  $$('select').each(function(s) {
    if (s.id.match(/^credit_reason_/) && s.id != ('credit_reason_' + except)){
      s.hide();
      }  
    }); 
}


function set_reason(reason) {
  $('reason').value = reason;
}

// function set_expire_date_reason(reason) {
//  $('reason').value = reason;
//  $("expire_customer").value = true ;
// }

function option_area(area) {
  $$('select').each(function(s) {
    if (!s.id.match(/^credit_reason_/)){
      s.hide();
    }
  });
  $('date_month').show();
  $('date_year').show();
  $('date_day').show();
  if (area == 'expire_customer') { 
    $('cancel_reason').show();
    $('date_picker').show();
  } else if ($('date_picker')) {
    $('date_picker').hide();
  }

  $('suspend_label', 'cancel_label').each(Element.hide);

  if (area == 'cancel' || area == 'expire_customer') $('cancel_reason', 'cancel_label').each(Element.show);
  if (area == 'suspend') $('suspend_reason', 'suspend_label').each(Element.show);

}

new Event.observe(window, 'load', function(e) { niceyNice(); });

function niceyNice() {
  $$('#option_set tr.selectable').each(function(dee) {
    new Event.observe(dee, 'click', function(e) {
      $$('#option_set tr').each(function(tr) { tr.style.background='#fff;'});
      Event.findElement(e, 'tr').style.background='#ffc;';
    });
  });
}

function swapOptions(obj,i,j) {
  var o = obj.options;
  var i_selected = o[i].selected;
  var j_selected = o[j].selected;
  var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
  var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
  o[i] = temp2;
  o[j] = temp;
  o[i].selected = j_selected;
  o[j].selected = i_selected;
  }

function getSelectedOption(obj)
{
  for (i=0; i<obj.options.length; i++) {
    if (obj.options[i].selected) {
      return i;
      }
    }
  return null;  
}

function findOption(obj, text)
{
  for (i=0; i<obj.options.length; i++) {
    if (obj.options[i].text == text) {
      return i;
      }
    }
  return null;  
}

function addOption(obj,text,value,selected) {
	if (obj!=null && obj.options!=null) {
	  if (!checkDuplicate(obj, text)){
		  obj.options[obj.options.length] = new Option(text, value, false, selected);
		  sortlist(obj);
		}
	}
}

function sortlist(obj) {
  arrTexts = new Array();
  for(i=0; i<obj.length; i++)  {
    arrTexts[i] = obj.options[i].text;
  }
  arrTexts.sort();
  for(i=0; i<obj.length; i++)  {
    obj.options[i].text = arrTexts[i];
    obj.options[i].value = arrTexts[i];
  }
}

function removeSelectedOptions(from) { 
	if (from.options.length == 0) { return; }
	if (from.type=="select-one" && from.selectedIndex > -1) {
		var prev = from.selectedIndex;
		
		from.options[prev] = null;
		if (prev < from.options.length)
			from.selectedIndex = prev;
		else if (from.options.length > 0)
			from.selectedIndex = from.options.length - 1;
		}
	else {
		for (var i=(from.options.length-1); i>=0; i--) { 
			var o=from.options[i]; 
			if (o.selected) { 
				from.options[i] = null; 
				} 
			}
		}
	}
	
	
function moveTypeAltIn(target_field)
{
  var alternate_field = $(target_field);
  var offers         = $('cc_offer_selection');
  var cc_xsale_fo   = $('cc_xsale_failover');
  var site_xsale_fo = $('cc_site_failover');
  var cross_sales   = $('cc_cross_sale_list');
  var i             = getSelectedOption(cross_sales);	
	if (i != null){
    var cs          = cross_sales.options[i];
    var in_offers    = findOption(offers, cs.text);
    var in_xsale_fo = (cc_xsale_fo.value == cs.text);
    var in_site_fo  = (site_xsale_fo.value == cs.text);

	 if (in_offers == null && in_xsale_fo == '' && in_site_fo == '' && alternate_field.value == '') {
     	alternate_field.value = cs.text;
		removeSelectedOptions(cross_sales);
		return save_alternate_xsale_as_hidden(cs.text);
    }
  }
}

function save_alternate_xsale_as_hidden(alternate_xsale){
  var offers    = $('cc_offer_selection');
  var i        = getSelectedOption(offers);
  var mainForm = $('alternate_xsale_container');
  var input = document.createElement('input');
  input.type  = 'hidden';
  var cross_sale_name = offers.options[i].text;
  input.name  = 'cc[alternate_xsale][' + cross_sale_name + ']'; 
  input.id  = 'cc_alternate_xsale_' + cross_sale_name; 
  $('alternate_xsale_container').value = input.value = alternate_xsale;
  if(input.id )
  	mainForm.appendChild(input)
}

function moveTypeAltOut(target_field)
{
  var alternate_field = $(target_field);
  var offers       = $('cc_offer_selection');
  var cross_sales = $('cc_cross_sale_list');
	if(alternate_field.value != '') addOption(cross_sales, alternate_field.value, alternate_field.value, true)  
		var hidden_field_id = 'cc_alternate_xsale_' + offers.value; 
		var hidden_field = $(hidden_field_id)
		if(hidden_field != null) hidden_field.remove();
		alternate_field.value = '';
}

function aaand(x,y){ return x && y; }

function checkDuplicate(obj, text)
{
  for (i=0; i<obj.options.length; i++){
    if (obj.options[i].text == text){
      return true;
    }
  }
  return false;
}

function findOptionWithAlert(obj, text)
{
  for (i=0; i<obj.options.length; i++) {
    if (obj.options[i].text == text) {
      alert( text + ' Already Being Used for Cross Sale');
      return i;
      }
    }
  return null;  
}

function toggle_element(id){
 element=$(id);

 if(element.style.display!='none'){
 	element.style.display='none'; //Hide it if it isn't
 }
else{
 	element.style.display='block'; //Show it if its hidden.
 }

 }

function disable_cross_sale_controls() {
  document.forms[0].disable();
  document.forms[0].elements['merchants'].enable();
  document.forms[0].elements['sites[]'].enable();
}

function enable_cross_sale_controls() {
  document.forms[0].enable();
}

// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
  for (i=0; i<obj.options.length; i++) {
    if (obj.options[i].selected) {
      if (i != 0 && !obj.options[i-1].selected) {
        swapOptions(obj,i,i-1);
        obj.options[i-1].selected = true;
        }
      }
    }
  }

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
  for (i=obj.options.length-1; i >= 0; i--) {
    if (obj.options[i].selected) {
      if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
        swapOptions(obj,i,i+1);
        obj.options[i+1].selected = true;
            }
          }
        }
      }   //  that which doesn't kill you ... gives you brain damage


function date_selection(date){
  ourDate = new Date()
  if(date.value == 'Current Day') {
    var timesuffix = (ourDate.getHours() > 12) ? ' PM' : ' AM' ;
    var hours = ourDate.getHours() % 12;
    var mins = ourDate.getMinutes() - ourDate.getMinutes() % 5;
    if (hours < 10) { hours = '0' + hours}
    if (mins < 10) { mins = '0' + mins}
    var time = hours.toString() + ':' + mins.toString() + timesuffix;
    $('end_time').value = time;
  }
  else if (date.value == 'Previous Day') { 
    // alert($('start_day').options.selected)
     $('start_day').value = 6;
 	}
}


function collapseMe(expander){
  Element.hide(expander);
}

function expandMe(expander){
	Element.show(expander);
}


function toggle_check(me, other){
  other.checked = false;
  me.checked = true;
}

function other_on(other, state){
	if(!state){
		other.checked = true;
	}
}

//Transaction Detail Javascript

   function addItem(all)
   {
      var thisForm      = document.forms.params_form;
      var srcList       = $('infoAvail');
      var dstList       = $('reporter_infoSelected');

			$('reporter_infoList').value = '';

      if (!all)
      {
         moveDualList(srcList, dstList, false);
      }
      else if (all == 1 || all == 3)
      {
         moveDualList(srcList, dstList, true);
      }
      else if (all == 2)
      {
         var srcListTotal  = srcList.options.length;
         var thisItemTxt;
         moveDualList(srcList, dstList, false);
      }

      dstListTotal  = dstList.options.length;

      for(i=0;i<dstListTotal;i++)
      {
         $('reporter_infoList').value += dstList.options[i].value;
         if (i != dstListTotal-1)
         {
            $('reporter_infoList').value += ":";
         }
      }
      sortSelect(srcList);
      sortSelect(dstList);
      return(false);
   }

   function removeItem(all)
   {
      var thisForm      = document.forms['params_form'];
      var dstList       = $('reporter_infoSelected');
      var srcList       = $('infoAvail');

      $('reporter_infoList').value = '';

      if (!all)
      {
         moveDualList(dstList, srcList, false);

         var dstListTotal  = dstList.options.length;
         for(i=0;i<dstListTotal;i++)
         {
            $('reporter_infoList').value += dstList.options[i].value;
            if (i != dstListTotal-1)
            {
               $('reporter_infoList').value += ":";
            }
         }
      }
      else
      {
         moveDualList(dstList, srcList, true);
      }

      sortSelect(srcList);
      sortSelect(dstList);
      return(false);
   }

   function addSearch(flag)
   {
      var thisForm     = document.forms['params_form'];
      var srcList      = $('reporter_searchBy');
      var dstList      = $('reporter_searchSelected');
      var dstListTotal = "";

      if (!flag)
      {
         var srcSelected  = srcList.selectedIndex;
         if (srcSelected != -1)
         {
            var thisItem     = srcList.options[srcSelected].value;
            var resultSet    = thisItem.split("^");
            var textVal      = "";
            var dstVal       = "";
            var dstTxt       = "";

						$('reporter_searchList').value = '';

            // thisForm.searchList.value = '';

            if (resultSet[1] == 'textBox' && $('reporter_textEntry').value == '')
            {
               alert('Please enter a valid search value');
               $('reporter_textEntry').focus();
            }
            else
            {
               dstListTotal = $('reporter_searchSelected').options.length;

               if (dstListTotal == 1 &&
                   dstList.options[0].text == '----SEARCH----')
               {
                  dstList.options[0] = null;
                  dstListTotal--;
               }

               if (resultSet[1] == 'textBox')
               {
                  if (resultSet[0] == 'CC/ACH/EDD')
                  {
                     var acctNum = $('reporter_textEntry').value;
                     var invalidChar = /[^0-9-]/;
                     var matchResult = acctNum.match(invalidChar);
                     if (matchResult != null)
                     {
                        alert('Please enter a valid value');
                        $('reporter_textEntry').focus();
                        return(false);
                     }
                  }
                  else if (resultSet[0] == 'IP Address')
                  {
                     var ipAddr = $('reporter_textEntry').value;
                     var invalidChar = /[^0-9.]/;
                     var matchResult = ipAddr.match(invalidChar);
                     if (matchResult != null)
                     {
                        alert('Please enter a valid value');
                        $('reporter_textEntry').focus();
                        return(false);
                     }
                  }
                  textVal = $('reporter_textEntry').value;
               }
               else if (resultSet[1] == 'dropDown')
               {
                  textVal = $('reporter_dropDownSearch').options[$('reporter_dropDownSearch').selectedIndex].text;
               }

               // dstVal = resultSet[0];
               dstTxt = dstVal = resultSet[0] + '-' + textVal;

               var addFlag = 1;

               // if user tries to add more than one value per criteria
               for(i=0;i<dstListTotal;i++)
               {
                  var str = resultSet[0];
                  var text = dstList.options[i].text;
                  var result = text.match(str);

                  if (result != null)
                  {
                     alert('You can add only one value for ' + resultSet[0]);
                     addFlag = 0;
                  }
               }

               if (addFlag == 1)
               {
                  dstList.options[dstListTotal] = new Option(dstTxt,dstVal);
                  dstListTotal++;
               }
            }
         }
      }
      else if(flag == 1)
      {
         dstListTotal = 0;
         var dstVal= 'Max Matches';
         var dstTxt= 'Max Matches-100';
         dstList.options[dstListTotal] = new Option(dstTxt,dstVal);
         dstListTotal++;
         dstVal= 'Sale Type';
         dstTxt= 'Sale Type-All New Txn';
         dstList.options[dstListTotal] = new Option(dstTxt,dstVal);
         dstListTotal++;
      }
      else if (flag == 2)
      {
         dstListTotal = 0;

      }

      $('reporter_searchList').value = '';
      for(i=0;i<dstListTotal;i++)
      {
         $('reporter_searchList').value += dstList.options[i].text;
         if (i != dstListTotal-1)
         {
            $('reporter_searchList').value += ":";
         }
      }
      sortSelect(srcList);
      sortSelect(dstList);
      return(false);
   }

   function removeSearch()
   {
      var thisForm      = document.forms['params_form'];
      var dstList       = $('reporter_searchSelected');
      var checkSelected = dstList.selectedIndex;
      if (checkSelected != -1)
      {
         var dstListTotal  = dstList.options.length;
         var listTotal     = dstListTotal;
         var itemToRemove  = 0;
         $('reporter_searchList').value = '';

         while(dstListTotal > 0)
         {
            itemToRemove = (dstListTotal - 1)
            if (dstList.options[itemToRemove].selected &&
                dstList.options[itemToRemove].selected != null)
            {
               dstList.options[itemToRemove] = null;
               listTotal--;
            }
            dstListTotal--;
         }
         if (listTotal == 0)
         {
            dstTxt = '----SEARCH----';
            dstVal = '/';
            dstList.options[listTotal] = new Option(dstTxt,dstVal);
            $('reporter_searchList').value = '';
         }
         else
         {
            for(i=0;i<listTotal;i++)
            {
               $('reporter_searchList').value += dstList.options[i].text;
               if (i != listTotal-1)
               {
                  $('reporter_searchList').value += ":";
               }
            }
         }
      }
      sortSelect(dstList);
      return(false);
   }

   function browser(id)
   {
      var nn4 = (document.layers) ? true : false
      var ie = (document.all) ? true : false
      var dom = (document.getElementById && !document.all) ? true : false

      if (ie)
      {
         return(document.all[id]);
      }
      if (nn4)
      {
         return(document.layers[id]);
      }
      if (dom)
      {
         return(document.getElementById(id));
      }
   }

   function showLayer(id)
   {
      var nn4   = (document.layers) ? true : false
      var ie    = (document.all) ? true : false
      var dom   = (document.getElementById && !document.all) ? true : false
      var layer = browser(id);

      if('ie')
      {
         layer.style.visibility = "visible";
      }
      else if('dom')
      {
         layer.style.visibility = "visible";
      }
      else if('nn4')
      {
         layer.visibility = "visible";
      }
      return(false);
   }

   function hideLayer(id)
   {
      var nn4 = (document.layers) ? true : false;
      var ie = (document.all) ? true : false;
      var dom = (document.getElementById && !document.all) ? true : false;
      var layer=browser(id);

      if(nn4 == 'true')
      {
         layer.visibility = "hidden";
      }
      else
      {
         layer.style.visibility = "hidden";
      }
      return(false);
   }

   function handleSearch()
   {
      var thisForm    = document.forms['params_form'];
      var thisItem    = $('reporter_searchBy').selectedIndex;
      var listTotal   = $('reporter_searchBy').options.length;
      var thisItemSel = $('reporter_searchBy').options[thisItem].value;
      var counter     = 0;
      var message     = "";
      var resultSet   = "";
      for (var i=0;i<listTotal;i++)
      {
         if ($('reporter_searchBy').options[i].selected)
         {
            counter++;
         }
      }

      if (counter > 1)
      {
         alert('Too Many Fields Selected');
      }
      else
      {
         resultSet = thisItemSel.split("^");
         showLayer(resultSet[1]);
         if (resultSet[1] == 'textBox')
         {
            hideLayer('dropDown');
            $('reporter_textEntry').value = '';
            $('reporter_textEntry').focus();
         }
         else
         {
            hideLayer('textBox');
            populateDropDown(resultSet[0]);
            $('reporter_dropDownSearch').focus();
         }
      }
      return(false);
   }



   function sortSelect(obj)
   {
      var o = new Array();
      if (obj.options==null)
      {
         return;
      }
      for (var i=0; i<obj.options.length; i++)
      {
         o[o.length] = new Option( obj.options[i].text, obj.options[i].value,
                                   obj.options[i].defaultSelected,
                                   obj.options[i].selected);
      }
      if (o.length==0)
      {
         return;
      }
      o = o.sort( function(a,b) {
                   if ((a.text+"") < (b.text+"")) { return -1; }
                   if ((a.text+"") > (b.text+"")) { return 1; }
                   return 0;
                   } );

      for (var i=0; i<o.length; i++)
      {
         obj.options[i] = new Option(o[i].text, o[i].value,
                                     o[i].defaultSelected, o[i].selected);
      }
   }
   var Sale_TypeArray   =  new Array(
      "('All New Txn')"
         ,
      "('Renewal')"
         ,
      "('Trial')"
         ,
      "('Standard')"
         ,
      "('One-Time')"
         ,
      "('Conversion')"
         );
   var Txn_TypeArray    =  new Array(
      "('Sale')"
         ,
      "('Credit')"
         );
   var Member_StateArray    =  new Array(
     "('ach_nsf_limit_exceeded')", "('canceled')", "('cc_nsf_limit_exceeded')", "('cc_nsf_pending')", "('chargeback')", "('duplicate_membership')", "('failed')", "('hard_gateway_error')", "('limited_access')", "('monthly_pending')", "('monthly_pending_canceled')", "('monthly_pending_limit_exceeded')", "('paid_for')", "('pending_cancel')", "('purchaseable')", "('redirected')", "('suspended')");
   var Pay_MethodArray  =  new Array(
      "('ACH')"
         ,
      "('Credit Card')"
         );
   var Max_MatchesArray =  new Array(
"('50')","('100')","('150')","('200')","('250')","('300')","('1000')","('All')");   

function populateDropDown(selected)
   {
      selected = selected.replace(" ", "_");
      var selectedArray = eval(selected + "Array");
      while (selectedArray.length < $('reporter_dropDownSearch').options.length)
      {
         $('reporter_dropDownSearch').options[($('reporter_dropDownSearch').options.length - 1)] = null;
      }

      for (var i=0; i < selectedArray.length; i++)
      {
         eval("$('reporter_dropDownSearch').options[i]=" + "new Option" + selectedArray[i]);
      }
   }

// Dual list move function
function moveDualList( srcList, destList, moveAll ) 
{
  // Do nothing if nothing is selected
  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )
  {
    return;
  }
  newDestList = new Array( destList.options.length );
  var len = 0;
  for( len = 0; len < destList.options.length; len++ ) 
  {
    if ( destList.options[ len ] != null )
    {
      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
    }
  }
  for( var i = 0; i < srcList.options.length; i++ ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       // Statements to perform if option is selected
       // Incorporate into new list
       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );
       len++;
    }
  }

  // Sort out the new destination list
  newDestList.sort( compareOptionValues );   // BY VALUES
//  newDestList.sort( compareOptionText );   // BY TEXT
  // Populate the destination with the items from the new array
  for ( var j = 0; j < newDestList.length; j++ ) 
  {
    if ( newDestList[ j ] != null )
    {
      destList.options[ j ] = newDestList[ j ];
      destList.options[ j ].selected = false;
    }
  }

  // Erase source list selected elements
  for( var i = srcList.options.length - 1; i >= 0; i-- ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       // Erase Source
       //srcList.options[i].value = "";
       //srcList.options[i].text  = "";
       srcList.options[i]       = null;
    }
  }
} 

// Compare two options within a list by VALUES
function compareOptionValues(a, b) 
{ 
  // Radix 10: for numeric values
  // Radix 36: for alphanumeric values
  var sA = parseInt( a.value, 36 );  
  var sB = parseInt( b.value, 36 );  
  return sA - sB;
}

// Compare two options within a list by TEXT
function compareOptionText(a, b) 
{ 
  // Radix 10: for numeric values
  // Radix 36: for alphanumeric values
  var sA = parseInt( a.text, 36 );  
  var sB = parseInt( b.text, 36 );  
  return sA - sB;
}

function fnPasteTag(title)
{
   var link;
   link=document.params_form.EMAIL_BODY.value.replace(/\^/i, title);
   if (document.params_form.EMAIL_BODY.value==link) {
      var message = "To substitute text, please place the ^ character " +
                    "in the location you would like to insert dynamic " +
                    "replacement text.";
      alert(message);
   }
   else
   {
      document.params_form.EMAIL_BODY.value=link;
   }
}

function fnPreview()
{
   document.params_form.EMAIL_BODY.blur();
   var result = document.params_form.EMAIL_BODY.value.search(/\^/i);
   var result2 = document.params_form.EMAIL_BODY.value.search(/\"/i);
   if (result != -1)
   {
      var message = "Email text contains unsubstituteed tag(s).\n" +
                    "Please substitute or delete any ^ characters.";
      alert(message);
   }
   else if (result2 != -1)
   {
      var message2 = "Email text contains \" character(s), please " +
                     "delete any \" characters.";
      alert(message2);
   }
   else
   {
      document.forms.params_form.REQUEST.value="Preview";
      document.params_form.action='#'; // CONSIDER add preview email form here
      document.forms.params_form.submit();
   }
}

function fnCheckLink()
{
   document.params_form.EMAIL_BODY.blur();
   var result = document.params_form.EMAIL_BODY.value.search(/\^/i);
   var result2 = document.params_form.EMAIL_BODY.value.search(/\"/i);
   if (result != -1)
   {
      var message = "Email text contains unsubstituteed tag(s).\n" +
                    "Please substitute or delete any ^ characters.";
      alert(message);
   }
   else if (result2 != -1)
   {
      var message2 = "Email text contains \" character(s), please " +
                     "delete any \" characters.";
      alert(message2);
   }
   else
   {
      document.forms.params_form.REQUEST.value="Save Changes";
      document.forms.params_form.submit();
   }
}

function fnDelete()
{
   document.params_form.EMAIL_BODY.blur();
   if (confirm("Are you sure you want to permanently delete this " +
               "confirmaiton email?") == 1)
   {
      document.forms.params_form.REQUEST.value="Delete";
      document.forms.params_form.submit();
   }
}

///////////////////////////////////////////////////////////
// display pop up message to the user when there is no
// email message found for the specific merch/site/prod
///////////////////////////////////////////////////////////
if (("966" != 0) &&
    ("3" !=  "3") &&
    ("" != "Rework Email"))
{
   alert("You do not have a merchant specific" +
         " confirmation email.\nDefaulting confirmation email to the" +
         " English merchant level.");
}

function validate_email(email){
  if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email))){
    alert('Invalid Email Format');
    return true;
  }
  return false;
}

function reset_form(f){
  arr = f.elements; 
  for(var index = 0, len = arr.length; index < len; ++index){ 
    if (arr[index].type == 'text'){ 
      arr[index].clear(); 
    }else if (arr[index].type == 'select-one'){ 
      arr[index].selectedIndex = 0; 
    }
  }
}

function validate_affiliate_fields(){
  var warnings = "";
  if(!$("reporter_simulator_percentage").value.match(/^\d+$/)){
    warnings += " Number only for Percentage.\n";
  }
  if(!$('reporter_affiliate_payout').value.match(/^[\d\.]+$/)){
    warnings += " Numbers and decimal points only for Payout";
  }
   
  if(warnings == "") return true;
  alert(warnings);
  return false;
}  
