﻿var clockID = 0;

function DayOfYear(D)
{ 
    var t = +D, d = new Date(+D)
    d.setMonth(0, 0) // Previous Dec 31, same time
    return Math.round((t-d)/864e5) /* Round allows Summer Time */
}

function UpdateClock()
{
    if(clockID)
    {
        clearTimeout(clockID);
        clockID  = 0;
    }

    var tDate = new Date();
                                  
    var TotalSeconds = DayOfYear(tDate) * 24 * 60 * 60 
				        + tDate.getHours() * 60 * 60
                        + tDate.getMinutes() * 60
                        + tDate.getSeconds();
                    
    if(document.all)
        document.getElementById('time').innerText = addCommas("" + TotalSeconds);
    else
        document.getElementById('time').textContent = addCommas("" + TotalSeconds);

    clockID = setTimeout("UpdateClock()", 1000);
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function StartClock()
{
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock()
{
   if(clockID)
   {
      clearTimeout(clockID);
      clockID  = 0;
   }
}
StartClock();
        
function on(imgName, imgObjName)
{
	document.images[imgName].src = eval(imgObjName + ".src");
	return true;
}

function clearField(htmlObject)
{
   if (htmlObject != null)
   {
       htmlObject.value = "";
   }
}

function selectField(htmlObject)
{
   if (htmlObject != null)
   {
       htmlObject.select();
   }
}

function SubmitCart(ItemID, Quantity)
{   
	window.location = "../basket/cart.aspx?id=" + ItemID + "&qty=" + Quantity;
}
			
function clearForm()
{
	var frm = document.forms[0];

	for ( i=0; i<frm.length; i++ )
	{
		if ( ( frm.elements[i].type == "text" ) || ( frm.elements[i].type == "textarea" ) || ( frm.elements[i].type == "password" ) )
		{
			frm.elements[i].value = "";
		}
		else if ( frm.elements[i].type == "select-one" )
		{
			frm.elements[i].options[0].selected = true;
		}
		else if ( frm.elements[i].type == "checkbox" )
		{
			frm.elements[i].checked = false;
		}
	}
}
	

function openWin(img)
{
  winId = window.open('','newwin','width=650,height=400');
  winId.document.write('<body onLoad="if (window.focus) window.focus()"><center>');
  winId.document.write('<img src="' + img + '">');
  winId.document.write('</center></body>');
  winId.document.close();
}





//rotating banner

function loadRotatingBanner()
{ 
    index1 = 0;
    listofimages = new Array(4);
    listofimages[0] = new Image()
    listofimages[0].src = "images/rotate/Encapsulampsm_sm.gif"
    listofimages[1] = new Image()
    listofimages[1].src = "images/rotate/UVConstraightcoils_sm.gif"
    listofimages[2] = new Image()
    listofimages[2].src = "images/rotate/HO_uvr104_sm.gif"
    listofimages[3] = new Image()
    listofimages[3].src = "images/rotate/SO_uvr101_sm.gif"
    listofimages[4] = new Image()
    listofimages[4].src = "images/rotate/RLM33_uvr115_sm.gif"
    listofimages[5] = new Image()
    listofimages[5].src = "images/rotate/Hyatt519coil_sm.gif"
    listofimages[6] = new Image()
    listofimages[6].src = "images/rotate/UVConoffsetcoils_sm.gif"


    thetimer = setTimeout("changeimage()", 500);

} 

function changeimage()
{ 
    index1 = index1 + 1
    if (index1 == "7")
    {
        index1 = 0 
    }
    imagesource = listofimages[index1].src
    document.images["imgRotate"].src = imagesource
    thetimer = setTimeout("changeimage()", 5000);
} 

function changepage()
{
//    if (index1 == 0)
//    {
//        newlocation = "http://www.access.wvu.edu/itrc/" 
//    }
//    else if (index1 == 1)
//    {
//        newlocation = "http://www.wvu.edu" 
//    }
//    else if (index1 == 2)
//    {
//        newlocation = "http://www.oit.wvu.edu"
//    }
//    else if (index1 == 3)
//    {
//        newlocation = "http://www.access.wvu.edu" 
//    }
//    location = newlocation 
}


function NumersOnly(f)
{
    var re = /^[0-9]*$/;
    if (!re.test(f.value))
    {
        alert("Only numbers allowed!");
        f.value = f.value.replace(/[^0-9]/g,"");
    }
} 

