// -------------------------------------------------------------
function uploadingpopup() {

  l = getElement('lollipop');
  f = getElement('uploadform');
  f.style.visibility = 'hidden';
  f.style.display    = 'none';
  l.style.visibility = 'visible';
  l.style.display    = 'block';

}

// -------------------------------------------------------------
function showgiftrows() {
//not using gifts right now, so this is commented
/*
  checked = false;
  for ( i = 0; !checked && ( i < document.forms["input"]["purchase"].length ); i++ ) {
    if ( document.forms["input"]["purchase"][ i ].checked == true )
      checked = document.forms["input"]["purchase"][ i ].value;
  }

  g = getElement('gift');
  if ( checked == 'g' ) {
    g.style.visibility = 'visible';
    g.style.display    = 'block';
  }
  else {
    g.style.visibility = 'hidden';
    g.style.display    = 'none';
  }
*/
//if we have a member that comes to the modify user page and the initial value is either 'no purchase' or 'free limited membership', then hide credit card options...
 if (typeof document.forms["input"]["purchase"]!="undefined"){
  if (document.forms.input.purchase[0].checked){
    elements = Array( 'trpaymentinfo');

    for ( i in elements ) {

      o = getElement( elements[i] );

      if ( o ) {
        o.classname = '';
        o.style.visibility = 'hidden' ;
        o.style.display    = 'none' ;
      }

    }
  }else{
    elements = Array( 'trpaymentinfo');

    for ( i in elements ) {

      o = getElement( elements[i] );

      if ( o ) {
        o.classname = '';
        o.style.visibility = 'visible' ;
        o.style.display    = '' ;
      }

    }

  }
 }




}

// -----------------------------------------------------------stufftohide-
function sth() {
//hide credit card options if 'free limited membership' is the intial value

if (typeof document.forms["input"]!="undefined"){
/*
 if (typeof document.forms["input"]["productid"]!="undefined"){
  if (document.forms["input"]["productid"][0].checked){
    elements = Array( 'trcardtype', 'trnameoncard', 'trcardnumber', 'trexpiration', 'trcardcvs', 'contactinfo', 'traddress', 'trcity', 'trstate', 'trzip', 'trcountry', 'trpaymentinfo', 'trphone');

    for ( i in elements ) {

      o = getElement( elements[i] );

      if ( o ) {
        o.classname = '';
        o.style.visibility = 'hidden' ;
        o.style.display    = 'none' ;
      }

    }
  } 
 }
*/

//if credit card is not checked, then hide all the credit card options

 if (typeof document.forms["input"]["paymenttype"]!="undefined"){
  if (!document.forms.input.paymenttype[0].checked){
    elements = Array( 'trcardtype', 'trnameoncard', 'trcardnumber', 'trexpiration', 'trcardcvs', 'contactinfo');

    for ( i in elements ) {

      o = getElement( elements[i] );

      if ( o ) {
        o.classname = '';
        o.style.visibility = 'hidden' ;
        o.style.display    = 'none' ;
      }

    }
  }
 }
//if we have a member that comes to the modify user page and the initial value is either 'no purchase' or 'free limited membership', then hide credit card options...
 if (typeof document.forms["input"]["purchase"]!="undefined"){
  if (document.forms.input.purchase[0].checked){ 
    elements = Array( 'trpaymentinfo');

    for ( i in elements ) {

      o = getElement( elements[i] );

      if ( o ) {
        o.classname = '';
        o.style.visibility = 'hidden' ;
        o.style.display    = 'none' ;
      }

    }
  }
 }

/*
   if (document.forms["input"]["productid"][0].checked){
     o = getElement( 'traddress' );
     o.style.visibility='hidden';
     o.style.display   ='none';
     alert("heh heh!");
   }else{
     alert("crap");
   }
*/
}
}
// -------------------------------------------------------------
function validaterenewal() {

//  if ( null == document.forms.input.paymenttype[0] )
//    return true;

  ok =
    (
      document.forms["input"]["autorenewal"].checked && 
      document.forms["input"]["paymenttype"][0].checked 
    ) ||
    !document.forms["input"]["autorenewal"].checked
  ;

  return ok;

}


// -------------------------------------------------------------
function validateccandpurchase() {

//if there is no purchase, ignore no entry in CC fields

  ok =
    !document.forms["input"]["purchase"][0].checked
  ;

  return ok;

}


// -------------------------------------------------------------
function validategiftemail( regexp ) {

  giftid = -1;

  for ( i = 0; i < document.forms.input.purchase.length; i++ ) {
    if ( document.forms.input.purchase[i].value == 'g' )
      giftid = i;
  } 

  if ( ( giftid != -1 ) && document.forms.input.purchase[giftid].checked ) {
    
    ok = 
      document.forms["input"]["giftemail"].value.match( regexp ) == 
      document.forms["input"]["giftemail"].value;
    return ok;

  }
  else
    return true;

}

// -------------------------------------------------------------
function validatecardtype() {

//  if ( 
//       ( null == document.forms.input.paymenttype[0] &&
//	!document.forms.input.purchase[0].checked ) ||
//       (document.forms.input.paymenttype[0].checked  &&
//	!document.forms.input.purchase[0].checked )  ) {

    ok = false;
    for ( i = 0; !ok && ( i < document.forms.input.cardtype.length ); i++ ) {
      ok = ok || ( document.forms.input.cardtype[ i ].checked == true );
    }

    return ok;

//  }
//  else
//    return true;

}


// -------------------------------------------------------------
function cleanvalidaterequired( element, regexp, mustmatch ) {
    ok =
      document.forms["input"][ element ].value.match( regexp ) ==
      document.forms["input"][ element ].value;

    if ( mustmatch )
      return ok;
    else
      return !ok;
}
// -------------------------------------------------------------
function freememvalidaterequired( element, regexp, mustmatch ) {
 if (
  !document.forms.input.productid[0].checked
 ){
    ok =
      document.forms["input"][ element ].value.match( regexp ) ==
      document.forms["input"][ element ].value;

    if ( mustmatch )
      return ok;
    else
      return !ok;

  }else return true;
}

// -------------------------------------------------------------
function validaterequired( element, regexp, mustmatch ) {

  if (  
       ( null == document.forms.input.paymenttype[0] &&
	!document.forms.input.purchase[0].checked ) ||
       ( document.forms.input.paymenttype[0].checked &&
	!document.forms.input.purchase[0].checked )   ) {
    ok = 
      document.forms["input"][ element ].value.match( regexp ) == 
      document.forms["input"][ element ].value;

    if ( mustmatch ) 
      return ok;
    else
      return !ok;
  }
  else
    return true;

}

// -------------------------------------------------------------
function showcreditcardrows( type ) {

  elements = Array( 'trcardtype', 'trnameoncard', 'trcardnumber', 'trexpiration', 'trcardcvs', 'contactinfo' );
  v        = getElement('visiblerow');

  for ( i in elements ) {

    o = getElement( elements[i] );

    if ( o ) {
      o.classname = '';
      o.style.visibility = ( type == 'creditcard' ? 'visible' : 'hidden' );
      o.style.display    = ( type == 'creditcard' ? v.style.display : 'none' );
    }

  }
    

}

// -------------------------------------------------------------
function freeuserorder( type ) {

  elements = Array(  'trnewsletter', 'trretentionemails','traddress','traddress','trcity','trstate','trzip','trcountry','trphone','trpaymentinfo' );
  v        = getElement('visiblerow');

  for ( i in elements ) {

    o = getElement( elements[i] );

    if ( o ) {
      o.classname = '';
      o.style.visibility = ( type == '3' ? 'hidden' : 'visible' );
      o.style.display    = ( type == '3' ? 'none' : v.style.display );
    }

  }


}

// -------------------------------------------------------------
function getElement( id, indoc ) {

  if ( undefined == indoc ) 
    indoc = document;

  obj = null;

  if ( indoc.getElementById ) {
    obj = indoc.getElementById( id );
  }
  else
    if ( indoc.all ) 
      obj = indoc[ id ];

  return obj;

}

// ----------------------------------------------------------------------------
function selectall( name ) {

  e = getElement( name );

  for ( i = 0; i < e.length; i++ )
    e[i].selected = true;

}

// ----------------------------------------------------------------------------
function checkall( name, value ) {

  e = document.getElementsByTagName( 'input' );

  for ( i = 0; i < e.length; i++ ) {
    if ( e[i].name.substring( 0, name.length ) == name )
      e[i].checked = value;
  }

}

// ----------------------------------------------------------------------------
function addrecipient() {

  e      = document.getElementsByTagName( 'input' );
  emails = opener.document.forms.input.emails.value;

  for ( i = 0; i < e.length; i++ ) {
    
    if ( 
         e[i].checked &&
         ( 
           ( e[i].name.substring( 0, 10 ) == 'contactcbx' )
           ||
           ( e[i].name.substring( 0, 6 ) == 'grpcbx' )
         )
       )
    if ( emails.length ) 
      emails += '\n' + e[i].value;
    else
      emails = e[i].value;

  }

  opener.document.forms.input.emails.value = emails;

}
// ----------------------------------------------------------------------------
//this function gives all browsers the abilty to copy text to the end user clipboard
function copy(text2copy) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text2copy);
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}


//----------------------------------------------------------------
//this function controls the popups on the premium animations
function writeConsole(content) {
 top.consoleRef=window.open('','myconsole',
  'width=300,height=300'
   +',menubar=0'
   +',toolbar=0'
   +',status=0'
   +',scrollbars=0'
   +',resizable=1')
 top.consoleRef.document.writeln(
  '<html><head>'
  +'<meta http-equiv="Content-Language" content="en-us">'
  +'<link rel="stylesheet" href="style.css">'
  +'<title>Download Animation</title></head><body bgcolor=white onLoad="self.focus()">'
  +'<p align="center"><img src="'
  +content
  +'"></p>'
  +'<p align="center"><b>To Save Animation</b><br>Right click on animation and choose<br>&quot;Save Picture As...&quot;<br>'
  +'Mac users: Control Click on animation.</p>'
  +'<p align="center"><span class="signinbuttons"><A href="javascript: self.close ()">Close Window</A></span></p>'
  +'</body></html>'
 )
 top.consoleRef.document.close()
}


//----------------------------------------------------------------
//this function hides the flash interface and shows the processed anim
function hideFlash(myUrl, color) {
	var ele = document.getElementById('flashDiv');
	ele.style.display = 'none';
	var myContent = '<img src="' + myUrl + '">';
	document.getElementById('myAnim').innerHTML = myContent;
	//document.getElementById('myAnim').innerHTML = color;
	document.getElementById('myResults').style.display = 'block';
	if ( color == 999999 ) {
	document.getElementById('myColor').style.backgroundImage = 'url(images/checker.gif)';
	} else {
	document.getElementById('myColor').style.backgroundColor = color;
	document.getElementById('myColor').style.backgroundImage = 'none';

	}

}
	
//----------------------------------------------------------------
//this function shows the flash interface after anim is viewed

function findFlash() {
document.getElementById('myResults').style.display = 'none';
document.getElementById('flashDiv').style.display = 'block';
}

