﻿function writeCookie(name, value) { document.cookie = name + '=' + value; }
function readCookie(name) { var search = name + '='; var rVal = ''; if (document.cookie.length > 0) { offset = document.cookie.indexOf(search); if (offset != -1) { offset += search.length; end = document.cookie.indexOf(';', offset); if (end == -1) end = document.cookie.length; rVal = unescape(document.cookie.substring(offset, end)) } } return rVal; }
function eraseCookie(name) { createCookie(name, ''); }
function bakeCookie(cookiename, cookievalue, expirementInSec, domain) { if (expirementInSec) { if (domain) { var a = new Date(); a = new Date(a.getTime() + 1000 * expirementInSec); document.cookie = cookiename + '=' + cookievalue + '; path=/; domain=' + domain + '; expires=' + a.toGMTString() + ';'; } else { var a = new Date(); a = new Date(a.getTime() + 1000 * expirementInSec); document.cookie = cookiename + '=' + cookievalue + '; path=/; expires=' + a.toGMTString() + ';'; } } else { document.cookie = cookiename + '=' + cookievalue + '; path=/;'; } }
function eatCookie(cookiename) { var cookie = document.cookie; var a = cookie.split(cookiename + '='); var b = a[1].split(';'); var cookievalue = b[0]; return cookievalue; }

function Ablur() { if (IE) ah = IE.tags('a'); else if (document.getElementById) ah = document.getElementsByTagName('a'); else return; for (i = 0; i < ah.length; i++) ah[i].onfocus = function() { if (this.blur) this.blur(); }; }

function getField(fieldID) { return cross(fieldID).value; }
function getEventObject(ev) { ev = ev || window.event; if (ev.srcElement) return ev.srcElement; else return ev.target; }
function getNextHref(that) { var child = that.childNodes; for (i = 0; i < child.length; i++) { var subChild = child[i].childNodes; for (j = 0; j < subChild.length; j++) if (subChild[j].href != '') return subChild[j].href; } }
function getStyleVal(obj, attr) { return (IE) ? obj.currentStyle[attr] : document.defaultView.getComputedStyle(obj, null).getPropertyValue(attr); }
function getDocumentHeight() { if (document.body.scrollHeight && navigator.appVersion.indexOf('Win') != -1) { if (document.body.scrollHeight && document.body.scrollHeight != 0) return document.body.scrollHeight; } else if (document.documentElement.scrollHeight) { return document.documentElement.scrollHeight; } else if (document.documentElement.offsetHeight) { return document.documentElement.offsetHeight; } }
function getWinHeight() { if (typeof (window.innerHeight) == 'number') { return window.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { return document.documentElement.clientHeight; } else if (document.body && document.body.clientHeight) { return document.body.clientHeight; } else { return 0; } }
function getWinWidth() { if (typeof (window.innerWidth) == 'number') { return window.innerWidth; } else if (document.documentElement && document.documentElement.clientWidth) { return document.documentElement.clientWidth; } else if (document.body && document.body.clientWidth) { return document.body.clientWidth; } else { return 0; } }
function getPageHeight() { if (document.documentElement && document.documentElement.scrollHeight) { return document.documentElement.scrollHeight; } else if (document.body && document.body.scrollHeight) { return document.body.scrollHeight; } else if (window.innerHeight && window.scrollMaxY) { return window.innerHeight + window.scrollMaxY; } else { return 0; } }
function getPageWidth() { if (document.documentElement && document.documentElement.scrollWidth) { return document.documentElement.scrollWidth; } else if (document.body && document.body.scrollWidth) { return document.body.scrollWidth; } else if (window.innerWidth && window.scrollMaxX) { return window.innerWidth + window.scrollMaxX; } else { return 0; } }
function getHeight(obj) { var height; if (document.defaultView && window.getComputedStyle) { var style = document.defaultView.getComputedStyle(obj, null); height = parseInt(style.getPropertyValue('height'), 10); if (window.opera && !document.getElementsByClassName) { height -= parseInt(style.getPropertyValue('padding-top'), 10); height -= parseInt(style.getPropertyValue('padding-bottom'), 10); height -= parseInt(style.getPropertyValue('border-top-width'), 10); height -= parseInt(style.getPropertyValue('border-bottom-width'), 10); } height += parseInt(style.getPropertyValue('padding-top'), 10); height += parseInt(style.getPropertyValue('padding-bottom'), 10); height += parseInt(style.getPropertyValue('border-top-width'), 10); height += parseInt(style.getPropertyValue('border-bottom-width'), 10); } else if (obj.currentStyle) { height = obj.offsetHeight; } return height; }
function getWidth(obj) { var width; if (document.defaultView && window.getComputedStyle) { var style = document.defaultView.getComputedStyle(obj, null); width = parseInt(style.getPropertyValue('width'), 10); if (window.opera && !document.getElementsByClassName) { width -= parseInt(style.getPropertyValue('padding-left'), 10); width -= parseInt(style.getPropertyValue('padding-right'), 10); width -= parseInt(style.getPropertyValue('border-left-width'), 10); width -= parseInt(style.getPropertyValue('border-right-width'), 10); } width += parseInt(style.getPropertyValue('padding-left'), 10); width += parseInt(style.getPropertyValue('padding-right'), 10); width += parseInt(style.getPropertyValue('border-left-width'), 10); width += parseInt(style.getPropertyValue('border-right-width'), 10); } else if (obj.currentStyle) { width = obj.offsetWidth; } return width; }
function getRealTop(el) { var typ = typeof el; var obj = (typ == 'object') ? el : null; yPos = obj.offsetTop; tempObj = obj.offsetParent; while (tempObj != null) { yPos += tempObj.offsetTop; tempObj = tempObj.offsetParent; } return yPos; }
function getRealLeft(el) { var typ = typeof el; var obj = (typ == 'object') ? el : null; xPos = obj.offsetLeft; tempObj = obj.offsetParent; while (tempObj != null) { xPos += tempObj.offsetLeft; tempObj = tempObj.offsetParent; } return xPos; }
function setPageHeight(j, offset) { newHeight = getPageHeight() - offset; if (newHeight > j.height()) { j.height(newHeight); } }
function setWinHeight(j, offset) { newHeight = getWinHeight() - offset; if (newHeight > j.height()) { j.height(newHeight); } }
function myScrollTop() { if (document.documentElement.scrollTop) { return document.documentElement.scrollTop; } else if (document.body.scrollTop) { return document.body.scrollTop; } else if (window.scrollTop) { return window.scrollTop; } else { return 0; } }
function myScrollLeft() { if (document.documentElement.scrollLeft) { return document.documentElement.scrollLeft; } else if (document.body.scrollLeft) { return document.body.scrollLeft; } else if (window.scrollLeft) { return window.scrollLeft; } else { return 0; } }
function compareStyleVal(obj, attr, val) { return (IE) ? (obj.currentStyle[attr] == val) : (document.defaultView.getComputedStyle(obj, null).getPropertyValue(attr) == val) }
function centerMe(el) { var obj = cross(el); var display = getStyleVal(obj, 'display'); var hidden = compareStyleVal(obj, 'display', 'none'); var visibility = getStyleVal(obj, 'visibility'); var invisible = compareStyleVal(obj, 'visibility', 'hidden'); if (hidden) { if (!invisible) obj.style.visibility = 'hidden'; obj.style.display = 'block'; } obj.style.top = myScrollTop() + Math.round(getWinHeight() / 2) - Math.round(getHeight(obj) / 2) + 'px'; obj.style.left = myScrollLeft() + Math.round(getWinWidth() / 2) - Math.round(getWidth(obj) / 2) + 'px'; if (hidden) { obj.style.display = display; if (!invisible) obj.style.visibility = visibility; } }

function isInt(str) { var i = parseInt(str); if (isNaN(i)) return false; i = i.toString(); if (i != str) return false; return true; }
function isFloat(str) { var i = parseFloat(str.replace(',', '.')); if (isNaN(i)) return false; return i; }
function isValidEmail(src) { var emailReg = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i; var regex = new RegExp(emailReg); return regex.test(src); }
function isValidURL(url) { var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/; if (RegExp.test(url)) return true; return false; }
function isDate(str) { dy = str.split(".")[0]; mo = str.split(".")[1]; yr = str.split(".")[2]; if (!dy || !mo || !yr) return false; if (yr.length == 2 || yr.length == 4) { if (yr.length == 2) { var today = new Date(); yr = (parseInt(yr, 10) <= parseInt(today.getFullYear().toString().substring(2, 4), 10)) ? "20" + yr : "19" + yr; } } else return false; dyFull = (dy.toString().length == 1) ? "0" + dy : dy; moFull = (mo.toString().length == 1) ? "0" + mo : mo; mo = parseInt(mo, 10) - 1; var test = new Date(yr, mo, dy); if (test.getFullYear() == yr && mo == test.getMonth() && dy == test.getDate()) return true; else return false; }
function isDateInPast(date1, date2) { var date1 = date1.split("."); var date2 = date2.split("."); if (date1[2] > date2[2]) { return true; } else if (date1[2] == date2[2]) { if (date1[1] > date2[1]) { return true; } else if (date1[1] == date2[1]) { if (date1[0] > date2[0]) { return true; } } } return false; }

function clearAllTimeouts() { var i = window.setTimeout(function() { }, 100) + 1; while (i--) window.clearTimeout(i); }
function clearAllIntervals() { var i = window.setInterval(function() { }, 100) + 1; while (i--) window.clearInterval(i); }

function changeOpac(obj, opacity) { obj.style.filter = 'alpha(opacity=\' + opacity + \')'; obj.style.opacity = (opacity / 100); obj.style.MozOpacity = (opacity / 100); obj.style.KhtmlOpacity = (opacity / 100); }
function clearOpac(obj) { obj.style.filter = ''; obj.style.opacity = ''; obj.style.MozOpacity = ''; obj.style.KhtmlOpacity = ''; }
function fadeIn(el, opac, max) { if (window.outTimer) clearTimeout(outTimer); if (!max) { max = 100; } var obj = cross(el); var newOpac = opac + 20; if (newOpac < max) { changeOpac(obj, newOpac); if (opac == 0) obj.style.display = 'block'; inTimer = window.setTimeout('fadeIn(\'' + el + '\', ' + newOpac + ', ' + max + ')', 30); } else { if (window.inTimer) clearTimeout(inTimer); changeOpac(obj, max); } }
function fadeOut(el, opac, min) { if (window.inTimer) clearTimeout(inTimer); if (!min) { min = 0; } var obj = cross(el); var newOpac = opac - 10; if (newOpac > min) { changeOpac(obj, newOpac); outTimer = window.setTimeout('fadeOut(\'' + el + '\', ' + newOpac + ', ' + min + ')', 20); } else { if (window.outTimer) clearTimeout(outTimer); obj.style.display = 'none'; clearOpac(obj); } }

function wait(msecs) { var start = new Date().getTime(); var cur = start; while (cur - start < msecs) { cur = new Date().getTime(); } }
function cross(objectID) { if (document.getElementById) { if (document.getElementById(objectID)) { return document.getElementById(objectID); } else { return document.getElementsByName(objectID)[0]; } } else { return ie[objectID]; } }

function saveScrollPos(that) { if (window.pageYOffset) scrollposSearchResults = that.pageYOffset; else scrollposSearchResults = that.scrollTop; }
function loadScrollPos(that) { if (window.pageYOffset) that.pageYOffset = scrollposSearchResults; else that.scrollTop = scrollposSearchResults; }

function AddZero(num) { if (parseInt(num, 10) < 10) { return '0' + num; } else { return num; } }
function Left(str, n) { if (n <= 0) return ''; else if (n > String(str).length) return str; else return String(str).substring(0, n); }
function Right(str, n) { if (n <= 0) return ''; else if (n > String(str).length) return str; else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } }

//jquery
function doClickFirstLink(that) { var href = $(that).find("a").attr("href"); if (href.length > 0) eval(href); }
function AddGoogleTracking(googleID, pageName) { gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); $.getScript(gaJsHost + 'google-analytics.com/ga.js', function() { pageTracker = _gat._getTracker(googleID); if (pageName) { pageTracker._trackPageview(pageName); } else { pageTracker._trackPageview(); } }); }
function AddGoogleTrackingClick(pageClickName) { pageTracker._trackPageview(pageClickName); }

// v=110
function padLeft(val, ch, num) { var re = new RegExp(".{" + num + "}$"); var pad = ""; if (!ch) ch = " "; do  { pad += ch; }while(pad.length < num); return re.exec(pad + val)[0]; }
function padRight(val, ch, num){ var re = new RegExp("^.{" + num + "}"); var pad = ""; if (!ch) ch = " "; do { pad += ch; } while (pad.length < num); return re.exec(val + pad)[0]; }

