// ***Java Script Library*** //

//Jump Menu
function _jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// Confirm Delete 
function deleteItem(urlOut) {
 var where_to= confirm("Are you sure you want to delete this? - This action is permanent.");
 if (where_to== true)
 {
   window.location=urlOut;
 }
 else
 {
   null
  }
}

// Confirm Set Live 
function setLive(urlOut) {
 var where_to= confirm("Change This Issues Publication Status?");
 if (where_to== true)
 {
   window.location=urlOut;
 }
 else
 {
   null
  }
}

// Remote Pop-Up Window
function remote(theURL,winName,features){
  win2=window.open(theURL,winName,features)
  win2.creator=self
}

function flashRemote(theURL){
  win2=window.open(theURL,'popup','scrollbars=yes,status=no,width=750,height=500')
  win2.creator=self
}


// Remote Pop-Up Window B
function remote2(url){
  window.opener.location=url
  close();
}

// **FORM SUBMIT**
function submitForm(formValue,destPage) {
	document.getElementById(formValue).action = destPage;
	document.getElementById(formValue).submit();
}

// Hide/Show Toggle
function showHide(targetName) {
  if( document.getElementById ) { // NS6+
    target = document.getElementById(targetName);
  } else if( document.all ) { // IE4+
    target = document.all[targetName];
  }

  if( target ) {
    if( target.style.display == "none" ) {
      target.style.display = "inline";
    } else {
      target.style.display = "none";
    }
  }
  
}

// Swap Two Elements
function swapTargets(targetNameA,targetNameB) {
	if( document.getElementById ) { // NS6+
		targetA = document.getElementById(targetNameA);
		targetB = document.getElementById(targetNameB);
	} else if( document.all ) { // IE4+
		targetA = document.all[targetNameA];
		targetB = document.all[targetNameB];
	}

	if( targetA ) {
		if( targetA.style.display == "none" ) {
			targetA.style.display = "inline";
			targetB.style.display = "none";
			document.forms[0].articleEdit.disabled = false;
			document.forms[0].articleText.disabled = true;
		} else {
			targetA.style.display = "none";
			targetB.style.display = "inline";
			document.forms[0].articleEdit.disabled = true;
			document.forms[0].articleText.disabled = false;
		}
	}
}


// Clear Search Field  
function focusNClearInput(inputObject) {

    var hasBeenFocused = inputObject.getAttribute("hasBeenFocused") != null;

    if (!hasBeenFocused) {
        inputObject.setAttribute("hasBeenFocused", "true");
        inputObject.value = "";
        var thisForm = inputObject.form;
        for (ii = 0;  ii < thisForm.elements.length; ii++) {
            if (thisForm.elements[ii].type == "submit"){
                thisForm.elements[ii].disabled = false;
            }
        }

    }
  }
  
// Image Auto Resizer
function imageResize(page, mh, mw){
	var doober;
	//alert("I Are Run");
	//alert(page.images.length);
	for	(var i=0; i<page.images.length; i++){
		var img = page.images[i];
		//alert(img.id.substr(0,2));
		if(img.id.substr(0,2) != "U_"){
			//alert(img.width + '&' + img.height);
			if(img.width > img.height && img.width > mw){
				doober = img.width / mw;
				img.width = mw;
			} else if (img.height > img.width && img.height > mh){
				doober = img.height / mh;	
				img.height = mh;
			} else if (img.width == img.height && img.width > mw){
				img.heigh = mh;
				img.width = mw;
			} else {
				//alert('no action');
			}
		}
	}
}  

// Auto CutOff Picker
function cutOffer(item, targetName){
  if( document.getElementById ) { // NS6+
    target = document.getElementById(targetName);
  } else if( document.all ) { // IE4+
    target = document.all[targetName];
  }
  
  if(item.value == 2){
  	target.value = "500";
  }
  else if(item.value == 1){
  	target.value = "250";
  } 
  else {
  	target.value = "0"
  }
}


// Turn Obj On
function showObj(targetName) {
  if( document.getElementById ) { // NS6+
    target = document.getElementById(targetName);
  } else if( document.all ) { // IE4+
    target = document.all[targetName];
  }

  if( target ) {
    target.style.display = "inline";
  }
  
}

// Turn Obj Off
function hideObj(targetName) {
  if( document.getElementById ) { // NS6+
    target = document.getElementById(targetName);
  } else if( document.all ) { // IE4+
    target = document.all[targetName];
  }

  if( target ) {
    target.style.display = "none";
  }
  
}

// Textarea Max Chars
function profileTextCounter(txtArea,maxChars,spanName){
	var strTemp = "";
	if (txtArea.value.length > maxChars)
	{
		alert("Please shorten your answer.\r\nYour answer can contain up to " + maxChars + " characters, including letters, numbers and underscores.\r\n\nIf you need to submit more information, please upload an additional document and associate it to this question/commodity");
		strTemp = txtArea.value.substring(0, maxChars);
		txtArea.value = strTemp;
	}
document.getElementById(spanName).innerHTML = maxChars - txtArea.value.length;
}


//Get the img X and Y positions with an onMouseOver event
var d = document;

function findObj(overObj,newObj,menuObj) {
	var px = d.getElementById('mainNavMenu').offsetLeft;
	var py = d.getElementById('mainNavMenu').offsetTop;
	var nw = d.getElementById(newObj).offsetWidth;
	var nx = d.getElementById(newObj).offsetLeft;
	var ny = d.getElementById(newObj).offsetTop;
	var xLoc = px + nx;
	var yLoc = py;
	
	document.getElementById(menuObj).style.left = xLoc;
	document.getElementById(menuObj).style.top = yLoc;
	document.getElementById(overObj).style.width = nw;
	document.getElementById(menuObj).style.display = "inline";
}

//Show and Position Photo
function showPhoto(targetPhoto,sourcePhoto) {
	document.getElementById('photoDisp').innerHTML = '<img src=' + targetPhoto + ' border=0>';
	
	var photox = document.getElementById(sourcePhoto).offsetLeft;
	var photoy = document.getElementById(sourcePhoto).offsetTop;

	document.getElementById('photoContainer').style.display = "inline";
	
	//alert(photox + ':' + photoy);
}

// ***Java Script Library*** //
