//check browser
var version=0;
if (navigator.appVersion.indexOf("MSIE")!=-1){
	temp=navigator.appVersion.split("MSIE");
	version=parseFloat(temp[1]);
}
else
	version=0;

if (typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement) {
 HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode) {
  switch (where){
  case 'beforeBegin':
   this.parentNode.insertBefore(parsedNode,this)
   break;
  case 'afterBegin':
   this.insertBefore(parsedNode,this.firstChild);
   break;
  case 'beforeEnd':
   this.appendChild(parsedNode);
   break;
  case 'afterEnd':
   if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
   else this.parentNode.appendChild(parsedNode);
   break;
  }
 }

 HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr) {
  var r = this.ownerDocument.createRange();
  r.setStartBefore(this);
  var parsedHTML = r.createContextualFragment(htmlStr);
  this.insertAdjacentElement(where,parsedHTML)
 }


 HTMLElement.prototype.insertAdjacentText = function(where,txtStr) {
  var parsedText = document.createTextNode(txtStr)
  this.insertAdjacentElement(where,parsedText)
 }
}

function timeleft(difference) {
	//// difference is expected to be in miliseconds!
	var originaldiff=difference;
	difference=Math.abs(difference);
	//// remove miliseconds
	difference/=1000;
	var timestringsarray = new Array();
	var count=0;
	//// years
	var years = Math.floor(difference/29030400);
	if (years==1) {
		years="שנה";
		timestringsarray[count++]=years;
	} else if (years==2) {
		years="שנתיים";
		timestringsarray[count++]=years;
	} else if (years>2) {
		years+=" שנים";
		timestringsarray[count++]=years;
	} else {
		years="";
	}
	difference = difference%29030400;
		
	//// months
	var months = Math.floor(difference/2419200);
	if (months==1) {
		months="חודש";
		timestringsarray[count++]=months;
	} else if (months==2) {
		months="חודשיים";
		timestringsarray[count++]=months;
	} else if (months>2) {
		months+=" חודשים";
		timestringsarray[count++]=months;
	} else {
		months="";
	}
	difference = difference%2419200;
	//// days
	var days = Math.floor(difference/86400);
	if (days==1) {
		days="יום";
		timestringsarray[count++]=days;
	} else if (days==2) {
		days="יומיים";
		timestringsarray[count++]=days;
	} else if (days>2) {
		days+=" ימים";
		timestringsarray[count++]=days;
	} else {
		days="";
	}

	difference = difference%86400;
	//// hours
	var hours = Math.floor(difference/3600);
	if (hours==1) {
		hours="שעה";
		timestringsarray[count++]=hours;
	} else if (hours==2) {
		hours="שעתיים";
		timestringsarray[count++]=hours;
	} else if (hours>2) {
		hours+=" שעות";
		timestringsarray[count++]=hours;
	} else {
		hours="";
	}
	difference = difference%3600;
	//// minutes
	var minutes = Math.floor(difference/60);
	if (minutes==1) {
		minutes="דקה";
		timestringsarray[count++]=minutes;
	} else if (minutes>1) {
		minutes+=" דקות";
		timestringsarray[count++]=minutes;
	} else {
		minutes="";
	}
	difference = difference%60;
	//// seconds
	var seconds = Math.floor(difference);
	if (seconds==1) {
		seconds="שניה";
		timestringsarray[count++]=seconds;
	} else if (seconds>1) {
		seconds+=" שניות";
		timestringsarray[count++]=seconds;
	} else {
		seconds="";
	}
	/// output
	if (originaldiff<0) {
		return null;
	} else if (originaldiff<60) {
		return originaldiff + " שניות";
	} else {
		var stroutput="";
		var i=0;
		for (i=0;i<count-1;i++) {
				if (i>0)
					stroutput+=", ";
			stroutput+=timestringsarray[i];
		}
		if (count>1)
			stroutput+=" ו";
		stroutput+=timestringsarray[count-1];
		return stroutput;
	}
}

function date2timeleft(date,nowdate) {
	var difference = date-nowdate;
	return timeleft(difference)
}

function findPosition( oLink ) {
  if( oLink.offsetParent ) {
    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
      posY += oLink.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oLink.x, oLink.y ];
  }
}


//// general incrementation
function FieldDecrement( Field, intMin, intMax, intDelta ) {
	if ( parseInt( Field.value ) > intMin && parseInt( Field.value ) <= intMax )
	{
		FieldValueChange( Field, - intDelta );
	} else if( parseInt( Field.value ) > intMax ) {
		Field.value = intMax;
	} else if( parseInt( Field.value ) <= intMin ) {
		Field.value = intMin;
	}
}

function FieldIncrement( Field, intMin, intMax, intDelta ) {
	if ( parseInt( Field.value ) >= intMin && parseInt( Field.value ) < intMax )
	{
		FieldValueChange( Field, intDelta );
	} else if( parseInt( Field.value ) >= intMax ) {
		Field.value = intMax;
	} else if( parseInt( Field.value ) < intMin ) {
		Field.value = intMin;
	}
}

function FieldValueChange( Field, intDelta ) {
	Field.value = parseInt( Field.value ) + intDelta;
}

function writeDivs( externalDivStack, baseZindex, canvasDiv ) {
	if ( !baseZindex ) {
		baseZindex = 10000;
	}
	var divStack = new Array( );
	for ( var i=0; i < absoluteDivs.length; i++ ) {
		divStack[ i ] = '<DIV id="canvasElement'+i+'" name="canvasElement'+i+'" style="position:absolute;z-index:'+ ( baseZindex + i ) +';top:'+ absoluteDivs[ i ][ 1 ] +'px;left:'+ absoluteDivs[ i ][ 0 ] +'px" >'+ absoluteDivs[ i ][ 2 ] +'</DIV>';
	}
	document.getElementById( 'canvas' ).innerHTML = divStack.join( '' );
}

function validateDivs() {
	var offsetAbsolutePosition = 0;
	//if ( document.getElementById( 'maindisplay' ).align == 'center' )
	//{

		//if ( env.aBrowserCats[ 'ie' ] )
		//{
			offsetAbsolutePosition = Math.floor ( ( document.body.offsetWidth - 20 - document.getElementById( 'maindisplay' ).offsetWidth  ) / 2 );
		/*}
		else if ( env.aBrowserCats[ 'ns' ] )
		{
//					alert( document.body.offsetWidth + '*' +  document.getElementById( 'maindisplay' ).offsetWidth   );
		}*/
	/*} else if ( document.getElementById( 'maindisplay' ).align == 'right' && ( document.body.offsetWidth - 20 - document.getElementById( 'maindisplay' ).offsetWidth ) > 0  ) {
		offsetAbsolutePosition = document.body.offsetWidth - 20 - document.getElementById( 'maindisplay' ).offsetWidth;
	} else {
		offsetAbsolutePosition = 0;
	}*/

	if ( offsetAbsolutePosition < 0 )
	{
		offsetAbsolutePosition = 0;
	}
 
	for ( var i=0; i < absoluteDivs.length; i++ ) {
		if ( document.getElementById( 'canvasElement'+i ).left ) {
			document.getElementById( 'canvasElement'+i ).left = absoluteDivs[ i ][ 0 ] + offsetAbsolutePosition + 'px';
		} else if( document.getElementById( 'canvasElement'+i ).style.left ) {
			document.getElementById( 'canvasElement'+i ).style.left = absoluteDivs[ i ][ 0 ] + offsetAbsolutePosition + 'px'; 
		}
	}
}

function advtime() {
	/*document.all("movingclock").innerHTML =(clock.getHours()>=10 ? clock.getHours() : '0'+clock.getHours())+":"+(clock.getMinutes()>=10 ? clock.getMinutes() : '0'+clock.getMinutes())+":"+(clock.getSeconds()>=10 ? clock.getSeconds() : '0'+clock.getSeconds());
	setTimeout(advtime, 1000);
	clock.setTime(clock.getTime()+1000);*/
}

function rep_image(pic) {
	pic.src='http://gamer.co.il/gamer/images/default.jpg';
}
function rep_blanc(pic_name){
	document.images[pic_name].src='../images/blank.gif';
}

// This next little bit of code tests whether the user accepts cookies.
var acceptsCookies = false;
if(document.cookie == '') {
	document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
		if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) {
			WM_acceptsCookies = true; 
		}// If it succeeds, set variable
	} else { // there was already a cookie
	WM_acceptsCookies = true;
}

function set_Cookie (name, value, hours, path, domain, secure) {
	if (WM_acceptsCookies) { // Don't waste your time if the browser doesn't accept cookies.
		var not_NN2 = (navigator && navigator.appName 
			&& (navigator.appName == 'Netscape') 
			&& navigator.appVersion 
			&& (parseInt(navigator.appVersion) == 2))?false:true;
		if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
			if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
				var numHours = hours;
			} else if (typeof(hours) == 'number') { // calculate Date from number of hours
				var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
			}
		}
		document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
	}
} 


function kill_Cookie(name, path, domain) {
		document.cookie = name + '=0; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
} 

function go(whichURL){
	if (whichURL)
		location=whichURL[whichURL.selectedIndex].value;
	else
		return;
}
function get_date(){
	var mydate=new Date()
	var today = mydate.getDate();
	var hours = mydate.getHours();
	var minutes = mydate.getMinutes();
	var month = mydate.getMonth();
	var year = mydate.getYear();
		
	if (year < 1000)
		year+=1900
	if (month<10)
		month="0"+(month+1)
	if (today<10)
		today="0"+today
	if (hours<10)
		hours="0"+hours
	if (minutes<10)
		minutes="0"+minutes
	return hours+":"+minutes+" "+today+"/"+month+"/"+year
}
function mysql2normal_date(mysql){
	var chunks1=mysql.split(" ");
	var chunks2=chunks1[0].split("-");
	return chunks1[1]+" "+chunks2[2]+"/"+chunks2[1]+"/"+chunks2[0];
}
function time2int(year,month,day,hour,minute,sec){
	return sec+(minute*60)+(hour*360)+(day*8640)+(month*267840)+((year-2000)*97761600)
}
function mysql2time(mysql){
	var chunks1=mysql.split(" ");
	var chunks2=chunks1[0].split("-");
	return chunks2[2]+"/"+chunks2[1]+"/"+chunks2[0];
}

function str_replace(what_replace,with_replace,string){
	temp=string.split(what_replace);
	return_value="";
	size_arr=temp.length;
	for (i=0;size_arr>i;i++){
		return_value+=temp[i];
		if (temp[(i+1)])
			return_value+=with_replace;
	}
	return return_value;
}

function submitonce(theform) {
	// if IE 4+ or NS 6+
	//check_form();
	if (document.all || document.getElementById) {
		// hunt down "submit" and "reset"
		for (i=0;i<theform.length;i++) {
			var tempobj=theform.elements[i];
			if(tempobj.name.toLowerCase()=="submit") {
				//disable it
				tempobj.disabled=true;
			}
		}
	}
}
function open_window(address,win_name,op_tool,op_loc_box,op_dir,op_stat,op_menu,op_scroll,op_resize,op_wid,op_heigh){    
	win_name = win_name ? win_name : "Window";
	op_tool  = op_tool ? 1 : 0;    
	op_loc_box  = op_loc_box ? 1 : 0;    
	op_dir  = op_dir ? 1 : 0;    
	op_stat  = op_stat ? 1 : 0;    
	op_menu  = op_menu ? 1 : 0;    
	op_scroll  = op_scroll ? 1 : 0;    
	op_resize  = op_resize ? 1 : 0;    
	LeftPosition = (screen.width) ? (screen.width-op_wid)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-op_heigh)/2 : 0;
	option = "top="+TopPosition+",left="+LeftPosition+"toolbar="+ op_tool +",location="+ op_loc_box +",directories="+ op_dir +",status="+ op_stat+",menubar="+op_menu+",scrollbars="+op_scroll+",resizeable="+op_resize+",width="+op_wid+",height="+ op_heigh;
	win3 = window.open(address, win_name, option);  
	//win3.document.location=address;
	win3.focus();
}
function small_window(address,win_name){
	open_window(address,win_name,0,0,0,1,0,0,0,405,200)    
}

function raterlist_window(address,win_name, width ){
	width = !width ? 200 : width;
	open_window(address,win_name,0,0,0,1,0,1,0,423,width)    
}
function standard_window(address,win_name){
	open_window(address,win_name,0,0,0,1,0,0,0,350,490)    
}
function standard_window_scroller(address,win_name){
	open_window(address,win_name,0,0,0,1,0,1,0,600,480)   
} 
function standard_window_big(address,win_name){
	open_window(address,win_name,0,0,0,1,0,1,0,600,480)    
}

function standard_window_full(url, windowName){
	if (navigator.appName == 'Microsoft Internet Explorer' && (navigator.platform.substring(0,3) == 'Win')) {
		wComp=10;
		hComp=57;
	}
	else if (navigator.appName == 'Netscape' && navigator.platform.substring(0,3) == 'Win') {
		wComp=12;
		hComp=59;;
	}
	else if (navigator.platform == 'MacPPC' && navigator.appName == 'Netscape'){
		wComp=13;
		// extra 18 px for net on mac (don't know why?? but works)
		hComp=49;
	}
	else {
		wComp=13;
		hComp=31;		
	}

	winW=screen.width-wComp;
	winH=screen.height-hComp;

	finalFeature="left=0,top=0,width=" + winW + ",height=" + winH + ",scrollbars=yes";
	full=window.open(url,windowName,finalFeature);
	full.focus();

	if(navigator.platform.indexOf("MacPPC")!=-1 && navigator.appName.indexOf('Microsoft')!=-1)
	{
		full.resizeTo(winW,winH);
	}
}

function getMonthNum(abbMonth){
	var arrMon = new Array("Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec");
	for(i=0; i<arrMon.length; i++){
		if(abbMonth == arrMon[i])
		return i+1;
	}
}

function size_of_array(arr){
	for (i=0;arr[i];i++){}
	return i;
}
function get_rand(from,to){
	var ran=Math.ceil(Math.random()*(to-from+1))+from-1;
	return ran_number=ran; 
}

function preg_replace(str){
	var tags = new Array(/\[url=([^\]]*)\]([^\[]*)\[\/url\]/gi,/\[b\]([^\[]*)\[\/b\]/gi);
	var replacements = new Array("<a target=_blank class=article_text href=\"$1\">$2</A>","<B>$1</B>");
	for (var i=0;i<tags.length ;i++ )
	{
		str=str.replace(tags[i],replacements[i]);
	}
	return str;
}


function survey_vote(the_form,su){
	var vote
	var id
	if (su){
		for (i=0;i<the_form.survey.length;i++){
			if (the_form.survey[i].checked==true)
				vote=i;
		}
	}
	id=the_form.sid.value;
	standard_window_big('seker.php?id='+id+(su?'&vote='+vote:''), 'survy')
	return false;
}

function askuser(text,url){
	var x=window.confirm(text);
	if (x)
		location=url;
}

function woosh(obj){
	obj.style.display="none";
}
function show(obj){
	obj.style.display="block";
}

function mysqlstamp2js(stamp) {
	return stamp*1000;
}

function reset_TZ_offset(date,servertimezoneoffset,serversaving) {
	//// servertimezoneoffset must be supplied from the outside, use gettimeofday()
	var offset=date.getTimezoneOffset()*60*1000;
	//alert(serversaving+"="+daylightsaving_diff());
	////-((serversaving-daylightsaving_diff())*60*60*1000)
	date.setTime(date.getTime()+offset);/// we're now cancelled the offset
	date.setTime(date.getTime()-(servertimezoneoffset*60*1000))
}

function daylightsaving_diff() {
   var rightNow = new Date();
   var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
   var date2 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
   var temp = date1.toGMTString();
   var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
   var temp = date2.toGMTString();
   var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
   var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
   var hoursDiffDaylightTime = (date2 - date4) / (1000 * 60 * 60);
   if (hoursDiffDaylightTime == hoursDiffStdTime) { 
      return 0;
   } else {
      return 1;
   }
}

////////////////// real media banners

function DisplayAdsInIFrame(sitepage, position, width, height,bReturnString) 
 {
 	 //document.domain='gamer.co.il';
	 var sHTML = '<IFRAME ID="RM_'+position+'" NAME="RM_'+position+'" width="'+width+'" height="'+height+'" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" src="/gamer2/gen_html/banners.html?sitepage='+sitepage+'&position='+position+'&width='+width+'&height='+height+'"></IFRAME>';
	 if (bReturnString)
	{
		return sHTML;
	} else {
		document.write(sHTML);
	}

/*
	//if (regular_nana_banners_mode) {
		var oas = 'http://realmedia.nana.co.il/RealMedia/ads/';
		var RN = new String (Math.random());
		var RNS = RN.substring(2,11);
		var oaspage = sitepage + '/1' + RNS + '@' + position;
		
		var sHTML = '<IFRAME NAME=Banners WIDTH=' + width + ' HEIGHT=' + height + ' NORESIZE SCROLLING=No FRAMEBORDER=0 MARGINHEIGHT=0 MARGINWIDTH=0 SRC="' + oas + 'adstream_sx.ads/' + oaspage + '">';
		sHTML +='</IFRAME>';
	//}
	
	if (bReturnString)
	{
		return sHTML;
	}else{
		document.write(sHTML);
	}*/
 }


///////////////// end realmedia banners


function get_cookie(name) {
	if(document.cookie == '') { // there's no cookie, so go no further
		return false; 
	} else { // there is a cookie
		var firstChar, lastChar;
		var theBigCookie = document.cookie;
		firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
		var NN2Hack = firstChar + name.length;
		if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
			firstChar += name.length + 1; // skip 'name' and '='
			lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
			if(lastChar == -1)
				lastChar = theBigCookie.length;
			return unescape(theBigCookie.substring(firstChar, lastChar));
		} else { // If there was no cookie of that name, return false.
			return false;
		}
	}	
} 

function check_password(password,username,config){
	if (!config[7] || !incrementing_chars(password,username))
		whoosh_err(password_err8);
	else
		show_err(password_err8);
	if (!config[0] || check_value_length(password,config[0],15))
		whoosh_err(password_err1);
	else
		show_err(password_err1);

	if (check_invalid_chars(password))
		whoosh_err(password_err2);
	else
		show_err(password_err2);
	if (!config[6] || check_password_userinfo(password,username,"",""))
		whoosh_err(password_err7);
	else
		show_err(password_err7);
	if (!config[4] || countletters(password)>=config[4])
		whoosh_err(password_err4);
	else
		show_err(password_err4);
	if (!config[5] || countnumbers(password)>=config[5])
		whoosh_err(password_err3);
	else
		show_err(password_err3);
	if (!config[2] || keys_distance_check(password)<=config[2])
		whoosh_err(password_err5);
	else
		show_err(password_err5);
	if (!config[1] || char_repetition(password)<=config[1])
		whoosh_err(password_err6);
	else
		show_err(password_err6);/**/
}

function DisplayAds(sitepage, position, width, height) 
{
	var oas = 'http://realmedia.nana.co.il/RealMedia/ads/';
	var RN = new String (Math.random());
	var RNS = RN.substring(2,11);
	var oaspage = sitepage + '/1' + RNS + '@' + position;

	return '<SCRIPT type="text/javascript" SRC="' + oas + 'adstream_jx.ads/' + oaspage + '"></SCRIPT>';
}

// Writes HTML for banner object - was added after M$ ActiveX fix for IE

function DisplayPirsum(sHTML) {

document.write(sHTML);

}

// Function will overwrite any html object with itself, used as fix for M$

function RewriteObjectElement(oElement) {

if (oElement)

oElement.outerHTML = oElement.outerHTML;

}
