// newsletter use template button

function checkme(elemname) {
	document.getElementById(elemname).checked = true;
	//$("#"+elemname+"").checked = true;
	checkptcopy();
	}
	
function checkptcopy() {
	if ($('#use_template_no').attr("checked") == true) {
		$('#ptcopy1').show();
		$('#ptcopy2').show();
	} else {
		$('#ptcopy1').hide();
		$('#ptcopy2').hide();
		}
	}
		

// resize optional address field
	//$('textarea.formfield').hide();

// flip external link - add pages

function link_none() {
	$("#offsite_link").val('').attr('disabled','disabled');
	$("#external_url").val('').attr('disabled','disabled');
	
	$("#offsite_copy").val('').attr('disabled','disabled');
	$("#gallery_link").val('').attr('disabled','disabled');
	}

function link_pre() {
	$("#external_url").val('').removeAttr('disabled');
	$("#offsite_copy").removeAttr('disabled');
	
	$("#offsite_link").val('').removeAttr('disabled');
	
	$("#gallery_link").val('').attr('disabled','disabled');
	}

function link_custom() {
	$("#offsite_link").val('').removeAttr('disabled');
	$("#external_url").val('').removeAttr('disabled');

	$("#offsite_copy").val('').attr('disabled','disabled');
	$("#gallery_link").val('').attr('disabled','disabled');
	}
	
function link_gallery() {
	$("#gallery_link").removeAttr('disabled');
	$("#offsite_link").val('Click here to view [imagetitle]').removeAttr('disabled');
	$("#external_url").val('').removeAttr('disabled');

	$("#offsite_copy").val('').attr('disabled','disabled');
	}
	

//Reset search form

function resetsearch() {

	$("#search_artist").val('');
	$("#search_bool2").val('and');
	$("#search_category").val('');
	$("#search_bool5").val('and');
	$("#search_sub3").val('');
	$("#search_bool3").val('and');
	$("#search_sub1").val('');
	$("#search_bool1").val('and');
	$("#search_media").val('');
	$("#search_bool4").val('and');
	$("#search_sub2").val('');
	$("#search_bool7").val('and');
	$("#search_restrictions").val('');
	
	$("#searchtext").val('');
	}


//enter key to correct functions for forms

// all jQuery events are executed within the document ready function
$(document).ready(function() {


   $("#flogin_name, #flogin_pass").bind("keydown", function(event) {
      // track enter key
      var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
      if (keycode == 13) { // keycode for enter key
         // force the 'Enter Key' to implicitly click the Update button
         
         //floating login
         
         logmein(document.logform2.username.value,document.logform2.password.value);
         
         return false;
      } else  {
         return true;
      }
   }); // end of function
   
   $("#sflogin_name, #sflogin_pass").bind("keydown", function(event) {
      // track enter key
      var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
      if (keycode == 13) { // keycode for enter key
         // force the 'Enter Key' to implicitly click the Update button
         
         //login on member tools page
         
         document.logform.submit();
         
         return false;
      } else  {
         return true;
      }
   }); // end of function
   
   $("#lbnew_field").bind("keydown", function(event) {
      // track enter key
      var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
      if (keycode == 13) { // keycode for enter key
         // force the 'Enter Key' to implicitly click the Update button

		//add to new lb in floater
         
         createaddimgtolb(document.lbform2.lbnew.value,document.lbform2.lbimage.value);
         
         return false;
      } else  {
         return true;
      }
   }); // end of function
      

}); // end of document ready



//form scripts

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function togglecheck(e){
	document.getElementById(e).checked = !(document.getElementById(e).checked);
	}


//clear newsletter entry

function clearnews() {
	if (document.newsform.email.value == "email address") {
		document.newsform.email.value = "";
	}
}

function fillnews() {
	if (document.newsform.email.value == "") {
		document.newsform.email.value = "email address";
	}
}


//limiting text entry

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}


//ajax scripts for log in

function invokesignup() {

	$('#default_button').hide();
	$('#loading_button').show();

	signmeup(
		document.std_signup.email.value,
		document.std_signup.first.value,
		document.std_signup.last.value,
		document.std_signup.title.value,
		document.std_signup.company.value,
		document.std_signup.bus_type.value,
		document.std_signup.po_address.value,
		document.std_signup.address.value,
		document.std_signup.city.value,
		document.std_signup.state.value,
		document.std_signup.zip.value,
		document.std_signup.country.value,
		document.std_signup.phone.value,
		document.std_signup.homephone.value,
		document.std_signup.fax.value,
		document.std_signup.pager.value,
		document.std_signup.cell.value,
		document.std_signup.hiddenagree.value,
		document.std_signup.username.value,
		document.std_signup.password1.value,
		document.std_signup.password.value
		);
}

function signmeup(email,first,last,title,company,bus_type,po_address,address,city,state,zip,country,phone,homephone,fax,pager,cell,agree,username,password1,password) {
	$.ajax({
	
		type: "POST",
		url: "/signup/pass.asp",
		data: { email: email, first: first, last: last, title: title, company: company, bus_type: bus_type, po_address: po_address, address: address, city: city, state: state, zip: zip, country: country, phone: phone, homephone: homephone, fax: fax, pager: pager, cell: cell, agree: agree, username: username, password1: password1, password: password },
		timeout: 10000,
		success: signmeupcallback,
		error: signmeuperror
	
	});
	}
	
function signmeupcallback(data, status) {

		
		$('#formerrors').slideUp();
		
		$('#errorcontent').html("");
		$('#errorcontent').html(data);
		
		window.location = String(window.location).replace(/\#.*$/, "") + "#errors";
		$('#formerrors').slideDown();
		
		$('#loading_button').hide();
		$('#default_button').show();
		
		
	}
	
function signmeuperror(xhr, reason, ex) {
		
		$('#formerrors').slideUp();
		
		$('#errorcontent').html("");
		$('#errorcontent').html(xhr + " " + reason + " " + ex);
		
		window.location = String(window.location).replace(/\#.*$/, "") + "#errors";
		$('#formerrors').slideDown();
		
		$('#loading_button').hide();
		$('#default_button').show();

	}
	

//Jquery Centering Function

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}


//post log-in ajax lb list fill

function filllblist () {
	$('#dynamic_lb_list').load('/actions/fill_lb_list.asp')
	}

//ajax scripts for log out

function logmeout() {
	$.ajax({
	
		type: "POST",
		url: "/actions/logout_ajax.asp",
		data: {},
		timeout: 10000,
		success: logmeoutcallback,
		error: logmeouterror
	
	});
	}
	
function logmeoutcallback(data, status) {
		$('#logout_trap').html(data);
		$('#container_login').show();
		$('#container_lightbox').hide();
		//initLogin();
		$('.lbcontent #inner #login_work_content').hide();
		$('.lbcontent #inner #login_init_content').show();
		membarOff();
		
		filllblist();
	}
	
function logmeouterror(xhr, reason, ex) {

	}

//init login window

function initLogin () {
		$('.lbcontent #inner #login_work_content').hide();
		$('.lbcontent #inner #login_init_content').show();
		togglemodwin();
	}

//ajax scripts for log in

function logmein(usernamex,passwordx) {
	$.ajax({
	
		type: "POST",
		url: "/actions/checkpass_ajax.asp",
		data: {username: usernamex, password: passwordx},
		timeout: 10000,
		success: logmeincallback,
		error: logmeinerror
	
	});
	}
	
function logmeincallback(data, status) {
		$('.lbcontent #inner #login_init_content').hide();
		$('.lbcontent #inner #login_work_content').show();
		$('.lbcontent #inner #login_work_content').html(data);
		
		//$('#container_login').delay(400).fadeOut(200,function() {
			//togglemodwin();
			//membarOn();
			//$('#container_login').hide();
			//$('#container_lightbox').delay(400).show(200);
		//}
		//);
		
		filllblist();
	}
	
function logmeinerror(xhr, reason, ex) {
		$('.lbcontent #inner #login_init_content').hide();
		$('.lbcontent #inner #login_work_content').show();
		$('.lbcontent #inner #login_work_content').html(reason + xhr + ex);
	}
	
function resetlogin() {
		$('.lbcontent #inner #login_work_content').hide();
		$('.lbcontent #inner #login_init_content').show();
	}
	
function closeloginwin() {

	$('#container_login').delay(400).fadeOut(200,function() {
			togglemodwin();
			membarOn();
			$('#container_login').hide();
			$('#container_lightbox').delay(400).show(200);
		});
	}
	
	

//ajax scripts for addimg image to lightbox

$(document).ajaxError(function(){
    if (window.console && window.console.error) {
        console.error(arguments);
    }
});


function addimgtolb(lblistx,lbimagex) {
	$.ajax({
	
		type: "POST",
		url: "/member_services/actions/context_lb_add_ajax.asp",
		data: {lblist: lblistx, lbimage: lbimagex},
		timeout: 10000,
		success: lbaddcallback,
		error: lbadderror
	
	});
	}
	
function createaddimgtolb(lbnewx,lbimagex) {
	$.ajax({
	
		type: "POST",
		url: "/member_services/actions/context_lb_create_add_ajax.asp",
		data: {lbnew: lbnewx, lbimage: lbimagex},
		timeout: 10000,
		success: lbaddcallback,
		error: lbadderror
	
	});
	}
	
function lbaddcallback(data, status) {
		filllblist();
		$('.lbcontent #inner #lb_init_content').hide();
		$('.lbcontent #inner #lb_work_content').show();
		$('.lbcontent #inner #lb_work_content').html(data);
	}
	
function lbadderror(xhr, reason, ex) {
		$('.lbcontent #inner #lb_init_content').hide();
		$('.lbcontent #inner #lb_work_content').show();
		$('.lbcontent #inner #lb_work_content').html(reason + xhr + ex);
	}
	
function resetlb() {
		$('.lbcontent #inner #lb_work_content').hide();
		$('.lbcontent #inner #lb_init_content').show();
	}

//ajax end

// member bar functions

function membarOn() {
	$('#public_options').fadeOut('200', function() {
		$('#member_options').fadeIn('200');
		});
	}
	
function membarOff() {
	$('#member_options').fadeOut('200', function() {
		$('#public_options').fadeIn('200');
		});
	}


function togglemodwin() {

	if (document.getElementById('lbfade').style.display == 'none') {
	
		/*$('#lbfloater').animate({
				top: '280px',
				opacity: 1
			}, 600, 'swing');*/
		$('#lbfloater').fadeIn(200);
		$('#all').animate({
				opacity: 0.3
			}, 200, 'swing');
		$('#lbfade').show();
		//$('#all').attr('class','all_faded');
		document.lbform2.lbnew.value = '';
		resetlb();
		
	} else {
	
		/*$('#lbfloater').animate({
				top: '-280px',
				opacity: 0
			}, 600, 'swing');*/
		$('#lbfloater').fadeOut(200);
		$('#all').animate({
			opacity: 1
			}, 200, 'swing');
		$('#lbfade').hide();
		//$('#all').attr('class','all');
		
	}
}

function toggleconfirmdeladmin() {

	if (document.getElementById('lbfade_confirm').style.display == 'none') {
	
		$('#lbfloater_confirm').fadeIn(200);
		$('#all').animate({
				opacity: 0.3
			}, 200, 'swing');
		$('#lbfade_confirm').show();
				
	} else {
	
		$('#lbfloater_confirm').fadeOut(200);
		$('#all').animate({
			opacity: 1
			}, 200, 'swing');
		$('#lbfade_confirm').hide();
		
	}
}




function toggleadv() {

	$('#rollout').slideToggle('fast');
	$('#searchchev').toggle();

	/*if (document.getElementById('rollout').style.display == 'none') {
			document.getElementById('rollout').style.display = 'block';
			document.getElementById('searchchev').style.display = 'none';
		} else {
			document.getElementById('rollout').style.display = 'none';
			document.getElementById('searchchev').style.display = 'block';
		}*/
		
	}

function toggleme(divid) {
	if (document.getElementById(divid).style.display == 'none') {
			document.getElementById(divid).style.display = 'block';
		} else {
			document.getElementById(divid).style.display = 'none';
		}
	}
	
	
//pause function

function pausecomp(millis){
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); } 
	while(curDate-date < millis);
} 


//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

/*
 
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

*/

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}

