
function photo_vote_result(e){

//document.getElementById('pet_photo1').style.display='none';

          var targ;
	  if (!e) var e = window.event;
	  if (e.target) targ = e.target;
	  else if (e.srcElement) targ = e.srcElement;

	  targid = targ.id;


	  if (targid == photo1_id) {

            winner = photo1_id;
            loser = photo2_id;

   }else {
           winner = photo2_id;
           loser = photo1_id;


   }





                                     doAjax('pe_js_xml_photo_vote.php','winner='+winner+'&loser='+loser,'photo_vote_populate','post','1');

                                     }



function photo_vote_populate(text1) {

//Set up the initial nodes

var photo_id_nodes = text1.getElementsByTagName("photo_id");
var photo_link_nodes = text1.getElementsByTagName("photo_link");
var photo_pet_nodes = text1.getElementsByTagName("photo_pet");
var photo_pet_name_nodes = text1.getElementsByTagName("photo_pet_name");
var photo_pet_category_name_nodes = text1.getElementsByTagName("photo_pet_category_name");

var number_votes_nodes = text1.getElementsByTagName("number_votes");
var last_five_pet_id_nodes = text1.getElementsByTagName("last_five_pet_id");
var last_five_pet_name_nodes = text1.getElementsByTagName("last_five_pet_name");

//--------------Photo1

                     while (document.getElementById('pet_photo1test').hasChildNodes()) {

                     document.getElementById('pet_photo1test').removeChild(document.getElementById('pet_photo1test').firstChild);

                     }

  while (document.getElementById('pet_photo1').hasChildNodes()) {

                     document.getElementById('pet_photo1').removeChild(document.getElementById('pet_photo1').firstChild);

                     }

//UPdate the Number


try {

document.getElementById('show_wait').innerHTML= "<h1>"+number_votes_nodes[0].childNodes[0].nodeValue+"</h1>";
number_votes_to_facebook = number_votes_nodes[0].childNodes[0].nodeValue;

if (number_votes_to_facebook > 9) {
document.getElementById('facebook_button').style.display = 'block';
}

//  document.write(search_term);

  }catch(err) {


number_votes_to_facebook = 0

  }

//Update the History

document.getElementById('last_five_history').innerHTML= "";

for (var i = 0; i<last_five_pet_id_nodes.length; i++) {


document.getElementById('last_five_history').innerHTML += "<a href=\"pe_view_pet.php?pet_id="+last_five_pet_id_nodes[i].childNodes[0].nodeValue+"\">"+last_five_pet_name_nodes[i].childNodes[0].nodeValue+"</a><br />";

}

//The Photo id

photo1_id = photo_id_nodes[0].childNodes[0].nodeValue;

//The Pet Name
document.getElementById('pet_name1').innerHTML = "<a href=\"pe_view_pet.php?pet_id="+photo_pet_nodes[0].childNodes[0].nodeValue+"\">"+photo_pet_name_nodes[0].childNodes[0].nodeValue+" the "+photo_pet_category_name_nodes[0].childNodes[0].nodeValue+"</a>";
//document.getElementById('pet_name1').innerHTML = photo1_id;

//document.getElementById('pet_photo1').innerHTML = (photo_link_nodes[0].childNodes[0].nodeValue+'Some Text');

/*var photo1test = new Image();
    photo1test.src = photo_link_nodes[0].childNodes[0].nodeValue;


var attach_photo1test = document.getElementById('pet_photo1test').appendChild(photo1test);
*/

//document.getElementById('pet_photo1test').innerHTML = "<img src=\""+photo_link_nodes[0].childNodes[0].nodeValue+"\" height=\"256px\" style=\" text-align:center; margin-top:10px; border: 2px solid #818db7;\" />"

    document.getElementById('pet_photo1').style.display='none';
    document.getElementById('pet_photo1_wait').innerHTML='<img src="images/wait30.gif">';
var photo1 = new Image();
    photo1.onload = displayPhoto1
    photo1.src = photo_link_nodes[0].childNodes[0].nodeValue;

    var attach_photo1 = document.getElementById('pet_photo1').appendChild(photo1);
    photo1.style.border="2px solid #818db7";
    photo1.id = photo1_id
    photo1.onclick = photo_vote_result;
//    document.getElementById('pet_photo1test').onclick = photo_vote_result;

function displayPhoto1(){
    document.getElementById('pet_photo1_wait').removeChild(document.getElementById('pet_photo1_wait').firstChild);;
//document.getElementById('pet_photo1test2').innerHTML = photo1.complete+' - '+photo1.width+' - '+photo1.height;

if ((photo1.width / photo1.height) > (300 / 256)) {

//  document.getElementById('pet_photo1test').innerHTML = photo1.width+' - '+photo1.height;
//       document.getElementById('pet_name1').innerHTML = 'Wide';

     photo1.style.height = ((photo1.height*300)/photo1.width)+'px';
     photo1.style.width = '300px';
;
}else if ((photo1.width / photo1.height) < (300 / 256)) {
//       document.getElementById('pet_name1').innerHTML = 'Tall';
//  document.getElementById('pet_photo1test').innerHTML = photo1.width+' - '+photo1.height;

     photo1.style.width = ((photo1.width*256)/photo1.height)+'px';
     photo1.style.height = '256px';
} else {
//       document.getElementById('pet_photo1test').innerHTML = photo1.width+' - '+photo1.height;
       document.getElementById('pet_name1').innerHTML = 'Dont know';
}

document.getElementById('pet_photo1').style.display='block';

}




//--------------Photo2

                     while (document.getElementById('pet_photo2').hasChildNodes()) {

                     document.getElementById('pet_photo2').removeChild(document.getElementById('pet_photo2').firstChild);

                     }

//The Photo id

photo2_id = photo_id_nodes[1].childNodes[0].nodeValue;


//The Pet Name

document.getElementById('pet_name2').innerHTML = "<a href=\"pe_view_pet.php?pet_id="+photo_pet_nodes[1].childNodes[0].nodeValue+"\">"+photo_pet_name_nodes[1].childNodes[0].nodeValue+" the "+photo_pet_category_name_nodes[1].childNodes[0].nodeValue+"</a>";
//document.getElementById('pet_name2').innerHTML = photo2_id
//document.getElementById('pet_photo1').innerHTML = (photo_link_nodes[0].childNodes[0].nodeValue+'Some Text');


    document.getElementById('pet_photo2').style.display='none';
    document.getElementById('pet_photo2_wait').innerHTML='<img src="images/wait30.gif">';
var photo2 = new Image();
    photo2.onload = displayphoto2
    photo2.src = photo_link_nodes[1].childNodes[0].nodeValue;

    var attach_photo2 = document.getElementById('pet_photo2').appendChild(photo2);
    photo2.style.border="2px solid #818db7";
    photo2.id = photo2_id
    photo2.onclick = photo_vote_result;
//    document.getElementById('pet_photo2test').onclick = photo_vote_result;

function displayphoto2(){

    document.getElementById('pet_photo2_wait').removeChild(document.getElementById('pet_photo2_wait').firstChild);;

if ((photo2.width / photo2.height) > (300 / 256)) {

     photo2.style.height = ((photo2.height*300)/photo2.width)+'px';
     photo2.style.width = '300px';


}else if ((photo2.width / photo2.height) < (300 / 256)) {

     photo2.style.width = ((photo2.width*256)/photo2.height)+'px';
     photo2.style.height = '256px';


} else {

       document.getElementById('pet_name2').innerHTML = 'Dont know';

}

     document.getElementById('pet_photo2').style.display='block';


}


 /*




//THE UNALLOCATED SKILLS SECTION
                     
//Clear the current skills

                     while (document.getElementById('unallocated_skills').hasChildNodes()) {

                     document.getElementById('unallocated_skills').removeChild(document.getElementById('unallocated_skills').firstChild);

                     }

var skill_id_nodes = unallocated_skills_nodes[0].getElementsByTagName("skill_id");
var skill_name_nodes = unallocated_skills_nodes[0].getElementsByTagName("skill_name");
var skill_action_nodes = unallocated_skills_nodes[0].getElementsByTagName("skill_action");
var skill_tier_nodes = unallocated_skills_nodes[0].getElementsByTagName("skill_tier");
var skill_arrow_gif_nodes = unallocated_skills_nodes[0].getElementsByTagName("skill_arrow_gif");






for (var j = 0; j<skill_id_nodes.length; j++) {

  var newskill = document.createElement('div');
  var attach_newskill = document.getElementById('unallocated_skills').appendChild(newskill);
  newskill.id = (skill_id_nodes[j].childNodes[0].nodeValue);


//Find the number of spaces

       var number_of_spaces = (skill_tier_nodes[j].childNodes[0].nodeValue)

       var space_text = ''

       for (var m = 1; m<number_of_spaces; m++) {

           space_text += String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)

       }
       var spaces_to_print = document.createTextNode(space_text)
       var print_spaces = document.createElement('span');
        var attach_para = newskill.appendChild(print_spaces)
        print_spaces.appendChild(spaces_to_print);

//Print the text with a different class and arrow depending on whether it is the bottom tier

  if (skill_action_nodes[j].childNodes[0].nodeValue == 'bottom') {

  newskill.className = 'skill_bottom_tier';

  var skill_name_to_print = document.createTextNode(skill_name_nodes[j].childNodes[0].nodeValue+' +')
  var print_skill_name = document.createElement('span');
  var attach_para = newskill.appendChild(print_skill_name);
  print_skill_name.appendChild(skill_name_to_print);
  print_skill_name.id = skill_id_nodes[j].childNodes[0].nodeValue
  print_skill_name.onclick=toggle_allocation;


  }else {

    newskill.className = 'skill_not_bottom_tier';
    
    var arrow_to_add = document.createElement('img');
    arrow_to_add.src = skill_arrow_gif_nodes[j].childNodes[0].nodeValue;
    var attach_arror = newskill.appendChild(arrow_to_add);


    var skill_name_to_print = document.createTextNode(skill_name_nodes[j].childNodes[0].nodeValue)
  var print_skill_name = document.createElement('span');
  var attach_para = newskill.appendChild(print_skill_name);
  print_skill_name.appendChild(skill_name_to_print);
  print_skill_name.id = skill_id_nodes[j].childNodes[0].nodeValue
  print_skill_name.onclick=openclose_tier;
  
  }




}

//THE ALLOCATED SKILLS SECTION
                     
//Clear the current skills

                     while (document.getElementById('allocated_skills').hasChildNodes()) {

                     document.getElementById('allocated_skills').removeChild(document.getElementById('allocated_skills').firstChild);

                     }

var skill_id_nodes = allocated_skills_nodes[0].getElementsByTagName("skill_id");
var skill_name_nodes = allocated_skills_nodes[0].getElementsByTagName("skill_name");
var skill_action_nodes = allocated_skills_nodes[0].getElementsByTagName("skill_action");
var skill_tier_nodes = allocated_skills_nodes[0].getElementsByTagName("skill_tier");
var skill_arrow_gif_nodes = allocated_skills_nodes[0].getElementsByTagName("skill_arrow_gif");

for (var j = 0; j<skill_id_nodes.length; j++) {

  var newskill = document.createElement('div');
  var attach_newskill = document.getElementById('allocated_skills').appendChild(newskill);
  newskill.id = (skill_id_nodes[j].childNodes[0].nodeValue);


//Find the number of spaces

       var number_of_spaces = (skill_tier_nodes[j].childNodes[0].nodeValue)

       var space_text = ''

       for (var m = 1; m<number_of_spaces; m++) {

           space_text += String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)+String.fromCharCode(160)

       }
       var spaces_to_print = document.createTextNode(space_text)
       var print_spaces = document.createElement('span');
        var attach_para = newskill.appendChild(print_spaces)
        print_spaces.appendChild(spaces_to_print);

//Print the text with a different class and arrow depending on whether it is the bottom tier

  if (skill_action_nodes[j].childNodes[0].nodeValue == 'bottom') {

  newskill.className = 'skill_bottom_tier';

  var skill_name_to_print = document.createTextNode(skill_name_nodes[j].childNodes[0].nodeValue+' -')
  var print_skill_name = document.createElement('span');
  var attach_para = newskill.appendChild(print_skill_name);
  print_skill_name.appendChild(skill_name_to_print);
  print_skill_name.id = skill_id_nodes[j].childNodes[0].nodeValue
  print_skill_name.onclick=toggle_allocation;


  }else {

    newskill.className = 'skill_not_bottom_tier';
    
    var arrow_to_add = document.createElement('img');
    arrow_to_add.src = skill_arrow_gif_nodes[j].childNodes[0].nodeValue;
    var attach_arror = newskill.appendChild(arrow_to_add);


    var skill_name_to_print = document.createTextNode(skill_name_nodes[j].childNodes[0].nodeValue)
  var print_skill_name = document.createElement('span');
  var attach_para = newskill.appendChild(print_skill_name);
  print_skill_name.appendChild(skill_name_to_print);
  print_skill_name.id = skill_id_nodes[j].childNodes[0].nodeValue
  print_skill_name.onclick=openclose_tier;
  
  }




}

*/

                     }



