
//Remove iframe from top
if (window.top.location != window.location) {
	loc = String( window.location );
	if ( loc.indexOf( 'start.no/forum' ) == -1 && loc.indexOf( 'start.no/external' ) == -1 )
  	window.top.location = window.location;
}

/*********************
 * Enkel Ok/Cancel test
 **********************
 */
function confirm_entry()
{
  input_box=confirm("Er du sikker?");
  if (input_box==true) { 
      return true;
  } else {
    return false;
  } 
}
/***********************************
 * Sender formen til gitt plassering
 ***********************************
 */
function changeActionSubmit(id, action, submit, confirm)
{
  var myElem = eval('document.'+id);
  myElem.action = action;
  if (submit==1){
    if(confirm==1){
      if(confirm_entry()){
	myElem.submit();
      }
    }else{ myElem.submit(); }
  }
  return id;
}
/********************************
 * Gå til link med bekreftelse
 ********************************
 */
function linkConfirm(link) {
  if (confirm_entry()){
    window.location.href = link;
  }
}
/********************************
 * Skriver ut annonser
 ********************************
 */
function adprint(adText)
{
  document.write(adText);
}

function setFocus()
{
  if( document.getElementById( 'search_input') )
  {
    document.getElementById( 'search_input').focus();
    document.getElementById( 'search_input').select();
  }
}

/********************************
 * Search functions
 ********************************
 */
function ss(w){
  window.status=w;
  return true;
}

function cs(){
  window.status='';
}

function ga(o,e)
{
  if (document.getElementById)
    {
      a=o.id.substring(1);
      p = "";
      r = "";
      g = e.target;
      if (g)
	{
	  t = g.id;
	  f = g.parentNode;
	  if (f) 
	    {
	      p = f.id;
	      h = f.parentNode;
	      if (h)
		r = h.id;
	    }
	}
      else
	{
	  h = e.srcElement;
	  f = h.parentNode;
	  if (f)
	    p = f.id;
	  t = h.id;
	}
      
      if (t==a || p==a || r==a)
	return true;
      
      location.href=document.getElementById(a).href;
    }
}

function googleclick( url )
{
  location.href = url;
}

function frontsearch_change( search )
{
  switch(search)
    {
    case "kvasir":
      document.getElementById('frontsearch_logo').src = "http://g2.start.no/search_logo/ny/kvasir.gif";
      document.getElementById('frontsearch_query').name = "qkv";
      document.getElementById('frontsearch').action = "http://www.start.no/spx/";
      break;
    case "telefon":
      document.getElementById('frontsearch_logo').src = "http://g2.start.no/search_logo/ny/telefonkatalogen.gif";
      document.getElementById('frontsearch_query').name = "qt";
      document.getElementById('frontsearch').action = "http://www.start.no/spx/";
      break;
    case "gs":
      document.getElementById('frontsearch_logo').src = "http://g2.start.no/search_logo/ny/gulesider.gif";
      document.getElementById('frontsearch_query').name = "qg";
      document.getElementById('frontsearch').action = "http://www.start.no/spx/";
      break;
    case "kart":
      document.getElementById('frontsearch_logo').src = "http://g2.start.no/search_logo/ny/gulesider.gif";
      document.getElementById('frontsearch_query').name = "qk";
      document.getElementById('frontsearch').action = "http://www.start.no/spx/";
      break;      
    case "filter":
      document.getElementById('frontsearch_logo').src = "http://g2.start.no/search_logo/ny/startno.gif";
      document.getElementById('frontsearch_query').name = "q";
      document.getElementById('frontsearch').action = "http://filter.start.no/sok/";
      break;
    case "shopping":
      document.getElementById('frontsearch_logo').src = "http://g2.start.no/search_logo/ny/gulesider.gif";
      document.getElementById('frontsearch_query').name = "qs";
      document.getElementById('frontsearch').action = "http://www.start.no/spx/";
      break;
    case "dittdistrikt":
      document.getElementById('frontsearch_logo').src = "http://g2.start.no/search_logo/ny/dittdistrikt.gif";
      document.getElementById('frontsearch_query').name = "qd";
      document.getElementById('frontsearch').action = "http://www.start.no/spx/";
      break;
    }

  document.getElementById('s_kvasir').className   = "";
  document.getElementById('s_telefon').className  = "";
  document.getElementById('s_telefon').className  = "";
  document.getElementById('s_gs').className  			= "";
  document.getElementById('s_kart').className  		= "";
  document.getElementById('s_filter').className   = "";
  document.getElementById('s_dittdistrikt').className = "";
  document.getElementById('s_'+search).className  = "selectedSearch";
  document.getElementById( 'selectedsearch' ).value=search;
}

function frontsearch_unfocus()
{
	chosen=document.getElementById( 'selectedsearch' ).value;
	document.getElementById( 's_'+chosen ).className = "selectedSearchBold";
}
function frontsearch_reset()
{
	chosen=document.getElementById( 'selectedsearch' ).value;
	document.getElementById( 's_'+chosen ).className = "selectedSearch";
	
}

/********************************
 * Warning
 ********************************
 */

function confirmWarning (uwid,startpass)
{
	if(startpass!="")
	{
		//Confirm blocking
		input_box=confirm('Jeg bekrefter med dette at jeg har lest og forstått blokkeringsmeldingen');
  	if (input_box==true) {
				request( WEBPATH + '/ajax/function_confirmWarning.php', 'req=confirmBlocked', true );

				//Remove warning
    		document.getElementById('warning_'+uwid).style.display = 'none';
		}
		
	}
	else
	{
		//Confirm warning
		input_box=confirm('Jeg bekrefter med dette at jeg har lest og forstått advarselen');
  	if (input_box==true) {
				request( WEBPATH + '/ajax/function_confirmWarning.php', 'req=confirmWarning&uwid=' + uwid, true );

				//Remove warning
    		document.getElementById('warning_'+uwid).style.display = 'none';
		}
		
	}
	
	
}

/********************************
 * Comments
 ********************************
 */
function CMTaddComplaint(cId, tId){
	input_box=confirm('Er du sikker på at du vil varsle redaksjonen i Start.no om denne kommentaren?');
  	if (input_box==true) {
  	request(WEBPATH + "ajax/ajax_comments.php", "req=addComplaint&cId="+cId+"&typeid="+tId, false);
  	}
}
function nl2br(str) {
  if(typeof(str)=="string")
    return str.replace(/(\r\n)|(\n\r)|\r|\n/g,"<br/>");
  else
    return str;
}
function CMTnew(onId, type, reply){
  if ( reply === undefined ) { 
    var comment = document.getElementById('comment_text').value;
    var commenttitle = document.getElementById('comment_title').value;
    reply = 'NULL';
  }else {
    var comment = document.getElementById('comment_text_'+reply).value;
    var commenttitle = document.getElementById('comment_title_'+reply).value;
  }

	
	
  if(comment.length>0){
    if(reply != 'NULL'){
      document.getElementById('module_commentReply_'+reply).style.display = 'none';
      document.getElementById('printCommentForm').style.display = 'block';
    }
    document.getElementById('comment_text').value = "";
    request(WEBPATH  + "ajax/ajax_comments.php", "req=addComment&typeid="+onId+"&type="+type+"&text="+urlEncode(comment)+"&title="+urlEncode(commenttitle)+"&reply="+reply, false);
  }
}
function CMTnewReply(onId){
  document.getElementById('module_commentReply_'+onId).style.display = 'block';
  document.getElementById('printCommentForm').style.display = 'none';
}
function CMTcloseReply(onId){
  document.getElementById('module_commentReply_'+onId).style.display = 'none';
  document.getElementById('printCommentForm').style.display = 'block';
}

/*Skipping between pages in comments + arena modules*/
function CMTdisplayNextPage( rowName, fromRow, toRow, totalNum, numPages, currPage, displayType, jumpToModule )
{
	num=1;
	
	//Set all non visible
	while(num<=totalNum)
	{
		resultrow=rowName + num;
		var currdiv = document.getElementById(resultrow);
    currdiv.className = 'CMT_moduleMain CMT_displayNone';
		num++;	
	}
	//Set desired rows visible
	while(fromRow<=toRow)
	{
		
		activerow=rowName + fromRow;
		checkrow=document.getElementById(activerow);
		if(checkrow)
		{
			if(displayType=='table-row')
			{
				checkrow.className = 'CMT_displayTableRow';
			}
			else
			{
				checkrow.className = 'CMT_moduleMain CMT_displayBlock';
			}
			
    	
		}
		fromRow++;	
	}
	
	//Mark seleced page
	i=1;
	while(i<=numPages)
	{
		skipname='skip_' + rowName + i;
		if(document.getElementById(skipname).className=='CMT_PageCurrent')
		{
			document.getElementById(skipname).className='CMT_PageLink';
		}
		if(i==currPage)
		{
			document.getElementById(skipname).className='CMT_PageCurrent';
		}
	
		i++;	
	}
	
	if(jumpToModule=="" || jumpToModule==undefined)
	{
		var jumpToModule="module_Comments";
	}
	
	if(jumpToModule!="off")
	{
		CMTscrollToPos(jumpToModule,0);
	}
	
}

function CMTscrollToPos( objId, offset )
{
	pObj = document.getElementById( objId );
	pos = CMTfindPos( pObj );
	window.scrollTo( 0, pos[ 1 ]);
}

function CMTfindPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
/******** end comments *******************************************************/

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function setLoading( objName )
{
	obj = document.getElementById( objName );
	obj.innerHTML = '<img src="http://g2.start.no/img/ajaxloader/circleloader_20x20_999999_transp.gif"/>';
}

function urlencode (str) {
    str = (str+'').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}