
// JavaScript Document

// get url vars
function getURLVar(urlVarName) {
//divide the URL in half at the '?' 
var urlHalves = String(document.location).split('?');
var urlVarValue = '';
if(urlHalves[1]){
//load all the name/value pairs into an array 
var urlVars = urlHalves[1].split('&');
//loop over the list, and find the specified url variable 
for(i=0; i<=(urlVars.length); i++){
if(urlVars[i]){
//load the name/value pair into an array 
var urlVarPair = urlVars[i].split('=');
if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
//I found a variable that matches, load it's value into the return variable 
urlVarValue = urlVarPair[1];
}
}
}
}
return urlVarValue;   
}



function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
   
   
function get_metal_value()
{
for (var i=0; i < document.theform.metal.length; i++)
   {
   if (document.theform.metal[i].checked)
      {
      var rad_val = document.theform.metal[i].value;
      }
   }
return rad_val
}


function get_shape_value()
{
for (var i=0; i < document.theform.shape.length; i++)
   {
   if (document.theform.shape[i].checked)
      {
      var rad_val = document.theform.shape[i].value;

      }
   }
return rad_val
}


function get_subcat_id_value()
{
for (var i=0; i < document.theform.subcat_id.length; i++)
   {
   if (document.theform.subcat_id[i].checked)
      {
      var rad_val = document.theform.subcat_id[i].value;

      }
   }
return rad_val
}

function clear_series_style() {
 
   rows=document.getElementById('series_table').getElementsByTagName("TR");
   for (var j=0; j<rows.length; j++)  {
    //if (j==2) {
    cells=rows[j].getElementsByTagName("TD");
    for (var i=0; i<cells.length; i++)  {
      
	  //cells[i].style.backgroundImage="url('graphics/item_selected.jpeg')";
	  cells[i].style.backgroundColor='';
	  cells[i].setAttribute("class", ""); 
	  cells[i].setAttribute("className", ""); 

    //} 
   }
  }
} 


function swapmetalbuttons(metal)
{
var metal = unescape(metal);

if (metal == '14K Yellow Gold')
{
document.button14KYellowGold.src='/graphics/sol_ring_builder/bar_yg_over.jpg';
document.button14KWhiteGold.src='/graphics/sol_ring_builder/bar_wg.jpg';
document.buttonplatinum.src='/graphics/sol_ring_builder/bar_plat.jpg';
}
if (metal == '14K White Gold')
{
document.button14KYellowGold.src='/graphics/sol_ring_builder/bar_yg.jpg';
document.button14KWhiteGold.src='/graphics/sol_ring_builder/bar_wg_over.jpg';
document.buttonplatinum.src='/graphics/sol_ring_builder/bar_plat.jpg';
}
if (metal == 'Platinum')
{
document.button14KYellowGold.src='/graphics/sol_ring_builder/bar_yg.jpg';
document.button14KWhiteGold.src='/graphics/sol_ring_builder/bar_wg.jpg';
document.buttonplatinum.src='/graphics/sol_ring_builder/bar_plat_over.jpg';

}
}

function swapshapebuttons(shape)
{
var shape = unescape(shape);

if (shape == 'BR')
{
document.buttonshaperound.src='/graphics/sol_ring_builder/shape_round_over.jpg';
document.buttonshapeprincess.src='/graphics/sol_ring_builder/shape_princess.jpg';
document.sol_search_banner.src='/graphics/category/diamond_rings/solitaire_BR_head.gif';
}
if (shape == 'PR')
{
document.buttonshaperound.src='/graphics/sol_ring_builder/shape_round.jpg';
document.buttonshapeprincess.src='/graphics/sol_ring_builder/shape_princess_over.jpg';
document.sol_search_banner.src='/graphics/category/diamond_rings/solitaire_PR_head.gif';
}
}

function show_settings(pg,mid)
{
	
	
metal = get_metal_value();
shape = get_shape_value();
subcat_id = get_subcat_id_value();

if (IsNumeric(pg))
{
	//true leave alone
}
else
{
	//not defined or not 1 set to 1
	pg=1;
}
document.location = "#searchbar";
ColdFusion.navigate('inc/settings_div.cfm?metal=' + metal + '&shape=' + shape  + '&pg=' + pg + '&mid='+ mid + '&subcat_id='+ subcat_id,'settings');
//settings.style.height = 330;
swapmetalbuttons(metal);
swapshapebuttons(shape);

document.getElementById("container_right").style.visibility = 'hidden';
}



function show_diamonds(metal,shape,pg,mid,series,did,subcat_id)
{
document.location = "#settingbar";
document.getElementById("container_right").style.visibility = 'visible';
ColdFusion.navigate('inc/diamonds.cfm?metal=' + metal + '&shape=' + shape + '&pg=' + pg + '&mid=' + mid  + '&series=' + series  + '&did='+ did + '&subcat_id=' + subcat_id,'container_right');

// }

// var MyThmUrl = function(DivID,DivClass,SelectedCell,tableID,itemcount)
// {

//hide divs

// document.getElementById('mid' + mid).style.visibility = 'visible'; 
// document.getElementById('Div2').style.visibility = 'hidden'; 

	// add content to div
// 	document.getElementById(DivID).style.visibility = 'visible'; 
// 	 ColdFusion.navigate(DivUrl,DivID);
	 // the divs class get set here
//	document.getElementById(DivID).className = DivClass; 
	
	//clear previous selectetions

document.getElementById('selected' + mid).style.background = '#7bbee0';
	
	
	
	// thecell.style.backgroundImage="url('graphics/item_selected_on.jpeg')";
	//change the height of the div
//	changeDivHeight(DivID,itemcount);
	
	
}






function show_detail(metal,shape,pg,mid,series,did)
{
ColdFusion.navigate('inc/detail.cfm?metal=' + metal + '&shape=' + shape + '&pg=' + pg + '&mid=' + mid  + '&series=' + series  + '&did=' + did,'container_right');
}


function show_settings_by_metal(metal)
{	

for (var i = 0; i < theform.metal.length; i++ ) {
	if (theform.metal[i].value == metal)
	{
	theform.metal[i].checked = true;

	}
}

shape = get_shape_value();
subcat_id = get_subcat_id_value();

	ColdFusion.navigate('inc/settings_div.cfm?metal=' + metal + '&shape=' + shape  + '&pg=' + 1 + '&mid='+ '' + '&subcat_id='+ subcat_id,'settings');
}

function show_settings_by_shape(shape)
{	

for (var i = 0; i < theform.shape.length; i++ ) {
	if (theform.shape[i].value == shape)
	{ 
	theform.shape[i].checked = true;

	}
}
metal = get_metal_value();
subcat_id = get_subcat_id_value();
ColdFusion.navigate('inc/settings_div.cfm?metal=' + metal + '&shape=' + shape  + '&pg=' + 1 + '&mid='+ '' + '&subcat_id='+ subcat_id,'settings');
}

function show_settings_by_subcat_id(subcat_id)
{	

for (var i = 0; i < theform.subcat_id.length; i++ ) {
	if (theform.subcat_id[i].value == subcat_id)
	{ 
	theform.subcat_id[i].checked = true;

	}
}

metal = get_metal_value();
shape = get_shape_value();
mid = getURLVar('mid');
show_settings(1,mid);
// ColdFusion.navigate('inc/settings_div.cfm?metal=' + metal + '&subcat_id=' + subcat_id  + '&pg=' + 1 + '&mid='+ '' + '&subcat_id='+ subcat_id,'settings');
}


function presetpage()
{
//set value of form prior to fetching settings

// fetch settings
mid = getURLVar('mid');



pg = getURLVar('pg');
if (IsNumeric(pg))
{	//true leave alone
}
else
{
	//not defined or not 1 set to 1
	pg=1;
}
metal = get_metal_value();
shape = get_shape_value();

did = getURLVar('did');
series = getURLVar('series');
subcat_id = getURLVar('subcat_id');


if (IsNumeric(mid)){
//	alert(metal);
	show_diamonds(metal,shape,pg,mid,series,did,subcat_id);
	}
}




function getElementLeft(elm) 
{
    var x = 0;

    //set x to elm’s offsetLeft
    x = elm.offsetLeft;

    //set elm to its offsetParent
    elm = elm.offsetParent;

    //use while loop to check if elm is null
    // if not then add current elm’s offsetLeft to x
    //offsetTop to y and set elm to its offsetParent

    while(elm != null)
    {
        x = parseInt(x) + parseInt(elm.offsetLeft);
        elm = elm.offsetParent;
    }
    return x;
}

function getElementTop(elm) 
{
    var y = 0;

    //set x to elm’s offsetLeft
    y = elm.offsetTop;

    //set elm to its offsetParent
    elm = elm.offsetParent;

    //use while loop to check if elm is null
    // if not then add current elm’s offsetLeft to x
    //offsetTop to y and set elm to its offsetParent

    while(elm != null)
    {
        y = parseInt(y) + parseInt(elm.offsetTop);
        elm = elm.offsetParent;
    }

    return y;
}

function Large(obj,theimg)
{
    var imgbox=document.getElementById("imgbox");
    imgbox.style.visibility='visible';
    var img = document.createElement("img");
    img.src=theimg;
    img.style.width='240px';
    img.style.height='240px';
    
    if(img.addEventListener){
        img.addEventListener('mouseout',Out,false);
    } else {
        img.attachEvent('onmouseout',Out);
    }             
    imgbox.innerHTML='';
    imgbox.appendChild(img);
    imgbox.style.left=(getElementLeft(obj)) +'px';
    imgbox.style.top=(getElementTop(obj)) + 'px';
}

function Out()
{
    document.getElementById("imgbox").style.visibility='hidden';
}



 