// JavaScript Document

/*
'################################################################################################
'# Site Name : Walmart - Diamond Ring								#																									
'# File Name: javascript.js									#
'# Description : 										#
'# Image Preload Function is used to load the image 						#
'# Preload function its Used to unload the Div Content theDiv is in Index page			#
'# JSdiamond is a JavaScript function to split the value and passed to Diamond.asp page		#
'# getdiamondValues is AJAX Function								#								
'# openEmailtoaFriend is a Email to your Friend to pass the model window to this file		#
'# openLargerimage is a Enlarge the Selected Ring Image to pass the model window to this file	#
'# History:											#
'# 161107	lq00	Original.								#
'# 211107	lq01	Validation function is added for Select Ring Size.			#
'# 291107	lq02	Image Zoom Java Script is added for Image Slde Show			#
'################################################################################################
*/ 

/***************** Image Preload******************************/
function MM_preloadImages() 
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/***************** Image Preload Clear ******************************/
function clearPreloadPage() 
{ //DOM
	if (document.getElementById)
	{
		document.getElementById('prepage').style.visibility='hidden';
	}
	else
	{
		if (document.layers)
		{ //NS4
		document.prepage.visibility = 'hidden';
		}
		else{ //IE4
		document.all.prepage.style.visibility = 'hidden';
		}
	}
}

/***************** JavaScript to split the Query String and pass the value to Ajax Document******************************/
function JSdiamond(strvalue,step) 
{
	window.status = "Please wait. Loading data....";
	if (step == 1)
	{
		var strsplitvalue = strvalue.split("|")
		var Shape = strsplitvalue[0]
		var Size = strsplitvalue[1]
		var Color = strsplitvalue[2]
		var Clarity = strsplitvalue[3]
		var Quality = Color+"|"+Clarity
		var MetalType = strsplitvalue[4]	
		var strURL = "Shape="+Shape+"&Size="+Size+"&Quality="+Quality+"&MetalType="+MetalType;
	}
	if (step == 2)
	{
		var strsplitvalue = strvalue.split("|")
		var Shape   = strsplitvalue[0]
		var Size = strsplitvalue[1]
		var Color = strsplitvalue[2]
		var Clarity = strsplitvalue[3]
		var Quality = Color+"|"+Clarity
		var MetalType = strsplitvalue[4]
		var RingStyle = strsplitvalue[5]	
		var strURL = "Shape="+Shape+"&Size="+Size+"&Quality="+Quality+"&MetalType="+MetalType+"&RingStyle="+RingStyle;
	}
	 strURL = "diamond.asp?"+strURL
	 getdiamondValues(strURL);
	// setTimeout('initSlideShow()',2000);
}

/***************** Ajax Document Code ******************************/

function getdiamondValues(strURL) 
{
    if (!enProceso && http) 
	{ 
       var url = strURL;
	   //alert("AJAX  = " + url);
       http.open("GET", url, true);
       http.onreadystatechange = handleHttpResponse;
       enProceso = true;
       http.send(null);
    }
}

function handleHttpResponse() 
{ 
    if (http.readyState == 4) 
	{ 
       if (http.status == 200) 
	   { 
          if (http.responseText.indexOf('invalid') == -1) 
		  {
             // Armamos un array, usando la coma para separar elementos
             Pageresults = http.responseText; 
			 document.getElementById("DiamondPage").innerHTML = Pageresults;
			 // Image Slide Show Process function
			 initSlideShow()
			 window.status = "Done";
             enProceso = false;
          }
       }
    }
}

function getHTTPObject() 
{
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
       try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) { xmlhttp = false; }
       }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
	{
       try 
	   {
          xmlhttp = new XMLHttpRequest();
       } 
	   catch (e) 
	   { 
	   xmlhttp = false; 
	   }
    }
    return xmlhttp;
}
var enProceso = false; // lo usamos para ver si hay un proceso activo
var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest

/***************** Open Email to a Friend function ******************************/ 
function openEmailtoaFriend(stritemnumber)
{
	emailwindow=dhtmlmodal.open("EmailBox", "iframe", "emailtoyourfriend.asp?itemnumber="+stritemnumber, "Send this design to a friend", "width=580px,height=380px,center=1,resize=0,scrolling=1")
} 

/***************** Open Larger image function ******************************/
function openLargerimage(stritemnumber)
{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	var ver = Array();
	ver = b_version.split(";");
	if(ver[1]==" MSIE 7.0"){
		var Width = "510px";
		var Height = "520px";
	}else if(ver[1]==" MSIE 6.0"){
		var Width = "525px";
		var Height = "520px";
	}else{
		var Width = "512px";
		var Height = "502px";
	}
	emailwindow=dhtmlmodal.open("ViewRing", "iframe", "view_ring.asp?itemnumber="+stritemnumber, "Your Diamond Ring", "width="+Width+",height="+Height+",top=15px,center=1,resize=0,scrolling=1")
} 


/***************** Validation for Select Ring Size function ******************************/
function validation()
{

	if (document.getElementById('ringSizeSelect').value == 0)
		{
			alert("Please select your ring size")
		document.getElementById('ringSizeSelect').focus;
		return false;
		}
		else
		{
			return true;
		}
} 

/***************** Image Slde Show Zoom ******************************/
function setZoom(img, dir, width, height, margin, zIndex, delay) 
{
  setTimeout(function() {
    if (img.dir==dir) {
      img.style.width=width;
      img.style.height=height;
      img.style.margin=margin;
      img.style.zIndex=zIndex;
      img.parentNode.parentNode.style.zIndex=zIndex;
    }
  }, delay);
}

function larger(img, width, height) 
{
  img.dir='rtl';
  now=parseInt(img.style.zIndex);
  now = 0
  for (i=now+1; i<=10; i++)
   {
    w=(width*(10+i))/20+'px';
    h=(height*(10+i))/20+'px';
    m=(-i)+'px 0 0 '+(-width*i/40)+'px';
    setZoom(img, 'rtl', w, h, m, i, 20*(i-now));
  }
}

function smaller(img, width, height) {
  img.dir='ltr';
  now=parseInt(img.style.zIndex);
  for (i=now-1; i>=0; i--) {
    w=(width*(10+i))/20+'px';
    h=(height*(10+i))/20+'px';
    m=(-i)+'px 0 0 '+(-width*i/40)+'px';
    setZoom(img, 'ltr', w, h, m, i, 20*(now-i));
  }
}


