﻿function ancorSummary()
{
    window.setTimeout(goToAncor, 50);
}
function goToAncor()
{
    document.location.href = '#summary';
}
function ShowHideHelp(div)
{
    divObj = document.getElementById(div);
    var e=document.getElementsByTagName("div");
    
    for(var i=0;i<e.length;i++)
    {
        
        if (e[i].title=='...' && divObj!=e[i])
        { 
            e[i].style.display = 'none'; 
            
        }
    }

    if (divObj!=null)
    {
        if (divObj.style.display == 'none')
        {
            divObj.style.display = '';
        }
        else
        {
            divObj.style.display = 'none'
        }
    }
}

function checkGetMail(getMail, txtMail)
{   
         var objgetMail = document.getElementById(getMail);
         var objtxtMail = document.getElementById(txtMail);

         if ( objgetMail.checked && objtxtMail.value == '' )
         {
            alert("יש למלא את שדה המייל במידה ורוצים לקבל עדכונים");
            objgetMail.checked = false;
         }
}
/* BirthDate validation */
function checkBirthDate()
{
    var objY = document.getElementById(clientIDcdBirthDate + "_ddlYear");
    var objM = document.getElementById(clientIDcdBirthDate + "_ddlMonth");
    var objD = document.getElementById(clientIDcdBirthDate + "_ddlDay");
    if ( objY.value=='-1' || objM.value=='-1' || objD.value=='-1' )
    {
        document.getElementById('tdBirthDateErr').style.display = 'block'
        //return false;
    }
    else
    {
        document.getElementById('tdBirthDateErr').style.display = 'none'
        //return true;
    }
} 
/*  ID functions     [start]      *************************/
var TZstring = "";
function RegularExpressionTZ(source, arguments)
{   
    result = validateTZ( arguments.Value)
    if ( result )
    {
         obj = document.getElementById(source.id.replace('cv','txt'));
         obj.value = TZstring;
    }
    arguments.IsValid = result;
}
function calcCheckSum(IdNum)
{
	var checkSum = 0;
	var curTotal = 0;
	var curDigit;
	var curVal;
	var i = 0;
	var curValTens;
	var curValSingle;
	for (i = 0; i < IdNum.length; i++){
		curDigit = IdNum.charAt(i);
		curVal = parseInt(curDigit, 10); 
		if ((i % 2) != 0){
			curVal = curVal * 2;
		}
		curValSingle = curVal % 10;
		curValTens = (curVal - curValSingle) / 10;
		curTotal += curValSingle + curValTens;
	}
	
	checkSum = (10 - (curTotal % 10)) % 10;
	return checkSum;
}
function validateTZ( val)
{
    var idstr = val;	
	idstr = removeLeading(idstr, "\\s");
	idstr = removeTrailing(idstr, "\\s");
	if (isEmpty(idstr))
		return false;
	if (idstr.length < 9){
		idstr = padLeading(idstr, "0", 9);
	}	
	var re = /^(\d{1,8})(\d)$/;
	if (!re.test(idstr))
		return false;
	var bareidnum = idstr.replace(re, "$1");
	var delim = idstr.replace(re, "$2");
	var checksum = idstr.replace(re, "$3");
	if (bareidnum.length < 8)
		bareidnum = padLeading(bareidnum, "0", 8);
    var calcchecksum = calcCheckSum(bareidnum);
	var checkSumVal = parseInt(checksum, 10);
	if (isNaN(checkSumVal)){
		checksum = calcchecksum.toString();
	} else if (calcchecksum != checkSumVal){
		return false;
	}
	gFieldPretified = bareidnum + checksum;	
	if ( gFieldPretified != idstr )
	    return false;
	TZstring = idstr;
	return true;
}

// String manipulation utilities.
function removeLeading(str, delims)
{
	var re = eval("/^[" + delims + "]+/");
	var newstr = str.replace(re, "");
	return newstr;
}

function padLeading(str, chr, count)
{
	var i;
	var outstr = "";
	
	if (count - str.length < 0){
		return str;
	}
	for (i = 0; i < count - str.length; i++){
		outstr = outstr + chr;
	}
	outstr += str;
	
	return outstr;
}

function removeTrailing(str, delims)
{
	var re = eval("/[" + delims + "]+$/");
	var newstr = str.replace(re, "");
	return newstr;
}
/*  ID functions     [end]      *************************/


function validateDate(source, arguments)
{
    arguments.IsValid = true;
    /*
    var objYear = document.getElementById(source.id.replace('cvDate','ddlYear'));
    var objDay = document.getElementById( objYear.id.replace('Year','Day'));
    var objMonth = document.getElementById( objYear.id.replace('Year','Month'));
    
    if ( objYear.value == "-1" && objDay.value == "-1" && objMonth.value == "-1" )
    {
        arguments.IsValid = true;
    }
    else if ( objYear.value == "-1" || objDay.value == "-1" || objMonth.value == "-1" )
    {
        arguments.IsValid = false;
    }
    */
}
//reminder/mortgage
function showRenewDate()
{
    var objRIType = document.getElementById( objReInsuranceTypeId+ '_0');
    if ( objRIType.checked )
        enableRenewDateFields ( 1 );
    else
        enableRenewDateFields ( 0 );
}
    
// JScript File
function showDateFields( val)
{
    if ( val.toLowerCase() == 'true' )
        enableRenewDateFields ( 1 );
    else
        enableRenewDateFields ( 0 );
}
//מופעל על ידי האוביקט
function disableInsTypeFields(obj)
{
try{var objCarIT =   document.getElementById(objCarInsType);
    var objYoungDA = document.getElementById(objYoungDriverage);
    var objYoungDAErr = document.getElementById(objYoungDriverage.replace('LeadsShortHome1_','LeadsShortHome1_rfv'))
    var objCarITErr = document.getElementById(objCarInsType.replace('LeadsShortHome1_','LeadsShortHome1_rfv'))
    
    if( objCarIT == null || objYoungDA == null || objYoungDAErr == null || objCarITErr == null)
        return;
        
    if ( obj.value == 1)
    {
        objCarIT.disabled = false;
        objYoungDA.disabled = false;  
        objCarIT.Visible = true;
        objYoungDA.Visible = true;  
    }        
    else
    {
        objCarIT.disabled = true;
        objYoungDA.disabled = true;        
         objCarIT.Visible = false;
        objYoungDA.Visible = false; 
               //hideShowErr(objCarITErr,'hidden')
        //hideShowErr(objYoungDAErr,'hidden')
    }}catch(e){}
}
// מופעל על ידי ה-סבמיט
function checkCarFields( InsObjName )
{
    var objCarIT =   document.getElementById(objCarInsType);
    var objYoungDA = document.getElementById(objYoungDriverage);
    var objYoungDAErr = document.getElementById(objYoungDriverage.replace('LeadsShortHome1_','LeadsShortHome1_rfv'))
    var objCarITErr = document.getElementById(objCarInsType.replace('LeadsShortHome1_','LeadsShortHome1_rfv'))
    
    var objIT =   document.getElementById(InsObjName);
    disableInsTypeFields(objIT);

   /* if ( objIT.value == 1 )
    {
        if ( objCarIT.value == '-1' )
            hideShowErr(objCarITErr,'')
        if ( objYoungDA.value == '-1' )
            hideShowErr(objYoungDAErr,'')
    }*/
}
function hideShowErr(divErr, stts)
{
        divErr.style.visibility = 'visible';
        if ( stts == 'hidden' )
            divErr.style.display = 'none';
        else
            divErr.style.display = 'block'
}

function enableRenewDateFields ( num )
{   
    //debugger;
    var objY =   document.getElementById(clientIDcdRenewDate + '_ddlYear');
    var objM =   document.getElementById(clientIDcdRenewDate + '_ddlMonth');
    var objD =   document.getElementById(clientIDcdRenewDate + '_ddlDay');
    if ( num == 1)
    {
        objY.disabled = false;
        objM.disabled = false;
        objD.disabled = false;
    }
    else
    {
        objM.disabled = true;
        objY.disabled = true;
        objD.disabled = true;
    }        
}

/***** handle area+cities */
// JScript File
function isEmpty(aTextField)
{
    var re = /\s/g; //Match any white space including space, tab, form-feed, etc. 
    str = aTextField.replace(re, "");
    if (str.length == 0) 
    {
        return true;
    } 
    else 
    {
        return false;
    }
} 
function isNumber(str)
{
    var re = new RegExp();
    re = /^\d{1,}$/   
    return str.match(re) 
}
function isDate(str)
{
    var re = new RegExp();
    //re = /^\(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$/   
    return str.match(re) 
}
function AddSlash(obj)
{
    //debugger;
    if(obj != null )
    {
        if(obj.value.length == 2  || obj.value.length == 5)
            obj.value += "/";
    }
}
function OpenHelpFilm()
{
    filmWindow = window.open('HelpVideo.htm' , 'filmWindow' );
}
function OpenClose()
{
    document.getElementById("tdTree").style.display = document.getElementById("tdTree").style.display == 'none' ? 'inline' : 'none';
}
function SetSession(Value)
{
    PageMethods.SetSession(Value, SetSessionSucceeded, SetSessionFailed, null);
}

function SetSessionSucceeded(results, ctl)
{
    
}

function SetSessionFailed(results, ctl)
{
    //alert(results.get_message());
}
function ValidateEnglish(e)
{
    if( !e ) { e = window.event; }
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
	return !(((theKey > 1487) && (theKey < 1515)) || theKey == 32);
}
function ValidateHebrew(e)
{
    if( !e ) { e = window.event; }
    capsDetect( e );
	//what (case sensitive in good browsers) key was pressed
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
    return (((theKey > 1487) && (theKey < 1515)) || theKey == 32 || theKey == 119 || theKey == 46 || theKey == 34 || theKey == 45|| theKey == 44|| theKey == 39);
        
}
function ValidateNumber(e)
{
     if( !e ) { e = window.event; } 
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
	
    return ((theKey > 47  )&&(theKey < 58) );
}

function capsDetect( e ) {
	if( !e ) { e = window.event; } 
	//what (case sensitive in good browsers) key was pressed
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
	//was the shift key was pressed
	var theShift = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) ); //bitWise AND
	//if upper case, check if shift is not pressed. if lower case, check if shift is pressed
	MWJ_say_Caps( ( theKey > 64 && theKey < 91 && !theShift ) || ( theKey > 96 && theKey < 123 && theShift ) );
}

function MWJ_say_Caps(say)
{
    //debugger;
    if(say)
    {
        e = window.event;
        document.getElementById("divToolTip").style.visibility = 'visible';
        document.getElementById("divToolTip").style.left = getAbsoluteLeft(e.srcElement.id);
        document.getElementById("divToolTip").style.top = getAbsoluteTop(e.srcElement.id)+e.srcElement.offsetHeight;
        
        setTimeout("FadeOut('divToolTip');",2000);
    }
}
function getAbsoluteLeftCombo(objectId, frameObjId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
    objectId = frameObjId + '_Div';
	o = document.getElementById(objectId)
    if ( o== null ) return "0px";
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	
	if( o == null )
	    return o;
	
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent;   // Get parent object reference
		oLeft += oParent.offsetLeft; // Add parent left position
		o = oParent	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}
function FadeOut(objname){
var objholder=document.getElementById(objname)
objholder.filters[0].apply()
objholder.style.visibility='hidden'
objholder.filters[0].play()
}

function ShowWait(visible)
{
    width = 200;
    height = 50; 
    x = (document.body.clientWidth - width)/2;
    y = (document.body.clientHeight - height)/2;
    var elem = document.getElementById('divShowPosition');
    var elem2 = document.getElementById('ctl00_UpdateProgress1');
    
    if(visible)
    {
        elem2.style.display = 'inline';
        document.getElementById('dicDisableScreen').style.display = 'inline';
        document.getElementById('dicDisableScreen').style.width = screen.width;
        document.getElementById('dicDisableScreen').style.height = screen.height;
        elem.style.left = x;
        elem.style.top = y;
    }
    else
    {
        document.getElementById('dicDisableScreen').style.display = 'none';
        elem2.style.display = 'none';
    }
}

function SetProgressBarPosition()
{
    width = 200;
    height = 50; 
    var elem = document.getElementById('divShowPosition');
    if(elem != null)
    {
        x = (document.body.clientWidth - width)/2;
        y = (document.body.clientHeight - height)/2;
        elem.style.left = x;
        elem.style.top = y;
    }
}
function AddZeroes(obj)
{
    if(obj != null)
    {
        if(obj.value.length < 9 && obj.value.length > 0)
        {
            obj.value = "000000000" + obj.value;
            obj.value = obj.value.substr(obj.value.length - 9)
        }   
    }
}
function OpenUseTerms()
{
    width = 600;
    height = 600; 
    x = (document.body.clientWidth - width)/2;
    y = (document.body.clientHeight - height)/2;
    window.open('UseTerms.aspx','UseTerms','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+' , left = ' + x + ' , top= '+ y);
}
function OpenExistsCustomer()
{
    width = 540;
    height = 370; 
    x = (document.body.clientWidth - width)/2;
    y = (document.body.clientHeight - height)/2;
    window.open('ExistsCustomer.htm','UseTerms','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,width='+width+',height='+height+' , left = ' + x + ' , top= '+ y);
}
function OpenAroma()
{

    window.open('aroma.htm','aroma','menubar=no,titlebar=no,scrollbars=yes,staus=yes,width=590,height=370');
}