/*
Page func
*/

function goToLink(link)
{


  if (window.Touch)
  {
    //alert("touch :)");
   //document.write("Touch!");
   document.location = link;
  }
  
  else   if (window.TouchEvent)
  {
   //alert("touch :)");
   //document.write("Touch!");
    document.location = link;
  }
  
  else
  {
   /*
    alert("no touch  :(");
      document.write("No touch");
      */
  }


}

function mouseOver(a,b,c)
{



  if (window.Touch)
  {
//document.location = d;
//alert('--');
  }
  
  else   if (window.TouchEvent)
  {
//document.location = d;
  }
  
  else
  {
  


document.getElementById("_"+a).style.display="none";
document.getElementById("_"+b).style.display="block";
document.getElementById("_"+c).style.display="block";

var widthC= parseInt(document.getElementById("_"+c).offsetWidth);
var widthB= parseInt(document.getElementById("_"+b).offsetWidth);
//centrering
var newWidth = (widthB/2) - (widthC/2);
document.getElementById("_"+c).style.left=newWidth+'px';

  }

}

function mouseOut(a,b,c)
{
document.getElementById("_"+b).style.display="none";
document.getElementById("_"+c).style.display="none";
document.getElementById("_"+a).style.display="block";
}

function mouseOverMenu(type,color1)
{
//alert(type);
//document.getElementById(type).style.color=color1;

var antal = 0;

/* för att markera samma typ
if(window.imageData !== undefined)
{
    for(image in imageData[0] )
    {
          if(imageData[1][antal] == type)
       {  
         
         document.getElementById("_"+imageData[0][antal]+'A').style.display="none";
         document.getElementById("_"+imageData[0][antal]+ 'B').style.display="block";
       }
       
       antal=antal + 1;
   }
}
*/

}

function mouseOutMenu(type,color2)
{
//alert(type);
//document.getElementById(type).style.color=color2;
var antal = 0;
/* för att markera samma typ
if(window.imageData !== undefined)
{
        for(image in imageData[0] )
        {
              if(imageData[1][antal] == type)
           {  
            
             document.getElementById("_"+imageData[0][antal]+'A').style.display="block";
             document.getElementById("_"+imageData[0][antal]+ 'B').style.display="none"; 
           }
            antal=antal + 1;
       }
 } 
 */ 
}



function showDiv(myDiv)
{
  
   var stat = document.getElementById(myDiv).style.display;

   if(stat=='none')
   {document.getElementById(myDiv).style.display="inline";}

}

/*
Admin func
*/


function getProjectRelations(myId,myDiv)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(myDiv).innerHTML=xmlhttp.responseText;
     


    }
  }
xmlhttp.open("GET","php/getProjectRelations.php?myId="+myId,true);
xmlhttp.send();
}



function getProjectImages(myId,myDiv)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(myDiv).innerHTML=xmlhttp.responseText;
    
    tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
        editor_selector : "mceEditor",
        editor_deselector : "mceNoEditor",
		plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline",
		theme_advanced_buttons2 : "search,replace,link,unlink,image,cleanup,code",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "admin.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		formats : {
			alignleft : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'left'},
			aligncenter : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'center'},
			alignright : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'right'},
			alignfull : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'full'},
			bold : {inline : 'span', 'classes' : 'bold'},
			italic : {inline : 'span', 'classes' : 'italic'},
			underline : {inline : 'span', 'classes' : 'underline', exact : true},
			strikethrough : {inline : 'del'}
		},

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
	
	//mod css js/tiny_mce/themes/advanced/skins/default/content.css
	
	/* ]]> */

    
//var myTextArea = document.getElementById("textarea_"+myId);

 /*
 
   var antal =0;
  
var myTextAreas = document.getElementsByName('text');
 
for (area in myTextAreas)
  {

  antal++;
  var myTextArea = document.getElementById("text_im_"+myId+'_'+antal);//text_im_'.$id.'_'.$antal_bilder.'
  //alert(myTextArea.tagName);
 
  if(myTextArea.tagName =='TEXTAREA' && antal>1)
  {
   //generateTinyMCE(myTextArea);
  }
  //alert(area);
  } 
 */


    }
  }
xmlhttp.open("GET","php/getProjectImages.php?myId="+myId,true);
xmlhttp.send();
}



function getProject(myId,myDiv)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(myDiv).innerHTML=xmlhttp.responseText;
    
var myTextArea = document.getElementById("textarea_"+myId); 
generateTinyMCE(myTextArea);

    }
  }
xmlhttp.open("GET","php/getProject.php?myId="+myId,true);
xmlhttp.send();
}

function getBlog(myId,myDiv)
{
//alert(myDiv);




if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(myDiv).innerHTML=xmlhttp.responseText;
    
    //alert(xmlhttp.responseText);
var myTextArea = document.getElementById("textarea_"+myId); 
generateTinyMCE(myTextArea);
    
    
    }
  }
xmlhttp.open("GET","php/getBlog.php?myId="+myId,true);
xmlhttp.send();


}


function generateTinyMCE(id) {
 if (!tinyMCE.get(id))
   tinyMCE.execCommand('mceAddControl', false, id);
 else
   tinyMCE.execCommand('mceRemoveControl', false, id);
}


function showHelp(str,myId)
{
if (str=="")
  {
  document.getElementById(myId).innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(myId).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","php/help.php?page="+str,true);
xmlhttp.send();
}

function show_confirm()
{
/*
var r=confirm("Vill du radera?");


if (r==true)
  {
  return true;//alert("You pressed OK!");
  }
else
  {
  return false ;//alert("You pressed Cancel!");
  }
*/
}

function help(page,myId)
{
if(document.getElementById(myId).style.display=='none')
{
document.getElementById(myId).style.display='block';
showHelp(page,myId);
}
else
{
document.getElementById(myId).style.display='none';
}

}

function closeHelp()
{

document.getElementById('help').style.display='none';


}
