
function contentHeight() {
	var myheight = 0;
	var targetHeight = 0;
	var topHeight = 0;
	myheight = document.getElementById('body-right').clientHeight;
	targetHeight = document.getElementById('body-left').clientHeight;
	topHeight = document.getElementById('top-content-box').clientHeight;
	if(myheight < targetHeight) {
		document.getElementById('body-right').style.height = (targetHeight) + 'px';
		myheight = targetHeight;
	}
	if(document.getElementById('left-box')) {
		document.getElementById('left-box').style.height = (myheight - topHeight - 10) + 'px';
	}
	if(document.getElementById('frontpage-left')) {
		document.getElementById('frontpage-left').style.height = (myheight - topHeight - 10) + 'px';
	}
} 
function currencySel(t) {
	window.location = base_url + 'home/currency/' + t.value + currentPage;
}

function language2(id) {
	window.location = base_url + 'home/language/' + id + currentPage;
}


function addEvent(element, type, handler) {
  if(typeof(element) == "string") {
   addEvent(window, element, type); 
   return 0;
  }
  // assign each event handler a unique ID
  if (!handler.$$guid) handler.$$guid = addEvent.guid++;
  // create a hash table of event types for the element
  if (!element.events) element.events = {};
  // create a hash table of event handlers for each element/event pair
  var handlers = element.events[type];
  if (!handlers) {
    handlers = element.events[type] = {};
    // store the existing event handler (if there is one)
    if (element["on" + type]) {
      handlers[0] = element["on" + type];
    }
  }
  // store the event handler in the hash table
  handlers[handler.$$guid] = handler;
  // assign a global event handler to do all the work
  element["on" + type] = handleEvent;
};
// a counter used to create unique IDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
  // delete the event handler from the hash table
  if (element.events && element.events[type]) {
    delete element.events[type][handler.$$guid];
  }
};

function handleEvent(event) {
  // grab the event object (IE uses a global event object)
  event = event || window.event;
  // get a reference to the hash table of event handlers
  var handlers = this.events[event.type];
  // execute each event handler
  for (var i in handlers) {
    this.$$handleEvent = handlers[i];
    this.$$handleEvent(event);
  }
};

/* Language Translator */
//Popup window for translator .
function translatorPopUp() {
	var translator;
	translator = window.open(base_url + 'home/translator/','Translator','status = 1, height = 700, width = 790, resizable=no, scrollbars=yes');
	if (window.focus) {translator.focus()}
}

// General Popup
function generalPopUp(gnrUrl) {
	var generalWindow;
	generalWindow = window.open(gnrUrl,'General_Window','status = 1, height = 700, width = 790, resizable=no, scrollbars=yes');
	if (window.focus) {generalWindow.focus()}
}

function popup(url) {
	var myWindow;
    var width = 600;
    var height = 400;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "subWind", windowFeatures);
    myWindow.focus();
    return false;
}


var selectedText = '';
var selectedField = '';
var selectedFieldElement = '';
var preselectedText = '';
var preselectedField = '';

function setTransFieldValue(selval,selFieldElm,selField) {
	preselectedText = selectedText;
	preselectedField = selectedField;
	selectedField = selField;
	selectedFieldElement = selFieldElm;
	selectedText = selval;
}

function initialLang() {
	addEvent(document, 'mouseup', function(e) {if(typeof(document.getSelection) != 'undefined') {if(selectedText != document.getSelection() || selectedFieldElement != this){setTransFieldValue(document.getSelection(),this,'win');}} else {if((document.selection.type != 'None')) {if(selectedText != document.selection.createRange().htmlText || selectedFieldElement != this){setTransFieldValue(document.selection.createRange().text,this,'win');}}}}, false); 
	addEvent(document, 'keypress', function(e) {if(typeof(document.getSelection) != 'undefined') {if(selectedText != document.getSelection() || selectedFieldElement != this){setTransFieldValue(document.getSelection(),this,'win');}}else {if((document.selection.type != 'None')) {if(selectedText != document.selection.createRange().htmlText || selectedFieldElement != this){setTransFieldValue(document.selection.createRange().text,this,'win');}}}}, false); 
	for(var i = 0; i < document.getElementsByTagName('INPUT').length; i++) {addEvent(document.getElementsByTagName('INPUT')[i], 'keypress', function() {if(this.type == 'text') {if(this.value.substring(this.selectionStart, this.selectionEnd) != '') {if(selectedText != this.value.substring(this.selectionStart, this.selectionEnd) || selectedFieldElement != this){setTransFieldValue(this.value.substring(this.selectionStart, this.selectionEnd),this,'inp');}}}}, false); addEvent(document.getElementsByTagName('INPUT')[i], 'mouseup', function() {if(this.type == 'text') {if(this.value.substring(this.selectionStart, this.selectionEnd) != '') {if(selectedText != this.value.substring(this.selectionStart, this.selectionEnd) || selectedFieldElement != this){setTransFieldValue(this.value.substring(this.selectionStart, this.selectionEnd),this,'inp');}}}}, false); }
}

addEvent(window,'load',function() {initialLang();});
