<!-- Javascript functions for new City of Cape Town web site -->

<!-- hide from older browsers

// detect browser type and load appropriate stylesheet

// if IE4 or later then get this stylesheet :
// (IE3 for Windows gets confused with straightforward check, hence the contorted logic)
if ((document.images) && (navigator.appName != "Netscape") && (navigator.appVersion.indexOf('Mac') == -1))
{
   document.writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"/includes/ie4style.css\">")
};

// if Nav4 and not Macintosh (1 point = 1.25-1.5 pixels) then get this stylesheet:
if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4) && (navigator.appVersion.indexOf('Mac') == -1)) 
{
   //  alert(document.location + "includes/ie4style.css")
   document.writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"/includes/ns4style.css\">") 
};

// if neither IE nor Navigator then get this stylesheet (don't lock out the underdog!):
if ((navigator.appName != "Netscape") && (navigator.appName != "Microsoft Internet Explorer"))
{
   document.writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"/includes/defaultstyle.css\">") 
};


// image preloader for mouseouvers
pic = new Array() ;
var picCount = 0 ;

var swapOn  = new Function("i","eval('document.image'+i).src=pic[i][0].src")
var swapOff = new Function("i","eval('document.image'+i).src=pic[i][1].src")

function preload(first, second)
{
 	pic[picCount] = new Array(2);
 	pic[picCount][0] = new Image() ;
 	pic[picCount][0].src = first ;
 	pic[picCount][1] = new Image() ;
 	pic[picCount][1].src = second ;
 	picCount++ ;
}

// open link in separate browser window
function startPopEvent(PopEvent)
{
var desktop=window.open(PopEvent,"_blank","toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,width=610,height=400,resizable");
}

// open link in separate browser window
function startPopEvent1(PopEvent)
{
var desktop=window.open(PopEvent,"_blank","toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes,width=740,height=500,resizable");
}

// open link in separate browser window
function startPopEvent2(PopEvent)
{
var desktop=window.open(PopEvent,"_blank","toolbar=no,location=yes,status=no,menubar=yes,scrollbars=yes,width=640,height=460,resizable");
}

// set focus to first field in form
function setFocus()
{
	document.feedbackform.elements[0].focus() ;
}

// check form fields for entry
function checkrequired(which) 
{
    var pass=true;
    if (document.images) 
    {
        for (i=0;i<which.length;i++)
        {
            var tempobj=which.elements[i];
            if (tempobj.name.substring(0,8)=="required") 
            {
                if (((tempobj.type=="text"||tempobj.type=="textarea")&&
                    tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
                        tempobj.selectedIndex==0))
                {
                    pass=false;
                    break;
                }
            }
        }
    }
    if (!pass)
    {
        shortFieldName=tempobj.name.substring(8,30).toUpperCase();
        alert("Please make sure the "+shortFieldName+" field is properly completed.");
        return false;
    }
    else
    return true;
}

// check for proper email address
function checkemail()
{
    txt=document.feedbackform.requiredEmail_address.value ;
	if (txt.indexOf("@")<3)
    {
        alert("Incorrect email address.  Please check the prefix and '@' sign.") ;
        return false;
    }
    if ((txt.indexOf(".com")<5)&&(txt.indexOf(".org")<5)
        &&(txt.indexOf(".gov")<5)&&(txt.indexOf(".net")<5)
            &&(txt.indexOf(".mil")<5)&&(txt.indexOf(".edu")<5)
                 &&(txt.indexOf(".co")<5)&&(txt.indexOf(".alt")<5)
				 	  &&(txt.indexOf(".ac")<5))
    {
        alert("Incorrect email address. Please check the suffix.") ;
	return false;
   }
   return true;
}

function makeRef()
{
    var strFields ;
    var opt
    strFields= document.choice.lstDirectorate.value ;
    strFields=strFields + " " + " AND w" + document.choice.lstMonth.value ;
	strFields= " AND w" + document.choice.lstMonth.value ;
	strFields= "w" + document.choice.lstMonth.value ;
    strFields= strFields +  document.choice.lstYear.value + document.choice.lstDirectorate.value ;
    //alert(strFields);
	//document.location.href="http://gw.cmc.gov.za/servlet/webpub?User.Context=&action=Library.Search&merge=doclist&User.lang=en&User.html=frames&Library.queryText=" + strFields + "&Library.queryField=All&Library.queryId=dom_001_44w.po_001_44w.library_agenda" ;
	document.location.href="http://gw.cmc.gov.za/servlet/webpub?User.context=&action=Library.Search&merge=HRdoclist&User.lang=en&User.html=frames&Library.queryField=ALL&Library.queryText=" + strFields + "&Library.queryText=&Library.queryText=&Library.queryText=&Library.queryText=&Library.queryText=&Library.queryText=&Library.queryText=&Library.queryText=&Library.queryText=&Library.queryId=dom-001-44w.po-001-44w.library-agenda";
}

// Clock 
var timerID = null
var timerRunning = false

function stopclock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function startclock()
{
    stopclock()
    showtime()
}

function showtime()
{
 	var isNS = (navigator.appName == 'Netscape' && parseInt(navigator.appVersion) >= 4);
    var now = new Date() ;
    var year = now.getYear() + ((isNS) ? 1900 : 0) ;
    var month = now.getMonth()  + 1 ;
    var day = now.getDate() ;
    var dateValue = " " + year ;
    dateValue  += "." + ((month < 10) ? "0" : "") + month ;
    dateValue  += "." + ((day < 10) ? "0" : "") + day ;
    document.clock.face.value = dateValue ;
    timerID = setTimeout("showtime()",1000) ;
    timerRunning = true ;
}


function SearchForm_Validator(theForm)
{

  if (theForm.Search.value == "")
  {
    alert("Please enter a value for the \"Search Criteria\".");
    theForm.Search.focus();
    return (false);
  }
  return (true);
}
// end hiding -->
<!-- end of file -->