/// <reference path="\\Srvil\company\wwwroot\JamesAllenTest\Content\_includes\jquery-1.4.4.js" />

/* Functionjs.js */
var FramedWindow;
var ReffererItemID;
var ReffererCategoryID;
var ShowCloseWindowTitle;
var nav = navigator.userAgent;
var compareView;
var TotalPrice = 0;
var tm;
var StoneID, ItemPriceForPreset;
var compareView = 1;
var moz = false;

var msie = (navigator.userAgent.toLowerCase().indexOf('msie') != -1);
var IE7andMOZ = window.XMLHttpRequest;
if ((nav.indexOf("Firefox") != -1) || (nav.indexOf("Netscape") != -1))
	moz = true;

if (!msie)
	var xmlDoc = document.implementation.createDocument("", "", null);
else
	var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

	
//Old $ function
function $(objID) {
	return document.getElementById(objID);
}

function IncludeShipping() {
	$('free-shipping').innerHTML = GetSourceHtml(site + '/Ajax/Free-Shipping.asp');
}



function LoadItem1(CatID, itemID, LoaderID) {
	if (LoaderID != undefined)
		//ShowLoadAnim1(LoaderID);
	url = 'Wedding-rings/LoadItem.asp?cid=' + CatID + '&ItemID=' + itemID;

	j$.get(url, function(data) {
		$('ItemConteainer').innerHTML = data;
		LoadFlashObject('swf/ring/ring_item.swf', 323, 240, 'ItemMovie', '&xmlPath=swf/ring/ring_item.asp?item=' + itemID, 1);
		//j$("select").styleSelect({ styleClass: "selectJA" });
		HideLoader();
		initDropDownMenu("#but_img");

	});

}

function sfHover() {
	var sfEls = document.getElementById("navbar").getElementsByTagName("li");
	for (var i = 0; i < sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			this.className += " hover";
		}
		sfEls[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
}


function InitTopMenu() {
	if (window.attachEvent) window.attachEvent("onload", sfHover);
}


var rsize;
function CheckSize() {
	rsize = $('RingSize').value;
	if (rsize == '') {
		alert("Please select ring size");
		return false
	}
}
function UpdateRing(Attach, ItemID, CategoryID) {

	UpdateAjaxRing("toshop=1&itemid=" + ItemID + "&cid=" + CategoryID + "&Attach=" + Attach + "&ringsize=" + rsize);
}


function ShowLoadAnim1(id)
{
		
	j$('#LoadAnim').show();
	$(id).appendChild($('LoadAnim'));
}

function ToShopCart(postURL, messageText, linkURL, ShopID)
{
	var ringSize = j$("#RingSize_" + ShopID).val();

	postURL = postURL + "&RingSize=" + ringSize;
	j$.post(postURL,
	function (data)
	{
		if (data != "")
		{
			messageText = data + '<br>' + GetMessageHtmlById(messageText);
			if (messageText != undefined)
			{
				ShowCompletedBox(messageText);
			}
		}
		else
		{
			document.location = linkURL;
		}

	});

}

function UpdateAjaxRing(params) {
	//alert(params);
	if (j$("#RingSize"))
		var rsz = "RingSize=" + j$("#RingSize").val() + "&";

	j$.get('Ajax/update_ring.asp?' + rsz + params, function (data) {
		//alert(data)
		if (data.indexOf("http") < 0)
			document.location = site + '/' + data;
		else
			document.location = data;
	});

}

function DoPost(postURL, messageText, linkURL) {
	j$.post(postURL, function(data) {
		//		alert(postURL);
		if (data != "") messageText = data + '\n' + messageText;
		if (messageText != undefined) {
			ShowDialogBox(null, messageText, function () { document.location = linkURL; }, "ui-mb-completed")
		}
	});
}

function removeEngrave(ShopID, ItemID) {

	if (ShopID == undefined) ShopID = ShopItemIDs[0];
	if (ItemID == undefined) ItemID = ShopItemIDs[1];
	j$.post("Ajax/SaveIngraving.asp", { IngeavingText: '', ShopID: ShopID, ItemID: ItemID }, function(data) { });
	j$("#InscriptionArea" + ShopID).css("display", "none");
	j$("#ClickHereInscriptionArea" + ShopID).css("display", "block");

}

var ingrvobj = null;
function processEngrave(font, text) {

	if (font == "Lucida Sans") text = text.toUpperCase()
	var textIn = text + ' [' + font + ']';
	j$("#InscriptionArea" + ShopItemIDs[0]).css("display", "block");
	j$("#InscriptionUserData" + ShopItemIDs[0]).css("display", "block");
	j$("#ClickHereInscriptionArea" + ShopItemIDs[0]).css("display", "none");

	j$("#InscriptionText" + ShopItemIDs[0]).html(textIn);
	j$.post("Ajax/SaveIngraving.asp", { IngeavingText: text + ' [Font: ' + font + ']', ShopID: ShopItemIDs[0], ItemID: ShopItemIDs[1] });
	CloseEngrave();
}

function CloseEngrave() {
	j$("#dv7").hide("slow");
}

var ShopItemIDs = new Array(2); // checkbox,ShopID
function ShowIngraving(obj, ShopID, ItemID) {
	ShopItemIDs[0] = ShopID;
	ShopItemIDs[1] = ItemID;
	LoadDiv(7, 'dv7', '', obj, [383, 276]);
}

function TrackMyPage(p) {
	if (pageTracker) {
		pageTracker._trackPageview(p);
	}
	return false;
}

// For Item Page
var PointerArrow;

var status = '';
function DOnClick() {
	$('hand').src = '_images/zoom/hand_off.jpg';
	$('3d').src = '_images/zoom/3d_on.png';
	status = '1';
}

function HandOnClick() {
	$('hand').src = '_images/zoom/hand_on.png';
	$('3d').src = '_images/zoom/3d_off.png';
	status = '2';
}

function Pic3dOut(obj) {
	a = status;
	if (a == '1')
	{ $('3d').src = '_images/zoom/3d_on.png'; }
	else if (a == '2')
	{ $('3d').src = '_images/zoom/3d_off.png'; }
	else if (a == '')
	{ $('3d').src = '_images/zoom/3d_off.png'; }
}

function PicHandOut(obj) {
	a = status;
	if (a == '2')
	{ $('hand').src = '_images/zoom/hand_on.png'; }
	else if (a == '1')
	{ $('hand').src = '_images/zoom/hand_off.png'; }
	else if (a == '')
	{ $('hand').src = '_images/zoom/hand_off.png'; }
}

function PicsRestore() {
	$('hand').src = '_images/zoom/hand_off.png';
	$('3d').src = '_images/zoom/3d_off.png';
	status = '';
}


function CloseDiv(did) {

	//if (j$("#" + did)) jQuery("#" + did).fadeOut("fast", function() { j$("#" + did).remove() })

	if (jQuery.browser.msie) {
		var obj = $(did);
		if (obj != null)
			obj.outerHTML = "";
	}
	else {
		jQuery("#" + did).hide().remove();
	}
	jQuery(".blockContent").hide().remove();
}

var ajaxWin;



function ShowLoaderAjax() {
	j$("#ItemConteainer").css({ 'background-color': '#f3f3f3', 'filter': 'alpha(opacity=70)', 'opacity': '0.7' });
	
	var ajaxDiv = j$("<div><img name='ImgLoading' src='/Slider2/Images/Loading.gif' width='64' height='64' /><br />" +
					"<div style='font-size: 16px; font-weight: bold; margin-top: 5px;'> " + 
						"Updating Data..." +
					"</div></div>");
	
	ajaxDiv.attr("id", "did")
		.css(
		{ position: 'absolute',
			display: 'none'
		})

		ajaxDiv.appendTo(document.body);
		position = GetCenterPosition(ajaxDiv);
		ajaxDiv.css({ top: position.top, left: position.left }).show();
		

}


function LoadDiv(pageid, did, url, obj, ObjectWHArr, zIndex) {

	if (!ObjectWHArr) ObjectWHArr = [0, 0, ''];
	var objWidth = 0, objHeight = 0;
	var content = "";
	var actionObj = jQuery(obj);

	var zindex = 1;
	zindex = (isNaN(zindex)) ? 1000 : zindex;

	//alert($("dv4"))

	if (ajaxWin) {
		ajaxWin.remove();
	}
				
	jQuery("#" + did).hide().remove();

	ajaxWin = j$("<div />");


	//zIndex = (zIndex == undefined) ? 30000 : zIndex;

	ajaxWin.attr("id", did)
		.css(
		{ position: 'absolute',
			display: 'none',
			zIndex: GetZIndex()
		})
		.data("type", obj).
		data("IsDrageble", true);


	switch (pageid) {
		case 1:
			{
				//CreateBlock(29990).show();
				ajaxWin.load("Ajax/CustomerFeedback.asp?divid=" + did + "&" + url, LoadDivComplete);
				break;
			}
		case 2: ajaxWin.load("Ajax/EmailThisPage.asp?divid=" + did + "&" + url, LoadDivComplete); break;
		case 3: ajaxWin.load("Ajax/ContactForm.asp?divid=" + did + "&" + url, LoadDivComplete); break;
		case 4: ajaxWin.load("Ajax/SimilarDiamonds.asp?divid=" + did + "&" + url, LoadDivComplete); break;
		case 5: ShowViewContainer( url, obj, ObjectWHArr);
			var blockArea = jQuery("#blockArea");
			blockArea.addClass("blockArea")
						 .css({ width: blockArea.width(), height: blockArea.height() });
			//.one("click", HideViewContainer);
			return; break;
		case 6: ajaxWin.load("/player/indexv.asp?divid=" + did + "&" + url, LoadDivComplete); ajaxWin.data("IsDrageble", false); break;
		case 7: ajaxWin.load("/Ajax/Ingraver.asp?" + did + "&" + url, LoadDivComplete); ajaxWin.data("IsDrageble", false); break;
		case 8: ajaxWin.load("/zoomitem2.asp?divid=" + did + "&" + url, LoadDivComplete); break;
		case 9: ajaxWin.load("Ajax/EmailCertificate.asp?divid=" + did + "&" + url, LoadDivComplete); break;
		
	}

	ajaxWin.appendTo(document.body);

	return ajaxWin;
}

function LoadDivComplete(responseText, textStatus, XMLHttpRequest) {
	switch (ajaxWin.data("type")) {
		case "player":
			position = GetPositionBySize(1240, 720, 0, 0);
			break;
		default:
			position = GetCenterPosition(ajaxWin);
			break;
	}
	jQuery(document.body).append(ajaxWin);
	ajaxWin.addClass("ui-window");
	ajaxWin.css({ top: position.top, left: position.left }).show();

	if (ajaxWin.data("IsDrageble"))
		ajaxWin.draggable({ scroll: false, containment: 'document' });

	HideLoader();
}


function ClosePlayer() {
	j$('#dv6').css("display", "none").remove();
}

function IncludeInscription(obj, inscription_price, shopid) {
	TotalPrice = (obj.checked) ? (parseInt(TotalPrice) + parseInt(inscription_price)) : (parseInt(TotalPrice) - parseInt(inscription_price));
	$("TotalPriceSpan").innerHTML = formatCurrency(TotalPrice);

	if ($("InscriptionPrice"))
		if (obj.checked) {
		$("InscriptionPrice").innerHTML = "<span class='pricetitle'>Inscription Price:</span> <span class='price' style='font-size:13px;width:50px'>" + formatCurrency(25) + "</span><br>";
	} else $("InscriptionPrice").innerHTML = "";

	if ($("InscriptionPriceLabel_" + shopid))
		$("InscriptionPriceLabel_" + shopid + "").innerHTML = (obj.checked) ? formatCurrency(25) : formatCurrency(0);


}


function ViewHD(item) {
	var pwidth = "1244";
	var pheight = "720";
	if (screen.width < 1240) pwidth = screen.width - 22;
	if (screen.height < pheight) pheight = screen.height;
	_gaq.push(['_trackPageview','ItemHDExperience.html']);
	//ShowLoader("#butt" + item, { img: "/_images/3HDLoader.gif", height: 16, width: 16, offsetX: 13 });
	LoadDiv(6, 'dv6', 'item=' + item + '&width=' + pwidth + '&height=' + pheight, 'player')
}

function ViewHD2(item) {
	var pwidth = "1244";
	var pheight = "720";
	if (screen.width < 1240) pwidth = screen.width - 22;
	if (screen.height < pheight) pheight = screen.height;
	LoadDiv(8, 'ItemZoom', 'ItemID=' + item, this);
}


function ViewImage(srcImage, sid) {

	$('shapes').style.display = (sid != undefined) ? 'block' : 'none';

	$('ItemZoomContainer').innerHTML = "<img id='" + sid + "' src='" + srcImage + "'>"

}




//function $(objID) {alert("");  return document.getElementById(objID); }


function TrackModule(m, l) {

	pic1 = new Image(1, 1);

	pic1.src = "TrackModule.asp?m=" + m + '&l=' + l;

}


var rsize;

function CheckSize() {

	if ($('ringsize')) {

		rsize = document.getElementsByName('ringsize')[0].value;

		if (rsize == '') {

			alert("Please select ring size");

			document.getElementsByName('ringsize')[0].focus();

			return false

		}

	}

}



function LoadImage(obj, StnID, ha, ImageType) {


	StoneID = (StnID != undefined) ? StnID : StoneID;

	ha = (ha == undefined) ? '' : ha;


	ImageType = (ImageType == undefined) ? '' : ImageType;


	hs.swfOptions = {

		version: "8",

		expressInstallSwfurl: null,

		flashvars: { xmlPath: "Loupe/LoupeData.asp?id=" + StoneID + "|" + ImageType },

		params: { wmode: "transparent" },

		attributes: {}

	};

	if (ha == 1)

		return hs.htmlExpand(obj, { objectType: 'swf', width: 720, objectWidth: 720, objectHeight: 359, maincontentText: 'You need to upgrade your Flash player' })

	else

		return hs.htmlExpand(obj, { objectType: 'swf', width: 583, objectWidth: 583, objectHeight: 359, maincontentText: 'You need to upgrade your Flash player' })

}


function formatCurrency(num) {

	num = num.toString().replace(/\$|\,/g, '');

	if (isNaN(num))

		num = "0";

	sign = (num == (num = Math.abs(num)));

	num = Math.floor(num * 100 + 0.50000000001);

	cents = num % 100; 

	num = Math.floor(num / 100).toString();

	if (cents < 10)

		cents = "0" + cents;

	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)

		num = num.substring(0, num.length - (4 * i + 3)) + ',' +
num.substring(num.length - (4 * i + 3));

	return (((sign) ? '' : '-') + '$' + num);

	//return (((sign)?'':'-') + '$' + num + '.' + cents);

}



function ProcessForm(sendInfo, frm, tpage, msgElmName, popupIDtoClose, popDivClose, clear_form, showMessage) {

	if (msgElmName != '')

		var msg = eval("document.getElementById('" + msgElmName + "')");

	else

		var msg = document.getElementById("msg");

	if (sendInfo.indexOf("correct") > 0) {

		return false;

	}

	if (clear_form) clearform(frm);

	if (popupIDtoClose == 9) {

		//alert(sendInfo);

		ShowCompletedBox(sendInfo);

		if (sendInfo.indexOf("correct") > 0) {

			return false;

		}

		$("popup").style.display = "none";

		return false;

	}

	if (popupIDtoClose == 3) {

		//alert(sendInfo);

		ShowCompletedBox(sendInfo);

		if ($('capt')) {

			$('capt').src = '_Captcha/aspcaptcha.asp?' + Math.random();

		}

		close_win1();

		return false;

	}


	if (popDivClose == 4) {

		if (clear_form) clearform(frm);

		if ($('msgReq1')) {

			$('capt5').src = '_Captcha/aspcaptcha.asp?' + Math.random();

		}

	}


	if (showMessage != undefined) {
		ShowCompletedBox(sendInfo);
	}

	if (popupIDtoClose != undefined) {

		var div = jQuery("#" + popupIDtoClose);
		div.hide().remove();
	   // var element = eval("document.getElementById('" + popupIDtoClose + "')");
	   // element.style.display = (element.style.display == 'block') ? 'none' : 'block';
	}

	else

		msg.innerHTML = sendInfo;


	if (clear_form) clearform(frm);

}



function PostData(frm, tpage, msgElmName, popupIDtoClose, popDivClose, clear_form, showMessage) {
  
   dataString = j$(frm).serialize();
   j$.post(tpage, dataString, function (data) 
		{ 
			if(data == 'Please insert correct Security check')
			{
			ShowAlertBox (data);
			$('capt').src = '_Captcha/aspcaptcha.asp?' + Math.random();
			}
			else
			{
			ProcessForm(data, frm, tpage, msgElmName, popupIDtoClose, popDivClose, clear_form, showMessage) 
			}
		});
	
	//}
   return false;
}




function clearform(frm) {


	for (i = 0; i < frm.length; i++) {

		switch (frm[i].type) {

			case "text": { frm[i].value = "" } break;

			case "textarea": { frm[i].value = "" } break;

		}

	}


}



function PrintIFRM(obj) {

	window.print(obj);

}


function ZoomIn(obj) {

	var zomVal = parseInt(obj.style.zoom) + 10;

	if (zomVal <= 100)

		obj.style.zoom = zomVal + "%";

}

function ZoomOut(obj) {

	var zomVal = parseInt(obj.style.zoom) - 10;

	if (zomVal >= 50)

		obj.style.zoom = zomVal + "%";

}


function displayElementBG(elmName, obj, bgOn, bgOff, objtoClose, showImage, hideImage) 
{

	var element = j$('#' + elmName);

	var blockToClose;

	objectToAnimate = element;

	if (elmName == 'TestimonialsTb')
		CreateTestimonials();

	if ($(obj)) {

		bg = element.css("display") == 'block' ? bgOff : bgOn;

		$(obj).style.background = "url(" + bg + ")";

	}



	if (showImage != undefined) {

		var btn = jQuery(obj);
		var isClosed = element.css("display") == 'block';

		if( btn.hasClass("ui-btn-plus") )
		{
			btn.toggleClass("ui-btn-minus");
		}
		else
		{
			 obj.src = (isClosed) ? showImage : hideImage;
		}

	}


	if (objtoClose) {

		blockToClose = j$("#" + objtoClose).slideUp();

	}


	element.slideToggle();


	return false;
}


var StartTop = 0;

var StartLeft = screen.width;

var ElementTop;

var ElementLeft;

var idII;


function getX(obj) {

	return (obj.offsetParent == null ? obj.offsetLeft : obj.offsetLeft + getX(obj.offsetParent));

}



function getY(obj) {

	return (obj.offsetParent == null ? obj.offsetTop : obj.offsetTop + getY(obj.offsetParent));

}



function add_to_wish(slot, nItemID, design, ItemType) {
	var ringSize = j$("#RingSize").val();

	jQuery.get("Ajax/AddToWishList.asp", { design: design, ItemID: nItemID, stones: slot, RingSize: ringSize, ItemType: ItemType }, function (data) 
	{
		ShowDialogBox(null, "AddToWishlistInfo", 
			function () { document.location = site.replace('https', 'http') + '/wish_list.asp'; }, "ui-mb-completed")
	});
	return;
}




var shape_br = 0;
function CheckShape(obj) {
	document.getElementById("HaTD").style.display = ((obj.value != 'BR')) ? 'none' : 'block';
	if ((obj.value != 'BR') && (shape_br == 0))
		document.getElementById('shape_Round').checked = false;
	shape_br++;
}

var num_clicks_color = 0;
var num_clicks_clarity = 0;

function openNewWin(num) {
	document.all("frmWrap").innerHTML = "<iframe scrolling='Auto' frameborder='0'  id='main_ifrm' src=''></iframe>";
	open_div(site + "/diamond_info.asp?id=" + num, 580, 450);
}






function open_float(str, n_width, n_height, ypos, xpos) {
	top.document.all("frmWrap").innerHTML = "<iframe scrolling='Auto' frameborder='0'  id='main_ifrm' src=''></iframe>";
	open_div(str, n_width, n_height, ypos, xpos);
	return;
}

var xmlhttp;


var LoadingDiv = null;

function ShowLoaderImage(id) {

	if ($(LoadingDiv)) {
		LoadingDiv.remove();
		LoadingDiv = null;
	}
	//alert(id);
	LoadingDiv = j$("<div  />");

	LoadingDiv.attr("id", id);


	LoadingDiv.html("<img border=0  src='_images/LoadAnim.gif'>");

	//LoadingDiv.css({ "left": screen.width / 2 + "px", "top": screen.height / 2 - 200 + "px" });
	LoadingDiv.css( { position:"absolute", top:0, left:0, zIndex:10000 } );
	LoadingDiv.appendTo(document.body);

	LoadingDiv.show();
	//alert(id);
}

function changePageSize(page_size) {

	ShowLoaderImage();

	document.paging.pageSize.value = page_size;

	document.paging.submit();

}


function jewel_sort(obj) {

	if ((obj.name == 'sortway') && (obj.value != '')) {

		document.paging.sortway.value = obj.value;

		document.paging.submit();

		return;

	}

	else {

		document.paging.catfilter.value = obj.value;

		document.paging.submit();

		return;

	}

}


function Browsing(currect_page, page, aPage) {

	document.paging.page_num.value = page;

	document.paging.currect_page.value = currect_page;

	document.paging.submit();

	return;

}




function goToPrevPage(page, pageLength) {

	document.paging.currect_page.value = (1 + page) * pageLength;

	document.paging.page_num.value = page;

	document.paging.submit();

}

function goToNextPage(page, pageLength) {

	document.paging.currect_page.value = page * pageLength + 1;

	document.paging.page_num.value = page;

	document.paging.submit();

}

function goToPage(page, pageLength) {

	document.paging.currect_page.value = page * pageLength + 1;

	document.paging.page_num.value = page;

	document.paging.submit();

}


function go_search(q_id) {

	document.form1.query.value = q_id;

	document.form1.submit();

}


function rem_compare(cid, rem_id) {

	ChangeDiamondTabData("dc", cid, '', 'rem=' + rem_id);

}

function rem_compare_all(cid, rem_id) {

	ChangeDiamondTabData("rem_all_dc", cid, '', 'rem=' + rem_id);

}

function compare_diamond() {

	document.frm_search.submit();

}




function rem_compare_diamond(slink, rem_id) {

	document.general_frm.action = "DiamondFrame.asp?action=dc&compare=1&rem=" + rem_id;

	document.general_frm.target = "frmData";

	document.general_frm.rem.value = rem_id;

	document.general_frm.submit();

}


var rootElement;

var isFirst = true;





var last_div_id;
last_div_id = 0;



var rootElement;
var isFirst = true;

var isShow = false;

function hide_menu(obj) {
	if (event.srcElement.id == 'itemmenu') {
		if (!isFirst) document.all['avi'].value = event.srcElement.id;
		isFirst = false;
	}
}

function MouseOver(obj) {
	oldbgcolor = obj.bgColor;
	obj.style.color = '#000000';
	obj.bgColor = '#FFF1D7';
}
function MouseOut(obj) {
	obj.style.color = '#000000';
	obj.bgColor = oldbgcolor;
}

function help_popup(stext) { window.open("help_page.asp?help=" + stext, "openNew", "scrollbars=yes,left=0,top=0,resizable=yes,toolbar=no,height=500,width=350"); }
function show_cert(name) { window.open("show_cert.asp?file=" + name, "openNew", "scrollbars=yes,left=0,top=0,resizable=yes,toolbar=no,height=600,width=750"); }
function show_pic(name) { window.open("show_pic.asp?file=" + name, "openNew", "scrollbars=yes,left=0,top=0,resizable=yes,toolbar=no,height=650,width=750"); }

function diamond_to_compare(cat_id, ItemID) {
	postURL = "Ajax/diamond_Tab.asp?compare=" + ItemID + "&cid=" + cat_id + "&act=dc&cview=1&reply=no";
	DoPost(postURL, "This diamond was added to your comparison list. Would you like to view the list now?", "/diamonds/diamond-comparison.asp");
} 

function ChangeDiamondTabData(action, categoryID, itemID, extraData) {
	if ($("dividerin"))
		var tabDiv = j$("#dividerin");
	else
		var tabDiv = j$("#dividerin_out");
	//alert(compareView);
	if (tabDiv) {
		urlReferer = "";
		url = site + "/Ajax/diamond_Tab.asp?src_url=" + urlReferer + "&compare=" + itemID + "&cid=" + categoryID + "&act=" + action + "&cview=" + compareView + "&" + extraData;
		j$.get(url, function(data) {
			tabDiv.html(data)
			onBindComparationButtoms();
			SelectDiamonds();
		});
	}
	return;
}



function view_compare(cat_id, order_field, sort_way, framed) {
	var order_by = "";
	var sortway = "";
	if (order_field != undefined) order_by = "sortfield=" + order_field;
	if (sort_way != undefined) sortway = "&sortway=" + sort_way;
	if (cat_id == undefined) cat_id = "130";
	compareView = 1;
	ShowCloseWindowTitle = 1
	if (framed != undefined) ShowCloseWindowTitle = 0;
	ChangeDiamondTabData("dc", cat_id, '', order_by + sortway);
}

function compare_win(cat_id, item_id, useDynamic) {
	document.frm_search.target = "_parent";
	var slots = "";
	for (i = 0; i < document.frm_search.compare.length; i++) {
		if (document.frm_search.compare[i].checked == true)
			slots = slots + document.frm_search.compare[i].value + ",";
	}

	if (slots == "") {
		alert("Please check diamond to compare.")
		return false;
	}
	else
		slots = slots + '-1'

	compareView = 1;
	ShowCloseWindowTitle = 0;
	document.getElementById("frmWrap").innerHTML = "<iframe scrolling='no' frameborder='0'  id='main_ifrm' src=''></iframe>";
	ChangeDiamondTabData("dc", cat_id, '' + slots + '', '');
	return;
}

function compare(cat_id, useDynamic) {
	document.frm_search.target = "_parent";
	var slots = "";
	for (i = 0; i < document.frm_search.compare.length; i++) {
		if (document.frm_search.compare[i].checked == true)
			slots = slots + document.frm_search.compare[i].value + ",";
	}

	if (slots == "") {
		var msg = "<b>Please add a stone <br>first <input type='checkbox' checked='checked'/>and then press</b><br>";
		msg += "<img src='_images/but_compare.gif'/>";
		DrMsg.Show(msg, "comp", 275, 83);
		return false;
	}
	else
		slots = slots + '-1';
	ChangeDiamondTabData("dc", cat_id, '' + slots + '', '');
}

function compare_diamonds(cat_id, sfrom, sitem) {
	if ((cat_id == "130") || (cat_id == "131") || (cat_id == "53"))
		document.frm_search.action = "compare.asp";
	else
		document.frm_search.action = "compare.asp?cid=" + cat_id + "&compare_diamonds=1";
	if (sfrom != "frame")
		document.frm_search.target = "_parent";
	else {
		document.frm_search.target = "_self";
		document.frm_search.action = "DiamondFrame.asp?itemid=" + sitem + "&cid=" + cat_id + "&action=dc";
	}
	document.frm_search.submit();
}



function get_image(obj) {
	for (j = 0; j <= obj.childNodes.length - 1; j++) {
		if (obj.childNodes[j].tagName == "IMG") {
			return obj.childNodes[j];
		}
		else {
			return get_image(obj.childNodes[0]);
		}
	}
}


function ReplaceItemImage(target_obj, src_pic) {
	target_obj.src = site + "/" + src_pic;
}

function replace_pic(src_pic, target_obj) {
	var link = jQuery("a[href*=" + src_pic + "]");
	var parent = link.parents("table:first");
	var img = parent.find("img:first");
	img.attr("src", "/_images/education/" + src_pic);
}


function replace_image(obj_name, pic_src) {
	eval("document.getElementById('" + obj_name + "').src = pic_src");
}


function doTab(tab_id) {
	document.paging.page_num.value = "";
	document.paging.currect_page.value = "";
	document.paging.tab.value = tab_id;
	document.paging.submit();


}




function view_item(slink) {

	top.document.location = slink; // + "&shape="+document.general_frm.shape_selected.value;

}


function sorttable(field, sort, page) {

	document.paging.sortfield.value = field;

	document.paging.sortway.value = sort;

	document.paging.submit();

}


function set_style(val) {

	document.paging.cid.value = val;

	document.paging.currect_page.value = "1";

	document.paging.action = "build_your_ring.asp?cid=" + val + "&cmb=1";

	document.paging.submit();

}


function set_style_3d(val) {

	document.paging.cid.value = val;

	document.paging.currect_page.value = "1";

	document.paging.submit();

}


function view_compare_diamonds(stype) {

	var DiamStr = new Array(2);

	DiamStr[0] = new String("");

	DiamStr[1] = new String("");


	var counter = 0;

	for (i = 0; i < document.frm_search.compare.length; i++) {

		if (document.frm_search.compare[i].checked == true) {

			counter++;

			DiamStr[counter - 1] = document.frm_search.compare[i].value;

			if (counter == 3) {

				dv = document.getElementById("lyr5");

				Ypos = getY(document.getElementById("comp"));

				Xpos = getX(document.getElementById("comp")) - 250;

				ElementTop = Ypos;

				ElementLeft = Xpos;

				StartTop = Ypos;

				StartLeft = 0;

				dv.style.top = ElementTop;

				dv.style.visibility = 'visible';

				idII = window.setInterval("runElement(1)", 1);

				return false;

			}

		}

	}

	if (counter != 2) {

		dv = document.getElementById("lyr5");

		Ypos = getY(document.getElementById("comp"));

		Xpos = getX(document.getElementById("comp")) - 250;

		ElementTop = Ypos;

		ElementLeft = Xpos;

		StartTop = Ypos;

		StartLeft = 0;

		dv.style.top = ElementTop;

		dv.style.visibility = 'visible';

		idII = window.setInterval("runElement(1)", 1);

		return false;


	}

	var sDiam1 = DiamStr[0].split("-");

	var sDiam2 = DiamStr[1].split("-");

	if (stype == 'certificates') view_certificates(sDiam1[0], sDiam2[0]);

	if (stype == 'pictures') view_pictures(sDiam1[0], sDiam2[0]);

	return;


}


function open_grading(num, stype, frame, url) {

	var link = "/grading_report.asp?pic=" + num + "&type=" + stype;
	return ShowInfoWindow(link, 'ui-mb-diamonds_cert');
	return false;
}


function open_win_1(str, n_width, n_height, toolbar) {
	var toolb = (toolbar != undefined) ? toolbar : 'yes';
	window.open(str, "myWindow", "height=" + n_height + ",width=" + n_width + ",scrollbars=yes,resizable=yes,toolbar=" + toolb);
 }

function print_item(ntype, item_id, cat_id) {
	str = site + "/PrintItem.asp?cid=" + cat_id + "&item=" + item_id + "&type=" + ntype + "&print=1";
	open_win_1(str, 900, 7000);
}


function item_print() { window.print(); }



function open_print() { window.open("PrintOrder.asp", "displayWindow", "scrollbars=1,toolbar=no,width=800,height=500,top=0,left=0'"); }







function cleanString(str) {

	for (; str.charAt(str.length - 1) == " "; ) {

		str = str.slice(0, (str.length - 2));

	}

	for (; str.charAt(0) == " "; ) {

		str = str.slice(1, (str.length - 1));

	}

	return str;

}


function AddShopping() {

	if (document.all['ringsize'])

		if (document.frm1.ringsize.value == '') {

		alert("Please select Ring Size");

		return;

	}

	document.frm1.submit();
}

function select_ring(slink) {
	if (document.all['ringsize'])
		if (document.all['ringsize'].value == '') {
		alert("Please select Ring Size");
		document.all['ringsize'].focus();
		return;
	}
	if (document.all['ringsize'])
		document.location = slink + "&ringsize=" + document.all['ringsize'].value;
	else
		document.location = slink;

}


//function openNewWin3d(){window.open(site+"/show3d.asp","displayWindow","left=100,top=50,resizable=yes,scrollbars=no,toolbar=no,height=460,width=950");}





function cleanString(str) {

	for (; str.charAt(str.length - 1) == " "; ) {

		str = str.slice(0, (str.length - 2));

	}

	for (; str.charAt(0) == " "; ) {

		str = str.slice(1, (str.length - 1));

	}

	return str;

}


function cleanSpace(str) {

	var arrTemp = str.split(" ");

	str = arrTemp.join("");

	arrTemp = str.split("-");

	str = arrTemp.join("");

	return str;

}


function isValidCharacter(str, strType) {

	var isMail = false;

	var isURL = false;

	var isFile = false;

	if (strType == "eMail")

		isMail = true;

	else if (strType == "URL")

		isURL = true;

	else if (strType == "file")

		isFile = true;

	for (i = 0; i < str.length; i++) {

		if (!isMail && str.charCodeAt(i) == 64)

			return false;

		if (!isURL && !isFile && (str.charCodeAt(i) == 58 || str.charCodeAt(i) == 41 || str.charCodeAt(i) == 40))

			return false;

		if (!isURL && str.charCodeAt(i) == 47)

			return false;

		if (!isFile && str.charCodeAt(i) == 92)

			return false;

		if (str.charCodeAt(i) < 45 || str.charCodeAt(i) > 122 || str.charCodeAt(i) == 96 || (str.charCodeAt(i) > 58 && str.charCodeAt(i) < 63) || (str.charCodeAt(i) > 90 && str.charCodeAt(i) < 92) || (str.charCodeAt(i) > 92 && str.charCodeAt(i) < 95)) {

			return false;

		}

	}

	return true;

}



function IsValidData(objForm, oArrInputs) {

	var strCheck = "";

	var isValid = true;


	if (oArrInputs) {

		var arrInputs = new Array();

		for (count = 0; count < oArrInputs.length; count++)

			arrInputs[count] = oArrInputs[count];

	}


	for (count = 0; count < arrInputs.length; count++) {

		if (objForm[arrInputs[count].inputName]) {

			strCheck = cleanString("" + objForm[arrInputs[count].inputName].value).toLowerCase();

			switch (arrInputs[count].type) {

				case 0:

					{						// Text
						//alert('aaaaaaaaaaa'); 
						if (arrInputs[count].isMust && strCheck == "") {

							//alert( arrInputs[count].userName );
							ShowAlertBox(arrInputs[count].userName);

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						break;

					}

				case 17:

					{						// Credit Card

						if (arrInputs[count].isMust && Mod10(strCheck) == false) {

							//ShowAlertBox("The card number you have entered is invalid.");
							ShowAlertBox("CardNumberInvalidInfo");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						break;

					}

				case 1:

					{						// Number

						var arrTempValue = strCheck.split(".");

						if (arrInputs[count].isMust && strCheck == "") {

							ShowAlertBox("" + arrInputs[count].userName + "");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						if (arrTempValue.length > 2) {

							ShowAlertBox("" + arrInputs[count].userName + "");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						else {

							for (iCounter = 0; iCounter < arrTempValue.length; iCounter++) {

								if (isNaN(arrTempValue[iCounter])) {

									ShowAlertBox("" + arrInputs[count].userName + "");

									objForm[arrInputs[count].inputName].focus();

									objForm[arrInputs[count].inputName].select();

									isValid = false;

									return isValid;

								}

							}

						}

						break;

					}

				case 2:

					{						// TextArea

						if (arrInputs[count].isMust && strCheck == "") {

							ShowAlertBox("" + arrInputs[count].userName);

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						break;

					}

				   case 3:

					{						// Radio Button

						if (arrInputs[count].isMust)
						{

							var bSelected = false;

							var oControl = objForm[arrInputs[count].inputName];

							if (oControl.length)
							{

								for (nIndex = 0; nIndex < oControl.length; nIndex++)
								{

									if (oControl[nIndex].checked)
									{

										bSelected = true;

										break;

									}

								}

							}

							else
							{

								bSelected = oControl.checked;

							}


							if (!bSelected)
							{

								if (arrInputs[count].inputName == "include_price_on_receipt")
								{
									ShowDialogBox(null, "" + arrInputs[count].userName + ".")
									uiMessageBox.find(".ui-mb-btnAction")
											.removeAttr("onclick")
											.click(
												function ()
												{
													var value = jQuery(this).val().toUpperCase();

													var radio = jQuery("input[name='include_price_on_receipt']");
													switch (value)
													{
														case "YES":
															radio.eq(0).attr("checked", "checked");
															break;
														case "NO":
															radio.eq(1).attr("checked", "checked");
															break;
													}
													HideMessageBox();
													//	form.trigger("submit");
												}
												);
								}
								else
								{
									ShowAlertBox("" + arrInputs[count].userName + ".");
								}

								return bSelected;

							}

						}

						break;

					}

				case 4:

					{						// Checkbox


						//ShowAlertBox('test');

						if (arrInputs[count].isMust) {

							var bSelected = false;

							var oControl = objForm[arrInputs[count].inputName];

							if (oControl.length) {

								for (nIndex = 0; nIndex < oControl.length; nIndex++) {

									if (oControl[nIndex].checked) {

										bSelected = true;

										break;

									}

								}

							}

							else {

								bSelected = oControl.checked;

							}


							if (!bSelected) {

								ShowAlertBox( arrInputs[count].userName );
                                //ShowAlertBox("You must agree to the Terms of Use first.");
								return bSelected;

							}

						}

						break;

					}

	case 5:

		{						// Select

			if (arrInputs[count].isMust && (objForm[arrInputs[count].inputName].selectedIndex == -1 || objForm[arrInputs[count].inputName].value == "")) {

				
				if (arrInputs[count].userName.indexOf("You must") >= 0)
					ShowAlertBox(arrInputs[count].userName);
				else
					ShowAlertBox("No " + arrInputs[count].userName + " was selected !");

				objForm[arrInputs[count].inputName].focus();

				isValid = false;

				return isValid;

			}

			break;

		}

				case 6:

					{						// Hidden

						if (arrInputs[count].isMust && strCheck == "") {

							ShowAlertBox("" + arrInputs[count].userName + "");

							isValid = false;

							return isValid;

						}

						break;

					}

				case 7:

					{						// File

						if (arrInputs[count].isMust && (strCheck == "" && !(objForm["Exist_" + arrInputs[count].inputName]))) {

							ShowAlertBox("No " + arrInputs[count].userName + " was selected !");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						var arrFilePath = strCheck.split("\\");

						var strFileName = arrFilePath[arrFilePath.length - 1];

						if (!isValidCharacter(strFileName, "file")) {

							ShowAlertBox("File name is not valid !");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						break;

					}

				case 8:

					{						// Date

						if (arrInputs[count].isMust && strCheck == "") {

							ShowAlertBox("Please enter " + arrInputs[count].userName + " !");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						if (!isValidDate(strCheck) && strCheck != "") {

							ShowAlertBox("The date inserted in " + arrInputs[count].userName + " is not valid");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						break;

					}

				case 9:

					{						// eMail

						if (arrInputs[count].isMust && strCheck == "") {

							ShowAlertBox("" + arrInputs[count].userName + "");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						if (strCheck != "" && (((strCheck.lastIndexOf('@') < 1) || (strCheck.lastIndexOf('.') < 1) || (strCheck.lastIndexOf('.') < 2 + strCheck.lastIndexOf('@')) || (strCheck.lastIndexOf('.') > strCheck.length - 3) || (strCheck.lastIndexOf('.') < strCheck.length - 5) || (strCheck.lastIndexOf(' ') != -1) || (strCheck.lastIndexOf('.@') != -1) || (strCheck.lastIndexOf('@.') != -1)))) {

							ShowAlertBox("" + arrInputs[count].userName + "");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						break;

					}

				case 10:

					{						// Currency

						var arrTempValue = strCheck.split(".");

						if (arrInputs[count].isMust && strCheck == "") {

							ShowAlertBox("Please enter a valid " + arrInputs[count].userName + "");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						if (arrTempValue.length > 2) {

							ShowAlertBox("Please enter a valid " + arrInputs[count].userName + "");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						else {

							if (arrTempValue.length > 1) {

								if (isNaN(arrTempValue[arrTempValue.length - 1]) || arrTempValue[arrTempValue.length - 1].length > 2) {

									ShowAlertBox("Please enter a valid " + arrInputs[count].userName + "");

									objForm[arrInputs[count].inputName].focus();

									objForm[arrInputs[count].inputName].select();

									isValid = false;

									return isValid;

								}

							}

							var arrTempValue = arrTempValue[0].split(",");

							if (isNaN(arrTempValue[0])) {

								ShowAlertBox("Please enter a valid " + arrInputs[count].userName + " is not valid !");

								objForm[arrInputs[count].inputName].focus();

								objForm[arrInputs[count].inputName].select();

								isValid = false;

								return isValid;

							}

							for (iCounter = 1; iCounter < arrTempValue.length; iCounter++) {

								if (isNaN(arrTempValue[iCounter]) || arrTempValue[iCounter].length != 3) {

									ShowAlertBox("Please enter a valid " + arrInputs[count].userName + "");

									objForm[arrInputs[count].inputName].focus();

									objForm[arrInputs[count].inputName].select();

									isValid = false;

									return isValid;

								}

							}

						}

						break;

					}

				case 11:

					{						// URL

						if (arrInputs[count].isMust && strCheck == "") {

							ShowAlertBox("Please enter " + arrInputs[count].userName + " !");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						if ((arrInputs[count].isMust || strCheck != "") && (strCheck.indexOf("http://") != 0 || !isValidCharacter(strCheck, "URL") || strCheck == "http://") || strCheck == "http://www.") {

							//if ((arrInputs[count].isMust || strCheck != "") && ((strCheck.indexOf("www.") != 0 && strCheck.indexOf("http://www.") != 0) || strCheck.lastIndexOf(".")<strCheck.indexOf("www.")+6 || !isValidCharacter(strCheck, "URL"))) {

							ShowAlertBox("The URL inserted in " + arrInputs[count].userName + " is not valid");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						break;

					}

				case 12:

					{						// Select Multiple

						if (arrInputs[count].isMust && strCheck == "") {

							//ShowAlertBox("No " + arrInputs[count].userName + " was selected !");
							ShowAlertBox("" + arrInputs[count].userName + "");

							isValid = false;

							return isValid;

						}

						break;

					}

				case 13:

					{						// Counter

						break;

					}

				case 14:

					{						// DHTML control

						objForm[arrInputs[count].inputName].value = document.all[arrInputs[count].inputName + "Control"].Dom.body.innerHTML;

						strCheck = objForm[arrInputs[count].inputName].value

						if (arrInputs[count].isMust && strCheck == "") {

							ShowAlertBox("No " + arrInputs[count].userName + " was selected !");

							isValid = false;

							return isValid;

						}

						break;

					}

				case 15:

					{						// Phone - Pax

						if (arrInputs[count].isMust && strCheck == "") {

							ShowAlertBox("Please enter " + arrInputs[count].userName + " !");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						if (isNaN(cleanSpace(strCheck))) {

							ShowAlertBox("Please enter a valid " + arrInputs[count].userName + "");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						if (strCheck.length < 10) {

							ShowAlertBox("Phone number is a required field and must include the area code");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						break;

					}


				case 16:

					{						// Password

						if (strCheck == "") {

							ShowAlertBox("Please enter " + arrInputs[count].userName + " !");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						if (strCheck.length < 2 || strCheck.length > 10 || strCheck.indexOf(" ") != -1) {

							ShowAlertBox("Please enter a valid " + arrInputs[count].userName + "");

							objForm[arrInputs[count].inputName].focus();

							objForm[arrInputs[count].inputName].select();

							isValid = false;

							return isValid;

						}

						break;

					}

				default:

					{						// Custom

						if (!customCheck(objForm, arrInputs[count], strCheck))

							return false;

						else

							continue;

					}

			}

		}

	}

	return isValid;

}








function Mod10(ccNumb) {  // v2.0

	var valid = "0123456789"  // Valid digits in a credit card number

	var len = ccNumb.length;  // The length of the submitted cc number

	var iCCN = parseInt(ccNumb);  // integer of ccNumb

	var sCCN = ccNumb.toString();  // string of ccNumb

	sCCN = sCCN.replace(/^\s+|\s+$/g, '');  // strip spaces

	var iTotal = 0;  // integer total set at zero

	var bNum = true;  // by default assume it is a number

	var bResult = false;  // by default assume it is NOT a valid cc

	var temp;  // temp variable for parsing string

	var calc;  // used for calculation of each digit


	// Determine if the ccNumb is in fact all numbers

	for (var j = 0; j < len; j++) {

		temp = "" + sCCN.substring(j, j + 1);

		if (valid.indexOf(temp) == "-1") { bNum = false; }

	}

	// if it is NOT a number, you can either alert to the fact, or just pass a failure

	if (!bNum) {

		bResult = false;

	}

	// Determine if it is the proper length 

	if ((len == 0) && (bResult)) {  // nothing, field is blank AND passed above # check

		bResult = false;

	} else {  // ccNumb is a number and the proper length - let's see if it is a valid card number

		if (len >= 15) {  // 15 or 16 for Amex or V/MC

			for (var i = len; i > 0; i--) {  // LOOP throught the digits of the card

				calc = parseInt(iCCN) % 10;  // right most digit

				calc = parseInt(calc);  // assure it is an integer

				iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit

				i--;  // decrement the count - move to the next digit in the card

				iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb

				calc = parseInt(iCCN) % 10;    // NEXT right most digit

				calc = calc * 2;                                 // multiply the digit by two

				// Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,

				// I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.

				switch (calc) {

					case 10: calc = 1; break;       //5*2=10 & 1+0 = 1

					case 12: calc = 3; break;       //6*2=12 & 1+2 = 3

					case 14: calc = 5; break;       //7*2=14 & 1+4 = 5

					case 16: calc = 7; break;       //8*2=16 & 1+6 = 7

					case 18: calc = 9; break;       //9*2=18 & 1+8 = 9

					default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers

				}

				iCCN = iCCN / 10;  // subtracts right most digit from ccNum

				iTotal += calc;  // running total of the card number as we loop

			}  // END OF LOOP

			if ((iTotal % 10) == 0) {  // check to see if the sum Mod 10 is zero

				bResult = true;  // This IS (or could be) a valid credit card number.

			} else {

				bResult = false;  // This could NOT be a valid credit card number

			}

		}

	}

	return bResult; // Return the results

}




function re_order(fld) {

	var last_sort_fld = document.paging.sortfield.value;

	var last_sort_way = document.paging.sortway.value;

	if (fld == last_sort_fld)

		document.paging.sortway.value = (last_sort_way == "asc") ? "desc" : "asc";

	else

		document.paging.sortway.value = "asc";

	if ((fld == 'carat') && (last_sort_fld == '')) document.paging.sortway.value = "desc";

	document.paging.sortfield.value = fld;

	document.paging.submit();


}



function re_order_compare(fld, ItemID) {

	var last_sort_fld = document.paging.sortfield.value;

	var last_sort_way = document.paging.sortway.value;

	if (fld == last_sort_fld)

		document.paging.sortway.value = (last_sort_way == "asc") ? "desc" : "asc";

	else

		document.paging.sortway.value = "asc";

	if ((fld == 'carat') && (last_sort_fld == '')) document.paging.sortway.value = "desc";

	var sort_way = (last_sort_way == "asc") ? "desc" : "asc";


	extraData = "sortway=" + sort_way;

	extraData = extraData + "&sortfield=" + fld;

	ChangeDiamondTabData("fsd", "130", ItemID, extraData);

}



var startPos = 0;



function view_diamond(item_id) {
	document.getElementById("DiamondPage").innerHTML = GetSourceHtml("diamond_clean.asp?item=" + item_id);
}

var idI;
var LoadingMenu = false;
var _dropMetalBox = null;


/* Dead code?
function ShowMetalMenu(divID, obj) {

	var objMenu = document.getElementById("dropMetal" + divID);
	objMenu.style.visibility = objMenu.style.visibility= 'visible' ? 'hidden' : 'visible';
	obj.src = objMenu.style.visibility == 'visible' ? '_images/dropdownboxclose.gif' : '_images/dropdownbox.gif';

	//onHideMenuMetalHandler();
	_dropMetalBox = jQuery(objMenu);
	jQuery(document).bind("click", onHideMenuMetalHandler);

}
*/

/*

function ManageDropDown(url, params) {
	var definition = { itemId: "" }; //, sku: "",  ItemCounter: 1, cid: "" };
	var opts = jQuery.extend({}, definition, params);

	var container = (opts.element == undefined) ? jQuery("#dropdown" + opts.itemId) : jQuery(opts.element);

	//var container = jQuery("div.ui-clicked").first();
	var contentId = "dropcontent" + opts.itemId;
	var content = container.find("#" + contentId);
	var isActive = content.hasClass("ui-active");
   
	//jQuery("div.galery-dropdown").removeClass("ui-clicked");
	jQuery("table.ui-active, div.ui-active").hide().removeClass("ui-active");
	
  
	if (content.size() > 0) {
		if (!isActive) { content.show(); content.addClass("ui-active"); };

	}
	else {
		ShowLoader(container, opts = { align: "right", offsetX: -2 });
		jQuery.get(url, params,
		function (data) {
			jQuery(data)               
				.addClass("drop-content ui-active")
				.removeAttr("style")
				.attr("id", contentId)
				.appendTo(container);

			HideLoader();
		});
	}


	return container;
}




function ShowStudsMenu(ItemID, cid, obj) {
	ManageDropDown("/Ajax/StudsCompareTable.asp", { itemId: ItemID, cid: cid, element: obj });
}


*/

/* Region galery handlers */
function GaleryDropDownHandler(event) {

	var container = jQuery(this);
	var data = container.attr("id").split("-");
	var itemId = data[0];
	var params = { itemId: itemId }; 
	var url;

	if (container.hasClass("studs") ) {
	    params = { itemId: itemId, cid: data[1] };
        url = "/Ajax/StudsCompareTable.asp";
	}
	else {
	    params = { itemId: itemId, sku: data[1], item: itemId, ItemCounter: 1 };
	    url = "/Ajax/ItemBox.asp";
	}

	var content = container.find( "#" + itemId ).first();
	var isActive = content.hasClass("ui-active");

	jQuery("table.ui-active, div.ui-active").hide().removeClass("ui-active");

    //alert( isActive );

    if (content.size() > 0) 
    {
		if (!isActive) { content.show(); content.addClass("ui-active"); };

	}
	else {
		ShowLoader(container, opts = { align: "right", offsetX: -2 });
		jQuery.get(url, params,
		function (data) {
			jQuery(data)
				.addClass("drop-content ui-active")
				.removeAttr("style")
				.attr("id", itemId)
				.appendTo(container)
                .find(".get-item").click(GetItemBoxHandler);

			HideLoader();
		});
	}
}

function GetItemBoxHandler(event) {

    var selected = jQuery(this);
    var item = selected.parents("div.item-galery").first();
    var dropdown = selected.parents("div.galery-dropdown").first();
    var itemId = selected.attr("id");

    ShowLoader(dropdown, opts = { align: "right", offsetX: -1 });
    j$.post("Ajax/ItemBox.asp", { item: itemId, ItemCounter: 1, ContainerID: itemId },
		function (data) {
		    item.attr("id", "ItemBox" + itemId);
		    item.html(data);
		    item.find("div.galery-dropdown").click(GaleryDropDownHandler);
		    HideLoader();
		});
}

/* End region galery handlers */


function GetItemBox(item_id, ContainerID, ItemCounter) {

	if (isNaN(ItemCounter)) 
	{
		LoadItem1('', item_id, 'MetalCombo');
	}

	else {
		ShowLoader("#dropdown" + ContainerID, opts = { align: "right", offsetX: -2 });
		var item = j$("#ItemBox" + ContainerID);
		j$.post("Ajax/ItemBox.asp", { item: item_id, ItemCounter: ItemCounter, ContainerID: ContainerID },
		function (data) {
			item.attr("id", "ItemBox" + item_id);
			item.html(data);
			item.find("div.galery-dropdown").click(GaleryDropDownHandler);
		});

	}
}


function ShowMetalMenu1(item_id, obj, sku, ContainerID, ItemCounter, category) {

	var ProngSelector = $("ProngSelector");
	var ringsize = $("ringsize");

	var objMenu;


	if (ItemCounter == undefined) {

		objMenu = $("dropMetal" + item_id);
		objMenu.style.visibility = objMenu.style.visibility == 'visible' ? 'hidden' : 'visible';
		//objMenu.style.left = getX($("MetalSelectionTable"));

		if (ProngSelector) {
			ProngSelector.style.visibility = objMenu.style.visibility == 'visible' ? 'hidden' : 'visible';
			ringsize.style.visibility = objMenu.style.visibility == 'visible' ? 'hidden' : 'visible';
		}
		_dropMetalBox = jQuery(objMenu);

		if (objMenu.style.visibility == 'visible')
			setTimeout("jQuery(document).bind('click', onHideMenuMetalHandler);", 100);
	}

	else {

		objMenu = jQuery("#dropMetal" + item_id);
		objMenu.css("visibility", (objMenu.css("visibility") == "visible" ? "hidden" : "visible"));

		if (objMenu.css("visibility") == "hidden") return;

		if (ProngSelector) {
			ProngSelector.style.visibility = objMenu.style.visibility == 'visible' ? 'hidden' : 'visible';
			ringsize.style.visibility = objMenu.style.visibility == 'visible' ? 'hidden' : 'visible';
		}

		//objMenu.html("<strong style='color:#a02d2d'>Loading Menu ...</strong>");
		ShowLoader(obj);

		j$.post("Ajax/ItemBox.asp", { cat: category, sku: sku, item: item_id, ItemCounter: ItemCounter, ContainerID: ContainerID }, function (data) {
			objMenu.html(data);
			_dropMetalBox = objMenu;
			jQuery(document).bind("click", onHideMenuMetalHandler);

			HideLoader();
		}
			);

	}
}

function onHideMenuMetalHandler(e) {
	if (_dropMetalBox != null) {
		//_dropMetalBox.hide();
		_dropMetalBox.css("visibility", "hidden");
		_dropMetalBox = null;

	}
	jQuery(document).unbind("click", onHideMenuMetalHandler);
}



var OpenListObj = null;


function ShowList(objId) {

	var objMenu = $(objId);

	objMenu.style.display = objMenu.style.display == 'block' ? 'none' : 'block';

	OpenListObj = objMenu.style.display == 'block' ? $(objId) : null;



}









//===================================================================================================================




//===================================================================================================================

//	This function gets a url and opens a Xml HTTP object that will call execute this url and 

//	returns it's output.

//===================================================================================================================

function GetSourceHtml(url, sData) {

	if (sData == undefined) sData = "a";

	var xmlhttpObj;

	//Mozila's XML HTTP Object

	if (window.XMLHttpRequest) {

		try {

			//netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");

			xmlhttpObj = new XMLHttpRequest();

			xmlhttpObj.open("POST", url, false);

			xmlhttpObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

			//xmlhttpObj.setRequestHeader('Content-length', '10000');

			xmlhttpObj.send(sData);


		}

		catch (e) {

			//ShowAlertBox("(Mozilla) - " + e);

			return null;

		}

	} //end Mozila

	else if (window.ActiveXObject)	// IE's XML HTTP Object
	{



		xmlhttpObj = new ActiveXObject("Microsoft.XMLHTTP")

		if (xmlhttpObj) {

			//xmlhttpObj.onreadystatechange=AAS;

			xmlhttpObj.open("POST", url, false);

			xmlhttpObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')

			//xmlhttpObj.setRequestHeader('Content-length', '1000');

			xmlhttpObj.send(sData);

		}


	} //end IE


	return xmlhttpObj.responseText;

}


//===================================================================================================================

//	This function is responsible for the tab in the diamond information page to chage in client side.

//	it gets a chageTo var where:

//	"pd" 	= Product Details

//	"fsd" 	= Find Similar Diamonds

//	"dc"	= Diamond Comparison 

//===================================================================================================================


function show_diamond(DiamondObject, evt) {
	
	var tbObj = $("RecentlyViewedTB");

	var diamObj = $("DiamondDetails1");


	if (diamObj == null) {

		j$("<div id='DiamondDetails1' />").css({ position: "absolute", "z-index": 1000 }).appendTo(document.body);
		diamObj = $("DiamondDetails1");
	}

	if (DiamondObject == -1) {
		diamObj.style.visibility = 'hidden';
		return;

	}
	
	if (tbObj == null) {
		tbObj = evt.target;
	}


	var H = "ssssss";

	var s = '<div  style="width:193px; height:198px; background-image:url(\'Slider2/Images/InfoBG.png\'); z-index:1; padding-top:8px; background-repeat:no-repeat;">';



	s += "<table  cellpadding='0' cellspacing='0' style=\"margin:0px 2px 0px 20px;\">" +
			  "<tr><td height='22px' colspan=\"2\" style=\"padding-bottom:7px;\"><b style='color:#747474; font-size:11px;'>Diamond Info</b></td></tr>";

	s += "<tr><td style=\"color:#747474; font-size:11px; padding:0px; line-height:14px;\">Item#:</td><td style=\"color:#747474; font-size:11px; padding:0px 0px 0px 3px; line-height:14px;\"><a href=\"" + DiamondObject.dlink + "\">" + DiamondObject.did + "</a></td></tr>";


	s += "<tr><td style=\"color:#747474; font-size:11px; padding:0px; line-height:14px;\">Depth:</td><td style=\"color:#747474; font-size:11px; padding:0px 0px 0px 3px; line-height:14px;\">" + DiamondObject.ddepth + "</td></tr>";
	s += "<tr><td style=\"color:#747474; font-size:11px; padding:0px; line-height:14px;\">Table:</td><td style=\"color:#747474; font-size:11px; padding:0px 0px 0px 3px; line-height:14px;\">" + DiamondObject.dtable + "</td></tr>";
	s += "<tr><td style=\"color:#747474; font-size:11px; padding:0px; line-height:14px;\">Polish:</td><td style=\"color:#747474; font-size:11px; padding:0px 0px 0px 3px; line-height:14px;\">" + DiamondObject.dpolish + "</td></tr>";
	s += "<tr><td style=\"color:#747474; font-size:11px; padding:0px; line-height:14px;\">Symetry:</td><td style=\"color:#747474; font-size:11px; padding:0px 0px 0px 3px; line-height:14px;\">" + DiamondObject.dsymetry + "</td></tr>";
	s += "<tr><td style=\"color:#747474; font-size:11px; padding:0px; line-height:14px;\">Girdle:</td><td style=\"color:#747474; font-size:11px; width:20px ; padding:0px 0px 0px 3px; line-height:14px;\">" + DiamondObject.dgirdle + "</td></tr>";
	s += "<tr><td style=\"color:#747474; font-size:11px; padding:0px; line-height:14px;\">Measurement:</td><td style=\"color:#747474; font-size:11px; padding:0px 0px 0px 3px; line-height:14px;\">" + DiamondObject.dmeasur + "</td></tr>";
	s += "<tr><td style=\"color:#747474; font-size:11px; padding:0px; line-height:14px;\">Lab:</td><td style=\"color:#747474; font-size:11px; padding:0px 0px 0px 3px; line-height:14px;\">" + DiamondObject.dmeasur + "</td></tr>";




	s = s + "</table>";

	s += '</div>'; 



}



var cursor;

function getPosition(e) {

	e = e || window.event;

	cursor = { x: 0, y: 0 };

	if (e.pageX || e.pageY) {

		cursor.x = e.pageX;

		cursor.y = e.pageY;

	}

	else {

		var de = document.documentElement;

		var b = document.body;

		cursor.x = e.clientX +
			(de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);

		cursor.y = e.clientY +
			(de.scrollTop || b.scrollTop) - (de.clientTop || 0);

	}

	return cursor;

}




function ChangeDiamondTabData(action, categoryID, itemID, extraData) {
	if ($("dividerin"))
		var tabDiv = j$("#dividerin");
	else
		var tabDiv = j$("#dividerin_out");
	//alert(compareView);
	if (tabDiv) {
		urlReferer = "";
		url = site + "/Ajax/diamond_Tab.asp?src_url=" + urlReferer + "&compare=" + itemID + "&cid=" + categoryID + "&act=" + action + "&cview=" + compareView + "&" + extraData;
		j$.get(url, function(data) {
			tabDiv.html(data)
			onBindComparationButtoms();
			SelectDiamonds();
		});
	}
	return;
}




function ChangeDiamondTabSwitchCompare(action, categoryID, itemID, t, click) {

	if (click == undefined) click = "0";

	if (document.getElementById("dividerin"))

		var tabDiv = document.getElementById("dividerin");

	else

		var tabDiv = document.getElementById("dividerin_out");


	compareView++;
	compareView %= 2;
	tabDiv.innerHTML = GetSourceHtml(site + "/diamond_Tab.asp?click=" + click + "&ShowCloseWindowTitle=" + ShowCloseWindowTitle + "&frame=" + FramedWindow + "&ItemID=" + ReffererItemID + "&ccid=" + ReffererCategoryID + "&item=" + itemID + "&cid=" + categoryID + "&act=dc&cview=" + compareView);
	onBindComparationButtoms();
}




//===================================================================================================

//	This function lets showModelDialog to function even in browsers other the IE.

//	Note: the 'center' feature must be declared last (after 'dialogHeight' and 'dialogWidth'

//===================================================================================================


function ProccessCustomerRequest(ItemID, ImageType, FirstName, LastName, Email, Phone) {
	var result = false;
	j$.get("Ajax/SubmitGrading.asp", { ItemID: ItemID, ImageType: ImageType, FirstName: FirstName, LastName: LastName, Email: Email, Phone: Phone }, function(data) {
		if (data == "OK") valid(true); else valid(false);
	}); 

	
}

function getMovie() {
	var M$ = navigator.appName.indexOf("Microsoft") != -1
	return (M$ ? window : document)["image_viewer_extended_v2"]
	
}

function valid(returnreq) {
	getMovie().vrequest(returnreq);
}

//===================================================================================================

//	This function dynamcly loads a flash movie into the inputed div

//===================================================================================================



// function to open div in compare //

function SwitchMenu(obj) {

	try {

		if ($('sub_' + obj).style.display == 'none')

			$('sub_' + obj).style.display = '';

		else

			$('sub_' + obj).style.display = 'none';

	}

	catch (e) { }

}


function GoToSelect(url) {

	a = document.getElementById(url).value;

	window.open(a);

}



function UpdateStars(index) {

	for (i = 1; i <= index; i++) {

		$('IconStar' + i).src = 'http://static1.jamesallen.com/_images/page/icon_star_gold.gif';

	}

	for (i = index + 1; i <= 5; i++) {

		$('IconStar' + i).src = 'http://static1.jamesallen.com/_images/page/icon_star_gold_off.gif';

	}


	document.form1.score.value = index;

	$('IconsNum').innerHTML = index;

}



function ShowMessage(text, onSucessLink, onFailLink) {


	var answer = confirm(text)

	if (answer) {

		window.location = document.location = onSucessLink;

	}

	else {

		document.location = onFailLink;

	}

}

function ShowImage(objImg, newImg) {
	objImg.src = newImg;
}


function fieldValidate(strInputName, intType, strUserName, bolIsMust) {

	this.inputName = strInputName;

	this.type = intType;

	this.userName = strUserName;

	this.isMust = bolIsMust;

}

function LoadFlashObject(flashMovie, nWidth, nHeight, divID, params, wmode) {

	//creating the container for the banner


	var FlashBannerContainer = $(divID);
	if (!FlashBannerContainer) return false;
	var flashCode = "";

	flashCode += "<OBJECT id='image_viewer_extended_v2' style='top:0px;vertical-align:top;float:inherit' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'  ";

	flashCode += "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0'";

	flashCode += "WIDTH='" + nWidth + "' HEIGHT='" + nHeight + "' ALIGN='Top' VIEWASTEXT float='top' margin-left='15' >";

	flashCode += "<PARAM NAME=movie VALUE='" + flashMovie + "'>";
	flashCode += "<PARAM NAME=allowScriptAccess VALUE='always'>";
	flashCode += "<PARAM NAME=quality VALUE=high>";

	flashCode += "<param name=flashVars value='strVideoPath=" + params + "&bAutoLoop=true'/>";

	if (wmode != undefined) flashCode += "<param name='wmode' value='transparent'>"

	flashCode += "<EMBED  id='image_viewer_extended_v2' name='image_viewer_extended_v2'   allowScriptAccess='always' allowFullScreen='false'  flashVars='strVideoPath=" + params + "&bAutoLoop=true' style='margin-bottom:0;' src='" + flashMovie + "'  quality='high' WIDTH='" + (nWidth + 1) + "' HEIGHT='" + (nHeight + 1) + "' ALIGN='Top' "

	if (wmode != undefined) flashCode += " wmode='transparent' ";

	flashCode += "TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED>";

	flashCode += "</OBJECT>";

	FlashBannerContainer.innerHTML = flashCode;

}


