/**
* isytapi.js
*
* Version : 1.0
*
* Javascript API for isendyouthis.
*
* Copyright (c) 2011 isendyouthis.com
* http://www.isendyouthis.com/
*
*/
Date.prototype.toMSJSON = function () { var a = '"\\/Date(' + this.getTime() + ')\\/"'; return a }; (function ($) { IsytApi = new function (endpoint) { var localdomains = ":isendyouthis.com:craftgalleriesguide.com:"; this.serviceUrl = !endpoint ? "/services/IsytApi.asmx/" : endpoint; this.JSONP; this.SetHost = function (a) { if (a.indexOf("http") == -1) { a = "http://" + a } if (a.substring(a.length - 1) === "/") { a = a.substring(0, a.length - 1) } this.serviceUrl = a + "/services/IsytApi.asmx/" }; var MONTH_NAMES = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); var DAY_NAMES = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); var LZ = function (a) { return (a < 0 || a > 9 ? "" : "0") + a }; this.isDate = function (a, b) { var c = getDateFromFormat(a, b); if (c == 0) { return false } return true }; this.compareDates = function (a, b, c, d) { var e = getDateFromFormat(a, b); var f = getDateFromFormat(c, d); if (e == 0 || f == 0) { return -1 } else if (e > f) { return 1 } return 0 }; this.formatDate = function (a, b) { b = b + ""; var c = ""; var d = 0; var e = ""; var f = ""; var g = a.getYear() + ""; var h = a.getMonth() + 1; var i = a.getDate(); var j = a.getDay(); var k = a.getHours(); var l = a.getMinutes(); var m = a.getSeconds(); var n, o, p, q, r, s, t, u, v, w, x, k, y, z, A, B; var C = new Object; if (g.length < 4) { g = "" + (g - 0 + 1900) } C["y"] = "" + g; C["yyyy"] = g; C["yy"] = g.substring(2, 4); C["M"] = h; C["MM"] = LZ(h); C["MMM"] = MONTH_NAMES[h - 1]; C["NNN"] = MONTH_NAMES[h + 11]; C["d"] = i; C["dd"] = LZ(i); C["E"] = DAY_NAMES[j + 7]; C["EE"] = DAY_NAMES[j]; C["H"] = k; C["HH"] = LZ(k); if (k == 0) { C["h"] = 12 } else if (k > 12) { C["h"] = k - 12 } else { C["h"] = k } C["hh"] = LZ(C["h"]); if (k > 11) { C["K"] = k - 12 } else { C["K"] = k } C["k"] = k + 1; C["KK"] = LZ(C["K"]); C["kk"] = LZ(C["k"]); if (k > 11) { C["a"] = "PM" } else { C["a"] = "AM" } C["m"] = l; C["mm"] = LZ(l); C["s"] = m; C["ss"] = LZ(m); while (d < b.length) { e = b.charAt(d); f = ""; while (b.charAt(d) == e && d < b.length) { f += b.charAt(d++) } if (C[f] != null) { c = c + C[f] } else { c = c + f } } return c }; this.msJSON = function () { function str(a, b) { var c, d, e, f, g = gap, h, i = b[a]; if (i && typeof i === "object" && typeof i.toJSON === "function") { i = i.toJSON(a) } if (typeof rep === "function") { i = rep.call(b, a, i) } switch (typeof i) { case "string": return quote(i); case "number": return isFinite(i) ? String(i) : "null"; case "boolean": case "null": return String(i); case "object": if (!i) { return "null" } if (i.toUTCString) { return '"\\/Date(' + i.getTime() + ')\\/"' } gap += indent; h = []; if (typeof i.length === "number" && !i.propertyIsEnumerable("length")) { f = i.length; for (c = 0; c < f; c += 1) { h[c] = str(c, i) || "null" } e = h.length === 0 ? "[]" : gap ? "[\n" + gap + h.join(",\n" + gap) + "\n" + g + "]" : "[" + h.join(",") + "]"; gap = g; return e } if (rep && typeof rep === "object") { f = rep.length; for (c = 0; c < f; c += 1) { d = rep[c]; if (typeof d === "string") { e = str(d, i, rep); if (e) { h.push(quote(d) + (gap ? ": " : ":") + e) } } } } else { for (d in i) { if (Object.hasOwnProperty.call(i, d)) { e = str(d, i, rep); if (e) { h.push(quote(d) + (gap ? ": " : ":") + e) } } } } e = h.length === 0 ? "{}" : gap ? "{\n" + gap + h.join(",\n" + gap) + "\n" + g + "}" : "{" + h.join(",") + "}"; gap = g; return e } } function quote(a) { escapeable.lastIndex = 0; return escapeable.test(a) ? '"' + a.replace(escapeable, function (a) { var b = meta[a]; if (typeof b === "string") { return b } return "\\u" + ("0000" + (+a.charCodeAt(0)).toString(16)).slice(-4) }) + '"' : '"' + a + '"' } function f(a) { return a < 10 ? "0" + a : a } var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapeable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = { "\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", '"': '\\"', "\\": "\\\\" }, rep; return { stringify: function (a, b, c) { var d; gap = ""; indent = ""; if (typeof c === "number") { for (d = 0; d < c; d += 1) { indent += " " } } else if (typeof c === "string") { indent = c } rep = b; if (b && typeof b !== "function" && (typeof b !== "object" || typeof b.length !== "number")) { throw new Error("JSON.stringify") } return str("", { "": a }) }, parse: function (text, reviver) { function walk(a, b) { var c, d, e = a[b]; if (e && typeof e === "object") { for (c in e) { if (Object.hasOwnProperty.call(e, c)) { d = walk(e, c); if (d !== undefined) { e[c] = d } else { delete e[c] } } } } return reviver.call(a, b, e) } var j; cx.lastIndex = 0; if (cx.test(text)) { text = text.replace(cx, function (a) { return "\\u" + ("0000" + (+a.charCodeAt(0)).toString(16)).slice(-4) }) } if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) { j = eval("(" + text + ")"); return typeof reviver === "function" ? walk({ "": j }, "") : j } throw new SyntaxError("JSON.parse") } } } (); this.invoke = function (a, b, c, d, e, f) { var g; if (typeof this.JSONP != "undefined") { g = this.JSONP ? "y" : "n" } else { g = $.cookie("isytapijsonp"); if (!g) { var h = window.location.href.replace(/[^\/]*[\/]*[^\.]+\.([^\/]+).*/, "$1"); if (localdomains.indexOf(":" + h + ":") != -1) { g = "n" } else { g = "y" } $.cookie("isytapijsonp", g) } } if (g != "n") { this.invokejsonp(a, b, c, d); return } if (f == null) { f = false } var i = this.serviceUrl + a; var j = $.cookie("isytapikey"); var k = $.cookie("isytapihost"); if (j) { if (!b || b.length == 0) { b = {} } if (typeof b == "string") { b = $.evalJSON(b); convertdata = true } b.apikey = j; if (k) { b.apihost = k } b = $.toJSON(b) } if (b && typeof b != "string") { b = $.toJSON(b) } $.ajax({ data: b, dataType: "json", url: i, type: "POST", contentType: "application/json; charset=utf-8", timeout: 2e4, async: f, success: function (a) { if (e) { if (c) { c(a) } return } var b = a.d || a.d == null ? a.d : $.evalJSON(a); if (b && b.error) { if (d) { d(b.error) } } else if (c) { c(b) } }, error: function (a, b, c) { if (a.responseText && d) { if (a.responseText) { d(a.responseText) } else { d({ Message: "Unknown server error." }) } } return } }) }; this.invokejsonp = function (a, b, c, d) { var e = this.serviceUrl.replace(/IsytApi\.asmx/, "IsytApiJSONP.asmx") + a; var f = $.cookie("isytapikey"); var g = $.cookie("isytapihost"); if (f) { if (!b || b.length == 0) { b = {} } if (typeof b == "string") { b = $.evalJSON(b) } b.apikey = f; if (g) { b.apihost = g } } if (b) { if (typeof b == "string") { b = $.evalJSON(b) } var h = ""; for (var i in b) { if (h != "") { h += "&" } h += i + "=" + IsytApi.msJSON.stringify(b[i]) } e += "?" + h; b = "{}" } e += "&callback=?&jsonp=y"; $.ajax({ data: b, dataType: "jsonp", beforeSend: function (a) { if (a && a.overrideMimeType) { a.overrideMimeType("application/json;charset=UTF-8") } }, cache: true, url: e, contentType: "application/json; charset=utf-8", success: function (a) { var b; if (a) { b = a.d || a.d == null ? a.d : $.evalJSON(a) } if (b && b.error && d) { d(b.error) } else if (c) { c(b) } }, error: function (a, b, c) { if (!d) return; if (a.responseText) { if (a.responseText) { d(a.responseText) } else { d({ Message: "Unknown server error." }) } } return } }) }; this.GetImages = function (a, b, c, d, e) { this.invoke("GetImages", a, b, c, d, e) }; this.GetPortfolioImages = function (a, b, c, d, e) { if (typeof a == "object") { a = jQuery.toJSON(a) } this.invoke("GetPortfolioImages", a, b, c, d, e) }; this.GetSupplier = function (a, b, c, d, e) { if (typeof a == "object") { if (!a.htmloptions) { a.htmloptions = {} } a = jQuery.toJSON(a) } this.invoke("GetSupplier", a, b, c, d, e) }; this.GetWebsite = function (a, b, c, d, e, f, g, h) { var i = {}; i.websiteid = a; i.sectionid = b; i.includeproducts = c; i.htmloptions = !d ? null : d; this.invoke("GetWebsite", i, e, f, g, h) }; this.GetPortfolio = function (a, b, c, d, e) { if (typeof a == "object") { if (!a.htmloptions) { a.htmloptions = {} } a = jQuery.toJSON(a) } this.invoke("GetPortfolio", a, b, c, d, e) }; this.GetWebsiteProduct = function (a, b, c, d, e, f, g, h, i) { if (!d) { d = 0 } if (!e) { e = {} } var j = "{websiteid:" + a + ",sectionid:" + b + ",productid:" + c + ",productsizeid:" + d + ",htmloptions:" + $.toJSON(e) + "}"; this.invoke("GetWebsiteProduct", j, f, g, h, i) }; this.GetProduct = function (a, b, c, d, e, f, g) { if (!b) { b = 0 } if (!c) { c = {} } var h = "{id:" + a + ",sizeid:" + b + ",htmloptions:" + $.toJSON(c) + "}"; this.invoke("GetProduct", h, d, e, f, g) }; this.GetExhibition = function (a, b, c, d, e) { var f = "{id:" + a + "}"; this.invoke("GetExhibition", f, b, c, d, e) }; this.TellFriend = function (a, b, c, d, e) { this.invoke("TellFriend", a, b, c, d, e) }; this.ProductEnquiry = function (a, b, c, d, e) { if (typeof a == "object") { a = jQuery.toJSON(a) } this.invoke("ProductEnquiry", a, b, c, d, e) }; this.GetArticle = function (a, b, c, d, e, f) { if (!b) { b = {} } var g = "{id:" + a + ",htmloptions:" + $.toJSON(b) + "}"; this.invoke("GetArticle", g, c, d, e, f) }; this.GetOpportunities = function (a, b, c, d, e) { if (typeof a == "object") { if (!a.htmloptions) { a.htmloptions = {} } a = jQuery.toJSON(a) } this.invoke("GetOpportunities", a, b, c, d, e) }; this.GetOpportunity = function (a, b, c, d, e) { if (typeof a == "object") { if (!a.htmloptions) { a.htmloptions = {} } a = jQuery.toJSON(a) } this.invoke("GetOpportunity", a, b, c, d, e) }; this.GetBasket = function (a, b, c, d, e, f) { if (!b) { b = {} } var g = "{userguid:'" + a + "',htmloptions:" + $.toJSON(b) + "}"; this.invoke("GetBasket", g, c, d, e, f) }; this.RemoveFromBasket = function (a, b, c, d, e, f, g) { if (!c) { c = {} } var h = "{userguid:'" + a + "',basketid:" + b + ",htmloptions:" + $.toJSON(c) + "}"; this.invoke("RemoveFromBasket", h, d, e, f, g) }; this.AddSectionsToGrape = function (a, b, c, d, e, f) { var g = {}; g.websiteid = a; g.sectionids = b; this.invoke("AddSectionsToGrape", g, c, d, e, f) }; this.AddProductToGrape = function (a, b, c, d, e, f, g, h, i) { var j = {}; j.websiteid = a; j.sectionid = b; j.productid = c; j.intosectionid = d; j.newsectionname = e; this.invoke("AddProductToGrape", j, f, g, h, i) }; this.VisitorLogin = function (a, b, c, d, e, f, g) { var h = {}; h.username = a; h.password = b; h.websiteid = c; this.invoke("VisitorLogin", h, d, e, f, g) }; this.VisitorLogout = function (a, b, c, d) { var e = {}; this.invoke("VisitorLogout", e, a, b, c, d) }; this.GetAuthorisedVisitor = function (a, b, c, d) { var e = {}; this.invoke("GetAuthorisedVisitor", e, a, b, c, d) } } })(jQuery)
