function setPointer(theRow, theRowNum, theAction)
{
    var theCells = null;

    // 1.1 Sets the mouse pointer to pointer on mouseover and back to normal otherwise.
    if (theAction == "over" || theAction == "click") {
        theRow.style.cursor='pointer';
    } else {
        theRow.style.cursor='default';
    }
    
    return true;
} // end of the 'setPointer()' function


function confirmLink(theLink, theCommand)
{
    // Confirmation is not required in the configuration file
    if (confirmMsg == '') {
        return true;
    }

    var is_confirmed = confirm('Are you sure you want to:\n'+theCommand);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
} // end of the 'confirmLink()' function

function confirmSubmit(theCommand)
{
    var msg=theCommand;
    return confirm(msg);
}

    
function enableField()
{
document.edit_collection.photographer.disabled=false;
document.edit_collection.img_price.disabled=false;
document.edit_collection.img_url.disabled=false;
document.edit_collection.max_res.disabled=false;
document.edit_collection.keywords.disabled=false;
}

function genPopup(url, target, width, height) {
	window.open(url, target, 'width='+width+',height='+height+',toolbar=0,location=0,resizable=yes');
}


function openPop(strFile,nWidth,nHeight,bStatus,bscroll,btoolbar,blocation,bresize,bdirectories,bmenubar) {
	window.open(strFile, "help","toolbar=" + btoolbar + ",location=" + blocation + ",directories=" + bdirectories + ",menubar=" + bmenubar + ",status=" + bStatus + ",scrollbars=" + bscroll +",resizable=" + bresize + ",width=" + nWidth + ",height=" + nHeight);
}


function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}


var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name)
{
  if (document.getElementById)
  {
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
        this.obj = document.all[name];
        this.style = document.all[name].style;
  }
  else if (document.layers)
  {
        this.obj = document.layers[name];
        this.style = document.layers[name];
  }
}

function show_image_editor(flag)
{
        if (!DHTML) return;
        var x = new getObj('edit-image');
        x.style.display = (flag) ? 'inline' : 'none';
        
        if (!DHTML) return;
        var x = new getObj('view-image');
        x.style.display = (flag) ? 'none' : 'inline';
}


function show_img_dele(flag)
{
        if (!DHTML) return;
        var x = new getObj('img-dele');
        x.style.display = (flag) ? 'none' : 'inline'
}

function selectall(formElement)   { setAllSelect(true,formElement); }
function deselectall(formElement) { setAllSelect(false,formElement); }
	
function setAllSelect(state,formElement) {			
	var elFrm = document.img_grid; 		
	for (var i = 0; i < elFrm.elements.length; i++) {
		var ourEl = elFrm.elements[i];
		if (ourEl.type == "checkbox")
			if (ourEl.name.indexOf(formElement) != -1)
				ourEl.checked = state;
		}
}

function getSelected(){	
	var elFrm = document.img_grid; 
	var strParams = "";	
	
	//If selected, add image Id to the list
	for (var i = 0; i < elFrm.elements.length; i++) {
		var ourEl = elFrm.elements[i];
		if (ourEl.type == "checkbox")
			if (ourEl.checked && (ourEl.name.indexOf("photoid[]") != -1))				 
				strParams = strParams + ourEl.value + ",";					
	}
	//Remove Last delimiter.
	strParams = strParams.substr(0,strParams.length-1);	
	return strParams;
	
}

function saveLightbox() {

		var list = document.getElementById('lightbox-cells');
		var items = list.getElementsByTagName('div');
		var ids = '';
			
		for (var i = 0; i < items.length; i++)  {
			if (i > 0) ids += '|';
			var id = items[i].getAttribute('id');
			ids += id;
		}
		
		document.lightbox_edit.lightbox_order.value = ids;
		return true;

}

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function


/*

*
* checkKeywordLists()
*
* check for manually added keywords
*

*/

function checkKeywordLists(form) {

	cadena 		= form.keywords_all.value;

	// select
	valor 		= form.srchk1.value;
	if(valor!="") {

		if(cadena.indexOf(valor)==-1) {
			cadena+= " " + valor;
		}

	}

	// select
	valor 		= form.srchk2.value;
	if(valor!="") {

		if(cadena.indexOf(valor)==-1) {
			cadena+= " " + valor;
		}

	}

	form.keywords_all.value = cadena;
	form.submit();

}


/*

*
* countryEnableAddress(value)
*
* check for country and enable/disable address
*

*/

function countryEnableAddress(value) {

	if(value=="México" || value=="M&eacute;xico" || value=="Mexico") {
		
		var obj;
		obj = document.getElementById('row_mx');
		obj.style.display = 'block';
		obj.display = 'block';

		obj = document.getElementById('row_other');
		obj.style.display = 'none';
		obj.display = 'none';

	} else {
		
		var obj;
		obj = document.getElementById('row_mx');
		obj.style.display = 'none';
		obj.display = 'none';

		obj = document.getElementById('row_other');
		obj.style.display = 'block';
		obj.display = 'block';
		
	}


}


/*

*
* submitLightOrCart(value)
*
* check if user wants to add to cart or lightbox
*

*/

function imgGridAddToCart(value) {

	document.img_grid.action = "http://www.aprimeravista.net/index.cart.php";

	document.img_grid.submit();

}


/*

*
* shippingMethod()
*
* check for selected shipping method
*

*/

function shippingMethod(value) {

	if(value==2) {
		
		var obj;
		obj = document.getElementById('row_mail');
		obj.style.display = 'block';
		obj.display = 'block';

	} else {
		
		var obj;
		obj = document.getElementById('row_mail');
		obj.style.display = 'none';
		obj.display = 'none';

	}


}



/*

*
* confirmDeleteImage()
*
* confirm to delete an image from a photographer gallery
*

*/

function confirmDeleteImage(url, label) {
	
	if(confirm(label)) {
		
		window.location = url;
		
	}
	
}



