//*********************************************************************************
//		VALIDATION SCRIPTS
//*********************************************************************************


function validate_searchform()
{
frm=document.searchform;

if(isempty(frm.equitax_accno.value) && isempty(frm.cad_no.value) && isempty(frm.propowner_name.value) && isempty(frm.prop_address.value))
{alert("Please input at least one criteria for search");frm.prop_address.focus();return false;}

if(!isempty(frm.equitax_accno.value))
	{
	if(isNaN(frm.equitax_accno.value)){alert("Please input an Equitax Account Number without spaces or dashes");frm.equitax_accno.focus();return false;}
	if(frm.equitax_accno.value.length > 25){alert("Please input an Equitax Account Number upto 25 digits");frm.equitax_accno.focus();return false;}
	if(!chkSpacesDashes(frm.equitax_accno.value)){alert("Please input an Equitax Account Number without spaces or dashes");frm.equitax_accno.focus();return false;}
	}

if(!isempty(frm.cad_no.value))
	{
	if(isNaN(frm.cad_no.value)){alert("Please input a CAD Number without spaces or dashes");frm.cad_no.focus();return false;}
	if(frm.cad_no.value.length > 25){alert("Please input a CAD Number upto 25 digits");frm.cad_no.focus();return false;}
	if(!chkSpacesDashes(frm.cad_no.value)){alert("Please input a CAD Number without spaces or dashes");frm.cad_no.focus();return false;}
	}

if(!isempty(frm.propowner_name.value))
	{
	if(frm.propowner_name.value > 35){alert("Please input not more than 35 characters");frm.propowner_name.focus();return false;}
	if(!chkSemicolon(frm.propowner_name.value)){alert("Please input Property Owner name like Lastname; Firstname ");frm.propowner_name.focus();return false;}
	}

if(!isempty(frm.prop_address.value))
	{
	if(frm.prop_address.value > 50){alert("Please input not more than 50 characters");frm.prop_address.focus();return false;}
	if(!chkSemicolon(frm.prop_address.value)){alert("Please input Property Address like Street Number; Street Name ");frm.prop_address.focus();return false;}
	}
}


//*********************************************************************************
function WinOpen(url)
{	
	para="toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizeable=0,width=650,height=450";
	window.open(url,'Win',para);
}

function chkSpacesDashes(txtvalue)
{

if (txtvalue == "")
	{
		return false;
	}
	
	badStuff = "-";
	for (i=0; i<badStuff.length; i++)
	{
		badCheck = badStuff.charAt(i)
		if (txtvalue.indexOf(badCheck,0) != -1)
		{
			return false;
		}
		else
			return true;
	}

}

function chkSemicolon(txtvalue)
{

if (txtvalue == "")
	{
		return false;
	}
	goodStuff = ";";
	
	for (i=0; i<goodStuff.length; i++)
	{
		goodCheck = goodStuff.charAt(i)
		if (txtvalue.indexOf(goodCheck,0) != -1)
		{
			return true;
		}
		else
		return false;
	}

}

function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }

    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;

} // end of the 'setPointer()' function


function isempty(txtvalue)

{

txtvalue=txtvalue.replace(/\s/g,"")

if (txtvalue.length > 0)     return false; else return true;

}

   
       
function isDigit (c)
		{  
		 return ((c >= "0") && (c <= "9"))
		}
		


function validateEmail(email)
{
	
	// This function is used to validate a given e-mail 
	// address for the proper syntax
	
	if (email == ""){
		return false;
	}
	badStuff = ";:/,' \"\\";
	for (i=0; i<badStuff.length; i++){
		badCheck = badStuff.charAt(i)
		if (email.indexOf(badCheck,0) != -1){
			return false;
		}
	}
	posOfAtSign = email.indexOf("@",1)
	if (posOfAtSign == -1){
		return false;
	}
	if (email.indexOf("@",posOfAtSign+1) != -1){
		return false;
	}
	posOfPeriod = email.indexOf(".", posOfAtSign)
	if (posOfPeriod == -1){
		return false;
	}
	if (posOfPeriod+2 > email.length){
		return false;
	}
	return true
}	
