﻿var util={configEvents:function(){if(document.addEventListener){this.addEvent=function(el,type,func,capture){el.addEventListener(type,func,capture)};this.stopBubble=function(evt){evt.stopPropagation()};this.stopDefault=function(evt){evt.preventDefault()};this.findTarget=function(evt,targetNode,container){var currentNode=evt.target;while(currentNode&&currentNode!==container){if(currentNode.nodeName.toLowerCase()===targetNode){return currentNode;break}else{currentNode=currentNode.parentNode}};return false}}else if(document.attachEvent){this.addEvent=function(el,type,func){el["e"+type+func]=func;el[type+func]=function(){el["e"+type+func](window.event)};el.attachEvent("on"+type,el[type+func])};this.stopBubble=function(evt){evt.cancelBubble=true};this.stopDefault=function(evt){evt.returnValue=false};this.findTarget=function(evt,targetNode,container){var currentNode=evt.srcElement;while(currentNode&&currentNode!==container){if(currentNode.nodeName.toLowerCase()===targetNode){return currentNode;break}else{currentNode=currentNode.parentNode}};return false}}},createCookie:function(name,value,expiration,path,domain,secure){var data=name+"="+escape(value);if(expiration){var expiresAt=new Date();expiresAt.setTime(expiration);data+="; expires="+expiresAt.toGMTString()}if(path){data+="; path="+path}if(domain){data+="; domain="+domain}if(secure){data+="; secure"}document.cookie=data},findCookie:function(name){var query=name+"=";var queryLength=query.length;var cookieLength=document.cookie.length;var i=0;while(i<cookieLength){var position=i+queryLength;if(document.cookie.substring(i,position)===query){return someObject.findCookieValue(position)}i=document.cookie.indexOf(" ",i)+1;if(i==0){break}}return null},findCookieValue:function(position){var endsAt=document.cookie.indexOf(";",position);if(endsAt==-1){endsAt=document.cookie.length}return unescape(document.cookie.substring(position,endsAt))},eraseCookie:function(name){if(someObject.findCookie(name)){var data=name+"=";data+="; expires=Thu, 01-Jan-70 00:00:01 GMT";document.cookie=data}},sendRequest:function(url,func,postData){var xhr=this.createXHR();if(!xhr){return}var method=(postData)?"POST":"GET";xhr.open(method,url,true);xhr.setRequestHeader('User-Agent','XHR');if(postData){xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')}xhr.onreadystatechange=function(){if(xhr.readyState!==4){return}if(xhr.status!==200&&xhr.status!==304){alert('HTTP error '+xhr.status);return}func(xhr)};if(xhr.readyState===4){return}xhr.send(postData)},XHRoptions:[function(){return new XMLHttpRequest()},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],XHRmethod:null,configXHR:function(){var xmlhttp=false;for(var i=0,allOptions=this.XHRoptions.length;i<allOptions;i++){try{xmlhttp=this.XHRoptions[i]()}catch(e){continue}break}this.XHRmethod=i;this.createXHR=function(){var xmlhttp=this.XHRoptions[this.XHRmethod]();return xmlhttp}},insertAfter:function(parent,nodeToInsert,previousNode){parent.insertBefore(nodeToInsert,previousNode.nextSibling)}};