var firstYear = 1920;
var lastYear = new Date().getFullYear() + 1;
var trDisplay = 'block';
var tableDisplay = 'block';
var isIE = (navigator.appName).toLowerCase().indexOf("microsoft")>-1;

if ( isIE ) { 
	trDisplay = 'block';
	tableDisplay = 'block';
}
else {
	trDisplay = 'table-row';
	tableDisplay = 'table';
}

function trimFormElements(form) {
	var elements = form.elements;
	for(var i=0; i<elements.length; i++) {
		var e = elements[i];
		if( e.tagName.toUpperCase()=="INPUT" && (!e.type || e.type.toUpperCase()=="TEXT" ) ) {
			e.value = trimAll(e.value);
		}
		else if( e.tagName.toUpperCase()=="TEXTAREA" ) {
			e.value = trimAll(e.value);
		}
	}	
}

function clearFormElements(form) {
	var elements = form.elements;
	for(var i=0; i<elements.length; i++) {
		var e = elements[i];
		if( e.tagName.toUpperCase()=="INPUT" && e.type) {
			switch( e.type.toUpperCase() ) {
				case "CHECKBOX" : 
				case "RADIO" : e.checked =  false; break;
				case "PASSWORD" : 
				case "TEXT" : e.value = "";
			}
		}
		else if( e.tagName.toUpperCase()=="TEXTAREA" ) {
			e.value = "";
		}
		else if( e.tagName.toUpperCase()=="SELECT" ) {
			e.selectedIndex = 0; 
		}
	}	
}

function initSelect(from, to, selectedValue){
	if( !selectedValue )
		selectedValue = to + 1;
	document.writeln("<option value='-1'>...</option>");
	for(var i=from; i<=to; i++)  {
		document.writeln("<option value='"+i+"'");
		if( i==selectedValue ) {
			document.writeln(" selected='selected'");
		}
		document.writeln(">"+i+"</option>");
	}
}
	
function initTime(howmany,selectedValue){
	if( !selectedValue )
		selectedValue = lastYear + 10;
	for(var i=0; i<=howmany; i++)  {
		document.writeln("<option value='"+i+"'");
		if( i==selectedValue )
			document.writeln(" selected='selected'");
		document.writeln(">"+i+"</option>");		
	}
}

function arrangeDay( day, month, year ) { 
	if( typeof day == 'string' )
		day = document.getElementById(day);
	if( typeof month == 'string' )
		month = document.getElementById(month);
	if( typeof year == 'string' )
		year = document.getElementById(year);
	var day_count;
	if(  month.selectedIndex == 0 || year.selectedIndex == 0 )
		return;

	switch( month.options[ month.selectedIndex ].value ) {
		case "1"  : day_count = 31; break;
		case "2"  : if( (year.options[ year.selectedIndex ].value)%4 == 0 )
						day_count = 29;
					else
						day_count = 28;
					break;
		case "3"  : day_count = 31 ;  break;
		case "4"  : day_count = 30 ;  break;
		case "5"  : day_count = 31 ;  break;
		case "6"  : day_count = 30 ;  break;
		case "7"  : day_count = 31 ;  break;
		case "8"  : day_count = 31 ;  break;
		case "9"  : day_count = 30 ;  break;
		case "10" : day_count = 31 ;  break;
		case "11" : day_count = 30 ;  break;
		case "12" : day_count = 31 ;  break;
		default   : day_count = 31;
	}

	day.options.length = day_count+1;
	for( var i=29; i<=day_count; i++ ) {
		day.options[i].value = i;
		day.options[i].text = i +"";
	}
}

function isValidEmailAddress(str) {
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(str);
}

function isPositiveInteger(str) {
	return /^\+?\d+$/.test(str);
}

function isValidPhoneNumber(str) {
	return /^((\+?\d)?0)?([1-9]\d{9})$/.test(str);
}

function trimAll(str) {
	if( str!=null ) {
		while ( str.length>0 && "\t\n\r ".indexOf( str.charAt(str.length-1) ) != -1 )
			str=str.substring(0, str.length-1);
		while( str.length>0 && "\t\n\r ".indexOf( str.charAt(0) ) != -1 )
			str=str.substring(1,str.length);
	}
	return str;
}

function showMessage(div, message) {
	document.getElementById(div).style.visibility = 'visible';
	document.getElementById(div).innerHTML = message;
}	

function hideMessage(div) {
	document.getElementById(div).innerHTML = "";
	document.getElementById(div).style.visibility = 'hidden';
}	

function createAjax(div) {	
	var ajax = false;	
	var message = "Can not create XMLHttpRequest Object";
	//**************************************************	

	if (window.XMLHttpRequest) {
    	ajax = new XMLHttpRequest();
   	} 
	else if (window.ActiveXObject) {
    	try {
    		ajax = new ActiveXObject("Microsoft.XMLHTTP");
       	}
       	catch(e) {
       		try {
       			ajax = new ActiveXObject("Msxml2.XMLHTTP");
       		}
       		catch(e) { 
       			ajax=false; 
       			showMessage("div",	message);
       		}
       	}
   	}
   	else {  
   		ajax=false; 
		showMessage("div",	message);   	
   	}
   	return ajax;
}

function addEvent(component, eventName, _function) {
	if( component.addEventListener ) { //non microsoft
		component.addEventListener( eventName, _function, false); 
		return _function;
	}
	else if(component.attachEvent){
		component.attachEvent( "on"+ eventName, _function );
		return _function;
	}
	return null;
}

function removeEvent(component, eventName, _function) {
	if( component.removeEventListener ) { //non microsoft
		component.removeEventListener( eventName, _function, false); 
		return _function;
	}
	else if(component.detachEvent){
		component.detachEvent( "on"+ eventName, _function );
		return _function;
	}
	return null;
}

function loadXMLDoc(dname) {
	try   {
  		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  	}
	catch(e) {
  		try {
    		xmlDoc=document.implementation.createDocument("","",null);
    	}
  		catch(e) {alert(e.message);}
  	}
	try {
  		xmlDoc.async=false;
		xmlDoc.load(dname);
  		return(xmlDoc);
  	}
	catch(e) {alert(e.message);}
	return(null);
}

function loadXMLString(txt) {
	try { //Internet Explorer
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(txt);
		return(xmlDoc); 
  	}
	catch(e) {
  		try { //Firefox, Mozilla, Opera, etc.
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(txt,"text/xml");
			return(xmlDoc);
    	}
  		catch(e) {alert(e.message);}
  	}
	return(null);
}

function getWidth(obj) {
	function convert(str) {
		if(!str)
			return 0;
		str = str.replace("px","");
		if( isNaN(str) )
			return 0;
		return parseInt( str ); 
	}
	if( typeof obj == 'string' ) {
		obj = document.getElementById(obj);
	}
	var style; 
	if(  obj.currentStyle ) {
		style = obj.currentStyle;
	}
	else if(  document.defaultView && document.defaultView.getComputedStyle ) {
		style = document.defaultView.getComputedStyle(obj,null);
	} 
	else {
		style = obj.style;
	}
}

function setOpacity(elm, valueBetweenZeroAndOne) {
	// valueBetweenZeroAndOne = 1 > is transparent
	// valueBetweenZeroAndOne = 0 > is opaque
	elm.style.opacity = valueBetweenZeroAndOne; //firefox and others
	elm.style.filter = "alpha(opacity=" + 100*valueBetweenZeroAndOne + ")"; //ie
}

/**
 * create a model dialog.
 * create two layers. First layer make background unresponsive, second layer show dialog box
 * it is recommeded you dont create a new ModalDialog, instead use showMessageDialog and showElementDialog functions
 */
function ModalDialog() {
	var status = "closed";
	var initial_Z = 100;
	var idPrefix = "____sharedJsModal____";
		
	function getGlassPane() {
		return document.getElementById( getGlassPaneId() );
	}
	
	function getGlassPaneId() {
		return idPrefix+"glassPane";
	}
		
	function getMessagePane() {
		return document.getElementById( getMessagePaneId() );
	}
		
	function getMessagePaneId() {
		return idPrefix+"messagePane";
	}
		
	function getCloseImage() {
		return document.getElementById( getCloseImageId() );
	}
		
	function getCloseImageId() {
		return idPrefix+"closeImage";
	}
	
	/**
	 * hide this dialog if it is open
	 */
	this.hide = hide = function() {
		getGlassPane().style.display = "none";
		getMessagePane().style.display = "none";
		status = "closed";
	};	
	
	this.isClosed = function() {
		return status == "closed";
	};
	
	/**
	 * shows close icon on the top right
	 */
	this.showClose = function() {
		if( this.isClosed() )
			throw "dialog is closed, so can not call showClose";
		getCloseImage().style.display = "inline";
	};

	/**
	 * hides close icon on the top right
	 */
	this.hideClose = function() {
		if( this.isClosed() )
			throw "dialog is closed, so can not call showClose";
		getCloseImage().style.display = "none";
	};
	
	/**
	 * Show a modal dialog
	 * if left and top parameters not specified, dialog will be located to the middle of the main window 
	 * @param message : a string as an html text
	 * @param leftArg : distance to the left side of the main window
	 * @param topArg : distance to the top of the main window
	 */
	this.showMessage  = function(message, leftArg, topArg) {
		var newElement = document.createElement("div");
		newElement.innerHTML = message;
		showDialog(newElement, leftArg, topArg);
	};

	/**
	 * Show a modal dialog
	 * @param element : a dom element
	 * @param leftArg : distance to the left side of the main window
	 * @param topArg : distance to the top of the main window
	 */
	this.showElement = function(element, leftArg, topArg) {
		var copy = element.cloneNode(true);
		showDialog( copy, leftArg, topArg );
	};
	
	/**
	 * private
	 */
	function showDialog(element, leftArg, topArg) {
		if( element.style.display && element.style.display.toLowerCase() == "none" )
			element.style.display = "block";
		element.style.visibility = "visible";
		if( !getGlassPane() ) {
			createPanes();
		}

		var messagePane = getMessagePane();
		var glassPane = getGlassPane();
		var closeImage = getCloseImage();

		var children = messagePane.childNodes;
		for( var i=0; i<children.length; i++ ) {
			var e = children[i];
			if( closeImage!=e )
				messagePane.removeChild( e );
		}
		messagePane.appendChild( element );
		
		messagePane.style.display = "block";
		glassPane.style.display = "block";


		var left = leftArg, top = topArg;
		if( !leftArg || !topArg ) {
			left =  50;
			top = 50;
		}

		messagePane.style.left = left + "px";
		messagePane.style.top =  top+ "px";
		
		status = "open";	
	}
	
	/**
	 * private
	 */
	function createPanes() {
		//create glass pane
		var glassPane = document.createElement("div");
		glassPane.setAttribute("id", getGlassPaneId() );
		glassPane.style.display = "none";
		glassPane.style.position = "fixed";
		glassPane.style.left = "0px";
		glassPane.style.top = "0px";
		glassPane.style.margin = "0px";
		glassPane.style.padding = "0px";
		glassPane.style.width =  "100%";
		glassPane.style.height = "100%";
		glassPane.style.backgroundColor = "#d0d0d0";
		glassPane.style.zIndex = initial_Z;
		setOpacity(glassPane, 0.5);
		
		var messagePane = document.createElement("div");
		messagePane.setAttribute("id", getMessagePaneId() );
		messagePane.style.display = "none";
		messagePane.style.position = "fixed";
		messagePane.style.borderBottom = messagePane.style.borderRight = "outset 2px #c0c0c0";
		messagePane.style.padding = "2px 22px 5px 2px";
		messagePane.style.backgroundColor = "#FFFFFF";
		messagePane.style.overflow = "auto";
		messagePane.style.zIndex = initial_Z+1;
		setOpacity(messagePane, 1.0);
		
		var closeImage = document.createElement("span");
		closeImage.setAttribute("id", getCloseImageId() );
		closeImage.innerHTML = "&nbsp;X&nbsp;";
		closeImage.style.position = "absolute";
		closeImage.style.fontWeight = "bold";
		closeImage.style.top = "0px";
		closeImage.style.right = "0px";
		closeImage.style.border = "outset 2px #c0c0c0";
		closeImage.style.borderRight = "";
		closeImage.style.cursor = "pointer";
		closeImage.onclick = this.hide;

		messagePane.appendChild( closeImage );
		document.body.appendChild( glassPane );
		document.body.appendChild( messagePane );
	}
}

/**
 * show a modal dialog containing message
 * @param message : text to show
 * @param showCloseTime : if this parameter specified then if dialog has not been closed for showCloseTime miliseconds
 *                         a close link will appear after message
 */
function showMessageDialog(message, showCloseTime) {
	var dialog = window.dialog;
	if( !dialog ) {
		dialog = window.dialog = new ModalDialog();
	}
	/*if( !dialog.isClosed() ) {
		throw "another dialog already open";
	}
	*/
	
	var div = window.dialogDiv = document.createElement("div");
	div.style.padding = "3px";
	div.style.font = "normal 11px Verdana";
	div.style.color = "#333333";
	div.innerHTML = "<img src='/image/loading.gif' style='margin-right: 4px; border-width: 0px' />" + message; 
	dialog.showElement( div );
	dialog.hideClose();
	if( showCloseTime ) {
		dialog.timeout = window.setTimeout( 
				function() { 
					if( !dialog.isClosed() )
						dialog.showClose();
				},
				showCloseTime
		);
	}
}

function showElementDialog(message) {
	var dialog = window.dialog;
	if( !dialog ) {
		dialog = window.dialog = new ModalDialog();
	}
	dialog.showMessage(message);
}

function hideElementDialog() {
	dialog.hide();
}

/**
 * hides dialog
 */
function hideMessageDialog(str) {
	if( str ) {
		
	}
	else {
		dialog.hide();
	}
	try {
		window.clearTimeout( dialog.timeout );
		dialog.timeout = null;
	} catch(e) { } 
}

/**
 * refresh page 
 */
function reloadPage() {
	window.location = window.location.href.split("#")[0];
}

/**
 * reload opener window, from child window
 */
function reloadOpener() {
	if( window.opener ) 
		window.opener.location = window.opener.location.href.split("#")[0];
	else
		throw "window opener is null";
}

function createCookie(name,value,seconds) {
	var expires;
	if (seconds) {
		var date = new Date();
		date.setTime(date.getTime()+(seconds*1000));
		expires = "; expires="+date.toGMTString();
	}
	else 
		expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/**
 * if str is longer than maxLength, takes first (maxLength-3) characters of str
 * @param str : input string
 * @param maxLength : max length of string
 * @param appendStr : if parameter specified and str is longer than maxLength then this parameter will be appended to shorter str  
 * @return
 */
function cutString(str, maxLength, appendStr) {
	if( !str || str.length<=maxLength)
		return str;
	str.substring(0, maxLength-3) + (appendStr ? appendStr:'');
}

/**
 * show str in element#blockId for delay seconds and hide message for delay seconds
 * repeat this operation count times
 * @param blockId : id of dom element
 * @param str : message will be shown
 * @param count : how many times will be repeat
 * @param delay : delay between show and hide - hide and show
 */
function blinkMessage(blockId, str, count, delay) {
	count = count || 4;
	delay = delay || 350;
	var block = document.getElementById(blockId);
	block.style.visibility = "visible";
	block.innerHTML = str;
	for(var i=0; i<count; i++) {
		setTimeout( function(){ block.style.visibility = "visible"; }, (2*i+1)*delay);
		setTimeout( function(){ block.style.visibility = "hidden";}, (2*i+2)*delay);		
	}
	setTimeout( function(){ block.style.visibility = "visible"; }, (2*i+1)*delay);
}

function onEnter_clickButton(formId) {
	var form = document.getElementById( formId );
	var len = form.elements.length;
	var submit = null;
	for( var i=0; i<len; i++ ) {
		var element = form.elements[i];
		if( element.type && element.type=='submit' ) {
			submit = element;
		}
	}
	if( !submit )
		throw "can not find any type='submit' button";
	var keyPressEvent = function(event) {
		if(event.keyCode==13) {
			if( event.preventDefault ) {
				event.preventDefault();
			}
			else {
				event.returnValue = false;
			}
			submit.click();
		}
	};
	addEvent(form, "keypress", keyPressEvent );
}

function enterText_clickButton(textId, buttonId) {
	var text = document.getElementById(textId);
	var button = document.getElementById(buttonId);
	var keyPressEvent = function(event) {
		if(event.keyCode==13) {
			if( event.preventDefault ) {
				event.preventDefault();
			}
			else {
				event.returnValue = false;
			}
			button.click();
		}
	};
	addEvent(text, "keypress", keyPressEvent );
}

function preventEnterSubmit(formId) {
	var form = document.getElementById( formId );
	var keyPressEvent = function(event) {
		if(event.keyCode==13) {
			if( event.preventDefault ) {
				event.preventDefault();
			}
			else {
				event.returnValue = false;
			}
		}
	};
	addEvent(form, "keypress", keyPressEvent );
}

function reRenderMessage(id,hidden_id){
	var hiddenElement = document.getElementById(hidden_id);
	var element = document.getElementById(id);
	if ( element.hasChildNodes() ){
   		while ( element.childNodes.length >= 1 ){
     			  element.removeChild( element.firstChild );       
  			 } 
	}
	if(hiddenElement.hasChildNodes()){
		for(var i = 0 ; i< hiddenElement.childNodes.length ; i++){
			var child = hiddenElement.childNodes[i];
			element.appendChild(child);
		}
	}
}

function getEventTarget(event) {
	var targ;
	var evt = event || window.event;
	if (evt.target) targ = evt.target;
	else if (evt.srcElement) targ = evt.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}

function postParams(url, params) {
	/*
	var httpPort, httpsPort;
	if( dynamic ) {
		httpPort = dynamic["httpPort"];
		httpsPort = dynamic["httpsPort"];
	}
	httpPort = httpPort || 80;
	httpsPort = httpsPort || 443;
	var h = window.location;
	
	var isSecure =  url.indexOf('/secure/')>=0;

    // get the scheme we want to use for this page and
    // get the scheme used in this request
    var desiredScheme = isSecure ? "https:" : "http:";
    var usingScheme = h.protocol;
    
    var desiredPort = isSecure ? httpsPort : httpPort;
    var usingPort = h.port ? h.port : (h.protocol=="http:" ? 80 : 443);

    if ( desiredScheme != usingScheme || desiredPort != usingPort ) {
        url = desiredScheme + "//" + h.hostname + ":" + desiredPort + url;
    }
    */
    
	var form = document.createElement("form");
	form.method = "post";
	document.body.appendChild(form);
	form.action = url;
		
	for(var name in params ) {
		var value = params[name];
		var c = document.createElement("input");
		c.type = "hidden";
		c.name = name;
		c.value = value;
		form.appendChild( c );
	}
	form.submit();
	return false;
}

function logout() {
	var url = window.location.pathname;
	var params = { rj_logout:"true" };
	postParams( url, params );
}

function idyLogout() {
	postParams('/company/', {logout: true});
}

function round(value, fraction) {
	var multiplier = Math.pow(10, fraction);
	return Math.round( value*multiplier )/multiplier;
}


function searchInClips(element, url, pubName, date) {
	if( typeof element == 'string' )
		element = document.getElementById(element);
	element.value = trimAll( element.value );
	if( element.value ) {
		var params = {"words":  element.value};
		if( pubName )
			params["pubName"] = pubName;
		if( date )
			params["date"] = date; 
		postParams(
				dynamic.ctx + url,
				params
		);
	} 
}

function getWindowDimensions() {
	if(  isIE ) {
		return { width: document.body.clientWidth, height: document.body.clientHeight };
	}
	else {
		return { width: window.innerWidth, height: window.innerHeight };
	}	
}

/**
 * format message, like java's MessageFormat.format(str, args)
 * 
 * ex: input="{0}, the second {1}, again the first {0}", args = ["theFirst", "theSecond"], 
 * output="theFirst, the second theSecond, again the first theFirst"
 * 
 * ex: input="{0} newspaper ve {0} newspaper's clips", args = "Star", 
 * output="Star newspaper ve Star newspaper's clips"
 * 
 * @param input string which inclued {number} patterns
 * @param args replace array or replace element
 * @return formatted new string
 */
function formatMessage(input, args) {
	//check if args if array, if not then args into one-element array
	if( !(args instanceof Array)  ) {
		args = [ args ];
	}
		
	var ind = 0;
	var len = input.length;
	var newStr = "";
	var escaped = false;
	var numbers = "0123456789";

	while(ind < len) {
		var ch = input.charAt(ind);
		if(  ch=='{' ) {
			var num = "";
			var appended = false;
			while( ind<len ) {
				ch = input.charAt( ++ind );
				
				//try to find the number in the "{}" pair
				if( numbers.indexOf( ch )!=-1 ) {
					num += ch;
				}
				else if( ch=='}' ) {
					num = parseInt( num );
					newStr += args[ num ];
					appended = true;
					break; 
				}
				else if( ch=='{' ) {
					newStr += '{' + num;
					num = "";
					appended = false;
				}
				else {
					break;
				}
			}
			if( !appended ) {
				newStr += '{' + num + ch;
			}	   
		}
		else {
			//if the char is escape, simple add the next char
			//otherwise, append the char to new string
			if( ch=='\\' ) 
				newStr +=  ind<len-1? input.charAt(++ind) : ''; //check length, then append
			else 
				newStr += ch;		
		}
		ind++; 
	}
	 
	return newStr;
}

function getStyle(elm, styleProp) {
	var value;
	if (elm.currentStyle)
		value = elm.currentStyle[styleProp];
	else if (window.getComputedStyle)
		value = document.defaultView.getComputedStyle(elm,null).getPropertyValue(styleProp);
	return value;
}


function swapColors(elm){
	var bgColor = getStyle(elm, 'background-color') || getStyle(elm, 'backgroundColor');
	var color = getStyle(elm, 'color');
//	alert( "bgColor = " + bgColor + ",  color = " + color)
	elm.style.backgroundColor = color;
	elm.style.color = bgColor;
}


function __Logger__() {
	if( this.alreadyCreated ) {
		throw "an instance of Debugger already created";
	}
	this.alreadyCreated = true;
	
	var divWidth = 500, divHeight = 300, menuHeight = 20;
	var opacity = 1;

	var div = document.createElement("div");
	div.style.position = "fixed";
	div.style.width = divWidth + "px";
	div.style.height = divHeight + "px";
	div.style.top = "0px";
	div.style.left = "0px";
	setOpacity(div, 0.95); 
	div.style.border = "1px solid black";
	div.style.backgroundColor = "#e2e2e2";
	div.style.zIndex = "1000";
	
	var textArea = document.createElement("textarea");
	div.appendChild(textArea);
	textArea.style.margin = "0px";
	textArea.style.border = "1px solid black";
	textArea.disabled = true;
	textArea.style.position = "absolute";
	textArea.style.left = "5px";
	textArea.style.top = "5px";
	textArea.style.width = divWidth - 5 - 5 + "px";
	textArea.style.height = divHeight - 5 - 5 - 5 - 1 - 1 - menuHeight + "px";
	textArea.style.backgroundColor = "#e2e2e2";
	textArea.style.color = "black";
	textArea.value = "";
	
	var menu = document.createElement("div");
	div.appendChild(menu);
	menu.style.margin = "0px";
	menu.style.position = "absolute";
	menu.style.width = divWidth - 10 - 1 - 1 + "px";
	menu.style.height = menuHeight + "px";
	menu.style.left = "5px";
	menu.style.bottom = "5px";
	menu.style.border = "1px solid black";
	menu.style.textAlign = "right";
	
	var a = document.createElement("a");
	menu.appendChild(a);
	a.innerHTML = "[Hide]";
	a.style.textDecoration = "none";
	a.href = "#";
	a.style.paddingRight = "5px";
	a.style.color = "black";
	a.onclick = function() {
		if( this.innerHTML == "[Hide]" ) {
			textArea.style.display = "none";
			div.style.height = menuHeight + 5 + 5 + "px";
			this.innerHTML = "[Show]";
		}
		else {
			div.style.height = divHeight + "px";
			textArea.style.display = "block";
			this.innerHTML = "[Hide]";
		}
	};
	
	a = document.createElement("a");
	menu.appendChild(a);
	a.innerHTML = "[Close]";
	a.style.color = "black";
	a.href = "#";
	a.style.textDecoration = "none";
	a.style.paddingRight = "5px";
	a.onclick = function() {
		document.body.removeChild(div);
		window._Logger_ = "closed";
	};
	document.body.appendChild(div);
	
	this.log = function(message) {
		textArea.value = message + "\n" + textArea.value; 
	};
}

function log(message) {
	if( !window._Logger_ ) {
		window._Logger_ = new __Logger__();
	}
	if( window._Logger_ == 'closed' ) {
		return;
	}
	window._Logger_.log(new Date().toLocaleString() + " : \n |__" + message);
}

function removeChildren(elm) {
	while( elm.childNodes.length>0 ) {
		elm.removeChild( elm.childNodes[0] );
	}
}
//use turkish
function toLowerCase(str) {
	if( !str )
		return str;
	return str.replace(/İ/g,"i").replace(/I/g, "ı").toLowerCase();
}


function openPopup(url, windowName) {
	if(!windowName)
		windowName = 'popup_' + new Date().getTime();
	var win = window.open(url, windowName,
			"resizable=1, scrollbars=1, location=0, status=1, toolbar=0, menubar=0, top=20, left=20, directories=0, "+ 
			"width=980, height=600");
	if( win )
		win.focus();
	
	return win;
}

function refreshPage(win) {
	var win = win || window;
	win.location = win.location.toString();
}

function stopPropagation(event) {
	if(event.stopPropagation) 
	 	event.stopPropagation();
	 else
	 	event.cancelBubble = true;
}

function addScript(src) {
	var bdy = document.getElementsByTagName("body")[0];
	var script = document.createElement('script');
	script.setAttribute('type', 'text/javascript');
	script.setAttribute('src', src);
	bdy.appendChild(script);
} 

function addStyle(src) {
	var bdy = document.getElementsByTagName("body")[0];
	var style = document.createElement('link');
	style.setAttribute('type', 'text/css');
	style.setAttribute('rel', 'stylesheet');
	style.setAttribute('href', src);
	bdy.appendChild(style);
}

function hasVideoSupport() {
	var v = document.createElement('video');
	return !!v.canPlayType && v.canPlayType('video/mp4; codecs="avc1"');
}

var $player;
function playVideo(url, options, playerId) {
	if( !playerId )
		playerId = "player";
	stopVideo();
	if( hasVideoSupport() ) {
		$player = jq("<video></video>");
		$player.attr({	
			src: options.netConnectionUrl.replace("rtmp://", "http://")
					.replace("/tv_radyo", "/doc_path_3") + 
					"/" + url.substring(4),
			controls : "controls",
			preload : "preload"
		})
		.css({
			width : "100%",
			height : "100%"
			
		})
		.appendTo("#"+playerId);
	}
	else {
		$player = $f(playerId, options.core, {
			play : {
				replayLabel : 'Tekrar İzle'
			},
			clip : {
				provider : 'rtmp',
				autoBuffering : true,
				autoPlay : false,
				url : url
			},
			plugins : {
				controls : {
					url : options.controls
				},
				rtmp : {
					url : options.rtmp,
					netConnectionUrl : options.netConnectionUrl
				}
			}
		});
	}
}

function stopVideo() {
	if(!$player)
		return;
	if( hasVideoSupport() ) {
		$player.get(0).pause();
		$player.parent().empty();
	}
	else {
		$player.stop();
		$player.unload();
		jq( "#"+$player.id() ).empty();
	}
	$player = null;
}

function pauseVideo() {
	if(!$player)
		return;
	if( hasVideoSupport() ) {
		$player.get(0).pause();
	}
	else {
		$player.pause();
	}
}

function checkRequired(elements) {
	if( !jq.isArray(elements) )
		elements = [elements];
	var focused = false;
	var success = true;
	for(var i=0; i<elements.length; i++) {
		var $el = jq(elements[i]);
		$el.val(jq.trim($el.val()));
		if( !$el.val() ) {
			$el.data("border-color", $el.css("border-color"));
			$el.css("border-color", "#ff0000");
			$el.bind("keyup", function(){
				var $this = jq(this);
				$this.css("border-color", $this.data("border-color"));
				$this.removeData("border-color");
				$this.unbind("keyup");
			});
			if( !focused ) {
				focused = true;
				$el.focus();
			}
			success = false;
		}
	}
	return success;
}


function divideTableRow(table, column) {
	var $table = jq(table);
	var $remains = $table.find("tr:first td:gt("+(column-1)+")").remove();
	while($remains.length>0) {
		jq("<tr></tr>").append( $remains.filter(":lt("+column+")") ).appendTo($table);
		$remains = $remains.filter(":gt("+(column-1)+")");
	}
}
