//
// client_full_image.js
//
// by Mark Ward / Oasis Technologies
//
// for flannelworld.com
//
// 20071208
//



function view_similar(id) {
        createRequest();
        var myurl = "http://www.hemstitcher.com/ajax/vs_module.php?id="+id;
        request.open("GET",myurl, true);
        request.onreadystatechange =vs_handle_response;
        request.send(null);
	show_div("vs_display_div");
}



function vs_handle_response() {
        if(request.readyState==4) {
                var xmlDoc = request.responseXML;
                document.getElementById("vsd_main").innerHTML=xmlDoc.getElementsByTagName("data")[0].firstChild.nodeValue;
                get_doc_vert_pos();
                id = xmlDoc.getElementsByTagName("id")[0].firstChild.nodeValue;
		material_name = xmlDoc.getElementsByTagName("MaterialName")[0].firstChild.nodeValue;
		document.getElementById("vsd_material_name").innerHTML=material_name;
                document.getElementById("vs_display_div").style.top=doc_vert_pos;
        }
}



function hide_div(div_name) {
        document.getElementById(div_name).style.display='none';
}



function show_div(div_name) {
        document.getElementById(div_name).style.display='block';
}



N = (document.all) ? 0 : 1;


var request;

function createRequest() {
  try {
    request = new XMLHttpRequest();
  } catch (trymicrosoft) {
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        request = false;
      }
    }
  }

  if (!request)
    alert("Error initializing XMLHttpRequest!");
}


function client_display_full_notion_image(id) {
        createRequest();
        document.getElementById("full_image").src="http://www.flannelworld.com/Images/blank.gif";
        var myurl = "http://www.flannelworld.com/ajax/cl_fi_n_module.php?id="+id;
        request.open("GET",myurl, true);
        request.onreadystatechange =fin_handle_response;
        request.send(null);
}

function client_display_full_image(id) {
	show_cfi_div();
        createRequest();
        document.getElementById("full_image").src="http://www.flannelworld.com/Images/blank.gif";
        var myurl = "http://www.hemstitcher.com/ajax/cl_fi_module.php?id="+id;
        request.open("GET",myurl, true);
        request.onreadystatechange =fi_handle_response;
        request.send(null);
}


var doc_vert_pos;


function get_doc_vert_pos() {
        if(navigator.appName == "Netscape") {
                doc_vert_pos=window.pageYOffset;
        }
        else if(navigator.appName == "Microsoft Internet Explorer") {
                doc_vert_pos=document.body.scrollTop;
        }
}


var window_width;
var window_height;
var doc_height;


function get_window_dimensions() {
        if(navigator.appName == "Netscape") {
                window_width = window.innerWidth;
                window_height = window.innerHeight;
                doc_height = document.body.parentNode.clientHeight;
                doc_height = document.body.parentNode.scrollHeight;
        }
        else if(navigator.appName == "Microsoft Internet Explorer") {
                window_width = document.body.clientWidth;
                window_height = document.body.clientHeight;
                doc_height = document.body.scrollHeight;
        }
}


function show_cfi_div() {
        if ( typeof hide_selects=="function") {
                hide_selects();
        }
        make_full_size("fi_translucence");
        show_div("fi_translucence");
        show_div("client_full_image_div");
}


function hide_cfi_div() {
        hide_div("client_full_image_div");
        hide_div("fi_translucence");
        if (typeof hide_selects=="function") {
                show_selects();
        }
}


function fi_handle_response() {
        if(request.readyState==4) {
                var xmlDoc = request.responseXML;
                document.getElementById("full_image").src=xmlDoc.getElementsByTagName("data")[0].firstChild.nodeValue;
                if (xmlDoc.getElementsByTagName("material_name")[0].firstChild.nodeValue) {
                        document.getElementById("fi_material").innerHTML=xmlDoc.getElementsByTagName("material_name")[0].firstChild.nodeValue;
                }
                get_doc_vert_pos();
		id = xmlDoc.getElementsByTagName("id")[0].firstChild.nodeValue;
                document.getElementById("client_full_image_div").style.top=doc_vert_pos;
		document.getElementById("vsl").innerHTML='<span onclick="view_similar('+id+');">View all Value Sets that include this material</span>';
	request=null;
        }
}

function fin_handle_response() {
        if(request.readyState==4) {
                var xmlDoc = request.responseXML;
                document.getElementById("full_image").src=xmlDoc.getElementsByTagName("data")[0].firstChild.nodeValue;
                document.getElementById("fi_prod_name").innerHTML=xmlDoc.getElementsByTagName("product_name")[0].firstChild.nodeValue;
                get_doc_vert_pos();
                document.getElementById("client_full_image_div").style.top=doc_vert_pos;
                show_cfi_div();
        }
}


function make_full_size(div_name) {
        get_window_dimensions();
        document.getElementById(div_name).style.width=window_width;
        document.getElementById(div_name).style.height=doc_height;
}
