// JavaScript Document
//cooki function starts
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var 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;
};

function eraseCookie(name) {
	createCookie(name,"",-1);
};
//cooki function ends

function menuSelect(value){
	eraseCookie('menu');
	createCookie('menu',value,1);
};

function changeClass(id,nam){
	document.getElementById(id).setAttribute("class", nam);
};

function marainClass(wh){
	document.getElementById('wh').setAttribute("class", "marine_project_def");
	document.getElementById('ma').setAttribute("class", "marine_project_def");
	document.getElementById('il').setAttribute("class", "marine_project_def");
	document.getElementById('sy').setAttribute("class", "marine_project_def");
	document.getElementById('wo').setAttribute("class", "marine_project_def");
	
	document.getElementById(wh).setAttribute("class", "marine_project_act");
};

function page(x){
	eraseCookie("menu");
	createCookie("menu",'page'+i,1);
	var i=0;
	for(i=1;i<7;i++){		
		changeClass('page'+i,"page");	
	};
		changeClass('page'+x,"page_active");
};

function lin(ln){
	window.location=ln;
};

function TableOpen(i,id){
	if(i<10){
		document.getElementById(id).style.opacity="0."+i+"px";
		timer(i,"tb");
	};
};

function timer(i,mod,id){
	if(i<10){
		i=i+1;
	}else{
		i=0;
	};
	if(mod=="tb"){
		setTimeout("TableOpen("+i+","+id+");",70);
	};
};

function imgCh(id){	
	document.getElementById("im1").style.visibility="hidden";
	document.getElementById("im1").style.display="none";
	
	document.getElementById("im2").style.visibility="hidden";
	document.getElementById("im2").style.display="none";
	
	document.getElementById("im3").style.visibility="hidden";
	document.getElementById("im3").style.display="none";
	
	document.getElementById("im4").style.visibility="hidden";
	document.getElementById("im4").style.display="none";
	
	document.getElementById("im5").style.visibility="hidden";
	document.getElementById("im5").style.display="none";
	
	document.getElementById(id).style.visibility="visible";
	document.getElementById(id).style.display="block";	
};

function hid(id){
	var element = document.getElementById(id);	
	element.style.visibility="hidden";	
	element.style.display="none";
};

function show(id){
	var element = document.getElementById(id);
	element.style.visibility="visible";
	element.style.display="block";
};

var eid="sample";
/*This function block for gradual fadding*/
function Opec(i,sw){
	var k=i;
	var element = document.getElementById(eid);
	var op=(k/100);
	if(sw==0){		
		if(i<100){
			element.style.visibility="visible";
			element.style.display="block";
			element.style.opacity = op;
			element.style.filter = 'alpha(opacity='+k+')';
			apear(k,'null',0);
		};
	}else{
		if(i>1){			
			element.style.opacity = op;
			element.style.filter = 'alpha(opacity='+k+')';
			apear(k,'null',1);
		}else{
			element.style.visibility="hidden";
			element.style.display="none";
		};
	};	
};
function apear(i,id,sw){
	var j=i;
	var spd=1;
	if(sw==0){
		if(j<100){
			j=j+2;
		}else{
			j=0;
		};
		if(id!='null'){
			eid=id;
		};
		var fun='Opec('+j+',0);';	
		setTimeout(fun,spd);
	}else{
		if(j>0){
			j=j-2;
		}else{
			j=100;
		};
		if(id!='null'){
			eid=id;
		};
		var fun='Opec('+j+',1);';	
		setTimeout(fun,spd);
	};
};
function hand(el){	
	apear(100,el,1);
	setTimeout("apear(0,"+el+",0)",1300);
};
function swap(id,co,num){
	var el=co;
	for(i=1;i<num;i++){
		el=co+i;
		hid(el);
	};
	eid=id;
	apear(0,id,0);
};
/*
apear(i,id,sw)
this function is used for gradual fading and gradual rise up
for fading use i as 100 and sw as 1
for rise up i and sw will be 0
speed can be changed through spd value higher value slow and lower value speed has to be none 0 integer
*/

function radio_hide(hid,vid){
	var element = document.getElementById(hid);
	element.style.visibility="hidden";
	element.style.display="none";
	
	element = document.getElementById(vid);
	element.style.visibility="visible";
	element.style.display="block";
};

function hide(hid){
	var element = document.getElementById(hid);
	element.style.visibility="hidden";
	element.style.display="none";
};

function swapClass(id,co,num,onClass,offClass){
	var el=co;
	for(i=1;i<num;i++){
		el=co+i;
		changeClass(el,offClass);
	};
	changeClass(id,onClass);
};

function swapImg(i){
	if(i<7){
		num=i+1;
	}else{
		num=1;
	};
	document.images['mainImg'].src='images/aboutus/img'+num+'.jpg';
	timerAbout(15000,num);
};

function timerAbout(tim,i){	
	setTimeout("swapImg("+i+")",tim);
};

function imgSwap(img, swap) { 
   img.src = imgs[swap].src;
};

function imgSwapId(img, swap) { 
   document.getElementById(img).src = imgs[swap].src;
};


function imgSlide(swap,ma,tim) {	
   imgSwapId('home', swap);      
   changeSlide(swap,ma,tim);

};

function changeSlide(swap,ma,tim){
	var obj;
	if(swap<ma){		
		obj=Number(swap)+1;
		setTimeout("imgSlide("+obj+","+ma+","+tim+")",tim);		
	}else{
		obj=12;
		setTimeout("imgSlide("+obj+","+ma+","+tim+")",tim);
	}
};

function rollover(nam,fil){
	document.images[nam].src=fil;
};

function output(blog,msg){
	document.getElementById(blog).innerHTML = msg;
}

function boldSelected(fieldId)
{
  var textComponent = document.getElementById(fieldId);
  var input=document.getElementById(fieldId).value;
  var selectedText;
  var apend;
  var outPut;
  // IE version
  if (document.selection != undefined)
  {
    textComponent.focus();
    var sel = document.selection.createRange();
    selectedText = sel.text;
  }
  // Mozilla version
  else if (textComponent.selectionStart != undefined)
  {
    var startPos = textComponent.selectionStart;
    var endPos = textComponent.selectionEnd;
    selectedText = textComponent.value.substring(startPos, endPos)
  }

  apend="<strong>"+selectedText+"</strong>";
  ourPut=input.replace(selectedText, apend);
  document.getElementById(fieldId).value=ourPut;
}

function radioSetVal(id,val){
	document.getElementById(id).value = val;
}
function passVal(sourse,dest){
	document.getElementById(dest).value = document.getElementById(sourse).value;
	alert(document.getElementById(sourse).value);
}

function boldTxt(id,sum,num){
	for(i=1;i<(sum+1);i++){
		document.getElementById(id+i).style.fontWeight="normal";
	}
		document.getElementById(id+num).style.fontWeight="bold";
};

var sliPos=0;
function sliding(id,option,ma){
	if(option=="next"){
		if((-ma)<sliPos){
			sliPos=sliPos-85;
			document.getElementById(id).style.marginLeft=sliPos+"px";
		}
	}else{
		if(0>sliPos){
			sliPos=sliPos+85;
			document.getElementById(id).style.marginLeft=sliPos+"px";
		}
	}
}

function load(lin) {
window.open(lin,'','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
}
