var tabClass = Object;
var receiveReq = photoAjax();

function setActTab(idTab) {
	tabClass.actTab = idTab;
}

function changeTab(idTab) {
	document.getElementById('tabText').innerHTML = tab[idTab];

	
	document.getElementById(idTab).style.background.repeat='no-repeat';
	document.getElementById(tabClass.actTab).style.color='#000000';

	setActTab(idTab);
}

function activeTab(idTab) {
	document.getElementById(idTab).style.color='#555555';
}

function unactiveTab(idTab) {
	if (idTab != tabClass.actTab) {
		
		document.getElementById(idTab).style.background.repeat='no-repeat';

		document.getElementById(idTab).style.color='#000000';
	}
}

function hidePhotoBox() {
	document.getElementById('photoBox').style.display='none';
}

function showPhotoBox() {
	document.getElementById('photoBox').style.display='inline';
}


function hideBox(id) {
	document.getElementById(id).style.display='none';
}

function showBox(id) {
	document.getElementById(id).style.display='inline';
}



function showAnotherPhoto(path2Photo) {
	document.getElementById('photoBoxBig').src=JURL+'/www/img/products/'+path2Photo;
	
}

function showThirdLine() {
	if (document.getElementById('headerLine').style.display=='none') {
		document.getElementById('thirdLine').style.display='none';
		document.getElementById('headerLine').style.display='inline';
	} else {
		document.getElementById('thirdLine').style.display='inline';
		document.getElementById('headerLine').style.display='none';
	}
}

function confirmAction() {
	if (!confirm("Are you sure?")) {
		return false;
	}
	return true;
}

function confirmAccountDelete(n) {
	if (n > 0)
		return confirm("Are you sure you wish to delete this account?\nThis account has " + (n == 1 ? "1 member" : n + " members") + " which will also be deleted.");
	else
		return confirm("Are you sure you wish to delete this account?");
}

function confirmAndSubmit(form_name, value) {
	if (!confirm("Are you sure?")) {
		return false;
	}
	form = document.getElementById(form_name);
	if(form != null) {
		form.submitName.value = value;
		form.submit();
	}
	return true;
}

function confirmSetAndSubmit(form_name, element_name, element_value, submit_value) {
	if (!confirm("Are you sure?")) {
		return false;
	}
	element = document.getElementById(element_name);
	form = document.getElementById(form_name);
	if(element != null && form != null) {
		element.value = element_value;
		form.submitName.value = submit_value;
		form.submit();
	}
	return false
}


/*function confirmActionSaveBilling() {
	if (!confirm("The billing information entered is different from the data in our database. Do you want to update your registration data with the information entered?")) 
	{
		return false;
	}
	else
	{
		window.location.href = JURL + "/confirmOrder/save/";	
	}
	return true;
}*/


function confirmActionCredit() {
	if (!confirm("Are you sure that you want to delete this Info?")) {
		return false;
	}
	document.getElementById('registration').submit();
	return true;
}

function confirmActionAddress(typea, zip1, zip2, id) {
	
	if(typea=="no"){	
		if (!confirm("Are you sure that you want to DELETE this address?")) {
			return false;
		}
		document.formuad.submit();
		return true;
	}else{
		if (zip1 != zip2)
		{
			if (!confirm("The saved zip code is different from the one you entered in the shopping cart. You will be redirected to calculate the shipping costs using the saved zip code. Do you want to continue?"))		
			{
				return false;	
			}
			else
			{
				document.formuad.submit();
				return true;
			}
		}
		else
		{
			document.getElementById("shipping_firstname").value=addresses[id]["name"];
			document.getElementById("shipping_lastname").value=addresses[id]["lastname"];
			document.getElementById("shipping_address1").value=addresses[id]["address1"];
			document.getElementById("shipping_address2").value=addresses[id]["address2"];
			document.getElementById("shipping_apartment").value=addresses[id]["apartment"];
			document.getElementById("shipping_city").value=addresses[id]["city"];
			
			
            divide = addresses[id]["phone"].split("-");
			
			
			document.getElementById("shipping_phone1").value=divide[0];
			document.getElementById("shipping_phone2").value=divide[1];
			document.getElementById("shipping_phone3").value=divide[2];
			
			
			document.getElementById("shipping_company").value=addresses[id]["company"];
			
			
			for (i=0;i<document.getElementById('shipping_state').length;i++)
			{
			
			if (addresses[id]["state"] == document.getElementById('shipping_state').options[i].text)
			{
			document.getElementById('shipping_state').options[i].selected = true;
			
			}
			}
		}
	}
}

function changestate(id1,id2){
	
	if (id1 == 'none')
		document.getElementById(id2).style.display= "none";
	else
		document.getElementById(id2).style.display= "";
}



//** Tab Content script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Nov 8th, 06

var enabletabpersistence=0 //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj){
var ulid=linkobj.parentNode.parentNode.id //id of UL element
var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
for (var i=0; i<ullist.length; i++){
ullist[i].className=""  //deselect all tabs
if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
}
linkobj.parentNode.className="selected"  //highlight currently clicked on tab
document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
var thetab=document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber]
if (thetab.getAttribute("rel"))
expandcontent(thetab)
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
tabcontentIDs[ulid]=new Array()
tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
if (enabletabpersistence==1) //if persistence feature turned on
setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
var ullist=document.getElementById(ulid).getElementsByTagName("li")
for (var i=0; i<ullist.length; i++){
if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
return ullist[i].getElementsByTagName("a")[0]
break
}
}
}

function initializetabcontent(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
setCookie(arguments[i], "")
var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
var ulobj=document.getElementById(arguments[i])
var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
for (var x=0; x<ulist.length; x++){ //loop through each LI element
var ulistlink=ulist[x].getElementsByTagName("a")[0]
if (ulistlink.getAttribute("rel")){
savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
ulistlink.onclick=function(){
expandcontent(this)
return false
}
if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
expandcontent(ulistlink) //auto load currenly selected tab content
}
} //end inner for loop
if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
var culistlink=getullistlinkbyId(arguments[i], clickedontab)
if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
expandcontent(culistlink) //auto load currenly selected tab content
else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
}
} //end outer for loop
}


function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value){
document.cookie = name+"="+value //cookie value is domain wide (path=/)
}


function numbers(e)
{
	var key;
	if(e.keyCode) // IE
		key = e.keyCode;
	else if(e.which) // Netscape/Firefox/Opera
		key = e.which;

	if ((key < 48 || key > 57) && key != 8 && key != 10 && key != 13)
		return false;

	return true;
}


function zero(){var count=0; 

    number=document.forms[1].elements.length; 
    for(a=0;a<number;a++){ 
    if (document.forms[1].elements[a].value=="" || document.forms[1].elements[a].value=="0"){document.forms[1].elements[a].style.backgroundColor="#ffffff";count++;} 
    else{document.forms[1].elements[a].style.backgroundColor="white";} 
    } 
    if(count==number){alert("Please enter a number greater than zero");return false} 
    else{return true} 
    }

///////////////////////////////////////////////////////////////
function photoAjax() 
{ 
	var xmlhttp=false; 
	try 
	{ 
		//AJAX object for new versions of IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	} 
	catch(e) 
		{ 
			try 
			{ 
				// AJAX object for old versions of IE 
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
			} 
			catch(E) { xmlhttp=false; } 
		} 
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") 
	{ 
		// AJAX object for non IE browsers
		xmlhttp=new XMLHttpRequest(); 
	} 
	return xmlhttp; 
}

function showBigPhoto(path2Photo,altTag,photoUrl) {
	
	//If the XmlHttpRequest object is not in the middle of a request, star a new asynchronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
	//Set the connection as a GET to CargarEstructura.html.
	receiveReq.open("POST", photoUrl+'/showPhoto/', true);
	receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//Set the function that will be called each time the object changes its state.
	receiveReq.onreadystatechange = handleShowBigPhoto; 
	//Make the actual request.
	receiveReq.send("src=" + escape(escape(path2Photo).replace(/\./g, "%2E")) + '&alt=' + escape(escape(altTag).replace(/\./g, "%2E")));
	}	
	
}
			
function handleShowBigPhoto() {
//Check if the state of XmlHttpRequests is finished.
if (receiveReq.readyState == 4) {
	//Set the content of the tag where results will be shown.
	document.getElementById('photo_result').innerHTML = receiveReq.responseText;
	}
}

function OpenPopUpEmail() 
{ 
var strFeatures = "scrollbars=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=yes, width=600, height=500, top=85, left=140";
var Pagina = JURL+"/tellAFriend/";
objNewWindow = window.open(Pagina,"newWin", strFeatures); 
objNewWindow.focus(); 
} 

/////////////////////////////////////////////////////////////////////////////////////////////




function moveUp(element) {
  for(i = 0; i < element.options.length; i++) {
    if(element.options[i].selected == true) {
      if(i != 0) {
        var temp = new Option(element.options[i-1].text,element.options[i-1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i-1] = temp2;
        element.options[i-1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function moveDown(element) {
  for(i = (element.options.length - 1); i >= 0; i--) {
    if(element.options[i].selected == true) {
      if(i != (element.options.length - 1)) {
        var temp = new Option(element.options[i+1].text,element.options[i+1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i+1] = temp2;
        element.options[i+1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function updateList(list, textBox) {

  textBox.value = '';
  for(i = 0; i < list.options.length; i++) {
    if (i == 0) {
      textBox.value += list.options[i].value;
    } else {
      textBox.value += ',' + list.options[i].value;
    }
  }
}
function swap(list) {
  var j = 0;
  for(i = 0; i < list.options.length; i++) {
    if(list.options[i].selected == true) {
      j++;
      switch (j) {
        case 1:
        var i1 = i;
        var temp = new Option(list.options[i].text, list.options[i].value);
        break;
        case 2:
        var i2 = i;
        var temp2 = new Option(list.options[i].text, list.options[i].value);
        break;
      }
    }
  }
  if (j != 2) {
    alert('Only 2 items can be swapped');
  } else {
    list.options[i1] = temp2;
    list.options[i1].selected = true;
    list.options[i2] = temp;
    list.options[i2].selected = true;
  }
}






















// PickList II script (aka Menu Swapper)- By Phil Webb (http://www.philwebb.com)
// Visit JavaScript Kit (http://www.javascriptkit.com) for this JavaScript and 100s more
// Please keep this notice intact

function move(fbox, tbox) {
     var arrFbox = new Array();
     var arrTbox = new Array();
     var arrLookup = new Array();
     var i;
     var j;
     var passed;
     
     for(i=0; i<tbox.options.length; i++) {
          arrLookup[tbox.options[i].text] = tbox.options[i].value;
          arrTbox[i] = tbox.options[i].text;
     }
     var fLength = 0;
     var tLength = arrTbox.length
     for(i=0; i<fbox.options.length; i++) {
     	passed=0;
     	for(j=0;j<tbox.options.length;j++){
     		if(tbox.options[j].value==fbox.options[i].value)
     			passed=1;
     	}
     			
          arrLookup[fbox.options[i].text] = fbox.options[i].value;
          if(fbox.options[i].selected && fbox.options[i].value != "") {
          	if(passed==0){
               arrTbox[tLength] = fbox.options[i].text;
               tLength++;
               }
          } else {
               arrFbox[fLength] = fbox.options[i].text;
               fLength++;
          }
     }
    // arrFbox.sort();
    // arrTbox.sort();
    //fbox.length = 0;
     tbox.length = 0;
     var c;
     for(c=0; c<arrFbox.length; c++) {
          var no = new Option();
          no.value = arrLookup[arrFbox[c]];
          no.text = arrFbox[c];
          //fbox[c] = no;
     }
     for(c=0; c<arrTbox.length; c++) {
     	var no = new Option();
     	no.value = arrLookup[arrTbox[c]];
     	no.text = arrTbox[c];
     	tbox[c] = no;
     }
}






function move1(fbox) {
     var arrFbox = new Array();
    
     var arrLookup = new Array();
     var i;
  
     var fLength = 0;
     
     for(i=0; i<fbox.options.length; i++) {
          arrLookup[fbox.options[i].text] = fbox.options[i].value;
          if(fbox.options[i].selected && fbox.options[i].value != "") {
              fi=0
          } else {
               arrFbox[fLength] = fbox.options[i].text;
               fLength++;
          }
     }
   //  arrFbox.sort();
    
   fbox.length = 0;
    
     var c;
     for(c=0; c<arrFbox.length; c++) {
          var no = new Option();
          no.value = arrLookup[arrFbox[c]];
          no.text = arrFbox[c];
          fbox[c] = no;
     }
     
}












function selectAll(box) {
     for(var i=0; i<box.length; i++) {
     box[i].selected = true;
     }
}






////////////////////////////////////////////////////////////////////////////
