function ValidateAddress(source, arguments)
{
    var args;
    args = arguments.Value.toUpperCase();
            
     var subString = new Array(10);
    subString[0] = "P.O. BOX";
    subString[1] = "P.O BOX";
    subString[2] = "PO. BOX";
    subString[3] = "PO BOX";
    subString[4] = "P.O.BOX";
    subString[5] = "P.OBOX";
    subString[6] = "PO.BOX";
    subString[7] = "POBOX";
    subString[8] = "POB ";
    subString[9] = "P. O.";
    subString[10] = "P O B";

    for (j = 0; j < subString.length; j++)
    {
        for (i = 0; i <= args.length - subString[j].length; i++)
        {
        
            //Veljo   
            if (args.substring(i, subString[j].length + i) == subString[j])
            
            {
                arguments.IsValid = false;
                return arguments;
            }
        }
    }
            
    arguments.IsValid = true;
    return arguments;
}

function printPage(){
	var Obj1 = document.getElementById('btnPrint');
	var Obj2 = document.getElementById('btnBack');
	if (Obj1 != null)
	    Obj1.style.visibility = 'hidden';
	if (Obj2 != null)
		Obj2.style.visibility = 'hidden';
	
	window.print();
	
	if (Obj1 != null)
	    Obj1.style.visibility = 'visible';
	    
	if (Obj2 != null)
		Obj2.style.visibility = 'visible';
}



function CheckMinLength3(source, arguments)
{		
	if (arguments.Value.length > 2)
	{
		arguments.IsValid=true;
		return true;
	} 
	else
	{
		arguments.IsValid=false;
		return false;
	}
}

function CheckPolicyDaySpan22(InceptionDate,ExpiratonDate)
{		
	if ( jsDateDiff(InceptionDate,ExpiratonDate,'d',true) > 366 )
	{
		alert("There is more than a year between the Inception and Expiration date!");
	}
}

//Sets exp. date to 1 year of inc date.
function SetAutoExpirationDate(InceptionDate, ExpiratonDate)
{
	if (InceptionDate.length > 5)
	{    	
		ExpDateString = AddYearToDate(InceptionDate, false, 1);
		var ExpDate = new Date(ExpDateString);
		ExpiratonDate.SetDate(InceptionDate);
		ExpiratonDate.SetYear(InceptionDate.getYear() + 1);
	}
}

function ConvertUTCToEUR(UTCDate)
{

    //Veljo changed the logic according to the new rdp API
    var Month = UTCDate.getMonth() + 1;
    var EURDateString = Month.toString() + "/" + UTCDate.getDate().toString() + "/" + UTCDate.getFullYear().toString();
    
    return EURDateString;
}

function AddYearToDate(OriginalDate,IsEuroFormat,YearsToAdd)
{ 
	var newDate;
	if(IsEuroFormat)
	{	// i.e. dd/mm/yyyy format
		var dstr = OriginalDate.split("/");    
		newDate = dstr[1] + "/" + dstr[0] + "/" + dstr[2]; 
	}
	else
	{
		// mm/dd/yyy format
		newDate = OriginalDate
	}
	
	d = new Date(newDate);        
	d.setFullYear(YearsToAdd + d.getFullYear());
	
	d.setMonth(d.getMonth() + 1);
    return(d.toString());
    
}
 

function jsDateDiff( startD, endD, interval, rounding ) {
    var iOut = 0; var bufferA = Date.parse( startD );
	var bufferB = Date.parse(endD);var number = bufferB-bufferA ;

    // what kind of add to do?
    switch (interval.charAt(0)) {
        case 'd': case 'D':
            iOut = parseInt(number / 86400000) ;
			if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            iOut = parseInt(number / 3600000 ) ;
            if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            iOut = parseInt(number / 60000 ) ;
            if(rounding) iOut += parseInt((number % 60000)/30001) ;
            break ;
        case 's': case 'S':
            iOut = parseInt(number / 1000 ) ;
            if(rounding) iOut += parseInt((number % 1000)/501) ;
            break ;
        default:
	        return null;
    }
    return iOut ;
}


function BeforeInsurerRowDeleted(WebGrid, uwgInsurer)
{		
			return !ConfirmAction("Are you sure you want to remove this Insurer?");			
}



function MenuOn(tdRef){
	tdRef.className ='MenuItmA';	
}

function MenuOff(tdRef){
	tdRef.className ='MenuItm';	
}

var popUp; 
function OpenCalendar(idname, postBack,RelPath)
{
	popUp = window.open(RelPath+'Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal','width=204,height=206,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
	theform.elements[id].setActive();
}

//Policy, Endorsment page.
function OpenWin(WindowURL, WinName) {

    var win = $find(WinName);
    if (win != null) {
        win.setUrl(WindowURL);
        win.setSize(700, 450);
        win.Center();
        win.show();
    }
}

//Confirm User Action 
function ConfirmAction(msg){
	return confirm(msg);
}

function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz az well)
    return oWindow;
}

function CloseOnReload() {
    GetRadWindow().Close();
}	