<!-- 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=yes,status=no,menubar=yes,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=780,height=550,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");
}

// open link in separate browser window
function startPopEvent3(PopEvent)
{
var desktop=window.open(PopEvent,"_blank","toolbar=no,location=yes,status=no,menubar=no,scrollbars=yes,width=560,height=490,resizable");
}

// open link in separate browser window
function startPopEvent4(PopEvent)
{
var desktop=window.open(PopEvent,"_blank","toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,width=600,height=500,resizable");
}

// open link in separate browser window
function startPopEvent5(PopEvent)
{
var desktop=window.open(PopEvent,"_blank","toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=680,height=480,resizable");
}

// open link in separate browser window
function startPopEvent6(PopEvent)
{
var desktop=window.open(PopEvent,"_blank","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=800,height=600");
}

// open link in separate browser window
function startPopEvent7(PopEvent)
{
var desktop=window.open(PopEvent,"_blank","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=770,height=500");
}

function SubCouncilPopup(PopEvent)
{
	var desktop=window.open(PopEvent,"SubCouncil","toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=650,height=500");
	desktop.focus();
}

function Sub_CouncilPopup(PopEvent)
{
	var desktop=window.open(PopEvent,"Sub_Council","toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=650,height=500");
	desktop.focus();
}

// set focus to first field in form
function setFocus()
{
	document.feedbackform.elements[0].focus() ;
}


//new window for planningtools
function newWindow(sURL)
 {
var newWindow;
newWindow = window.open(sURL,"Map","width=770,height=450,resizable=no");

}

// 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.");
        tempobj.focus();        
	return false;
    }
    else if(checkemail())
    {    return true;	}
    else 
    {	document.feedbackform.requiredEmail_address.focus();
		return false;	}
}

// check for proper email address
function checkemail()
{
    var 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;
   }
   if (validateEmailReply(txt))
   {   return true;	}
   else
   {	
		document.feedbackform.requiredEmail_address.value = "";		
		document.feedbackform.requiredEmail_address.focus();
		//txt.onfocus();
		return false;		
	}
}

//Check if more than one reply address is supplied
function validateEmailReply(emailreply)
{    
	//var emailreply = document.feedbackform.requiredEmail_address.value;    
	if(emailreply.indexOf('@')<0)
	{       alert('There must be an @ sign in your e-mail address');        
			return false;    
	}
	else if(emailreply.indexOf('@') != emailreply.lastIndexOf('@'))
	{       alert('You are only allowed to supply one email address');        
			return false;        
	} 
	/*else if(emailreply.indexOf('.')<0)
	{       alert('There must be at least one period in your e-mail address');        
			return false;    
	} 
	else if(emailreply.lastIndexOf('.')<emailreply.indexOf('@'))
	{       alert('There must be at least one period following your @ sign in your e-mail address');        
			return false;    
	}  */  
	return true;
}

// Focus on first form element
function myFocus()
{
	if (document.forms.length > 0)
	{
	 
		daform = document.forms[document.forms.length-1]
		max = daform.elements.length
		
		if (max > 0) 
		{
			for(i=0;i<max;i++)
			{
				if (daform[i].type == "text" || daform[i].type == "textarea" || daform[i].type == "password")
				{
					daform[i].focus()
					return true
				}
			}
		}
	}
	return true;
}
// make document query for GroupWise DMS
function makeRef()
{
    var strFields, strFields1, mno, mname, mnth, x ;
    mnth = document.choice.lstField2[document.choice.lstField2.options.selectedIndex].value;
    //alert(mnth) ;
    //alert(document.choice.lstField1[document.choice.lstField1.options.selectedIndex].value)
    
    fullstr = unescape(document.choice.lstField1[document.choice.lstField1.options.selectedIndex].value)
    charpos = fullstr.indexOf("/")
    mtname= fullstr.substr(0,charpos)
    mtcode=fullstr.substr(charpos+1,fullstr.length)
    
   //alert(charpos)
    //alert(mtname)
    //alert(mtcode)
    mname = mnth.substr(2);
    mno = mnth.substring(0,2);
    //alert(mno + " " + mname);
   
    if (document.choice.optR1[0].checked)
    {
		 strType=document.choice.optR1[0].value ;
    }
    
    else 
    {
		if(document.choice.optR1[1].checked)
		{
			strType=document.choice.optR1[1].value ;
		}
		else
		{
			strType=document.choice.optR1[2].value ;
		}
    }
    
    if ((strType=="Agenda") || (strType=="Minutes"))
	{
		
		//strFields =  document.choice.lstField1[document.choice.lstField1.options.selectedIndex].value;
		
		if ((mtcode == "EXCO") || (mtcode == "IEMT") || (mtcode == "SPEX") || (mtcode == "SPC"))
		{
			strFields =  escape(mtcode)
		}
		else
		{
			strFields =  escape(mtname)
		}
		
		strFields =  strFields + "%20" + strType + "%20";
		
		if (mnth!= "All")
		{
			strFields=  strFields + mname ;	
		}
		
		strFields=  strFields + "%2020" + document.choice.lstField3[document.choice.lstField3.options.selectedIndex].value;
		strFields1= strFields +  strType;
		
    }
	
	if (mtname == "Council")
	{
		 document.location.href="http://gw.capetown.gov.za/servlet/webpub?User.context=&action=Library.Search&merge=UnicityCouncil" + strType + "doclist&User.lang=en&User.html=frames&Library.queryText=&Library.queryField=SUBJECT&Library.queryCount=999&Library.queryText=" + strFields + "&Library.queryId=dom_001_44w.po_002_44w.library_agenda";
	}
	
	else
	{
		if (mtcode == "EXCO")
		{
			document.location.href="http://gw.capetown.gov.za/servlet/webpub?User.context=&action=Library.Search&merge=UnicityExco" + strType + "doclist&User.lang=en&User.html=frames&Library.queryText=&Library.queryField=SUBJECT&Library.queryText=" + strFields + "&Library.queryCount=999&Library.queryId=dom_001_44w.po_002_44w.library_agenda";
		}
		else
		{
			document.location.href="http://gw.capetown.gov.za/servlet/webpub?User.context=&action=Library.Search&merge=UnicityCommittee" + strType +"doclist&User.lang=en&User.html=frames&Library.queryText=&Library.queryField=SUBJECT&Library.queryText=" + strFields + "&Library.queryCount=999&Library.queryId=dom_001_44w.po_002_44w.library_agenda";
		}
	}

	
	if (strType=="Reports")
		{	
			if (mtname =="Council")
			{
				strFields= "C" + "%3F%3F/"
				strFields= strFields + "%3F%3F/";
				
				if (mnth== "All")
				{
					strFields=  strFields + "%3F%3F/";	
				}
				else
				{	
					strFields=  strFields + mno + "/";	
				}
					strFields=  strFields + document.choice.lstField3[document.choice.lstField3.options.selectedIndex].value ;
					document.location.href="http://gw.capetown.gov.za/servlet/webpub?User.context=&action=Library.Search&merge=UnicityCouncilReportsdoclist&User.lang=en&User.html=frames&Library.queryText=&Library.queryField=SUBJECT&Library.queryCount=999&Library.queryText=" + strFields + "&Library.queryId=dom_001_44w.po_002_44w.library_agenda";
			}
			else
				if (mtcode =="EXCO")
				{
					strFields= "EXCO" + "%3F%3F/"
					strFields= strFields + "%3F%3F/";
				
					if (mnth== "All")
					{
						strFields=  strFields + "%3F%3F/";	
					}
					else
					{	
						strFields=  strFields + mno + "/";	
					}
					
					strFields=  strFields + document.choice.lstField3[document.choice.lstField3.options.selectedIndex].value ;
					document.location.href="http://gw.capetown.gov.za/servlet/webpub?User.context=&action=Library.Search&merge=UnicityExcoReportsdoclist&User.lang=en&User.html=frames&Library.queryText=&Library.queryField=SUBJECT&Library.queryCount=999&Library.queryText=" + strFields + "&Library.queryId=dom_001_44w.po_002_44w.library_agenda";
				}
				else
				{
					strFields= mtcode + "%3F%3F/"
					strFields= strFields + "%3F%3F/";
					
					if (mnth== "All")
					{
						strFields=  strFields + "%3F%3F/";	
					}
					else
					{	
						strFields=  strFields + mno + "/";	
					}
					
					strFields=  strFields + document.choice.lstField3[document.choice.lstField3.options.selectedIndex].value ;
					document.location.href="http://gw.capetown.gov.za/servlet/webpub?User.context=&action=Library.Search&merge=UnicityCommitteeReportsdoclist&User.lang=en&User.html=frames&Library.queryText=&Library.queryField=SUBJECT&Library.queryText=" + strFields + "&Library.queryCount=999&Library.queryId=dom_001_44w.po_002_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);
}

function linkurl()
{
	document.form1.action = document.form1.url[document.form1.url.options.selectedIndex].value;
	var szurl = '';
	szurl = document.form1.url[document.form1.url.options.selectedIndex].value;
	parent.location.href = szurl;
	
}

// dropdown box script

CSAg = window.navigator.userAgent; CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);
function IsIE() { return CSAg.indexOf("MSIE") > 0;}
function CSIEStyl(s) { return document.all.tags("div")[s].style; }
function CSNSStyl(s) { return CSFindElement(s,0); }
function CSFindElement(n,ly) { if (CSBVers < 4) return document[n];
	var curDoc = ly ? ly.document : document; var elem = curDoc[n];
	if (!elem) { for (var i=0;i<curDoc.layers.length;i++) {
		elem = CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
	return elem;
}

function CSURLPopupShow(formName, popupName, target) {
	var form  = CSFindElement(formName);
	var popup = form.elements[popupName];
	window.open(popup.options[popup.selectedIndex].value, target);
	popup.selectedIndex = 0;
}

function AccNoCheck(AccNo) 
{
var blvalidAccNo = true;
var intArrWeight = new Array(3, 2, 1, 2, 3, 4, 5, 6);
var intArrAccNo = new Array(0, 0, 0, 0, 0, 0, 0, 0);
var strAccNo = "";
var intProduct = 0;
var intTotal = 0;
var intRemainder = 0;
var intLastDigit = 0;

if (AccNo.length == 9)
{
	intLastDigit = parseInt(AccNo.slice(8, 9));
	strAccNo = AccNo.slice(0,8);
	for(i=0; i<strAccNo.length; i++)
	{
		intArrAccNo[i] = strAccNo.slice(i,i+1);
		intProduct = intArrWeight[i] * intArrAccNo[i];
		intTotal = intTotal + intProduct;
/*		alert("i: " + i + "\n strAccNo.slice(i,1): " + strAccNo.slice(i,i+1) 
					+ "\n intArrWeight[i]: " + intArrWeight[i] 
					+ "\n intProduct: " + intProduct
					+ "\n intTotal: " + intTotal);*/
	}
	intRemainder = (intTotal % 9);
/*	alert("intTotal: " + intTotal + 
				"\n modulus: " + (intTotal % 9) + 
				"\n intRemainder: " + intRemainder + 
				"\n AccNo.slice(8, 9): " + AccNo.slice(8, 9));*/
	if(intRemainder !== intLastDigit)
	{
/*	alert("\n intRemainder: " + intRemainder + 
				"\n AccNo.slice(8, 9): " + AccNo.slice(8, 9));*/
		blvalidAccNo = false;
	}
}
else
{
	blvalidAccNo = false;
}
return blvalidAccNo;
}

// end hiding -->

<!-- end of file -->
