﻿var sort = "1 ASC,";
var active = 0;
var moreOp = 0;
var strMsg = "";
var gSliderGup = 267;
var gCid = 130;
var gHA = false;
var gSearchType = 'Loose'; // Loose /Ring   
var gST = 'Loose';
var coockie = new Coockie();
var jas = "slider2/";
var gAdmin = '0';
function $(v) { return document.getElementById(v); };
function no$(v) { var sv = new String(v); return sv.replace(/,/g, "").replace("$", ""); };

/********************************************************
LI
********************************************************/
//#region
function LI(name, title, centerImg, slctdImage, notSlctdImg, rightImg, rightSlctdImg) {
	this.IsSlctd = false;
	this.IsEnabled = true;
	this.Name = name;
	this.Title = title;
	if (centerImg != null) { this.CenterImg = centerImg; };

	this.SlctdImage = slctdImage;
	this.NotSlctdImg = notSlctdImg;
	this.ListName = "";
	this.ItemNum = 0;
	this.Width = 20;
	this.RightImg = rightImg;
	this.RightSlctdImg = rightSlctdImg;
};
LI.prototype.SetIsSlctd = function(isSlctd) {
	this.IsSlctd = isSlctd;
	var e = $(this.ListName + this.ItemNum);
	e.style.backgroundImage = (isSlctd) ? 'url(' + this.SlctdImage.src + ')' : 'url(' + this.NotSlctdImg.src + ')';
	if (this.RightImg)
		$(this.ListName + this.ItemNum + 'Right').src = (isSlctd) ? this.RightSlctdImg.src : this.RightImg.src;
};
LI.prototype.Toggle = function() {
	this.SetIsSlctd(!this.IsSlctd);
};
LI.prototype.GetHtml = function() {
	var html = '<td onclick="' + this.ListName + '.Click(' + this.ItemNum + ')" id="' + this.ListName + this.ItemNum + '" style="background-image: url(' + this.NotSlctdImg.src + '); width:' + this.Width + 'px; text-align:left; vertical-align:top;">';
	var height = eval(this.ListName + ".Height");
	if (this.RightImg)
		html += '<div style="position: absolute; width:' + this.Width + 'px;"><img id="' + this.ListName + this.ItemNum + 'Right" src="' + this.RightImg.src + '" style="position:relative; left:' + (this.Width - 6) + 'px;" ></div>';
	html += '<table cellspacing="0" cellpadding="0" style="position: absolute; width:' + this.Width + 'px; height:' + height + 'px;"><tr><td style="text-align:center; vertical-align:middel;">';
	if (this.CenterImg != null && this.CenterImg != 'undefined')
		html += '<img style="visibility:visible;" src="' + this.CenterImg + '"/>';
	else
		html += '<span style="visibility:visible;">' + this.Title + '</span>';
	html += '</td></tr></table></td>';
	return html;
};
//#endregion

/********************************************************
Buttonlist
********************************************************/
//#region
function Buttonlist(name, itemWidth, height) {
	this.List = new Array();
	this.Count = 0;
	this.Name = name;
	this.DisplayNAme = name;
	this.SlctdItem = null;
	this.ItemWidth = itemWidth;
	this.Height = height;
	this.Mode = "Redio";
};
Buttonlist.prototype.Select = function(ItemNum) {
	if (this.SlctdItem != null)
		this.SlctdItem.SetIsSlctd(false);
	this.List[ItemNum].SetIsSlctd(true);
	this.SlctdItem = this.List[ItemNum];
};
Buttonlist.prototype.SelectRange = function(values) {
	var vals = "," + values + ",";
	for (var i = 0; i < this.List.length; i++) {
		if (vals.indexOf("," + this.List[i].Name + ",") > -1)
			if (this.Mode == "Redio")
			this.Select(i);
		else
			this.List[i].SetIsSlctd(true);
	}
};
Buttonlist.prototype.SelectKeyRange = function(Keys) {
	for (var i = 0; i < this.List.length; i++) {
		if (Keys.indexOf(i.toString()) > -1)
			this.List[i].SetIsSlctd(true);
	}
};
Buttonlist.prototype.Toggle = function(ItemNum) {
	this.List[ItemNum].Toggle();
};
Buttonlist.prototype.Click = function(ItemNum) {
	if (this.List[ItemNum].IsEnabled) {
		if (this.Mode == "Redio")
			this.Select(ItemNum);
		else
			this.Toggle(ItemNum);

		coockie.Set(gSearchType + "_" + this.Name, this.GetSlctdValues());
		if (active == 1) {
			GetData(1);
		}
	}
};
Buttonlist.prototype.LoadFromCoockie = function() {
	if (coockie.Get(gSearchType + "_" + this.Name))
		this.SelectRange(coockie.Get(gSearchType + "_" + this.Name));
};
Buttonlist.prototype.SetEnabled = function(values) {
	for (var i = 0; i < this.List.length; i++) {
		if (values.indexOf(this.List[i].Name) > -1)
			this.List[i].IsEnabled = true;
		else {
			this.List[i].IsEnabled = false;
			this.List[i].NotSlctdImg = new Image();
			this.List[i].NotSlctdImg.src = 'img/Titlebgl.gif';
			this.List[i].RightImg = new Image();
			this.List[i].RightImg.src = jas + 'Images/DisableRight.gif';
			this.List[i].SetIsSlctd(false);
		}
	}
};
Buttonlist.prototype.Add = function(listItem) {
	listItem.ListName = this.Name;
	listItem.ItemNum = this.Count;
	listItem.Width = this.ItemWidth;
	this.List[this.Count] = listItem;
	this.Count += 1;
};
Buttonlist.prototype.GetHtml = function() {
	var html = "<table class=\"Pane\" cellpadding=\"0\" cellspacing=\"0\"><tr>";
	html += "<td class=\"LableText\" style=\"height:" + this.Height + "px; width: 42px;\">";
	html += "<span style=\"visibility:visible;\" title=\"Click button to select\">" + this.DisplayNAme + "</span>";
	html += "</td>";
	for (var i = 0; i < this.Count; i++) {
		html += this.List[i].GetHtml();
	}
	html += "</tr></table>";
	return html;
};
Buttonlist.prototype.GetSlctdValues = function(isTitle) {
	var sv = "", f = false;
	for (var i = 0; i < this.Count; i++) {
		if (this.List[i].IsSlctd) {
			if (f)
				sv += ",";
			sv += isTitle ? this.List[i].Title : this.List[i].Name;
			f = true;
		}
	}
	return sv;
};
//#endregion

// Cookies
//#region
function eraseCookie() {
	createCookie("", -1);
};

function createCookie(value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = ";expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = "R2SearchClient=" + value + expires + ";domain=jamesallen.com";
};

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length, c.length);
	}
	return null;
};

function Coockie() {
	this.Dict = new Array();
}

Coockie.prototype.Save = function() {
	var coockieStr = "";
	for (key in this.Dict) {
		coockieStr += key + "|" + this.Dict[key] + "&";
	}
	createCookie(escape(coockieStr), 1);
}

Coockie.prototype.Load = function(forceClient) {
	var coockieClient = unescape(readCookie("R2SearchClient"));
	var coockieServer = unescape(readCookie("R2SearchServer"));
	if (!forceClient) {
		if (coockieClient == null)
			coockieClient = coockieServer;
		else {
			var clientTime = coockieClient.substring(coockieClient.indexOf("Now", 0), coockieClient.indexOf("TimeEnd", 0))
			var ServerTime = coockieServer.substring(coockieServer.indexOf("Now", 0), coockieServer.indexOf("TimeEnd", 0))
			if (clientTime != ServerTime)
				coockieClient = coockieServer;
		}
	}
	var keyValuePairs = coockieClient.split('&');
	for (var i = 0; i < keyValuePairs.length; i++) {
		var kv = keyValuePairs[i].split('|');
		this.Dict[kv[0]] = kv[1];
	}
	//strMsg += "<hr/>coockieClient=" + coockieClient +"<hr/>coockieServer=" +  coockieServer;
}

Coockie.prototype.Set = function(key, value) { this.Dict[key] = value; }
Coockie.prototype.Get = function(key) { return this.Dict[key]; }
//#endregion

/********************************************************
Sliders
********************************************************/
//#region
function SliderItem(title, visible, minRange, maxRange) {
	this.Title = title;
	this.Visible = visible;
	this.MinRange = minRange;
	this.MaxRange = maxRange;
	this.FromValue = minRange;
	this.ToValue = maxRange;
}

SliderItem.prototype.GetHtml = function() {
	this.FromValue = this.CalcValue(0);
	this.ToValue = this.CalcValue(1);
	var s = "<table cellpadding=\"0\" cellspacing=\"0\" class=\"SildePane\"><tr>" +
            "<td class=\"LableText\" style=\"width: 42px;\">" +
             "<span style=\"visibility:visible;\">" + this.Title + "</span></td>" +
            "<td>";
	if (NIE1) s += "<div style=\"margin-left: 1px;\" >";
	s += " <div style=\"position: absolute; width: 296px; visibility:visible;\">" +
                    "<div id=\"SliderTrackMin\" class=\"TrackShadow\" style=\"float: left;\"></div> " +
                    "<div id=\"SliderTrackMax\" class=\"TrackShadow\" style=\"float: right;\"></div>" +
                "</div>" +
                "<div style=\"position: absolute; width: 296px; visibility:visible;\">" +
                       "<img id=\"SliderThumbMinImg\"  src=\"img/sliderMin.gif\" width=\"10\" height=\"21\" alt=\"\" style=\"z-index: 200; cursor:pointer; position: relative; left: 5px; display: inline;\" />" +
                   "    <img id=\"SliderThumbMaxImg\"  src=\"img/sliderMax.gif\" width=\"10\" height=\"21\" alt=\"\" style=\"z-index: 200; cursor:pointer; position: relative; left: 268px; display: inline;\" />" +
                "</div>" +
                "<div style=\"position: absolute; width: 296px; z-index:1000; visibility:visible;\">" +
                       "<img id=\"SliderThumbMin\" src=\"" + jas + "Images/sliderTT.gif\" width=\"10\" height=\"21\" alt=\"\" style=\"z-index: 200; cursor:pointer; position: relative; left: 5px; display: inline;\" />" +
                   "    <img id=\"SliderThumbMax\" src=\"" + jas + "Images/sliderTT.gif\" width=\"10\" height=\"21\" alt=\"\" style=\"z-index: 200; cursor:pointer; position: relative; left: 268px; display: inline;\" />" +
                "</div>" +
                "<div id=\"SliderValueDisplay\" onmouseover=\"document.onselectstart = function () { return false; };\" onmouseout=\"document.onselectstart=null;\" style=\"color: black; position: absolute; z-index: 100; cursor: default;font-family: Verdana; width: 296px; font-size: 10px; text-align:center; margin-top:3px;  visibility:visible;\">" + this.FromValue + " - " + this.ToValue + "</div>" +
                "<img name=\"Track\" src=\"img/blank.gif\" width=\"296px\" height=\"21px\" alt=\"\">";
	if (NIE1) s += "</div>";
	s += "</td></tr></table>";
	s = s.replace(/Slider/g, this.Title);
	////strMsg += "<hr/><textarea>" + s + "</textarea>";
	return s;
}

SliderItem.prototype.CalcValue = function(inputVal) {
	return (this.MinRange + (inputVal * (this.MaxRange - this.MinRange))).toFixed(1);
}

function number_format(a, b, c, d) {
	// number_format(number, decimals, comma, formatSeparator)
	a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
	e = a + '';
	f = e.split('.');
	if (!f[0]) f[0] = '0';
	if (!f[1]) f[1] = '';
	if (f[1].length < b) {
		g = f[1];
		for (i = f[1].length + 1; i <= b; i++) {
			g += '0';
		}
		f[1] = g;
	}
	if (d != '' && f[0].length > 3) {
		h = f[0];
		f[0] = '';
		for (j = 3; j < h.length; j += 3) {
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = d + i + f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
	c = (b <= 0) ? '' : c;
	return f[0] + c + f[1];
}

SliderItem.prototype.CalcNormal = function(value) {
	return (value - this.MinRange) / (this.MaxRange - this.MinRange);
}

SliderItem.prototype.SetValues = function(fromVal, toVal) {
	var min = parseInt(this.CalcNormal(fromVal) * gSliderGup) + 5;
	if (fromVal < this.CalcValue(min))
		min = min - 1;
	var max = parseInt(this.CalcNormal(toVal) * gSliderGup) + 1;
	if (toVal > this.CalcValue(max))
		max = max + 1;
	SetSliderValues(this.Title, min, max);
}

SliderItem.prototype.LoadFromCoockie = function() {
	var from = coockie.Get(gSearchType + "_" + this.Title + "From");
	if (!from)
		from = this.MinRange;
	var to = coockie.Get(gSearchType + "_" + this.Title + "To");
	if (!to)
		to = this.MaxRange;
	this.SetValues(from, to);
}
//#endregion

/********************************************************
Drag & Drop
********************************************************/
//#region
var NIE1 = (document.all) ? 0 : 1;
var ob1, X, Y, offsetX, offsetY, thambType, curSlider;
function MD(e) {
	testMMEventCounter += 1;
	var thumb = (NIE1) ? e.target : event.srcElement;
	if (thumb.id.indexOf("Thumb") > -1) {
		var tmbType = (thumb.id.indexOf("Max") > -1) ? "Max" : "Min";
		var sliderName = thumb.id.replace(/Min/, "").replace(/Max/, "").replace(/Thumb/, "")
		// cancel out any text selections
		document.body.focus();
		// prevent text selection in IE
		document.onselectstart = function() { return false; };

		ob1 = thumb.style;
		offsetX = parseInt(thumb.style.left);
		offsetY = parseInt(thumb.style.top);
		thambType = tmbType;
		curSlider = Sliders[sliderName];
		if (NIE1) { X = e.pageX; Y = e.pageY; }
		else { X = event.clientX; Y = event.clientY; }

		return false;
	}
}

var testMMEventCounter = 0;
function MM(e) {
	testMMEventCounter += 1;
	if (curSlider) {
		var sliderName = curSlider.Title;
		var l = (NIE1) ? e.pageX : event.clientX;
		l += -X + offsetX;
		if (thambType == "Min") {
			if (l > 4 && l < parseInt($(sliderName + 'ThumbMax').style.left) + 4 && l % 2 == 0)
				SetSliderValues(sliderName, l, null);
		}
		else {
			if (l > parseInt($(sliderName + 'ThumbMin').style.left) - 4 && l < 269 && l % 2 == 0)
				SetSliderValues(sliderName, null, l);
		}
		return false;
	}
}

function SetSliderValues(sliderTitle, min, max) {
	if (min) {
		$(sliderTitle + 'ThumbMin').style.left = min;
		$(sliderTitle + 'ThumbMinImg').style.left = min;
		$(sliderTitle + 'TrackMin').style.width = min;
		var f = Sliders[sliderTitle].CalcValue((min - 3 - 2) / gSliderGup);
		Sliders[sliderTitle].FromValue = (f < Sliders[sliderTitle].MinRange) ? Sliders[sliderTitle].MinRange : f;
	}
	if (max) {
		$(sliderTitle + 'ThumbMax').style.left = max;
		$(sliderTitle + 'ThumbMaxImg').style.left = max;
		$(sliderTitle + 'TrackMax').style.width = (277 - max);
		var t = Sliders[sliderTitle].CalcValue((max - 3 + 2) / gSliderGup);
		Sliders[sliderTitle].ToValue = (t > Sliders[sliderTitle].MaxRange) ? Sliders[sliderTitle].MaxRange : t;
	}
	if (sliderTitle == 'Carat')
		$(sliderTitle + 'ValueDisplay').innerHTML = ' &nbsp; &nbsp; &nbsp; &nbsp; ';
	else
		$(sliderTitle + 'ValueDisplay').innerHTML = '';
	$(sliderTitle + 'ValueDisplay').innerHTML += Sliders[sliderTitle].FromValue;
	$(sliderTitle + 'ValueDisplay').innerHTML += " - " + Sliders[sliderTitle].ToValue;
}

function MU() {
	ob1 = null; thambType = null;
	if (curSlider) {
		coockie.Set(gSearchType + "_" + curSlider.Title + "From", curSlider.FromValue);
		coockie.Set(gSearchType + "_" + curSlider.Title + "To", curSlider.ToValue);
		coockie.Save();
		GetData(1);
	}
	curSlider = null;  //document.onselectstart=null;

}
document.onmousedown = MD;
document.onmousemove = MM;
document.onmouseup = MU;
//#endregion

/********************************************************
Get Data & Display It
********************************************************/
//#region
var pageSize = 10;
function GetXmlUrl(PageNum) {
	coockie.Set("pageSize", pageSize);
	coockie.Set("moreOp", moreOp);
	var qs = "PS=" + pageSize + "&PN=" + PageNum + "&S=" + Shape.GetSlctdValues();
	qs += "&C=" + Cut.GetSlctdValues();
	qs += "&Col=" + Color.GetSlctdValues();
	qs += "&Cla=" + Clarity.GetSlctdValues();
	qs += "&CrtF=" + Sliders["Carat"].FromValue;
	qs += "&CrtT=" + Sliders["Carat"].ToValue;
	qs += "&PrF=" + no$(Sliders["Price"].FromValue);
	qs += "&PrT=" + no$(Sliders["Price"].ToValue);
	if (moreOp == 1) {
		qs += "&Pol=" + Polish.GetSlctdValues();
		qs += "&Sym=" + Symmetry.GetSlctdValues();
		qs += "&Fluor=" + Fluor.GetSlctdValues();
		qs += "&Lab=" + Lab.GetSlctdValues();
		if (Sliders["Depth"].FromValue != Sliders["Depth"].MinRange)
			qs += "&DptF=" + Sliders["Depth"].FromValue;
		if (Sliders["Depth"].ToValue != Sliders["Depth"].MaxRange)
			qs += "&DptT=" + Sliders["Depth"].ToValue;
		if (Sliders["Table"].FromValue != Sliders["Table"].MinRange)
			qs += "&TblF=" + Sliders["Table"].FromValue;
		if (Sliders["Table"].ToValue != Sliders["Table"].MaxRange)
			qs += "&TblT=" + Sliders["Table"].ToValue;
	}
	qs += "&OrderBy=" + sort.substring(0, sort.length - 1);
	qs += "&MOP=" + (moreOp == 1).toString();
	qs = jas + "Search.ashx?" + qs;
	strMsg += "<br/> " + qs;
	return qs;
};

function sendRequest(url, callback, postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method, url, true);
	req.setRequestHeader('User-Agent', 'XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	req.onreadystatechange = function() {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
			//			alert('HTTP error ' + req.status);
			return;
		}
		callback(req);
	}
	if (req.readyState == 4) return;
	req.send(postData);
};

var XMLHttpFactories = [
	        function() { return new XMLHttpRequest() },
	        function() { return new ActiveXObject("Msxml2.XMLHTTP") },
	        function() { return new ActiveXObject("Msxml3.XMLHTTP") },
	        function() { return new ActiveXObject("Microsoft.XMLHTTP") }
        ];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i = 0; i < XMLHttpFactories.length; i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		} catch (e) { continue; }
		break;
	}
	return xmlhttp;
};

function GetData(pageNumber, order) {
	if (!pageNumber || pageNumber + '' == 'undefined') {
		if (coockie.Get("PageNumber"))
			pageNumber = coockie.Get("PageNumber");
		else
			pageNumber = 1;
	}

	ShowUpdatingStatus();
	if (order != 'SAME') {
		if (order == '' || order == null || order == 'undefined') {
			if (coockie.Get("Sort"))
				sort = coockie.Get("Sort");
			else
				sort = '';
		}
		else {
			var so = order + " DESC,";
			if (sort.indexOf(so, 0) >= 0)
				sort = order + " ASC," + sort.replace(so, "");
			else
				sort = so + sort.replace(order + " ASC,", "");
		}
	}
	sendRequest(GetXmlUrl(pageNumber), GotData);
	coockie.Set("Sort", sort);
	coockie.Set("PageNumber", pageNumber);
	coockie.Save();
}

var xslDom;
sendRequest(jas + "Search.xsl", setXsl);

function setXsl(req) {
	//strMsg +=  "<hr/>setXsl(req)";
	if (NIE1)
		xslDom = getDomFromXml(req.responseText);
	else {
		xslDom = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0");
		xslDom.async = false;
		xslDom.loadXML(req.responseText);
	}
}

function GotData(req) {
	var xml = req.responseText;
	if (gST != "Loose") {
		var url = document.location.toString();
		url = url.substring(0, url.indexOf("?"));
		xml = xml.replace(/NoLink/, url);
		//strMsg = xml;
	}
	else
	{ xml = xml.replace(/NoLink/, ''); }
	$('SearchResults').innerHTML = xslt(getDomFromXml(xml), xslDom);
	gvDetailsData = tbSearchResults();
	HideUpdatingStatus();
	ShowInfo();
}

function ShowInfo() {
	var selectedValue;

	$('TopBound').innerHTML = "We have " + number_format($('NOR').innerHTML, 0, '.', ',') + " <b>" + Shape.GetSlctdValues() +
        "</b> diamonds between <b>" + Sliders["Carat"].FromValue + "-" + Sliders["Carat"].ToValue +
        "</b> carat";

	if (no$(Sliders["Price"].FromVlue) != Sliders["Price"].MinRange || no$(Sliders["Price"].ToValue) != Sliders["Price"].MaxRange)
		$('TopBound').innerHTML += ", <b>" + Sliders["Price"].FromValue + "-" + Sliders["Price"].ToValue + "</b>";

	if (Color.GetSlctdValues() != '')
		$('TopBound').innerHTML += ", <b>" + Color.GetSlctdValues() + "</b> color";

	if (Clarity.GetSlctdValues() != '')
		$('TopBound').innerHTML += ", <b>" + Clarity.GetSlctdValues() + "</b> clarity";

	if (Cut.GetSlctdValues() != '')
		$('TopBound').innerHTML += ", <b>" + Cut.GetSlctdValues().replace(/HA/, "H&A") + "</b> cut";

	if (moreOp == 1) {
		if (Polish.GetSlctdValues() != '')
			$('TopBound').innerHTML += ", <b>" + Polish.GetSlctdValues() + "</b> polish";

		if (Symmetry.GetSlctdValues() != '')
			$('TopBound').innerHTML += ", <b>" + Symmetry.GetSlctdValues() + "</b> symmetry";

		if ((selectedValue = Fluor.GetSlctdValues(true)) != "")
			$('TopBound').innerHTML += ", <b>" + selectedValue + "</b> Fluor";

		if ((selectedValue = Lab.GetSlctdValues(true)) != "")
			$('TopBound').innerHTML += ", <b>" + selectedValue + "</b> Certificate";

		if (Sliders["Depth"].FromVlue != Sliders["Depth"].MinRange || Sliders["Depth"].ToValue != Sliders["Depth"].MaxRange)
			$('TopBound').innerHTML += ", <b>" + Sliders["Depth"].FromValue + "-" + Sliders["Depth"].ToValue + "</b> Depth";

		if (Sliders["Table"].FromVlue != Sliders["Table"].MinRange || Sliders["Table"].ToValue != Sliders["Table"].MaxRange)
			$('TopBound').innerHTML += ", <b>" + Sliders["Table"].FromValue + "-" + Sliders["Table"].ToValue + "</b> table";
	}
	$('TopBound').innerHTML += ".";
}

function ShowUpdatingStatus() {
	$("Loading").style.left = (findPosX($('TopBound')) + 345 - parseInt($("Loading").style.width) / 2) + "px";
	$("Loading").style.top = (findPosY($('TopBound')) + 50) + "px"; ;
	$("Loading").style.display = 'block';
};

function HideUpdatingStatus() {
	$("Loading").style.display = 'none';
}

function getDomFromXml(xml) {
	if (typeof ActiveXObject != 'undefined') {
		var dom = new ActiveXObject("Microsoft.XMLDOM");
		dom.async = false;
		dom.loadXML(xml);
	}
	else {
		parser = new DOMParser();
		dom = parser.parseFromString(xml, "text/xml");
	}
	return dom;
}

function xslt(xmlDoc, xslDoc) {
	var transform;
	if (typeof ActiveXObject != 'undefined') {
		var template = new ActiveXObject("MSXML2.XSLTemplate.3.0")
		template.stylesheet = xslDoc;
		var xslProc = template.createProcessor()
		xslProc.input = xmlDoc;
		xslProc.addParameter("Admin", gAdmin)
		xslProc.transform()
		transform = xslProc.output;

	}
	else {
		var xsl = new XSLTProcessor();
		xsl.importStylesheet(xslDoc);
		xsl.setParameter(null, "Admin", gAdmin);
		var fragment = xsl.transformToFragment(xmlDoc, document);
		if (fragment.childNodes.length > 0)
			transform = fragment.childNodes[0].innerHTML;
		else
			alert("error");
	}
	return transform;
}

function ShowAdvance(mode) {
	$('advance1').style.display = mode;
	$('advance2').style.display = mode;
	$('advance3').style.display = mode;
	$('advance4').style.display = mode;
	moreOp = (mode == 'none') ? 0 : 1;
	if (active == 1)
		GetData(1, '');
}
//#endregion

/********************************************************
Imaplamentation
********************************************************/
//#region
var loaded = 0
function ReportLoaded() {
	loaded++;
	if (loaded > 7)
		LoadSearch();
};

var Shape = new Buttonlist("Shape", 30, 34);
Shape.Mode = "Redio";

function LoadShape() {
	Shape.Add(new LI("Round", "", "img/blank.gif", iSH, iNSH, iNSHR, iSHR));
	Shape.Add(new LI("Princess", "", "img/blank.gif", iSH, iNSH, iNSHR, iSHR));
	Shape.Add(new LI("Emerald", "", "img/blank.gif", iSH, iNSH, iNSHR, iSHR));
	Shape.Add(new LI("Asscher", "", "img/blank.gif", iSH, iNSH, iNSHR, iSHR));
	Shape.Add(new LI("Oval", "", "img/blank.gif", iSH, iNSH, iNSHR, iSHR));
	Shape.Add(new LI("Radiant", "", "img/blank.gif", iSH, iNSH, iNSHR, iSHR));
	Shape.Add(new LI("Pear", "", "img/blank.gif", iSH, iNSH, iNSHR, iSHR));
	Shape.Add(new LI("Heart", "", "img/blank.gif", iSH, iNSH, iNSHR, iSHR));
	Shape.Add(new LI("Marquise", "", "img/blank.gif", iSH, iNSH, iNSHR, iSHR));
	Shape.List[Shape.Count - 1].Width = 28;
	Shape.Add(new LI("Cushion", "", "img/blank.gif", iSH, iNSH, irb, iSHR));
	ReportLoaded()
};

var Cut = new Buttonlist("Cut", 69, 34);
Cut.Mode = "Toggle";
function LoadCut() {
	var iCutS = new Image();
	//var iCutNS = new Image();
	iCutS.src = jas + "Images/TrueHearts.gif";
	//iCutNS.src = "img/cut_img74.gif";
	Cut.Add(new LI("HA", "", "img/blank.gif", iCutS, iNSH));
	Cut.List[Cut.Count - 1].Width = 90;
	Cut.Add(new LI("Ideal", "Ideal", null, iSH, iNSH, iNSHR, iSHR));
	Cut.Add(new LI("Premium", "Premium", null, iSH, iNSH, iNSHR, iSHR));
	Cut.Add(new LI("Good", "Good", null, iSH, iNSH, irb, iSHR));
	ReportLoaded()
}

var imgS = new Image(); var imgNS = new Image(); var imgR = new Image(); var imgRS = new Image();
var iSHR = new Image(); var iSH = new Image(); var iNSHR = new Image(); var iNSH = new Image();
var irb = new Image();
var Color = new Buttonlist("Color", 43, 21);
Color.Mode = "Toggle";
function LoadColor() {
	var ics = new Image();
	ics.src = "img/color1.gif";

	Color.Add(new LI("D", "D", null, ics, imgNS, imgR, irb));
	Color.List[Color.Count - 1].Width = 42;
	ics = new Image();
	ics.src = "img/color2.gif";
	Color.Add(new LI("E", "E", null, ics, imgNS, imgR, irb));
	Color.List[Color.Count - 1].Width = 42;
	ics = new Image();
	ics.src = "img/color3.gif";
	Color.Add(new LI("F", "F", null, ics, imgNS, imgR, irb));
	Color.List[Color.Count - 1].Width = 42;
	ics = new Image();
	ics.src = "img/color4.gif";
	Color.Add(new LI("G", "G", null, ics, imgNS, imgR, irb));
	ics = new Image();
	ics.src = "img/color5.gif";
	Color.Add(new LI("H", "H", null, ics, imgNS, imgR, irb));
	ics = new Image();
	ics.src = "img/color6.gif";
	Color.Add(new LI("I", "I", null, ics, imgNS, imgR, irb));
	ics = new Image();
	ics.src = "img/color7.gif";
	Color.Add(new LI("J", "J", null, ics, imgNS, irb, irb));

	ReportLoaded()
};
var Clarity = new Buttonlist("Clarity", 38, 21);
Clarity.Mode = "Toggle";
function LoadClarity() {
	Clarity.Add(new LI("IF", "IF", null, imgS, imgNS, imgR, imgRS));
	Clarity.Add(new LI("VVS1", "VVS1", null, imgS, imgNS, imgR, imgRS));
	Clarity.Add(new LI("VVS2", "VVS2", null, imgS, imgNS, imgR, imgRS));
	Clarity.Add(new LI("VS1", "VS1", null, imgS, imgNS, imgR, imgRS));
	Clarity.Add(new LI("VS2", "VS2", null, imgS, imgNS, imgR, imgRS));
	Clarity.Add(new LI("SI1", "SI1", null, imgS, imgNS, imgR, imgRS));
	Clarity.Add(new LI("SI2", "SI2", null, imgS, imgNS, imgR, imgRS));
	Clarity.Add(new LI("I1", "I1", null, imgS, imgNS, irb, imgRS));
	Clarity.List[Clarity.Count - 1].Width = 32;
	ReportLoaded();
};

var Polish = new Buttonlist("Polish", 75, 21);
Polish.Mode = "Toggle";
var Symmetry = new Buttonlist("Symmetry", 75, 21);
Symmetry.Mode = "Toggle";
function LoadPolishSymmetry() {
	//imgNS.src = "img/polish.gif";
	Polish.Add(new LI("EX,ID", "Excellent", null, imgS, imgNS, imgR, imgRS));
	Polish.Add(new LI("VG", "Very Good", null, imgS, imgNS, imgR, imgRS));
	Polish.Add(new LI("GD", "Good", null, imgS, imgNS, imgR, imgRS));
	Polish.Add(new LI("FR", "Fair", null, imgS, imgNS, irb, imgRS));
	Polish.List[Polish.Count - 1].Width = 73;

	Symmetry.DisplayNAme = "Symm'";
	Symmetry.Add(new LI("EX,ID", "Excellent", null, imgS, imgNS, imgR, imgRS));
	Symmetry.Add(new LI("VG", "Very Good", null, imgS, imgNS, imgR, imgRS));
	Symmetry.Add(new LI("GD", "Good", null, imgS, imgNS, imgR, imgRS));
	Symmetry.Add(new LI("FR", "Fair", null, imgS, imgNS, irb, imgRS));
	Symmetry.List[Symmetry.Count - 1].Width = 73;
	ReportLoaded();
};

var Fluor = new Buttonlist("Fluor", 75, 21);
Fluor.Mode = "Toggle";
function LoadFluor() {
	Fluor.Add(new LI("NN", "None", null, imgS, imgNS, imgR, imgRS));
	Fluor.Add(new LI("FT", "Faint", null, imgS, imgNS, imgR, imgRS));
	Fluor.Add(new LI("MB", "Medium", null, imgS, imgNS, imgR, imgRS));
	Fluor.Add(new LI("S", "Strong", null, imgS, imgNS, imgR, imgRS));
	//Clarity.List[Clarity.Count - 1].Width = 72;
	ReportLoaded();
};

var Lab = new Buttonlist("Lab", 100, 21);
Lab.Mode = "Toggle";
function LoadLab() {
	Lab.Add(new LI("GIA", "GIA", null, imgS, imgNS, imgR, imgRS));
	Lab.Add(new LI("AGS", "AGS", null, imgS, imgNS, imgR, imgRS));
	Lab.Add(new LI("IGI", "IGI", null, imgS, imgNS, imgR, imgRS));
	//Clarity.List[Clarity.Count - 1].Width = 72;
	ReportLoaded();
};

var Sliders = new Array();
function LoadSliders() {
	Sliders["Carat"] = new SliderItem("Carat", true, 0.20, 10.00);   //Carat
	Sliders["Carat"].CalcValue = CaratCalcValue;
	Sliders["Carat"].SetValues = SetValues;
	Sliders["Price"] = new SliderItem("Price", true, 400, 1000000);   //Price
	Sliders["Price"].CalcValue = PriceCalcValue;
	Sliders["Price"].SetValues = SetValues;
	Sliders["Depth"] = new SliderItem("Depth", true, 55.0, 80.0);   //Depth
	Sliders["Table"] = new SliderItem("Table", true, 52.0, 80.0);   //Table  
};
function CaratCalcValue(inputVal) {
	var max = this.MaxRange;
	if (inputVal < 1)
		max = 6;
	return (this.MinRange + (((inputVal * inputVal * 0.9) + (Math.pow(inputVal, 4) * 0.1)) * (max - this.MinRange))).toFixed(2);
}
function SetValues(fromVal, toVal) {
	var min = 8; var max = 268;
	if (fromVal != this.MinRange)
		min = FindPixel(fromVal, 8, 268, this.Title, -2); //-1
	if (toVal != this.MaxRange)
		max = FindPixel(toVal, min - 6, 268, this.Title, 2); //1
	SetSliderValues(this.Title, min, max);
};

function FindPixel(value, min, max, sn, offset) {
	var x, mid;
	var val = parseFloat(no$(value));
	while (max - min > 1) {
		mid = parseInt((min + max) / 2);
		x = parseFloat(no$(Sliders[sn].CalcValue((mid - 3 + offset) / gSliderGup)));
		if (val == x)
			return mid;
		else if (val > x)
			min = mid;
		else
			max = mid;
	};
	if (max - min == 1) {
		if (offset == -2)
			return min;
		else
			return max;
	}
	return mid;
}

function PriceCalcValue(inputVal) {
	var caratval = inputVal * inputVal * (10000 - this.MinRange) * (1 / 0.16);
	caratval = parseInt((this.MinRange + caratval) / 10) * 10;
	if (inputVal > 0.40) {
		caratval = inputVal * (20000 - this.MinRange) * (1 / 0.70);
		caratval = parseInt((this.MinRange + caratval) / 100) * 100;
	}
	if (inputVal > 0.70) {
		caratval = Math.pow(inputVal, 4) * (100000 - this.MinRange) * (1 / 0.81450625);
		caratval = parseInt((this.MinRange + caratval) / 1000) * 1000;
	}
	if (inputVal > 0.95) {
		var n = (1 - inputVal) / 0.05;
		caratval *= n;
		caratval += Math.pow(inputVal, 6) * (1 - n) * (this.MaxRange - this.MinRange)
		caratval = parseInt((this.MinRange + caratval) / 10000) * 10000;
	}
	return "$" + number_format(caratval, 0, '.', ',');
}

var i1 = new Image();
i1.src = "img/sliderMin.gif";
var i2 = new Image();
i2.src = "img/sliderMax.gif";
var i3 = new Image();
i3.src = jas + "Images/trackShadow.gif";
var i4 = new Image();
i4.src = jas + "Images/ShapesBG.gif";
var i5 = new Image();
i5.src = jas + "Images/SliderBG.gif";
var i6 = new Image();
i6.src = "img/view.gif";
setTimeout("load()", 1);

function load() {
	imgS.src = jas + "Images/bgSelect.gif";
	imgRS.src = jas + "Images/rightSelect.gif";
	iSHR.src = jas + "Images/iSHR.gif";
	iSH.src = jas + "Images/iSH.gif";
	irb.src = jas + "Images/rb.gif";
	imgR = irb;
	iNSHR = irb;
	LoadSliders();
	setTimeout("LoadShape()", 1);
	setTimeout("LoadCut()", 1);
	setTimeout("LoadColor()", 500);
	setTimeout("LoadClarity()", 1);
	setTimeout("LoadPolishSymmetry()", 1);
	setTimeout("LoadFluor()", 1);
	setTimeout("LoadLab()", 1);
};

function LoadSearch() {
	$('topBack').style.height = (NIE1) ? '20px' : '17px';
	$("CaratPane").innerHTML = Sliders["Carat"].GetHtml();
	$("PricePane").innerHTML = Sliders["Price"].GetHtml();
	$("ShapePane").innerHTML = Shape.GetHtml();
	$("CutPane").innerHTML = Cut.GetHtml();
	$("ColorPane").innerHTML = Color.GetHtml();
	$("ClarityPane").innerHTML = Clarity.GetHtml();

	$("PolishPane").innerHTML = Polish.GetHtml();
	$("SymmetryPane").innerHTML = Symmetry.GetHtml();
	$("FluorPane").innerHTML = Fluor.GetHtml();
	$("LabPane").innerHTML = Lab.GetHtml();
	$("DepthPane").innerHTML = Sliders["Depth"].GetHtml();
	$("TablePane").innerHTML = Sliders["Table"].GetHtml();
	InitDetailpanel();
	InitSearchValues();

	(moreOp == 0) ? ShowAdvance('none') : ShowAdvance('');
	active = 1;
	GetData();
}

function LoadFromCoockie(forceClient, searchType) {
	gST = searchType;
	coockie.Load(forceClient);
	Shape.LoadFromCoockie();
	Color.LoadFromCoockie();
	Clarity.LoadFromCoockie();
	Cut.LoadFromCoockie();
	Polish.LoadFromCoockie();
	Symmetry.LoadFromCoockie();
	Sliders["Carat"].LoadFromCoockie();
	Sliders["Price"].LoadFromCoockie();
	Sliders["Depth"].LoadFromCoockie();
	Sliders["Table"].LoadFromCoockie();
	if (coockie.Get("pageSize"))
		pageSize = coockie.Get("pageSize");
	if (coockie.Get("moreOp"))
		moreOp = coockie.Get("moreOp");
}

function StartSliders() {
	ReportLoaded();
}
//#endregion

/*****************************************************************************************/
var oDet; // details panel object
var sp;
var goDetails;
var goPointer;
var IsOverPannel = false;
var lastRowIndx;
function ShowDetailsPanel(e) {
	if (hideTimeout != null) {
		window.clearTimeout(hideTimeout);
		hideTimeout = null;
	}

	lastRowIndx = e.rowIndex;
	var ind = e.rowIndex;
	var s = GetDetailsData(ind);
	oDet = new DetailsPanel(s, e);
	oDet.show();
}

function HideDetailsPanel(num) {
	if (num == 777 && !NIE1) {
		if (window.event && window.event.toElement && window.event.toElement.id == "goPointer")
			return;
	}
	try {
		oDet.hide();
	} catch (e) {
		// do nothing
	}
}

function InitDetailpanel() {
	sp = $("spDetObj");    // placeholder
	goDetails = document.createElement("span");  // details panel span
	sp.appendChild(goDetails);

	var si = "<img src='img/blank.gif'/>";

	goDetails.style.width = "160px";
	goDetails.style.height = "220px";

	goDetails.innerHTML = "" +
		"<div id=\"goDetailsInner\" onmouseover=\"KeepShowing(true);\" onmouseout=\"HideDetailsPanel(5);\"" +
			" style=\"width:160px; z-index:5; display: none; position: absolute; padding-right: 20px;\">" +
		"<table  width='160px;' height='100%' cellpadding='0' cellspacing='0' border='0' zzstyle='filter:progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135,strength=4);' >" +
		"<tr height='2px'>" +
			"<td>" + si + "</td>" +
			"<td>" + si + "</td>" +
			"<td>" + si + "</td>" +
			"<td>" + si + "</td>" +
			"<td>" + si + "</td>" +
		"</tr>" +
		"<tr height='1px'>" +
			"<td width='1px'>" + si + "</td>" +
			"<td width='1px'>" + si + "</td>" +
			"<td bgcolor='#6F6F6F'>" + si + "</td>" +
			"<td width='1px'>" + si + "</td>" +
			"<td width='1px'>" + si + "</td>" +
		"</tr>" +
		"<tr height='1px'>" +
			"<td>" + si + "</td>" +
			"<td bgcolor='#6F6F6F'>" + si + "</td>" +
			"<td bgcolor='#FBFCF6'>" + si + "</td>" +
			"<td bgcolor='#6F6F6F'>" + si + "</td>" +
			"<td>" + si + "</td>" +
		"</tr>" +
		"<tr>" +
			"<td bgcolor='#6F6F6F'>" + si + "</td>" +
			"<td bgcolor='#FBFCF6'>" + si + "</td>" +
			"<td bgcolor='#FBFCF6' valign='top' style='padding:5' id='tdDetails'></td>" +
			"<td bgcolor='#FBFCF6'>" + si + "</td><td bgcolor='#6F6F6F'>" + si + "</td>" +
		"</tr>" +
		"<tr height='1px'><td>" + si + "</td>" +
			"<td bgcolor='#6F6F6F'>" + si + "</td><td>" + si + "</td>" +
			"<td bgcolor='#6F6F6F'>" + si + "</td><td>" + si + "</td>" +
		"</tr>" +
		"<tr height='1px' >" +
			"<td width='1px'>" + si + "</td>" +
			"<td width='1px'>" + si + "</td>" +
			"<td bgcolor='#6F6F6F'>" + si + "</td>" +
			"<td width='1px'>" + si + "</td>" +
			"<td width='1px'>" + si + "</td>" +
		"</tr>" +
		"</table>" +
		"</div>";

	// triangular pointer
	goPointer = document.createElement("div");  //pointer image
	goPointer.id = "goPointer";
	sp.appendChild(goPointer);
	goPointer.style.position = "absolute";
	goPointer.style.display = "none";
	goPointer.style.margin = "10px 3px 10px 0px";
	goPointer.style.border = "solid 1px white";
	goPointer.style.backgroundColor = "white";
	goPointer.innerHTML = "<img src='slider2/Images/tria.gif' onmouseover='KeepShowing();' />";

	if (!NIE1)
		goPointer.style.zIndex = 3;
	else {
		goPointer.style.zIndex = 3;
		goPointer.onmouseover = KeepShowing;
	}
};

function KeepShowing(noTimeout) {
	goDetails.style.display = "block";
	goPointer.style.display = "block";

	if (hideTimeout != null) {
		window.clearTimeout(hideTimeout);
		hideTimeout = null;
	}

	if (!noTimeout)
		setTimeout("KeepShowing(true);", 100);
}

function DetailsPanel(s, e) {
	this.ofY = findPosY(e);
	this.s = s;
	this.show = ShowDetails;
	this.hide = HideDetails;
};

// methods functions
function ShowDetails() {
	if (hideTimeout != null) {
		window.clearTimeout(hideTimeout);
		hideTimeout = null;
	}

	var t = this.ofY - 110;
	var topY = findPosY($('TopBound'));
	var buttonY = findPosY($('BottomBound'));
	var ofX = findPosX($('BottomBound'));
	if (t <= topY + 20)
		t = topY + 20;
	if (t >= buttonY - 265)
		t = buttonY - 265;
	SetPosition(goPointer, this.ofY - 7, ofX - 10);
	SetPosition(goDetails, t, ofX - 170);
	$('tdDetails').innerHTML = this.s;
	$("goDetailsInner").style.display = "block";
}

var hideTimeout = null;
function HideDetails() {
	hideTimeout = window.setTimeout("HideDetailsTimeout();", 500);
}

function HideDetailsTimeout() {
	if (hideTimeout == null)
		return;
	
	goDetails.style.display = "none";
	goPointer.style.display = "none";
	
	if (hideTimeout != null) {
		window.clearTimeout(hideTimeout);
		hideTimeout = null;
	}
}

function SetPosition(element, top, left) {
	element.style.top = top;
	element.style.left = left
	element.style.display = "block";
	element.style.position = 'absolute';
};

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent)
		while (1) {
		curleft += obj.offsetLeft;
		if (!obj.offsetParent)
			break;
		obj = obj.offsetParent;
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
};

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent)
		while (1) {
		curtop += obj.offsetTop;
		if (!obj.offsetParent)
			break;
		obj = obj.offsetParent;
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
};

//////////////////////////////////////////////////////////////////////////////////////// 

var gvDetailsData;
function tbSearchResults() {
	if ($("tbSearchResults")) {
		var tb = $("tbSearchResults");
		var ar = tb.childNodes[0].childNodes;
		var res = new Array();
		res[0] = new Array();
		var strData = [];
		var columnsList = $('thDetailsObjColumns');

		var strColumnsData = SplitAndReturnTable(columnsList.innerHTML);
		for (var j = 0; j < strColumnsData.length; j++) {
			res[0][j] = strColumnsData[j];
		};

		var tdData = [];
		tdData = document.getElementsByName('flDetailsObj');
		var k = 1;
		for (var i = 0; i < tdData.length; i++) {
			res[k] = new Array();
			strData = SplitAndReturnTable(tdData[i].innerHTML);

			for (var j = 0; j < strData.length; j++) {
				res[k][j] = strData[j];
			};
			k++;
		};
		return res;
	}
};

function SplitAndReturnTable(nStr) { return table = nStr.split('|'); };

function GetDetailsData(n) {
	var s = "<table width='100%' cellpadding='1' cellspacing='0' border='0'>" +
              "<tr><td height='22px'><b style='color:#000000'>Diamond Info</b></td></tr>";
	for (var i = 0; i < gvDetailsData[0].length; i++) {
		s += "<tr><td class='detUnderlined'><b>" + gvDetailsData[0][i] + ": </b>" + gvDetailsData[n][i] + "</td></tr>";
	};
	var sn = gvDetailsData[n][0];
	if (gST == "Loose" || gHA == true) {
		s += "<tr><td height='22px' id=\"addThis\"><a href=\"javascript://\" onmouseover=\"$('dropmenu1').style.display='block'\" style=\"color:#0000cc;\">Add this diamond to<span style=\"text-decoration:none; font-size:14px;\"> >></span></a>&nbsp;";
		s += "<div id=\"dropmenu1\" style=\"z-index:5; display:none; position:absolute; background-color:#F6F6F6; border:solid 1px black; padding:5px 5px 5px 5px; margin:5px 5px 5px 5px; \">";
		s += "<div class=\"InPopup\"><a href=\"update_ring.asp?cid=130&cmb=1&stoneID=" + sn + "\">To a ring</a></div>";
		s += "<div class=\"InPopup\"><a href=\"update_ring.asp?cid=130&toshop=1&StoneID=" + sn + "\">To shopping cart</a></div>";
		s += "<div class=\"InPopup\"><a href=\"javascript:add_to_wish('" + sn + ",')\">To wish list</a></div>"
		s += "<div class=\"InPopup\"><a href=\"javascript:diamond_to_compare('130'," + sn + ")\">To comparison</a></div></div>";
		s += "</td></tr>";
	}
	else {
		s += "<tr><td height='22px' id=\"addThis\"><a href=\"update_ring.asp?cid=" + gCid + "&cmb=1&stoneID=" + sn + "\" style=\"color:#0000cc;\">Add Diamond to Ring</a>&nbsp;";
		s += "</td></tr>";
	}
	s += "<tr><td height='22px'><b style='color:#000000'>Shipping Info</b></td></tr>";
	s += "<tr><td class='detUnderlined'>" + GetDiamondShippingInfo() + "</td></tr>";
	s += "</table>";
	return s;
};
var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var myDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

function formatString(date, inc) {
	var dd1 = date.getUTCDate();
	date.setUTCDate(dd1 + inc);
	n_month = date.getUTCMonth();
	n_year = date.getUTCFullYear();
	n_day = date.getUTCDate();
	var thisDay = date.getDay();
	return (myDays[thisDay] + ' ' + m_names[n_month] + ' ' + n_day + 'th ' + n_year);
};

function GetDiamondShippingInfo() {
	var DiamondDetails, ShipInfo = "";
	var DayAdd = "";
	var DayName = "";
	var now = new Date();
	if (now.getDay() == 1)
		DayAdd = 2;
	if (now.getDay() == 5)
		DayAdd = 4;
	if (now.getDay() == 6)
		DayAdd = 3;

	var d = new Date();
	var curr_date = d.getDate();
	var curr_month = d.getMonth();
	curr_month++;
	var curr_year = d.getFullYear();
	var newdt = curr_month + "/" + curr_date + "/" + curr_year;
	var ff = new Date(newdt);

	if ((DayAdd != "") && (now > ff))
		ShipInfo = ShipInfo + "Order By 4:00pm EST Monday and receive on ";
	else if (now > ff)
		ShipInfo = ShipInfo + "Order By 4:00pm EST today and receive on ";
	else
		ShipInfo = ShipInfo + "Order By 4:00pm EST today and receive on ";

	var newd = new Date();
	if (DayAdd != "") {
		var newd = new Date();
		ShipInfo = ShipInfo + formatString(now, DayAdd);
	}
	else {
		if (now > ff) {
			if (now.getUTCDay() == 4)
				ShipInfo = ShipInfo + formatString(now, 5);
			else
				ShipInfo = ShipInfo + formatString(now, 1);
		}
		else
			ShipInfo = ShipInfo + formatString(now, 1);
	};
	ShipInfo = ShipInfo + " as a loose diamond.";
	return ShipInfo;
};