// functions

function showid(id) {
	if (document.getElementById(id).style.visibility == 'hidden' 
		|| document.getElementById(id).style.visibility == '') {
		document.getElementById(id).style.visibility = 'visible';
	} else {
		document.getElementById(id).style.visibility = 'hidden';
	}
}

function toggleDiv(divName) {
    thisDiv = document.getElementById(divName);
    if (thisDiv) {
        if (thisDiv.style.display == "none") {
            thisDiv.style.display = "block";
        }
        else {
            thisDiv.style.display = "none";
        }
    }
    else {
        alert("Error: Could not locate div with id: " + divName);
    }
}

function dispatch(myelementid,url,querystring,formid) {
	if (formid == '') {
		Element.setOpacity(myelementid, 0,{ duration: .2, from:1.0-0 });
		var test = new Ajax.Updater(myelementid,url,{method: 'post',
			onComplete:function(){ new Effect.Appear(myelementid,
			{ duration: .2, from:0-1.0 });},
			onFailure: function(){ 
				alert("AJAX dispatch failed" + url);
			},
			postBody: querystring,
			asynchronous:true, 
			evalScripts:true}
		);
	} else {
		Element.setOpacity(myelementid, 0);
		new Ajax.Updater(myelementid,url,
		{onComplete:function(){ new Effect.Appear(myelementid,
		{ duration: .2, from:0-1.0 });},
		parameters: $(formid).serialize(true) + '&' + 
		querystring,asynchronous:true, evalScripts:true});
	}
}

function noenter() { // prevents return from submitting form
	return !(window.event && window.event.keyCode == 13); 
}

function makeQS(testVar,whichVar) {
	var qs = '';
	var amp = '';
	for (var i = 0; i < 10; i++){
		qs = qs + amp + whichVar + '=' + testVar[i];
		amp = '&';
	}
	alert(testVar.length + ' ' + qs);
}

function passJSON (objectName,updateItem) {
	querystring = 'json=' + Object.toJSON(objectName) + "&current_id=" + tempsku.uniqueid;
	if (updateItem!='') {
		querystring+= '&update=' + updateItem;
	}
	dispatch ('js_loader','/ajax/update_worksheet',querystring,'');
	setTimeout("dispatch ('sessioninfo','/ajax/session','','')",1000);  // temp for debug
}

function help(div,innerdiv,ajax,querystring,formid) {
	url = '/ajax/' + ajax;
	dispatch(innerdiv,url,querystring,formid);
	new Effect.Appear(div, {duration: .5});
}

function hideHelp(div) {
	new Effect.DropOut(div);
}

function ajaxPopup(div,innerdiv,ajax,querystring,formid) {
	url = '/ajax/' + ajax;
	dispatch(innerdiv,url,querystring,formid);
	new Effect.BlindDown(div, {duration: .5});	
}

function ajaxPopupColor(div,innerdiv,ajax,querystring,formid) {
	url = '/ajax/' + ajax;
	dispatch(innerdiv,url,querystring,formid);
	if (document.getElementById('tab_list')) { //.style.display != 'none') {
		new Effect.Fade('tab_list', { duration: .5});
		document.getElementById('tab_list').style.height = '0px';
		document.getElementById('tab_wrap').style.height = '0px';
	}
	new Effect.Appear(div, { duration: .5});
	passJSON(tempsku);
}

function ajaxPopupClose(div) {
	new Effect.BlindUp(div, {duration: .2});


	if (document.getElementById('tab_list')) {
		document.getElementById('tab_list').style.height = '500px';
	}
	document.getElementById('tab_wrap').style.height = '500px';

	//if (document.getElementById('tab_list') == 'none') {
	new Effect.Appear('tab_list', { duration: .5});
	//}
}

function ajaxPopupColorClose(div) {
	new Effect.Fade(div, {duration: .2});	
}

Effect.BlindUpFromRight = function(element) {
  element = $(element).cleanWhitespace();
  element.makeClipping();
  return new Effect.Scale(element, 0,
    Object.extend({ scaleContent: false,
      scaleY: false,
      restoreAfterFinish: true,
      duration: .3,
      afterFinishInternal: function(effect) {
        effect.element.hide();
        effect.element.undoClipping();
      }
    }, arguments[1] || {})
  );
}

Effect.BlindDownFromRight = function(element) {
  element = $(element).cleanWhitespace();
  var elementDimensions = element.getDimensions();
  return new Effect.Scale(element, 100, Object.extend({
    scaleContent: false,
    scaleY: false,
    scaleFrom: 0,
    scaleMode: {originalHeight: elementDimensions.height, 
    	originalWidth: elementDimensions.width},
    restoreAfterFinish: true,
    duration: .5,
    afterSetup: function(effect) {
      effect.element.makeClipping();
      effect.element.setStyle({width: '0px'});
      effect.element.show();
    },
    afterFinishInternal: function(effect) {
      effect.element.undoClipping();
    }
  }, arguments[1] || {}));
}

function vscroller (deltay, movingdiv) {
	topofdiv = document.getElementById(movingdiv).style.top;
	topPos = topofdiv.replace(/px/g, '');
	topPos = topPos * 1;
	if ((typeof pixelcount != 'undefined') && (topPos+deltay+pixelcount) >= 0 && (topPos+deltay) <= 0) {
		new Effect.Move (movingdiv,{ x: 0, y: deltay, mode: 'relative'});
	}
}

function closehf() {
	document.getElementById('header').style.display = 'none';
	document.getElementById('miniheader').style.display = 'block';
}

function openhf() {
	document.getElementById('header').style.display = 'block';
	document.getElementById('miniheader').style.display = 'none';
}

function loadhf() {
	Effect.BlindUp('header', {duration: 2, afterFinish: function(){Effect.BlindDown('miniheader', {duration: .2});}});
}


function designView(script,design,hex,blank,alt_media) {
	imgsrv = 'http://image01.demandmade.com/';
	phpsrv = 'http://image02.demandmade.com/';

	if (script == 'garment') {
		document.getElementById('design_photo').className= 'gar';
		if (alt_media) {
			document.getElementById('design_photo').style.backgroundImage = 'url('+alt_media+')';
		} else {
			document.getElementById('design_photo').style.backgroundImage = 'url('+phpsrv+'php/garment.php/des_id,'+design+'/large,1/hex,'+hex+'/blank,'+blank+'/des.jpg)';
		}

	} else if (script == 'backgarment') {
		document.getElementById('design_photo').className= 'gar';
		if (alt_media) {
			document.getElementById('design_photo').style.backgroundImage = 'url('+alt_media+')';
		} else {
			document.getElementById('design_photo').style.backgroundImage = 'url('+phpsrv+'php/backgarment.php/des_id,'+design+'/large,1/hex,'+hex+'/blank,'+blank+'/des.jpg)';
		}


	} else if (script == 'thumb') {
		document.getElementById('design_photo').className= 'des';
		document.getElementById('design_photo').style.backgroundImage = 'url('+phpsrv+'php/thumb.php/des_id,'+design+'/large,1/hex,'+hex+'/des.jpg)';
	} else {
		document.getElementById('design_photo').style.backgroundImage = 'url('+imgsrv+'IMGSRV/sc/x400/s/product_media/'+design+')';
	}
}

function do_admin_featured (desId,doParam) {
        var txtDiv = 'admin_des_featured_'+desId;

        new Ajax.Updater(txtDiv, '/ajax/admin_featured_design',
                        { 
                          method: 'get',
                          parameters: 'des_id='+desId+'&'+doParam+'=1'
                        }
                       );
}

function sub_ret_f2() {
        return;
}

function select_option_jump( s ){
	if(s[s.selectedIndex].value != ''){
		var location = s[s.selectedIndex].value;
		s.selectedIndex = 0;
		window.location = location;
	} else {
		return false;
	}
}

function buttonswitch (id,button){
	document.getElementById(id).src = '/images/yerzies2/sitenav/'+button;
}
