var context_menu_enabled = false;
var RTELoad_Finished = false;
var loadedStory = false;
var key_Enabled;
var key_shiftKey = 0;
var key_ctrlKey = 1;
var default_title = "";
var server_msg_mode = false;
var next_func;
var cix = 0;
var bd = ("function" == typeof globalCaps) ? new globalCaps() : new Object();
var baseHostRef = "";
window.onload = init_document_load;

function clipLongImageURLs__(sText){
//	var loong = (baseHostRef) ? baseHostRef : "xxx"; //"src=\"http://" + thisHost + "/";
	return String(sText).replace(/\baseHostRef/gi, "");
}

function shiftDate(nDays){ var inDays = isN(nDays) ? nDays : 0; return new Date(new Date().getTime() + inDays * 24 * 60 * 60 * 1000); }

function out(){	document.write("<br>" + arguments[0]); }
function randomNumber() { return Math.round(Math.random()*10000); }
function randomNumberBetween(min,max) {	return(Math.round((max-min)*Math.random())+min); }
function isString(){ var v = arguments[0]; var result = Boolean("string" == typeof v); if(result) return true; if("object" != typeof v) return false; return Boolean(v.constructor == String); }
function isSelected( val1, val2 ) { if ( String( val1 ) == String( val2 ) ) { return " selected"; } return ""; }
function isChecked( val1, val2 ) { if ( String( val1 ) == String( val2 ) ) { return " checked"; } return ""; }
function makeBold() { var str = new String( arguments[0] ) ; if( true != arguments[1] ) { return str; } return "<B>" + str + "</B>"; }
function isN() { if (isNaN(arguments[0])) { return false; } var s = new String(arguments[0]); if (-1 != s.indexOf(",")) { return false; } if(true == arguments[1]) { return true; } return (-1 == s.indexOf(".")); }
function milliDif() { return new Date().getTime(); }
function getTimeZoneOffSet() { if ( true == arguments[0] ) { return Math.round( Number(0 - new Date().getTimezoneOffset()) / 60 ); } else { return Number(0 - new Date().getTimezoneOffset()); } }
function shiftDate(nDays){ var inDays = isN(nDays) ? nDays : 0; return new Date(new Date().getTime() + inDays * 24 * 60 * 60 * 1000); }
function nChar(_char, n){ var s = new String(""); var charX = ("number" == typeof _char) ? String.fromCharCode(_char) : new String(_char); for(var i=0;i<n;i++){ s += charX; } return s; }
function linerMessage(){ var msg = ( undefined == arguments[0] ) ? "" : arguments[0]; var omsg = ( undefined == arguments[1] ) ? "" : arguments[1]; return " onmouseover=\"top.status='" + msg + "';if(document.all){this.style.textDecoration='underline';}return true;\" onmouseout=\"top.status='" + omsg + "';if(document.all){this.style.textDecoration='none';}return true;\" "; }

function init_document_load(){
  top.status = "";
  if("string" == typeof defaultWindowStatus) top.status = defaultWindowStatus;
  if("string" == typeof defaultWindowStatus) top.defaultStatus = defaultWindowStatus;
  if ("function" == typeof init) init();
	if("function" == typeof next_func){
//		alert(typeof(next_func) + " next_func::calling..");
		setTimeout("next_func()", 10);
		
	};
  if(("function" == typeof refresh_page)&&(do_refresh==true)){
    var ___refresh_page_timeout = (!isNaN(refresh_page_timeout)) ? refresh_page_timeout : 5*60;
    setTimeout("refresh_page()", ___refresh_page_timeout*1000 );
  }
  if("function" == typeof check_form) setTimeout("check_form()", 10);
}

function refresh_page_status(){
cix++;window.setTimeout( "refresh_page_status()", 1000 );
if(cix>=refresh_page_timeout){/*self.document.body.title = */ top.status = "waiting reload.";return;}
top.status = String(refresh_page_timeout-cix) + " seconds to reload  ::  Server Time : 18:43:43\" on path \"../../../../pub/news/getdoc\"";
/*self.document.body.title = */ // top.document.title = String(refresh_page_timeout-cix) + " seconds to reload  ::  Server Time : 18:43:43; PahtInfo is \"../../../../pub/news/getdoc\"";
}

function setup_context_menu_handler()
{
 if(!document.all) return;
		if ( "function" == typeof handle_context_menu )
		{
//			alert("Document '" + location.href + location.search + "' loaded with handle_context_menu() enabled ..");
			if ( "number" == typeof arguments[0] )
			{
				if ( ( key_shiftKey == arguments[0] ) || ( key_ctrlKey == arguments[0] ) )
				{
					key_Enabled = arguments[0];
					context_menu_enabled = true;
				}
			}
			document.body.oncontextmenu = handle_context_menu;
		}
		if( "function" == typeof handle_messages && false )
		{
			with( document )
			{
			//	ondblclick = onmousedown = onmouseup = onmouseover = onmouseout = onkeyup = onclick = onselectstart = handle_messages;
			}
		}
}

function handle_context_menu()
{
	var oEl = event.srcElement;
//	top.document.title = "TAG : " + oEl.tagName;
    var tagName = (oEl.tagName) ? oEl.tagName.toUpperCase() : "";
	if(("TEXTAREA" == tagName)||(("INPUT" == tagName)&&("TEXT" == oEl.type.toUpperCase())))
	{
		return true;
	}
	else
	{
//		return true;
		if ( context_menu_enabled )
		{
			if ( key_Enabled == key_shiftKey ) return event.shiftKey;
			if ( key_Enabled == key_ctrlKey ) return event.ctrlKey;
		}
		return false;
	}
	/*
	top.document.title = "TAG : " + oEl.tagName;
	return event.ctrlKey;
	return true;
	var s = "TAG: '" + oEl.tagName + "'; ";
	s += "CLASS: '" + oEl.className + "'; ";
	s += " (" + event.clientX + "," + event.clientY + ")";
	top.status = s;
	*/
}

function a(){
	if( true == arguments[1]){
		if("object" == typeof arguments[2]){
			if(document.all) arguments[2].innerHTML += "<br>" + arguments[0];
		}
		else
		document.write("<br>" + arguments[0]);
	}
	else alert("Message :\n" + arguments[0]);
}

function sessionCookiesEnabled()
{
		return cookiesEnabled( "ASPSESSIONID" );
//		var cookieString = new String( document.cookie ); if ( 0 == cookieString.length ) { return false; } return ( Boolean( -1 != cookieString.indexOf( "ASPSESSIONID" ) ) )
}

function cookiesEnabled()
{
		var cookieString = new String( document.cookie );
		if ( 0 == cookieString.length ) { return false; }
		var cookieEl = ( "undefined" != typeof arguments[0] ) ? new String( arguments[0] ) : new String( "" );
		if ( 0 == cookieEl.length ) { return false; }
		return ( Boolean( -1 != cookieString.indexOf( cookieEl ) ) )
}
//	sessionCookiesEnabled() === cookiesEnabled( "ASPSESSIONID" )
function setCookie( cookieStr, expDate, path, domain)
{
	if ( "undefined" == typeof cookieStr ) return false;
	var cDate;
	if ( "undefined" == typeof expDate )
	{
		cDate = new Date(); var cTime = cDate.getTime(); cTime += 600000; cDate.setTime(cTime);
	}
	else
	{
		cDate = expDate;
	}
	var cPath = ( "undefined" == typeof path ) ? "../../../../default.htm" : path;
	var cDomain = ( "undefined" == typeof path ) ? "." : domain;
	if ( "." == domain ) return false;
	document.cookie = cookieStr + "; path=" + cPath + "; expires=" + cDate.toGMTString() + "; domain=" + cDomain + "";
	var test = new String( document.cookie );
	return ( Boolean( -1 != test.indexOf( cookieStr ) ) );
}

function setBasicCookie( cName, Props , Years )
{	// disabled function ..
	return false;
	var today = new Date();
	var expiration = new Date( today.getTime() + ( Years * 365 * 24 * 60 * 60 * 1000 ) );
	document.cookie = escape(cName) + "=" + Props + "; path=/; expires=" + expiration.toGMTString();
}

function goToURL(sUrl, bDontKeepInHistory){
	var url = (arguments[0]) ? new String(arguments[0]) : new String("");
	if (0 == url.length) url = "../../../../default.htm";
	if (true == arguments[1]) { window.location.replace(url); return;}
	location.href=url;
}

function ow(sURL, sWinName, iWidth, iHeight, sWinProperties, sBodyText){
	//self.name = "mainwindow";
        var ___win___ = winMaker(sURL, sWinName, iWidth, iHeight, sWinProperties, sBodyText); if(parseInt(navigator.appVersion)>3) ___win___.focus();
}

// var w = winMaker("../../../../help/@1", "HelpWin", 200, 160, "resizable=no,scrollbars=yes,status=no");
function winMaker(sURL, sWinName, iWidth, iHeight, sWinProperties, sBodyText){
	var url = (("string" == typeof arguments[0]) || (String == arguments[0].constructor)) ? new String(arguments[0]) : new String("");
	var winName = (("string" == typeof arguments[1]) ? new String(arguments[1]) : new String("popupWindow"));
	var iw = (("number" == typeof arguments[2]) ? arguments[2] : 300);
	var ih = (("number" == typeof arguments[3]) ? arguments[3] : 200); var DefaultProperties = "resizable=yes,scrollbars=yes,status=no,menubar=no,directories=no,copyhistory=no,menubar=0,directories=0";
	var wProps = ("string" == typeof arguments[4]) ? new String(arguments[4]) : new String("");
	var bodyString = ("string" == typeof arguments[5]) ? arguments[5] : "";
	if(0 == wProps.length) wProps = DefaultProperties;
	wProps += ",width=" + iw + ",height=" + ih + "" ;
//	alert( url + ";" + winName + ";" + bodyString + ";" + iw + "x" + ih + ";" + wProps );
	var popupWindow = window.open(url, winName, wProps);
	if(0 < bodyString.length){
		var popupWinDoc = popupWindow.document;
		popupWinDoc.write(bodyString);
		popupWinDoc.close();
	}
	return popupWindow;
}

function o(){
	if(!document.all){return true;}
	var obj;
	if("string" == typeof arguments[0]){
          obj = document.all(String( "" + arguments[0] ));
	}
	else if("object" == typeof arguments[0]){
          obj = arguments[0];
	}
	else{
          return false;
	}
	if(!obj){return false;}
	if(1 == arguments[1]){obj.style.textDecoration = 'underline'; return true;}
	obj.style.textDecoration = 'none'; return true;
}

function statusMsg(){
  if("string" == typeof arguments[0]){
          top.status = arguments[0];
  }
  else{
          top.status = top.defaultStatus; // "";
  }
  //	top.document.title = default_title;
  //	server_msg_mode = false;
}

function showStatus()
{
  var s = (arguments[0]) ? arguments[0] : "";//alert(s);
  top.status=s;
}

function globalCaps(){
	var UA = navigator.userAgent;
	if(UA.indexOf("MSIE") != -1){
		this.ie = true;
		var v = UA.charAt(UA.indexOf("MSIE") + 5);
		if(v == 2 ) this.ie2 = true;
		else if(v == 3 ) this.ie3 = true;
		else if(v == 4 ) this.ie4 = true;
		else if(v == 5 ) this.ie5 = true;
		else if(v == 6 ) this.ie6 = true;
		else if(v > 6 ) this.ie6_plus = true;
		if(this.ie4 || this.ie5 || this.ie6 || this.ie5_plus) this.UL = true;
	}else if(UA.indexOf("Mozilla") != -1 && UA.indexOf("compatible") == -1){
		this.nav = true;
		var v = UA.charAt(UA.indexOf("Mozilla") + 8);
		if(v == 2 ) this.nav2 = true;
		else if(v == 3 ) this.nav3 = true;
		else if(v == 4 ) this.nav4 = true;
		else if(v == 6 ) this.nav6 = true;
		else if(v > 4 ) { this.nav4 = true; this.nav4_plus = true; }
	}
	if(UA.indexOf("Windows 95") > 0 || UA.indexOf("Win95") != -1 || UA.indexOf("Win98") != -1 || UA.indexOf("Windows 98") != -1 || UA.indexOf("Windows NT") != -1) this.win32 = true;
	else if(UA.indexOf("Windows 3.1") != -1 || UA.indexOf("Win16") != -1) this.win16 = true;
	else if(UA.indexOf("Mac") != -1) this.anymac = true;
	else if(UA.indexOf("SunOS") != -1 || UA.indexOf("HP-UX") != -1 || UA.indexOf("X11") != -1) this.unix = true;
	else if(UA.indexOf("Windows CE") != -1) this.wince = true;
}

function daysInMonth(intmonth, intyear){
	if (intmonth == 9 | intmonth == 4 | intmonth == 6 | intmonth == 11)
		return 30;
	else if (intmonth != 2)
		return 31;
	else if (intyear == 2000)
		return 29;
	else if ((intyear % 4 != 0) || ((intyear % 100 == 0) && (intyear % 400 != 0))) 
		return 28;
	else
		return 29;
}

function adjustDay(dayop, monthop, yearop){
	var y="";
	if( (yearop.options[yearop.selectedIndex].value=='00') || (yearop.options[yearop.selectedIndex].value=='01') )
		y='20'+yearop.options[yearop.selectedIndex].value;
	else
		y='19'+yearop.options[yearop.selectedIndex].value;
	lastDay = daysInMonth(monthop.options[monthop.selectedIndex].value, y) - 1;
	var t=lastDay+1; var m=monthop.selectedIndex+1;
//	alert('Calculated lastDay value in the '+m+'. month of '+y+' is: '+t);
	if (dayop.selectedIndex > lastDay) {
//		alert('dayop has selected greater than real value, selected: '+dayop.selectedIndex+', real days: '+lastDay+'; now being changed..');
		dayop.selectedIndex = lastDay;
	}
}

function dateExplained() {
   monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
   myDate  = new Date();
   var year = myDate.getYear();
   if (year < 1000) year += 1900;
   return "<B>" + monthNames[myDate.getMonth()] + "  " + myDate.getDate() + ", " + year + "</B>";
}

function setHomePage(){
	document.text.style.behavior='url(#default#homepage)';
	document.text.sethomepage('../../../../../www.testdomain.com/');
}

function setBookmark(){
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)){
		window.external.AddFavorite ('../../../../../www.testdomain.com/default.htm','Test Domain');
	}
	else{
		alert( "To bookmark Test Domain with Netscape, press CTRL+D!" );
	}
}

function isInputEmpty(o,warning){
  if (o.value.length==0){alert(warning);  o.focus(); return true;}
}

function checkNum(o,theMin, theMax){
  if(isNaN(o.value)){alert("Number only please!"); o.value=""; return false;}
  else if (parseFloat(o.value)<theMin || parseFloat(o.value)>theMax){alert("The value given is out of range!");o.value=""; return false;}
}

function getRadioValue(radioObject) {
	var value;
	for (var i=0; i<radioObject.length; i++) {
	if (radioObject[i].checked) {
		value = radioObject[i].value;
		break;}
	}
	return value;
}

function isRadioNotChecked(o,warning){
  if(getRadioValue(o)==null){alert(warning);return true;}
}

function isNotSelected(o,warning){
  if(o.selectedIndex==0){alert(warning);o.focus(); return true;}
}

function isValidEmail(o, warning) {
	var locAt;
	var locPeriod;
	var okEmail;

	locAt = o.value.indexOf("@");
	okEmail = ((locAt != -1) && 
			   (locAt != 0) &&
			   (locAt != (o.value.length - 1)) &&
			   (o.value.indexOf("@", locAt + 1) == -1)
			  );
	if (okEmail) {
		// so far, so good
		locPeriod = o.value.indexOf(".");
		okEmail = ((locPeriod != -1) && (locPeriod != (o.value.length - 1)));
	}
	if ( okEmail==false ) {
     alert(warning);  o.focus();
     return okEmail;
   }

	return okEmail;
}

function checkRequired(f){
  if (isInputEmpty(f.fname,"Your first name is required.")){return false;}
  if (isInputEmpty(f.lname,"Your last name is required.")){return false;}
  if (isNotSelected(f.country_id,"Please select your country")){return false;} 
  if (isInputEmpty(f.wphone,"Phone is required.")){return false;}
  if (isValidEmail(f.email,"Please provide your Email address.")==false){return false;}
  if (isNotSelected(f.industry_id,"Please select your organization's primary industry")){return false;} 
  if (isNotSelected(f.orgsize_id,"Please select your organization size")){return false;} 
  f.submit();
  return true;
}

function showEl(elementId) 
{
	if(bd.nav6)
	{
		var myElement = document.getElementById(elementId);
		myElement.style.visibility = "visible";
	}
	else if(bd.nav4)
	{
   		eval("document.layers['"+elementId+"'].visibility='show';");
	}
	else if(bd.ie)
	{
		eval("document.all."+elementId+".style.visibility='visible';");
	}
}

function hideEl(elementId)
{
	if(bd.nav6)
	{
		var myElement = document.getElementById(elementId);
		myElement.style.visibility = "hidden";
	}
	else if(bd.nav4)
	{
   		eval("document.layers['"+elementId+"'].visibility='hide';");
	}
	else if(bd.ie)
	{
		eval("document.all."+elementId+".style.visibility='hidden';");
	}
}

function clearServerMsgBox()
{
if(!document.all) return; if(!document.all.msgBox_ServerMsg) return;
document.all.msgBox_ServerMsg.innerHTML = "";
}

function delay_ms(ms){
//	var MinMilli = 1000 * 60; var HrMilli = MinMilli * 60; var DyMilli = HrMilli * 24;
	var t = new Date().getTime();
	var _ms = (ms&&!isNaN(ms)) ? ms : 1; if(_ms>10*000) _ms = 10*000;
	while((new Date().getTime()-t)<_ms){;}
}

function strCompress(str, iWidth){
	if(!str) return String("");
	var _iWidth = (iWidth&&!isNaN(iWidth)) ? iWidth : 50;
	var result = ""; var pp = str;
	while(pp.length>_iWidth){
		if(""!=result) result += "\n";
		result += pp.substr(0, _iWidth);
		pp = pp.substr(_iWidth);
	}
	if(""!=pp){
		if(""!=result) result += "\n";
		result += pp;
	}
	return result;
}

function fnErrorTrap(sMsg,sUrl,sLine){
   var errHandlerResponse = "";
   errHandlerResponse += "\n"; //"\nAn error was thrown and caught!\n";
   errHandlerResponse += "HATA MESAJI: " + sMsg + "\n";
   errHandlerResponse += "SATIR: " + sLine + "\n";
   var _sURL = String(sUrl); if(_sURL.length>100){
   if(-1!=_sURL.indexOf("?")){
   var p1 = _sURL.substr(0,_sURL.indexOf("?")+1); var p2 = _sURL.substr(_sURL.indexOf("?")+1);
   p2 = strCompress(p2, 80)//if(p2.length>100) p2 = p2.substr(0,100) + "\n" + p2.substr(100);
   _sURL = p1 + "\n" + p2;
   }
   else{
   ; //_sURL = strCompress(_sURL, 100).substr(0,100) + "\n" + _sURL.substr(100);
   }
   }
   //errHandlerResponse += "URL : " + _sURL + "\n";
   errHandlerResponse += "URL : " + sUrl.substr(0, sUrl.indexOf("?")+1) + "...\n";
   // showErrorMessage = document.frm_articleeditor.debug && (document.frm_articleeditor.debug.checked == true);
   if(showErrorMessage) alert("SAYFADAKi BiR JavaScript iSLEMi SIRASINDA HATA OLUSTU:\n\n" + errHandlerResponse + "\n");
   return false;
}
