var maxphos=10;
var numphoselected=0;
var photos = new Array();
for(i=0;i<maxphos;i++) photos[i]="";


function getargs() {

	var query = location.search.substring(1); 
	var pairs = query.split("&"); 

	for(var i = 0; i < pairs.length; i++) {

    var arg=pairs[i].split("=");
		if(arg[0].substring(0,3)=="pho") {; //--only want the photo arguments 
  		var argvalue=unescape(arg[1])
  		photos[numphoselected++]=argvalue;  
    }
 
    if(numphoselected >= maxphos) break;              

	} //for(var i = 0; i < pairs.length; i++) {
}
getargs(); //--get the current args including the ordered photos


//phoselected=new string();
function addtophos(photo, phofile) {

  if(document.forms['photoorder'].elements[photo].checked) {

    if(numphoselected<maxphos) {
    

     numphoselected++;
		 for(i=0; i< maxphos; i++)
		   if(photos[i] == "") {
         photos[i]=phofile;
				 break;
			 }
        
  		//--set the background color of the cell
  		document.getElementById("d"+photo).style.backgroundColor = "red";
  		document.getElementById(photo).style.backgroundColor = "red";
  		//-------------
      
       		 
		} else {
//		alert("Too many photos")
		  document.forms['photoorder'];
		  return false;
		
		}

  } else { // this photo has been deselected so remove from the hidden fields
	  numphoselected--;
		if(numphoselected<0) numphoselected=0;
		for(i=0; i < maxphos; i++)
		  if(photos[i] == phofile) {
			  photos[i]="";
				break;
		  }

		//--set the bgcolor back to the default
  	document.getElementById("d"+photo).style.backgroundColor = "#000";
  	document.getElementById(photo).style.backgroundColor = "#000";
      
	}

}

function imageclick(phofile) {

  if(numphoselected<maxphos) {
		//--add the clicked on photo
		added=0;
	  for(i=0; i< maxphos; i++) {
			if(photos[i]!="")
				document.forms['photoorder'].elements[i].value=photos[i];
			else
				placenum=i;
			if(photos[i]==phofile) added=1;
		}
		if(!added)
			document.forms['photoorder'].elements[placenum].value=phofile;
					
		
//	 document.forms['photoorder'].elements['PAGE'].value=window.location;
	 document.forms.photoorder.submit();
	 document.forms['photoorder'];
   numphoselected++;
	 return false;
		
	} else {
//		alert("Too many photos")
		  document.forms['photoorder'];
		  return false;
	}
	
}


function clearall() {
  
	numphoselected=0;
	for(i=0; i < maxphos+1; i++) {
		 document.forms['photoorder'].elements[i].value="";
  }
  
	
	//--set the background color of the cell to default
//	for(var dpi=0; dpi < <?echo $dpnum;?>; dpi++) {
  var photocells=document.getElementById("photostable").getElementsByTagName("td");
	for(var dpi=0; dpi < photocells.length; dpi++) {
  	document.getElementById("dp"+dpi).style.backgroundColor = "#000";
  	document.getElementById("p"+dpi).style.backgroundColor = "#000";
	}
  
  
}


function chkorder() {

  if(numphoselected==0) {
	  alert("No photos selected");	
    document.forms['photoorder'];
	  return false;
	}
	else 
	{
	  for(i=0; i< maxphos; i++)
			if(photos[i]!="") document.forms['photoorder'].elements[i].value=photos[i];
		
//	  document.forms['photoorder'].elements['PAGE'].value=window.location;
	  document.forms.photoorder.submit();
	  return true;
	}
}


function go_select(formname, elname) {
  document.location=formname.elements[elname].options[formname.elements[elname].selectedIndex].value;
}


//------------------------------------------------------------------------------------------
function gophotopage(page) {

	var querystring="";
	for(i=0; i<maxphos; i++) {
		if(photos[i]!="") querystring+="&pho"+i+"="+photos[i];
	}
    
  if(window.vpgroup) vpgroupArg="&vpgroup="+vpgroup; else vpgroupArg="";

  //---construct the new location path
  window.location=location.pathname+"?vid="+vid+"&dp="+page+"&vedate="+vedate+vpgroupArg+querystring;
}

function resetform() {
if (document.forms.photoorder)
  document.forms.photoorder.reset();
}
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

//------------------------------------------------------------------------------------------
function checkphotos() {

	resetform();

	//--check to see if this photo is displayed and if so, check its box
  
  if( document.getElementById("photostable") ) {
  
    var photocells=document.getElementById("photostable").getElementsByTagName("td");
  	for(var dpi=0; dpi < photocells.length; dpi++) {
  		for(phoi=0; phoi < maxphos; phoi++) {
  			if(document.forms['photoorder'].elements["p"+dpi].value==photos[phoi]) { 
  				document.forms['photoorder'].elements["p"+dpi].checked=true;
  				
  				//--set the background color of the cell
        	document.getElementById("dp"+dpi).style.backgroundColor = "#f00";
        	document.getElementById("p"+dpi).style.backgroundColor = "#f00";
  			}
  		}
  	}

  }
/*
	for(var dpi=0; dpi < <?echo $dpnum;?>; dpi++) {
		for(phoi=0; phoi < maxphos; phoi++) {
			if(document.forms['photoorder'].elements["p"+dpi].value==photos[phoi]) { 
				document.forms['photoorder'].elements["p"+dpi].checked=true;
				
				//--set the background color of the cell
      	document.getElementById("dp"+dpi).style.backgroundColor = "#f00";
      	document.getElementById("p"+dpi).style.backgroundColor = "#f00";
			}
		}
	}
*/

} //function checkphotos() {
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
