var y = 0;
var dir=1;



var sec=0; RefTimeout=300;

function Reload(){
	location.href=document.URL;
	
}
function RefTime()
{
  
    sec=sec+1;
	if(sec>=RefTimeout){
		document.getElementById("divTime").innerHTML="Refreshing...";
		Reload();
		sec=0; }
	else {
	document.getElementById("divTime").innerHTML="Refresh after: "+(RefTimeout-parseInt(sec))+" second(s)";
	}
	setTimeout("RefTime()",1000);
}


function swapLayer(showDiv,HideDiv)
{
	var showdiv = document.getElementById(showDiv);
	var hidediv = document.getElementById(HideDiv);

	eval("showdiv.style.display = 'block';");
	eval("hidediv.style.display = 'none';");
	
	document.getElementById(showDiv+"_tab").className = "subtabon"
    document.getElementById(HideDiv+"_tab").className = "subtaboff"
    
}

function changeTEXT_DIRECTION(direction)
{
        if(direction="rtl")
        {
         
        	document.getElementById("mainBody").className = "arDir"
          
        }
        else

        if(direction="ltr")
        {
       	document.getElementById("mainBody").className = "enDir"

        }

}

         function resizeIframe(ifrm) {
                var height = document.documentElement.clientHeight;
                height -= document.getElementById(ifrm).offsetTop;
                
                // not sure how to get this dynamically
                height -= 20; /* whatever you set your body bottom margin/padding to be */
                
                document.getElementById(ifrm).style.height = height +"px";
                
            }
   
function chnageRequestTabs(showDiv,HideDiv,HideDiv1,HideDiv2)
{
	var showdiv = document.getElementById(showDiv);
	var hidediv = document.getElementById(HideDiv);
	var hidediv1 = document.getElementById(HideDiv1);
	var hidediv2 =document.getElementById(HideDiv2);
	eval("showdiv.style.display = 'block';");
	eval("hidediv.style.display = 'none';");
	eval("hidediv1.style.display = 'none';");
    eval("hidediv2.style.display = 'none';");

	if(showDiv=="tbHistory")
	{
//	window.frames['iHistory'].location.href = "History.aspx";
	document.getElementById("History_tab").className = "subtabon"
    document.getElementById("Request_tab").className = "subtaboff"
	document.getElementById("Resolution_tab").className = "subtaboff"
	document.getElementById("Communication_tab").className = "subtaboff"

    }
    else
    if(showDiv=="tbResolution")
	{
//	window.frames['iResolution'].location.href = "ViewResolution.aspx";
    document.getElementById("History_tab").className = "subtaboff"
    document.getElementById("Request_tab").className = "subtaboff"
	document.getElementById("Resolution_tab").className = "subtabon"
	document.getElementById("Communication_tab").className = "subtaboff"

    }else
    if(showDiv=="tbRequest")
    
    {
  	document.getElementById("History_tab").className = "subtaboff"
    document.getElementById("Request_tab").className = "subtabon"
	document.getElementById("Resolution_tab").className = "subtaboff"
	document.getElementById("Communication_tab").className = "subtaboff"

    }else
    
    if(showDiv=="tbCommunication")
    {
    document.getElementById("History_tab").className = "subtaboff"
    document.getElementById("Request_tab").className = "subtaboff"
	document.getElementById("Resolution_tab").className = "subtaboff"
	document.getElementById("Communication_tab").className = "subtabon"

    }
    
    	
}




function FullScreen(isShow)
{
ShowElement("tbTop",isShow);
ShowElement("divMenu",isShow);
}
function ShowElement(HideDiv,isShow)
{
	var hidediv = document.getElementById(HideDiv);
   // alert(isShow);
	if(isShow==1)
	{
	eval("hidediv.style.display = 'block';");
	}
	else
	{
	eval("hidediv.style.display = 'none';");
	}
}


function chnageAssetTabs(showDiv,HideDiv,HideDiv1,HideDiv2)
{
	var showdiv = document.getElementById(showDiv);
	var hidediv = document.getElementById(HideDiv);
	var hidediv1 = document.getElementById(HideDiv1);
	var hidediv2 =document.getElementById(HideDiv2);
	eval("showdiv.style.display = 'block';");
	eval("hidediv.style.display = 'none';");
	eval("hidediv1.style.display = 'none';");
    eval("hidediv2.style.display = 'none';");

	if(showDiv=="tbHistory")
	{
//	window.frames['iHistory'].location.href = "History.aspx";
	document.getElementById("History_tab").className = "subtabon"
    document.getElementById("Asset_tab").className = "subtaboff"
	document.getElementById("Relation_tab").className = "subtaboff"
	document.getElementById("Requests_tab").className = "subtaboff"

    }
    else
    if(showDiv=="tbRelation")
	{
//	window.frames['iResolution'].location.href = "ViewResolution.aspx";
	document.getElementById("History_tab").className = "subtaboff"
    document.getElementById("Asset_tab").className = "subtaboff"
	document.getElementById("Relation_tab").className = "subtabon"
	document.getElementById("Requests_tab").className = "subtaboff"

    }else
    if(showDiv=="tbRequests")
    
    {
	document.getElementById("History_tab").className = "subtaboff"
    document.getElementById("Asset_tab").className = "subtaboff"
	document.getElementById("Relation_tab").className = "subtaboff"
	document.getElementById("Requests_tab").className = "subtabon"

    }else
    
    if(showDiv=="tbAsset")
    {
	document.getElementById("History_tab").className = "subtaboff"
    document.getElementById("Asset_tab").className = "subtabon"
	document.getElementById("Relation_tab").className = "subtaboff"
	document.getElementById("Requests_tab").className = "subtaboff"

    }
    
    	
}

function changeMainTabs(showTab,url)
{
	var showtab = document.getElementById(showTab);
	document.getElementById(showTab+"_tab").className = "tabSelCenter celllink"
    document.getElementById(showTab+"_link").className = "tablinkwhite"
    
    location.href=url;
    
}


function editRequest(reqNumber,reg)
{
    
    window.frames['iRequest'].location.href = 'Request.aspx?reqNumber='+reqNumber+'&regId='+reg;
    	
}


function editAsset(assetId,typeId,module)
{
    
    window.frames['iAsset'].location.href = "hwAssetEntry.aspx?pg="+module+"&assetId="+assetId+"&typeId="+typeId;
    	
}

function CommunicationBack(reqNumber)
{
    
    window.frames['iCommunication'].location.href = 'ViewCommunication.aspx?reqNumber='+reqNumber;
    	
}

function editSolution(solutionId)
{
    
    window.frames['iSolution'].location.href = 'AddSolution.aspx?pop=0&solutionId='+solutionId;
    	
}

function addResolution(reqNumber)
{
    window.frames['iResolution'].location.href = 'Resolution.aspx?reqNumber='+reqNumber;
}

function callMe()
{
	var str = 'null';
	var showtab = 'true';
	if((str == 'changepass') || (showtab == 'false'))
	{
		swapLayer('changepass','language');
	}
	else
	{
		swapLayer('language','changepass');
	}
}


function swap(imageId) {

if(document.getElementById) {

        if(document.getElementById(imageId).src.indexOf('Req.gif')>-1) 
        {
        document.getElementById(imageId).src = "images/btnRClicked.gif";
        } 
        else 
        {
        document.getElementById(imageId).src = "images/btnReq.gif";
        }

        return false;
} 
else 
{


return true;
}
}

function IMG1_onclick() {

}

function IMG2_onclick() {

}

function ShowModalDLG(url,parentUrl,winSettings) 
{


    var ParmA ="";   var ParmB ="";   var ParmC =""; var MyArgs = new Array(ParmA,ParmB,ParmC);
    //var WinSettings = "center:yes;resizable:no;dialogHeight:500px; dialogWidth:700px"
    var MyArgs = window.showModalDialog(url, MyArgs, winSettings);
    if (MyArgs == null)
    {

    //window.alert("Nothing returned from child. No changes made to input boxes");
   // return false;
    }
    else
    {

       if(parentUrl != "None" && parentUrl != "NONE")
       {
       document.URL=parentUrl;
       }
      
    }
}



function ShowModalDLGWithValue(url,parentUrl,winSettings,controlId) 
{


    var ParmA ="";
    var ParmB ="";
    var ParmC ="";
    
    var MyArgs = new Array(ParmA,ParmB,ParmC);
    
    //var WinSettings = "center:yes;resizable:no;dialogHeight:500px; dialogWidth:700px"
    var MyArgs = window.showModalDialog(url, MyArgs, winSettings);
    if (MyArgs == null)
    {
    
    //window.alert("Nothing returned from child. No changes made to input boxes");
   // return false;
    }
    else
    {
       document.getElementById(controlId).value= MyArgs[0].toString();
       if(parentUrl != "None")
       {
       document.URL=parentUrl;
       }
      
    }
}


function Date_Load() {
p = arguments[0];
	var ParmA ;
var MyArgs = new Array(ParmA);
var WinSettings = "center:yes;resizable:no;dialogHeight:220px; dialogWidth:270px"
var a=window.showModalDialog("calendar.aspx",MyArgs, WinSettings);
document.getElementById(p).value= a[0].toString();
}


function OpenNewWin(url)
{
 var WinSettings = "width=500,height=300,status=no,resizable=no,top=200,left=200";
   
window.open(url,"",WinSettings);
}


function printpage()
{
	window.print();
}




function getLeaf(url) {
  return url.substring(url.lastIndexOf("/")+1);
}

function highlightCurrentMenuItem() {
  var currentLocation = getLeaf(document.location.href);

  //var menu = document.getElementById("nav");
   
  links = document.getElementById("nav").getElementsByTagName("a");
  for (i=0; i<links.length; i++) {
    var currentHref = links[i].getAttribute("href");
    var currentLeafName = getLeaf(currentHref);
    if (currentLeafName==currentLocation) { 
      // Setting class is needed for Mozilla compatibility - className appears to be correct 
      // according to the DOM spec
      links[i].setAttribute("class", "wizlinksactive");
      links[i].setAttribute("className", "wizlinksactive");

      // More obvious to use parentNode.parentNode.firstChild, but this
      // may give a whitespace text node.
      var menuHeader = links[i].parentNode
      menuHeader.setAttribute("class", "wizlinksactive");
      menuHeader.setAttribute("className", "wizlinksactive");
      break;
    }
  }
}


function showCells(){
  rows = document.getElementById("nav").getElementsByTagName("TABLE")[0].rows;
  for(i=0;i<rows.length;i++){
    cells = rows[i].cells;
    for(j=0;j<cells.length;j++){
      alert(i+"-"+j+": "+cells[j].innerHTML);
    }
  }
}

function SelectMainTab( cellValue){
  rows = document.getElementById("mainNav").getElementsByTagName("TABLE")[0].rows;
 
  for(i=0;i<rows.length;i++){
    cells = rows[i].cells;
    for(j=0;j<cells.length;j++){
    
     if(cellValue==cells[j].innerHTML)
     {
      cells[j-1].setAttribute("class", "tabSelLeft");
      cells[j-1].setAttribute("className", "tabSelLeft");
      
      cells[j].setAttribute("class", "tabSelCenter celllink");
      cells[j].setAttribute("className", "tabSelCenter celllink");
      
      cells[j+1].setAttribute("class", "tabSelRight");
      cells[j+1].setAttribute("className", "tabSelRight");
     
      
     //alert(i+"-"+j+": "+cells[j].innerHTML);
      
      break;
      }
    }
  }
}

function highlightCurrentMainTab(mInd) {
  var currentLocation = getLeaf(document.location.href);

  //mInd=getQval("pg");
  
  links = document.getElementById("mainNav").getElementsByTagName("a");
  for (i=0; i<links.length; i++) {
    var currentHref = links[i].getAttribute("href");
    var currentLeafName = getLeaf(currentHref);
    
    lInd = links[i].getAttribute("id");
 //getVarValue("pg",currentLeafName);
  //alert(lInd);
    if (lInd== mInd ||  currentLeafName==currentLocation) { 
    
      // Setting class is needed for Mozilla compatibility - className appears to be correct 
      // according to the DOM spec
      links[i].setAttribute("class", "tablinkwhite");
      links[i].setAttribute("className", "tablinkwhite");
      
      SelectMainTab(links[i].parentNode.innerHTML);
    //  alert(lInd);

    break;
    }
  }
}



function showDiv(divText , divName){
	var infodiv = parent.document.getElementById(divName);
	infodiv.innerHTML=divText;
	infodiv.style.visibility='visible';
	infodiv.style.top='300';



}

function hideDiv(divName){

	var infodiv = parent.document.getElementById(divName);
	infodiv.style.visibility='hidden';


}

function getQval(name)
{
var m, Q = window.location.search.substring(1);
if ('' != Q)
{
var re = new RegExp(escape(name) + '=([^&$]+)');
if (m = Q.match(re))
return m[1];
else return '';
}
return '';
}


function getVarValue(name,lnk)
{
var m, Q = lnk.substring(1);
if ('' != Q)
{
var re = new RegExp(escape(name) + '=([^&$]+)');
if (m = Q.match(re))
return m[1];
else return '';
}
return '';
}



/*
var x,y
var step=10
var flag=0


var message="Touching Your Life in So Many Ways ..........."
message=message.split("")

var xpos=new Array()
for (i=0;i<=message.length-1;i++) {
	xpos[i]=-50
}

var ypos=new Array()
for (i=0;i<=message.length-1;i++) {
	ypos[i]=-50
}

function handlerMM(e){
	x = (document.layers) ? e.pageX : document.body.scrollLeft+event.clientX
	y = (document.layers) ? e.pageY : document.body.scrollTop+event.clientY
	flag=1
}

function makesnake() {
	if (flag==1 && document.all) {
    	for (i=message.length-1; i>=1; i--) {
   			xpos[i]=xpos[i-1]+step
			ypos[i]=ypos[i-1]
    	}
		xpos[0]=x+step
		ypos[0]=y
	
		for (i=0; i<message.length-1; i++) {
    		var thisspan = eval("span"+(i)+".style")
    		thisspan.posLeft=xpos[i]
			thisspan.posTop=ypos[i]
    	}
	}
	
	else if (flag==1 && document.layers) {
    	for (i=message.length-1; i>=1; i--) {
   			xpos[i]=xpos[i-1]+step
			ypos[i]=ypos[i-1]
    	}
		xpos[0]=x+step
		ypos[0]=y
	
		for (i=0; i<message.length-1; i++) {
    		var thisspan = eval("document.span"+i)
    		thisspan.left=xpos[i]
			thisspan.top=ypos[i]
    	}
	}
		var timer=setTimeout("makesnake()",30)
}
function MouseMessage(mess)
{
for (i=0;i<=message.length-1;i++) {
    document.write("<span id='span"+i+"' class='spanstyle'>")
	document.write(message[i])
    document.write("</span>")
}

if (document.layers){
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;

}

*/





 
////change 1 to another integer to alter the scroll speed. Greater is faster
//var speed=1
//var currentpos=0,alt=1,curpos1=0,curpos2=-1
//function initialize(){
//startit()
//}
//function scrollwindow(){
//if (document.all &&
//!document.getElementById)
//temp=document.body.scrollTop
//else
//temp=window.pageYOffset
//if (alt==0)
//alt=2
//else
//alt=1
//if (alt==0)
//curpos1=temp
//else
//curpos2=temp
//if (curpos1!=curpos2){
//if (document.all)
//currentpos=document.body.scrollTop+speed
//else
//currentpos=window.pageYOffset+speed
//window.scroll(0,currentpos)
//}
//else{
//currentpos=0
//window.scroll(0,currentpos)
//}
//}
//function startit(){
//setInterval("scrollwindow()",50)
//}
// 
 
 
 
function scrollit() {
        if (y < document.body.scrollHeight  && dir==1) {
        
                window.scroll(0,y);
                y = y + 1;
                setTimeout('scrollit()', 1);
                
        }else
        {
         y=y-1;
         window.scrollTo(0,y);
                    if(y<=10 )
                    {
                  //alert( document.body.scrollHeight);
                  //document.body.offsetHeight

                    dir=1;
                    setTimeout('scrollit()', 5000);
                    }else
                    {
                    dir=2;
                    setTimeout('scrollit()', 1);

                    }
        }
}
