function showInfo2(tabs, show_tab, div){
    var obj, t;	
    var c = tabs.length;
    for(i=0;i<c;i++){
        t = tabs[i];
        obj = document.getElementById("tab_" + t);
        if( t != show_tab){
            obj.setAttribute("class", "none");
            obj.className = "none";
            if(div === true){
                document.getElementById("div_" + t).style.display='none';
            }else if(div === false){
                    
            }else{
                document.getElementById("div_" + t + "_" + current_so_sel_house).style.display='none';
            }
        }else{
            obj.setAttribute("class", "current");
            obj.className = "current";
            if(div === true){
                document.getElementById("div_" + t).style.display='block';
            }else if(div === false){
                    
            }else{
                document.getElementById("div_" + t + "_" + current_so_sel_house).style.display='block';
            }
        }	
    }
}
function copyAddressInfo(){
    
    var flds = 	new Array('zip', 'city', 'addr', 'lname', 'fname');
    var c = flds.length;
    for(i=0;i<c;i++){
        document.getElementById("s_" + flds[i]).value = document.getElementById( flds[i]).value;
    }
    document.getElementById('s_zoneid').value = document.getElementById('zoneid').options[document.getElementById('zoneid').selectedIndex].value;
    
}
// search RE Base show or hide sold home
function hideSoldHome(zn){
   document.getElementById('hide_sold').value = zn; 
   document.getElementById('form_search_result').submit();
}
//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// show/hide sub docs content on text pages
var opened_div = "";
function show_ex_div(div_id){
    if(opened_div != "" && opened_div != div_id){
        document.getElementById(opened_div).style.display = 'none';
    }
    var div = document.getElementById(div_id);
    if(div.style.display == "block"){
        div.style.display = "none";
        opened_div = "";
    }else{
        div.style.display = "block";
        opened_div = div_id;
    }
}

//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// show/hide login form on header
function show_login_form(){ showHideObj('loginform');}
//----------------------------------------------------------------------------
// show or hidee FAQ Favorites
function show_favorites_div(){showHideObj('favoritesdiv');}
//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// dhtml features to show user data


//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// sending form data to server
// div_id - parent object for <form> html content
// template_id - template wich replace div_id childs if no errors
function sendContactForm(form_id, div_id, template_id){
    var loader_id = show_loader_indicator(div_id, "");
    var data = {};
    data['name'] = document.getElementById('name').value;
    data['email'] = document.getElementById('emailxxx').value;
    data['subject'] = document.getElementById('subject').value;
    data['comments'] = document.getElementById('comments').value;
    data['pr_result'] = 0;
    data['captcha'] = document.getElementById('cf_captcha').value;
    data['mode'] = 'send';
    ajaxDataScript("/contact_ajax_send_form.html", data, "document.getElementById('" + loader_id + "').style.display='none';setBlock('"+div_id+"','"+template_id+"',req.responseJS,req.responseText)");
}
function sendContactFormMls(form_id, div_id, template_id){
    var loader_id = show_loader_indicator(div_id, "");
    ajaxData("/contact_ajax_send_form_mls.html", {data:document.getElementById(form_id),pr_result:0,mode:'send'}, "document.getElementById('" + loader_id + "').style.display='none';setBlock('"+div_id+"','"+template_id+"',req.responseJS,req.responseText)");
}

function sendCheckZipMls(form_id, div_id, template_id){
    var loader_id = show_loader_indicator(div_id, "");
    ajaxData("/check_zip_mls.html", {zip:document.getElementById('zip1').value}, "document.getElementById('" + loader_id + "').style.display='none';setCheckZipMls(req.responseJS,req.responseText)");
}
function setCheckZipMls(data,text){
	
	if(data['is_mls'] == '1'){
		document.getElementById('zzz').innerHTML = ' ' + data['zip'];
		document.getElementById("check_zip_mls").style.display = 'none';
		document.getElementById('no_mls').style.display = 'none';
		document.getElementById('mm_mls').style.display = 'block';
	}
	else{
		document.getElementById('zz').innerHTML = ' ' + data['zip'];
		document.getElementById('mm_mls').style.display = 'none';
		document.getElementById('no_mls').style.display = 'block';
	}
}

function sendPaymentForm(form_id, div_id, template_id){
    var loader_id = show_loader_indicator(div_id, "");
    ajaxData("/user_ajax_save_payment_info.html",{q : document.getElementById(form_id),pr_result:0 },"document.getElementById('" + loader_id + "').style.display='none';setBlock('"+div_id+"','"+template_id+"',req.responseJS,req.responseText)");
}

function showUserEditForm(div_id, template_id, pr_result){
    var loader_id = show_loader_indicator(div_id, "");
    ajaxData("/user_ajax_getinfo.html",{pr_result: pr_result },"document.getElementById('" + loader_id + "').style.display='none';setBlock('"+div_id+"','"+template_id+"',req.responseJS,req.responseText)");
}

function pingHouse(house_id){
    ajaxData("/ping_house.html",{house_id: house_id },"");
}

function sendTestimonialForm(form_id, div_id, template_id){
    var loader_id = show_loader_indicator(div_id, "2");
    ajaxData("/testimonials_ajax_save.html",{q : document.getElementById(form_id) },"document.getElementById('" + loader_id + "').style.display='none';setBlock('"+div_id+"','"+template_id+"',req.responseJS,req.responseText)");
}

function sendHouseCommentForm(form_id, div_id, template_id){
    var loader_id = show_loader_indicator(div_id, "2");
    ajaxData("/houses_comments_ajax_save.html",{q : document.getElementById(form_id), house_id :house_comment_id },"document.getElementById('" + loader_id + "').style.display='none';setBlock('"+div_id+"','"+template_id+"',req.responseJS,req.responseText);addCurrentComment(req.responseJS);testSetAttr(testOnpage, 2);prev_f(2);");
}

function sendContactSellerForm(form_id, div_id, template_id){
    var loader_id = show_loader_indicator(div_id, "2");
    ajaxData("/houses_contact_seller_ajax_save.html",{q : document.getElementById(form_id), house_id :document.getElementById('house_id').value },"document.getElementById('" + loader_id + "').style.display='none';setBlock('"+div_id+"','"+template_id+"',req.responseJS,req.responseText);if(req.responseText=='ok')document.getElementById('contact_link').style.display='none';");
}


function sendLoginForm(form_id, div_id, template_id){
    var loader_id = show_loader_indicator(div_id, "login");
    ajaxData("https://www.fizber.com/user_ajax_login.html",{q : document.getElementById(form_id)},"document.getElementById('" + loader_id + "').style.display='none';setBlock('"+div_id+"','"+template_id+"',req.responseJS,req.responseText);if(req.responseText=='ok'){setTimeout(\"showHideObj('login_form_2');\",1500);parseContactForm(req.responseJS)}");
}


function sendPartnershipForm(form_id, div_id, template_id){
    var loader_id = show_loader_indicator(div_id, "");
    ajaxData("/contact_ajax_send_form.html",{q : document.getElementById(form_id),pr_result:0 },"document.getElementById('" + loader_id + "').style.display='none';setBlock('"+div_id+"','"+template_id+"',req.responseJS,req.responseText)");
}
var pr_app_house = true;
function ajaxGetAppraiserInfo(house_id){
    if(pr_app_house){
        pr_app_house = false;
        document.getElementById('loader_rc').style.display='block';
        ajaxData("/detail_view_appraise_house.html",{house_id: house_id},"pasteDetViewAppraiser(req.responseJS,req.responseText)");
    }
}


function pasteDetViewAppraiser(hash, text){
    if(text == "err" || hash.length ==0){
        document.getElementById('div_recent_sold').innerHTML = 'No data available';
    }else{
        var div = document.getElementById('div_recent_sold');
        removeChildNodes(div);
        var ul = document.createElement("UL");
        var c = hash.length;
        var li;
        if(c > 10){
            c = 10;
        }
        var c_min = hash[0].price;
        var c_max = 0;
        for(i=0; i<c; i++){
            if (c_min > hash[i].price*1){c_min = hash[i].price;}
            if (c_max < hash[i].price*1){c_max = hash[i].price;} 
            li = document.createElement("LI");
            li.innerHTML = hash[i].close_date + " " +  hash[i].address + " - $" + hash[i].price
            ul.appendChild(li);
        }
        div.appendChild(ul);
        var apr = document.getElementById('appraise');
        var aprTxt = document.getElementById('appraiseTxt');
        aprTxt.innerHTML = '$' + c_min + ' - $' + c_max;
        apr.style.display = 'block';
    }
}




function parseContactForm(hash){
    var ids_input_id_value;
    var hash_input_id_value = new Array();
    var pr_parse_t_input_id_value = 0;
    if(hash.length){
        var c = hash.length;
        for (var i =0;i<c;i++){
            if(hash[i].type=="input_id_value"){
                hash_input_id_value[i] = hash[i].value;
                ids_input_id_value+="#"+hash[i].key+"#"+i+"||";
                pr_parse_t_input_id_value = 1;
            }
        }
    }
    if(pr_parse_t_input_id_value){
        parseTemplateIdValue(document.getElementById('contact_seller_form_table'), hash_input_id_value, ids_input_id_value);
    }
}



//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// testimonials functions
function getTestimonials(onpage, page, pr_get, pr_show){
    var loader_id = show_loader_indicator('testimonials_content_div', "");
    ajaxData("/testimonials_" + onpage + "_" + page + "_" + pr_get + ".html",{},"document.getElementById('" + loader_id + "').style.display='none';setTestimonials(req.responseJS,req.responseText, " + pr_show + ")"); 
    return false;
}

function setTestimonials(hash, text, pr_show){
    //console.debug(1)
    var content_obj = document.getElementById('testimonials_content_div');
    var rec_obj = document.getElementById('testimonials_content_div_template_message');
    if(!pr_show){    
        var nav_obj = document.getElementById('paging_p');
    }
    var message_obj, img_obj, author_obj, z, i, c, t;
    removeChildNodes(content_obj);
    if(hash){
        c = hash.length
        for(i=0;i<c;i++){
            if(hash[i].type == "rec"){
                message_obj = rec_obj.childNodes[0];
                img_obj = message_obj.childNodes[0];
                author_obj = rec_obj.childNodes[1].childNodes[0];
                link = rec_obj.childNodes[0].childNodes[1];
                if(link && link.childNodes[0]){
                    if (parseInt(hash[i].house_id) >0){
                        link.href = "listing_" + hash[i].house_id + ".html";
                        link.childNodes[0].style.display="block";
                    }else{
                        link.childNodes[0].style.display="none";
                    }
                }
                if(!pr_show){
                    img_obj.setAttribute('src', hash[i].photo.replace("\\","").replace("\\",""));
                }
                z = document.createTextNode(hash[i].message);
                message_obj.appendChild(z);
                z = document.createTextNode(hash[i].author);
                author_obj.appendChild(z);
                
                copyTemplate(content_obj, rec_obj);
                if(!pr_show){
                    message_obj.removeChild(message_obj.childNodes[2]);
                    img_obj.src = "";
                }else{
                    message_obj.removeChild(message_obj.childNodes[3]);
                }
                author_obj.removeChild(author_obj.childNodes[0]);
            }
            if(hash[i].type == "sets"){
                if(!pr_show){
                    if(nav_obj.childNodes[3].childNodes[0]){
                        nav_obj.childNodes[3].removeChild(nav_obj.childNodes[3].childNodes[0]);
                    }
                    z = document.createTextNode(hash[i].page.replace("\\",""));
                    nav_obj.childNodes[3].appendChild(z);
                }
                eval("testSetAttr(" + hash[i].np_page + ");");
            }
        }
    }
}

var testOnpage;
var testPage;
function testSetAttr(onpage, page){
    testOnpage = onpage;
    testPage = page;
}

function prev_f(pr_show){
        if(pr_show == 3){
        getMessagesListPage(testPage, 'prev');
    }else if(pr_show == 2){
        getHousesComments(testOnpage, testPage, 'prev');
    }else{
        getTestimonials(testOnpage, testPage, 'prev', pr_show);
    }
}

function next_f(pr_show){
    if(pr_show == 3){
        getMessagesListPage(testPage, 'next');
    }else if(pr_show == 2){
        getHousesComments(testOnpage, testPage, 'next');
    }else{
        getTestimonials(testOnpage, testPage, 'next', pr_show);
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// listing details page - photos rotator


function openFullPhotoPopup(src){
    var wnd = window.open('#', 'photos', 'width=10,height=10,location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no');
    wnd.document.write("<html><body style='margin:0px 0px 0px 0px'>");
    wnd.document.write("<a href='#' onclick='window.close();'>");
    wnd.document.write("<img src='" + src + "' border=0 onload=\"window.resizeTo(this.width, this.height+45);\">");
    wnd.document.write("</a></body></html>");
    
}

//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// template parser
//div_id - content place
// template_id - element with template
// hash - JSON object with data to parse
// text - some text 
// if hash has any alert  - parse template with errors and don't change curent template,
// in other case parse template with hash data (key - element id, value - data, type - type of parsing)
function setBlock(div_id, template_id, hash,text){
    //console.debug(1)   
    var div = document.getElementById(div_id);
    var template = document.getElementById(template_id);
    if(hash.alert){
        alert(hash.alert);
        return;
    }
    if(hash[0]){
        if(hash[0].key == "alert"){
            var pr_parse_t_errors = 0;
            var hash_errors = new Array
            var ids_errors=""
            var c = hash.length;
            for (var i = 1;i<c;i++){
                if(hash[i].type == "show_login_form"){
                    showHideObj('login_form_2');
                    document.getElementById('login_form_2').childNodes[0].childNodes[0].rows[0].cells[1].childNodes[0].focus();
                }else{
                    hash_errors[i] = hash[i].value;
                    ids_errors+="#"+hash[i].key+"#"+i+"||";
                    pr_parse_t_errors = 1;
                }
            }
            if (pr_parse_t_errors){
                parseTemplateErrors(div, hash_errors, ids_errors);
            }
            alert(hash[0].value);
            return;
        }
    }
    if(template_id != "table_form"){
	    removeChildNodes(div);
    	copyTemplate(div, template); 
    }
    var pr_parse_t_input_id_value = 0;
    var pr_parse_t_td_child = 0;
    var pr_parse_t_eval = 0;
    var hash_input_id_value = new Array
    var hash_td_child = new Array
    var hash_eval = new Array
    var ids_input_id_value=""
    var ids_td_child=""
    var ids_eval=""
    if(hash.length){
        var c = hash.length;
        for (var i =0;i<c;i++){
            if(hash[i].type=="input_id_value"){
                hash_input_id_value[i] = hash[i].value;
                ids_input_id_value+="#"+hash[i].key+"#"+i+"||";
                pr_parse_t_input_id_value = 1;
            }
            if(hash[i].type=="td_child"){
                hash_td_child[i] = hash[i].value;
                ids_td_child+="#"+hash[i].key+"#"+i+"||";
                pr_parse_t_td_child = 1;
            }
            if(hash[i].type=="eval"){
                hash_eval[i] = hash[i].value;
                ids_eval+="#"+hash[i].key+"#"+i+"||";
                pr_parse_t_eval = 1;
            }
        }
    }
    if (pr_parse_t_input_id_value){
        parseTemplateIdValue(div, hash_input_id_value, ids_input_id_value);
    }
    if (pr_parse_t_td_child){
        parseTemplateTdChild(div, hash_td_child, ids_td_child);
    }
    if (pr_parse_t_eval){
        parseTemplateEval(div, hash_eval, ids_eval);
    }
    return true;
}

//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// parse template with errors 
// add <div> with error text above element with incorrect data
function parseTemplateErrors(obj, hash_iv,ids){
    var a,i,child,str, t_id;
    var ix = 0; 
    if(obj.childNodes.length>0){
        var t =  obj.childNodes.length;
        for(i=0;i<t;i++){
            child = obj.childNodes[i+ix];
            if(child.childNodes){
                    parseTemplateErrors(child, hash_iv,ids);
            }
            if(child.id){
                str = child.id;
                if(str.indexOf("err_message") != -1){
                    obj.removeChild(child);
                    ix--;
                }
                if(ids.match(new RegExp('(.*)#'+child.id+'#([0-9]+)||')) && hash_iv[parseInt(RegExp.$2)]){
                    var z = document.createTextNode(hash_iv[parseInt(RegExp.$2)]);
                    var z1 = document.createElement("DIV") ;
                    z1.style.color = "#FFFFFF";
                    t_id = "err_message" + Math.round(Math.random() * 200);
                    z1.setAttribute("id", t_id);
                    z1.id = t_id;
                    z1.appendChild(z);
                    obj.insertBefore(z1,obj.childNodes[0]);
                    fade(t_id, 'fadeRule3');
                    fade(obj.childNodes[1].id, 'fadeRule2');
                    ix++;
                }
            }
            
        }
    }
}

//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// parse template with text data 
// add textNode to element with set ID
function parseTemplateTdChild(obj, hash_iv,ids){
    var a;
    if(obj.childNodes.length>0){
        var t =  obj.childNodes.length;
        for(var i=0;i<t;i++){
            child = obj.childNodes[i];
            if(child.childNodes){
                    parseTemplateTdChild(child, hash_iv,ids);
            }else{
                if(child.id){
                    if(ids.match(new RegExp('(.*)#'+child.id+'#([0-9]+)||')) && hash_iv[parseInt(RegExp.$2)]){
                        var z = document.createTextNode(hash_iv[parseInt(RegExp.$2)]);
                        child.appendChild(z);
                    }
                }
            }            
        }
    }
    
    if(obj.id){
        if(ids.match(new RegExp('(.*)#'+obj.id+'#([0-9]+)||')) && hash_iv[parseInt(RegExp.$2)]){
            var z = document.createTextNode(hash_iv[parseInt(RegExp.$2)]);
            obj.appendChild(z);
        }
        
    }
}

//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// parse template with data to evaluate 
// can use to change object properties
// data evaluate in format obj.[data]
// example: data = "value='dsfa'"  for <input type='text' id='some_id' value='111'>
// change  "111" to "dsfa"

function parseTemplateEval(obj, hash_iv,ids){
    var a;
    if(obj.childNodes.length>0){
        var t =  obj.childNodes.length;
        for(var i=0;i<t;i++){
            child = obj.childNodes[i];
            if(child.childNodes){
                    parseTemplateEval(child, hash_iv,ids);
            }else{
                if(child.id){
                    if(ids.match(new RegExp('(.*)#'+child.id+'#([0-9]+)||'))  && hash_iv[parseInt(RegExp.$2)]){
                        //alert("child."+ hash_iv[parseInt(RegExp.$2)])
                        eval("child."+ hash_iv[parseInt(RegExp.$2)]);
                    }
                }
            }            
        }
    }
    if(obj.id){
        if(ids.match(new RegExp('(.*)#'+obj.id+'#([0-9]+)||')) && hash_iv[parseInt(RegExp.$2)]){
            eval("obj."+ hash_iv[parseInt(RegExp.$2)])
        }
    }
}

//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// parse template with data for input fields

function parseTemplateIdValue(obj, hash_iv,ids){
    var a;
    if(obj.tagName=="FORM"){
        obj.id = "active_form";
    }
    if(obj.childNodes.length>0){
        var t =  obj.childNodes.length;
        for(var i=0;i<t;i++){
            child = obj.childNodes[i];
            if(child.childNodes){
                    parseTemplateIdValue(child, hash_iv,ids);
            }else{
                if(child.id){
                    if(ids.match(new RegExp('(.*)#'+child.id+'#([0-9]+)||'))  && hash_iv[parseInt(RegExp.$2)]){
                        child.value = hash_iv[parseInt(RegExp.$2)];
                    }
                }
            }            
        }
    }
    if(obj.id){
        if(ids.match(new RegExp('(.*)#'+obj.id+'#([0-9]+)||')) && hash_iv[parseInt(RegExp.$2)]){
            obj.value = hash_iv[parseInt(RegExp.$2)];
        }
    }
}

//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// copy inner DOM structure from template to div objects 

function copyTemplate(div, template){
    var c = template.childNodes.length
    var t
    for(i=0;i<c;i++){
        t = template.childNodes[i].cloneNode(true);
        div.appendChild(t);
    }    
    return 1;
}
//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// remove all 'obj' childs
function removeChildNodes(obj){
    if(obj.childNodes){
        var t =  obj.childNodes.length;
        for(var i=0;i<t;i++){
            child = obj.childNodes[i];
            if (child.nodeType == 1) {
                if(child.childNodes.length>0){
                    removeChildNodes(child);
                }
            }
        }
        while(obj.childNodes.length>0){
            obj.removeChild(obj.childNodes[0]);
        }
    }    
}

function deleteTableElements(tb_obj){
    var c1=tb_obj.rows.length;
    for(j=0;j<c1;j++){
        tb_obj.deleteRow(0);
    }   
}
function copyTableTemplate(tbl, src_table){
    var c = src_table.rows.length;
    var i;
    for(i=0;i<c;i++){
        row = tbl.insertRow(tbl.rows.length);
        if(src_table.rows[i].className !=""){
            row.className = src_table.rows[i].className;
        }
        copyTemplate(row, src_table.rows[i])
    }
}



//----------------------------------------------------------------------------
// by Yarosh A. <testtset@gmail.com>
// form checker

var so_form_elements = new Array(
//{key: 'cc_cvv', type: ['int','req']},
//{key: 'cc_number', type: ['int','req']},
{key: 'zip', type: ['int','req']},
{key: 'city', type: ['req']},
{key: 'addr', type: ['req']},
{key: 'lname', type: ['req']},
{key: 'fname', type: ['req']},
{key: 'zoneid', type: ['req_select']}
);




var buy_yard_sign_elements = new Array(
{key: 'req_phone', type: ['int', 'req']},
//{key: 'req_address', type: ['req']},
//{key: 'cc_number', type: ['int','req']},
//{key: 'cc_cvv', type: ['int','req']},
{key: 'zip', type: ['int','req']},
{key: 'city', type: ['req']},
{key: 'addr', type: ['req']},
{key: 'lname', type: ['req']},
{key: 'fname', type: ['req']},
{key: 'zoneid', type: ['req_select']},
{key: 's_zip', type: ['int','req']},
{key: 's_city', type: ['req']},
{key: 's_addr', type: ['req']},
{key: 's_lname', type: ['req']},
{key: 's_fname', type: ['req']},
{key: 's_zoneid', type: ['req_select']}
);




var sell_home_elements = new Array(
{key: 'reg_email', type: ['email', 'req']},
{key: 'reg_email_c', type: ['email', 'req']},
{key: 'lname', type: ['req']},
{key: 'fname', type: ['req']}

);

var sell_home_elements_login = new Array(
{key: 'log_password', type: ['req']},
{key: 'log_email', type: ['email', 'req']}
);


var edit_house_data = new Array(
                                          
{key: 'property_type', type: ['req_select']},
{key: 'price', type: ['int','req']},
{key: 'num_bedrooms', type: ['int']},
{key: 'num_bathrooms', type: ['float']},
{key: 'sq_footage', type: ['float']},
{key: 'year_built', type: ['int']},
{key: 'lot_size', type: ['float']},
{key: 'num_floors', type: ['int']},
{key: 'tax_value', type: ['int']},
{key: 'zone', type: ['req_select']},
{key: 'city', type: ['req']},
{key: 'zip', type: ['int','req']}

);

var edit_house_data_no_zip = new Array(										  
{key: 'property_type', type: ['req_select']},
{key: 'price', type: ['price','req']},
{key: 'num_bedrooms', type: ['int']},
{key: 'num_bathrooms', type: ['float']},
{key: 'sq_footage', type: ['float']},
{key: 'year_built', type: ['int']},
{key: 'lot_size', type: ['float']},
{key: 'num_floors', type: ['int']},
{key: 'tax_value', type: ['int']},
{key: 'zone', type: ['req_select']},
{key: 'city', type: ['req']}

);

var step4_form_el = new Array(
{key: 'phone', type: ['int', 'req']},
{key: 'lname', type: ['req']},
{key: 'fname', type: ['req']},
{key:'email', type: ['email']}
);

var cp_el = new Array(
{key: 'phone', type: ['int', 'req']},
{key: 'lname', type: ['req']},
{key: 'fname', type: ['req']},
{key:'email', type: ['email']}
);

var register_form_elements = new Array(

{key: 'b_zip', type: ['int']},
{key: 'email_', type: ['email', 'req']},
{key: 'email_c', type: ['email', 'req']},
{key: 'lname', type: ['words', 'req']},
{key: 'fname', type: ['words', 'req']}
);



var isEmail = false;
var curentValidatorHash = new Array();

function checkIsEmail(data,text,cur_el){
	var z,z1,t_id, pr_err;
	var parent, str;
	cur_el = document.getElementById(cur_el);
	parent = cur_el.parentNode;
     if(parent.childNodes[0]){
        l = parent.childNodes.length;
        for(j=0;j<l;j++){
            if(parent.childNodes[j]){
                str = parent.childNodes[j].id + '';
                if(str.indexOf("err_message") != -1){
                    parent.removeChild(parent.childNodes[j]);
                }
            }
        }
     }
	if(text=='ok'){
		isEmail = false;         
        //pr_err = 1;
	}
	else{
		//z = document.createTextNode("Another user has already registered with this email. If you are a returning user, click <a href='/sale-by-owner-user-area/index.html'>here</a> to log in, or, if you forgot your password, click <a href='https://www.fizber.com/sale-by-owner-user-area/forgot-password.html'>here</a>.");
		 z = "Another user has already registered with this email. If you are a returning user, click <a href='/sale-by-owner-user-area/index.html'>here</a> to log in, or, if you forgot your password, click <a href='https://www.fizber.com/sale-by-owner-user-area/forgot-password.html'>here</a>.";
         z1 = document.createElement("DIV") ;
         z1.style.width = '305px';
         t_id = "err_message" + Math.round(Math.random() * 200);
         z1.setAttribute("id", t_id);
         z1.id = t_id;
         //z1.appendChild(z);
         z1.innerHTML = z;
         if(parent.childNodes[0]){
             parent.insertBefore(z1,cur_el);				 
         }else{
             parent.appendChild(z1);				
         }
         fade(cur_el.id, 'fadeRule2');
         fade(t_id, 'fadeRule3');
		isEmail = true;
	}
}

function setValidatorAction(hash,reg){
    var c = hash.length;
    for (var i = 0;i<c;i++){ 
        curentValidatorHash[curentValidatorHash.length] = hash[i]
        var cur_el = document.getElementById(hash[i].key);
        try{
 			if (reg){
 				eval('cur_el.onblur = function (){checkFormForErrors(false,"' + hash[i].key + '","' + reg + '" )}');
 			}
 			else {
				eval('cur_el.onblur = function (){checkFormForErrors(false,"' + hash[i].key + '",' + false + ' )}');
        }
        }
        catch(e){
        	//alert(hash[i].key + " - not exist");
        }
    }
}

function checkFormForErrors( hash, element, reg){
    if (!hash){
        hash = curentValidatorHash;
    }
    var i,c1;
    var l = 0;
    var c = hash.length;
    var parent, str;
    var z,z1,t_id, pr_err;
    pr_err = 0;
    for (var i = 0;i<c;i++){ 
        hash[i].error = "";
        var cur_el = document.getElementById(hash[i].key);
        if(!cur_el){
            continue;
        }
        if(!element || element == hash[i].key){		
            c1 = hash[i].type.length;
            for(j=0;j<c1;j++){
                if(hash[i].type[j] == "int" && cur_el.value!=""){
                    if(/^\d{1,}$/.test(cur_el.value)){
                        
                    }else{
                        hash[i].error = "Please enter a valid number in this field.";
                    }
                }else if(hash[i].type[j] == "price" && cur_el.value!=""){
                    if(/^\d{1,}$/.test(cur_el.value)){
                        if(parseInt(cur_el.value)>20000){
                        
	                    }else{
	                        hash[i].error = "Please enter a valid price greater than $20000.";
	                    }
                    }else{
                        hash[i].error = "Please enter a valid number in this field.";
                    }
                }else if(hash[i].type[j] == "cc" && cur_el.value!=""){
                    if(/^\d{1,}$/.test(cur_el.value) && cur_el.value.length>12 && cur_el.value.length<17){
                        
                    }else{
                        hash[i].error = "Please enter a valid cc number in this field.";
                    }
                }else if(hash[i].type[j] == "cvv" && cur_el.value!=""){
                    if(/^\d{1,}$/.test(cur_el.value) && cur_el.value.length>2 && cur_el.value.length<5){
                        
                    }else{
                        hash[i].error = "Please enter a valid cvv code in this field.";
                    }
                }else if(hash[i].type[j] == "email" && cur_el.value!=""){
                    var test = function (v){return v;}
                    if(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(cur_el.value)){
                        if(reg){
                        	ajaxDataScript("/ajaxCheckEmail.html", {email:cur_el.value}, "checkIsEmail(req.responseData, req.responseText,'"+cur_el.id+"');");
                        }
						if (!/.*?earthlink.net$/.test(cur_el.value))
						{
							
                        }else {
							//hash[i].error = "To receive your password add support@fizber.com to your address book.";
							//cur_el.value = '';
						}
                    }else{
                        hash[i].error = "Please enter a valid email address.";
                    }
                }else if(hash[i].type[j] == "float" && cur_el.value!=""){
                    
                    var test = function (v){return v;}
                    if(/^\d{1,}\.{0,1}\d{0,}$/.test(cur_el.value)){
            
                    }else{
                        hash[i].error = "Please enter a valid float number in this field.";
                    }
                }else if(hash[i].type[j] == "date" && cur_el.value!=""){
                   	var c_err = false;
                    var test = function (v){return v;}
                    if(/^\d{4}-\d{2}-\d{2}$/.test(cur_el.value)){
            			var vl = cur_el.value.split("-");
            			if(parseInt(vl[0])<1900 || parseInt(vl[1])>12 || parseInt(vl[2])>31 ){
            				c_err = true;
            			}
                    }else{
                        c_err = true;
                    }
                    if(c_err){
                    	hash[i].error = "Please enter a valid date in this field.";
                    }

                }else if(hash[i].type[j] == "address" && cur_el.value!=""){
					var vl  = cur_el.value;
					vl = vl.toLowerCase() 
                    if(vl.indexOf("call for") != -1 || (vl.indexOf("call") != -1 && (vl.indexOf("address") != -1 || vl.indexOf("realtor") != -1 || vl.indexOf("owner") != -1))){
                        hash[i].error = "Please enter a valid address in this field.";
                    }
                }else if(hash[i].type[j] == "words" && cur_el.value!=""){
                    var test = function (v){return v;}
                    if(/^[^\d]{1,}$/.test(cur_el.value)){
                        
                    }else{
                        hash[i].error = "Please enter a valid value in this field.";
                    }
                }else if(hash[i].type[j] == "req" ){
                    if(cur_el.value == ""){
                        hash[i].error = "This is a required field.";
                    }
                }else if(hash[i].type[j] == "req_select"){
                    if(cur_el.options[cur_el.selectedIndex].value == ""){
                        hash[i].error = "This is a required field.";
                    }
                }			
            }
        
             parent = cur_el.parentNode;
             if(parent.childNodes[0]){
                l = parent.childNodes.length;
                for(j=0;j<l;j++){
                    if(parent.childNodes[j]){
                        str = parent.childNodes[j].id + '';
                        if(str.indexOf("err_message") != -1){
                            parent.removeChild(parent.childNodes[j]);
                        }
                    }
                }
             }
            if(hash[i].error!= "" ){
                 
                 z = document.createTextNode(hash[i].error);
                 z1 = document.createElement("DIV") ;
				 //z1.style.fontSize="85%";
                 t_id = "err_message" + Math.round(Math.random() * 200);
                 z1.setAttribute("id", t_id);
                 z1.id = t_id;
                 z1.appendChild(z);
                 if(parent.childNodes[0]){
                     parent.insertBefore(z1,cur_el);				 
                 }else{
                     parent.appendChild(z1);				
                 }
                 fade(cur_el.id, 'fadeRule2');
                 fade(t_id, 'fadeRule3');
                 
                pr_err = 1;
            }else{
                cur_el.style.borderColor = "#00B200";
            }
        }
    }
    if (pr_err || isEmail){  
        if(!element){
            alert('Please check form for errors');
        }
        return false;
    }else{
        return true;
    }
}

//-----------------------------------------------------
function changeMainPhoto(src){

    document.getElementById('main_photo_').src = src;
}
//----------------------------------------------------

function showAppForms(type, pricexx, typexx){
    var free = document.getElementById('free_app_form');
    if(free){
        free.style.display = 'none';
    }
    
    var buy = document.getElementById('money_app_form');
    buy.style.display = 'none';
    
    var price = document.getElementById('price_it');
    
    if(type == "free"){
        free.style.display = 'block';
    }
    if(type == "buy"){
    
        removeChildNodes(price);
        buy.style.display = 'block';
        price.innerHTML = pricexx;
        document.getElementById('buy_type').value = typexx;
    }
    
}

//==================================================================================
function showbuttons() {   

    var agt       = navigator.userAgent.toLowerCase();
    var IEMAC     = ((agt.indexOf("msie") != -1) && agt.indexOf("mac")!=-1);
    var N6        = (agt.indexOf("netscape6") != -1 || (agt.indexOf("netscape/6") !=-1 ));
    if ( N6 ) {
      return "Netscape 6 is unable to support our detailed reports.  Please upgrade to Nescape 7.<P>";
    }
    if ( IEMAC ) {
      return "<P>";
    }
    return "<P><FORM><INPUT TYPE='button' value='Calculate' Name='btnCallCalc' onClick='document.calculator.calculate()'><INPUT TYPE='button' value='View Report' Name='btnOpenNote' onClick='openNote()'></FORM>";
}

function openNote()
 { 
 
 var agt=navigator.userAgent.toLowerCase(); 
 var is_aol   = (agt.indexOf("aol") != -1);

 leftpos=0;
 if (screen) {
   leftpos=screen.width/2 - 300;
 } 

 if (is_aol) {
   var s = " ";
   s=document.calculator.sJavaScriptReport('HTML');
    document.write(s);
 }
 else {
   var OpenWindow=window.open("","newwin","toolbar=yes,menubar=yes,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=380,left="+leftpos+",top=20");
   var s = " ";
   s=document.calculator.sJavaScriptReport('HTML');
   OpenWindow.document.write(s);
   OpenWindow.document.close(); 
   OpenWindow.focus();
 }
 }
 
 //---------------------------------------------------------------
 function showGlossary(id){
    var loader_id = show_loader_indicator("ld", "");
    ajaxData("/glossary_get_description_" + id + ".html",{id: id},"document.getElementById('" + loader_id + "').style.display='none';showGlossaryDiv("+ id +",req.responseJS,req.responseText);");
}

var last_glossary_open_element = false;
function showGlossaryDiv(id, hash, text){
    
    if(last_glossary_open_element){
        last_glossary_open_element.parentNode.removeChild(last_glossary_open_element);	
    }
    
    var dv = document.createElement("DIV");
    var st = document.createElement("STRONG");
    var br = document.createElement("BR");
    var text = document.createTextNode(hash.text);
    var title = document.createTextNode(hash.title);
    var obj = document.getElementById('gloss_link_' + id);
    st.appendChild(title);
    dv.appendChild(st);
    dv.appendChild(br);
    dv.appendChild(text);
    
    copyTemplate(dv, document.getElementById('close_tpl'));
    
    dv.className="clear";
    dv.style.borderWidth = "1px";
    dv.style.borderStyle = "solid";
    dv.style.padding = "10px 5px 20px 10px";
    dv.style.margin = "10px";
    obj.parentNode.parentNode.insertBefore(dv,obj.parentNode);
    last_glossary_open_element = dv;
}
function closeLastGlossary(){
    if(last_glossary_open_element){
        last_glossary_open_element.parentNode.removeChild(last_glossary_open_element);	
    }
    last_glossary_open_element = false;
}
//-----------------------------------------------------------------------------




//----------------------------------------------------------------------------
// by Marat Novitsky <marat.novitsky@gmail.com>
// dhtml features to get suggestion data
function applySuggestion(div_id,data_to_send,data_to_fill){
    //var loader_id = show_loader_indicator(div_id, "");
    var target = "/ajax-suggestion-zip.html";
    var data = {zip: data_to_send};	
//	ajaxData(target,data,"document.getElementById('" + loader_id + "').style.display='none';applyFill(req.responseJS,req.responseText,{state:'"+data_to_fill['state']+"',city:'"+data_to_fill['city']+"'})");
    ajaxData(target,data,"applyFill(req.responseJS,req.responseText,{state:'"+data_to_fill['state']+"',city:'"+data_to_fill['city']+"'})");
}

function applyFill (data,text,dataToFill){
    //alert(data[0].city)
    if(text == 'error') return false;
    if(dataToFill['state']!="" && (data[0]['state'] || data[0]['zone_id'])){
        if(document.getElementById(dataToFill['state'])!='undefined'){
            var filled = 0;
            var obj = document.getElementById(dataToFill['state']);
            obj.style.display = 'block';
            for (i=0;i<obj.options.length;i++){
                if(obj.options[i].value == data[0]['state']){			
                    obj.options[i].selected = 'true';
                    filled = 1;
                }
            }
            if (filled!=1){
                for (i=0;i<obj.options.length;i++){
                    if(obj.options[i].value == data[0]['zone_id']){			
                        obj.options[i].selected = 'true';
                        filled = 1;
                    }
                }
            }
        }
    }
    
    if(dataToFill['city']!="" && data[0]['city']){
        if(document.getElementById(dataToFill['city'])){
            var obj = document.getElementById(dataToFill['city']);
            obj.style.display = 'block';
            obj.value = data[0]['city'];
        }
    }
}

//----------------------------------------------------------------------------
// by Marat Novitsky <marat.novitsky@gmail.com>
// dhtml features to get suggestion data
function showSuggestion(div_id,input_id,type,data_to_send,data_to_fill){	
    if(type == 'zip'){
        var target = "/ajax-suggestion-zip.html";
        var data = {zip: data_to_send};
    }
    else {
        var target = "/ajax-suggestion-city.html";
        var data = {city: data_to_send};
        data_to_fill = {state:'',city:''};
    }
    //alert(div_id+' '+input_id+' '+type+' '+data_to_send);
    ajaxData(target,data,"buildSuggestionList('"+div_id+"','"+input_id+"',req.responseJS,req.responseText,{state:'"+data_to_fill['state']+"',city:'"+data_to_fill['city']+"'})");
}

//----------------------------------------------------------------------------
// by Marat Novitsky <marat.novitsky@gmail.com>
// dhtml features to show suggestion area
function buildSuggestionList(div_id,input_id,hash,mess,data_to_fill){
    var t_div = document.getElementById(div_id);	
    if(mess=='error' || hash == 'error') {
        t_div.innerHTML = '';
        t_div.style.display = 'none';
        return false;
    }	
    var out = '';
    //alert(hash.length );
    for (i=0; i<hash.length;i++) {
        //if(hash[i]['zip']!='undefined'){
            out += '<a href="#" id="'+(hash[i]['zip'] || hash[i]['city'])+'" title="'+(hash[i]['zip'] || hash[i]['city'])+'" onclick="fill_in(this.id,\''+input_id+'\',\''+div_id+'\',{state:\''+hash[i]['zone_id']+'\',nstate:\''+hash[i]['state']+'\',city:\''+hash[i]['city']+'\'},{state:\''+data_to_fill['state']+'\',city:\''+data_to_fill['city']+'\'}); return false">'+(hash[i]['zip'] || hash[i]['city'])+'</a><br>';
        //}
        
    }
    if(out!=''){		
        t_div.innerHTML = out;
        t_div.style.display = 'block';
        //alert(t_div.style.display);
    }
}

//----------------------------------------------------------------------------
// by Marat Novitsky <marat.novitsky@gmail.com>
// src_id - copy from
// tar_id - paste to
// div_id - suggestion layer (must be hide after select)
// data - additional data like state, city, etc...
function fill_in (src_id,tar_id,div_id,data,data_to_fill){
    if(src_id && tar_id){
        var s = document.getElementById(src_id);
        var t = document.getElementById(tar_id);
        t.value = s.title;
        t.focus();
        if (t.createTextRange)
          {
           var r = t.createTextRange();
           r.collapse(false);
           r.select();
          }
        document.getElementById(div_id).style.display = 'none';		
//		if(document.getElementById('state' || 'zone' || 'zoneID')!='undefined'){
        if(data_to_fill['state']!=""){
            if(document.getElementById(data_to_fill['state'])!='undefined'){
                var filled = 0;
                var obj = document.getElementById(data_to_fill['state']);
                for (i=0;i<obj.options.length;i++){
                    if(obj.options[i].value == data['state']){			
                        obj.options[i].selected = 'true';
                        filled = 1;
                    }
                }
                if (filled!=1){
                    for (i=0;i<obj.options.length;i++){
                        if(obj.options[i].value == data['nstate']){			
                            obj.options[i].selected = 'true';
                            filled = 1;
                        }
                    }
                }
            }
        }
        if(data_to_fill['city']!=""){
            if(document.getElementById(data_to_fill['city'])){
                var obj = document.getElementById(data_to_fill['city']);
                obj.value = data['city'];
            }
        }
        
    }
    return false;
}

function hideSug(id){
    var obj = document.getElementById(id);
    
    if(obj!='undefined'){
        obj.style.display='none';
    }
}

function phideSug(id){
    
    if(document.getElementById(id).style.display=='block'){
        setTimeout('hideSug("'+id+'")',1000);
    }
}

function addCurrentComment(hash){
    if(hash['author'] && hash['message'] && hash['added']){
        obj = document.getElementById("comments_content");
        liObj = document.createElement("li");
        message = '<strong>'+hash['author']+'</strong><br /><em>'+hash['added']+'</em><br />'+hash['message'];
        liObj.innerHTML = message;
        obj.appendChild(liObj);
    }
    
}

//----------------------------------------------------------------------------
// by Marat Novitsky <marat.novitsky@gmail.com>
// src_id - copy from
// tar_id - paste to
// div_id - suggestion layer (must be hide after select)
// data - additional data like state, city, etc...
function getTruliaSales(c,s){
    if (c || s){
        document.getElementById("trulia_sales").style.display='block';
        var data = {city:c,state:s};
        var target = "/ajax-trulia.html";
        ajaxData(target,data,'displayTruliaSales(req.responseJS,req.responseText)');
    }
    else {
        return false
    }
}

function getTruliaSalesScript(c,s){
    if (c || s){

        document.getElementById("trulia_sales").style.display='block';
        var data = {city:c,state:s};
        var target = "/ajax-trulia.html";
        ajaxDataScript(target,data,'displayTruliaSales(req.responseJS,req.responseText)');
    }
    else {
        return false
    }
}

//----------------------------------------------------------------------------
// by Marat Novitsky <marat.novitsky@gmail.com>
function formatCurrency(num) {
        num = num.toString().replace(/\$|\,/g,'');
        if(isNaN(num)) num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10) cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
            num = num.substring(0,num.length-(4*i+3))+','+
            num.substring(num.length-(4*i+3));
        return (((sign)?'':'-') + '$' + num + '.' + cents);
    }

function displayTruliaSales(data,text){
    if(text=='ok'){
        var obj = document.getElementById("trulia_small");
        var tr = document.getElementById("loader_trulia");
tr.style.display='none';
        var im = document.createElement("img");
im.src = data['pic'];
if (data['pic'].indexOf('nograph') > -1) {
	im.style.width = '395px !important';
}
//im.onclick =function(){ document.getElementById("trulia_big").style.display="block";}
//im.setAttribute('title','Click here to enlarge');
        obj.appendChild(im);
//var obj1 = document.getElementById("trulia_big");
//var im_big = document.createElement("img");
//im_big.src = '/static' + data['pic'];
//im_big.onclick =function(){ document.getElementById("trulia_big").style.display="none";}
//obj1.appendChild(im_big); 
//obj1.style.display = 'none';
    }
}

function sendFriend(){
    var frm = document.getElementById('frmEmailafriend');	
    ajaxData('/ajax-email-friend.html', {q : frm}, "document.getElementById('loader_emailafriend').style.display='none'; displaySendFriend(req.responseJS,req.responseText);");

}

function displaySendFriend(hash,txt){
    if(txt=='ok'){
        document.getElementById('emailfriendOk').style.display='block';
    }
    else {
        document.getElementById('emailafriend_frm').style.display='block';
    }
}

function sendReport(){
    var frm = document.getElementById('frmReportError');	
    ajaxData('/ajax-report-error.html', {q : frm}, "document.getElementById('loader_reporterror').style.display='none'; displaySendReport(req.responseJS,req.responseText);");
}

function displaySendReport(hash,txt){
    if(txt=='ok'){
        document.getElementById('reporterrorOk').style.display='block';
    }
    else {
        document.getElementById('reporterror_frm').style.display='block';
    }
}

function claimHouse(){
    var frm = document.getElementById('frmClaim');	
    ajaxData('/ajax-claim-house.html', {q : frm}, "document.getElementById('loader_claimhouse').style.display='none'; displayClaimHouse(req.responseJS,req.responseText);");
}

function displayClaimHouse(hash,txt){
    if(txt=='ok'){
        document.getElementById('claimhouseOk').style.display='block';
    }
    else {
        document.getElementById('claimhouse_frm').style.display='block';
    }
}

function add_rem_comparison(house_id){
    obj = document.getElementById('comp_ch' + house_id);
    im_obj = document.getElementById('im_comp_ch' + house_id);
    house_id = "-" + house_id + "-"
    m = GetCookieValueByName('compare');
    if(m){
        if(m.indexOf(house_id)!= -1){
            m = m.replace(house_id, "");
            if(obj){
                obj.checked = false;
            }
        }else{
            if(obj){
                obj.checked = true;
            }
            m += house_id;
        }
    }else{
        m = house_id;
        if(obj){
            obj.checked = true;
        }
    }
    if (obj.checked==true){
        im_obj.src = "http://static.fizber.com/images/checkcompare.gif";
    }
    else {
        im_obj.src = "http://static.fizber.com/images/checkcomparenone.gif";
    }
    SetCookie('compare', m,'/','/');
    checkComparison();
    
}

function checkComparison(){
    if(!document.getElementById('compare_link_top')){
        return;
}
    m = GetCookieValueByName('compare');
    if(m){
        var count = m.split("--");
        count = count.length;
        document.getElementById('compare_link_top').style.display = "block";
        document.getElementById('compare_link_bottom').style.display = "block";
        document.getElementById('compare_link_bottom2').style.display = "block";
        document.getElementById('compare_link_top').innerHTML = "Compare " + count + " selected houses";
        document.getElementById('compare_link_top2').innerHTML = "Compare " + count + " selected houses";
        document.getElementById('compare_link_bottom').innerHTML = "Compare " + count + " selected houses";
    }else{
        document.getElementById('compare_link_top').style.display = "none";
        document.getElementById('compare_link_bottom').style.display = "none";
        document.getElementById('compare_link_bottom2').style.display = "none";
    }
}


var currentStep = 4;
function processSteps(step){	

    document.getElementById('loader_image').style.display='block';

    var frm = document.getElementById("form_step_" + step);
    var link = "https://www.fizber.com/home-for-sale/sell-home-step" + step +"_alt.html";
    ajaxData(link, {q : frm}, "document.getElementById('loader_image').style.display='none'; responseStepAnalyzer(req.responseJS,req.responseText);");	

    return false;
}

function responseStepAnalyzer(hash, text){
    if(text == "err"){
        var div  = document.getElementById('step_div_' + currentStep);
        var pr_parse_t_errors = 0;
        var hash_errors = new Array
        var ids_errors=""
        var c = hash.errors.length;
        for (var i = 0;i<c;i++){
            hash_errors[i] = hash.errors[i].value;
            ids_errors+="#"+hash.errors[i].key+"#"+i+"||";
            pr_parse_t_errors = 1;
        }
        if (pr_parse_t_errors){
            parseTemplateErrors(div, hash_errors, ids_errors);
        }
        alert('Check form for errors');
    }else{
        if(hash.contacts){
        
            var sel_obj = document.getElementById('sel_contact_true');
            var i;
            var opt_count  = sel_obj.options.length;
            for(i=0;i<c;i++){
                sel_obj.options[0] = null;
            }
            
            var c = hash.contacts.length;
            for (i=0;i<c;i++){
                if(hash.s_contact + " " == hash.contacts[i].id + " "){
                    sel_obj.options[i] = new Option (hash.contacts[i].name, hash.contacts[i].id, true, true);
                }else{
                    sel_obj.options[i] = new Option (hash.contacts[i].name, hash.contacts[i].id);
                }
            }
            if(document.getElementById('pr_use_contact').value=='new'){
                showHideObj('use_account_info');
                showHideObj('add_new_account');
                document.getElementById('pr_use_contact').value='ex';
            }
        }
        
        if(hash.next_step > maxstep){
            maxstep = hash.next_step;
        }
        showHideSteps(hash.next_step);
    }
}

function showHideSteps(next){
    if(next > maxstep){
        alert('Please complite all previous steps')
        return false;
    }
    
    document.getElementById('step_div_' + currentStep).style.display = "none";
    var cl = currentStep - 3;
    document.getElementById('st' + cl).className = "compl";
    
    currentStep = next
    document.getElementById('step_div_' + currentStep).style.display = "block";
    cl = currentStep - 3;
    document.getElementById('st' + cl).className = "current";
    if(next == 6){
        doShow()
    }
}

function userAjaxLogin(){
    document.getElementById('loader_image').style.display='block';
    var email = document.getElementById('log_email').value;
    var password = document.getElementById('log_password').value;
    ajaxData("https://www.fizber.com/user_ajax_login.html",
    {email: email, password: password},
    "document.getElementById('loader_image').style.display='none';step3Login(req.responseJS, req.responseText, '" + email + "');");
}

function index_advanced_search(e){
    
    i = document.getElementById('house_id'); 
    if (i){
       if (i.value != ''){
                window.location.href = "/" + i.value;
                if (undefined == e)
                   { 
                    e = window.event
                   }
                if (e.stopPropagation)
                   {
                    e.stopPropagation();
                   }
               else
                   {
                    e.cancelBubble = true;
                    }

            return false;
       }
    }
}




//----------------------------photos

var step7CurrentPhoto = 0;
var step7GlobalCounter = 0;
function step7CopyToOl(id){
    
    if(maxCountPhotos < step7CurrentPhoto + 1){
        alert('Upload not available');
        return;
    }	
    
    var fl_obj = document.getElementById(id);
    var ph_tpl = document.getElementById('photo_tpl');
    var fl_tpl = document.getElementById('file_tpl');	
    var ol_area = document.getElementById('ol_area');
    var temp_area = document.getElementById('temp_area');

    if(maxCountPhotos == step7CurrentPhoto + 1){
        fl_tpl.style.display = "none";
    }else{
        fl_tpl.style.display = "block";
    }
    
    copyTemplate(temp_area, ph_tpl);
    temp_area.childNodes[0].childNodes[0].innerHTML = fl_obj.value;
    temp_area.childNodes[0].id = "ph_li_" + step7GlobalCounter;
    fl_obj.style.display = "none";
    
    temp_area.childNodes[0].childNodes[5].name = "descr_" + step7GlobalCounter;
    temp_area.childNodes[0].childNodes[5].id = "descr_" + step7GlobalCounter;
    var del_a = temp_area.childNodes[0].childNodes[2];
    del_a.id = "del" + step7GlobalCounter;
    
    var el = document.createElement('input');
    el.type = 'file';
    el.name = 'photo';
    rnd = Math.round(Math.random() * 1000);
    el.id = 'photo_xx' + rnd;
    eval("el.onchange = function (){step7CopyToOl('" + el.id + "');}");
    
    copyTemplate(ol_area, temp_area);
    removeChildNodes(temp_area);
    
    
    removeChildNodes(document.getElementById('tmp_frm_area'));
    copyTemplate( document.getElementById('tmp_frm_area'), document.getElementById('frm_tpl_x'));
    var frm  = document.getElementById('tmp_frm_area').childNodes[0];
    //var frm = document.createElement('FORM');
    
    frm.action = "/";
    frm.setAttribute('enctype', "multipart/form-data");
    frm.enctype = "multipart/form-data";
    frm.method = "post";
    var zz = step7GlobalCounter + 1;
    frm.id = "photo_frm" + zz;
    frm.appendChild(el);
    
    var house_id = document.getElementById('house_id');
    var id = "-1";
    if (house_id) {
           id = house_id.value;	
    }
    el = document.createElement('input');
    el.type = 'hidden';
    el.name = 'house_id';
    el.value = id;
    frm.appendChild(el);
    
    fl_tpl.appendChild(frm);
    step7CurrentPhoto++;
    step7GlobalCounter++;
	uploaded_photos = uploaded_photos + 1;
	viewOnePhotoMes();
}

function viewOnePhotoMes(){
	try{
	if (uploaded_photos==1){
		document.getElementById("default_mes_photo").style.display = "none";
		document.getElementById("one_mes_photo").style.display = "block";

	} else{
		document.getElementById("default_mes_photo").style.display = "block";
		document.getElementById("one_mes_photo").style.display = "none";
		
	}
	}catch(e){}
	
}
     

function delNUplPhoto(obj){
    var id = obj.id;
    id = id.replace('del',"");
    maxCountPhotos++;
    document.getElementById('file_tpl').style.display='block';
    document.getElementById('file_tpl').removeChild(document.getElementById('photo_frm'+ id));
	uploaded_photos = uploaded_photos - 1;
	viewOnePhotoMes();	
}

function step7DelPhoto(id){
    document.getElementById('liph' + id).style.display = "none";
    document.getElementById('del_photo_' + id).checked = true;
    maxCountPhotos++;
    document.getElementById('global_upload_field').style.display = "block";
    document.getElementById('file_tpl').style.display = "block";
	
}

var photos_all;
function sendPhotos(counter){
    counter -= 1;
    if (counter<0){
		if(need_submit==1){
			need_submit=0;
			if(editHomeVal())document.getElementById('mainform').submit();
		}
		if(need_submit==2){
			need_submit=0;
			editHomeVal = function(){return true;}; 
			document.getElementById('mainform').submit();
		}
        return;
    }

    var dForm = document.getElementById('photo_frm' + (photos_all - counter));

    if(dForm){
        var li = document.getElementById('ph_li_'+ (photos_all - counter));
        var el = document.createTextNode(' Photo upload in progress');
        li.appendChild(el);
        el = document.createElement('span');
        el.id = "span_ph" + (photos_all - counter);
        li.appendChild(el);
        
        var dscr = document.getElementById('descr_'+ (photos_all - counter)).value;
        if(dscr != "Enter Description Here"){
            var el1 = document.createElement('input');
            el1.type = 'hidden';
            el1.name = 'photo_desc';
            el1.value = dscr;
            dForm.appendChild(el1);
        }

        setTimeout("placeProgressBar('" + el.id + "')",300);

        var str="";
        str += "addPicteFormFunc('',req.responseJS,req.responseText);";
        str += "document.getElementById('ol_area').removeChild(document.getElementById('ph_li_" + (photos_all - counter) + "'));";
        str += "sendPhotos(" + counter + ");";
        str += "document.getElementById('file_tpl').removeChild(document.getElementById('photo_frm" + (photos_all - counter) + "'));";
        
        ajaxData("/add_pic.html",{form : dForm, house_id: document.getElementById('house_id').value},str);
     }else{
        setTimeout("sendPhotos(" + counter + ")", 100)
     }
}

function placeProgressBar(id){

    var obj = document.getElementById(id);
    if(obj){
        var c = obj.innerHTML.length;
        if(c<10){
            obj.innerHTML +=".";
        }else{
            obj.innerHTML = "";
        }
        setTimeout("placeProgressBar('" + id + "')",300);
    }
}


function addPicteFormFunc(data,hash,text){
    if (text == "error"){
       if(hash.alert){
            alert(hash.alert);
            return ;
        }
    }

    if(maxCountPhotos < step7CurrentPhoto + 1){
		ajaxData("/delete_pic.html",{id: hash.photo_id, house_id: document.getElementById('house_id').value},"");
		alert('Upload not available');
		return;
    }	

    var pDiv  = document.getElementById('in_pic2');
    
    //main div
    var new_ph_div = document.createElement('DIV');
    new_ph_div.id = "photo_dv" + hash.photo_id;
    new_ph_div.className = "photodiv brd";
    
    //div with counter
    var counter_dv = document.createElement('DIV');
    counter_dv.className = "photocount";
    var obj_len = pDiv.childNodes.length + 1;
    counter_dv.appendChild(document.createTextNode('Photo #' + obj_len));
    
    
    //image div
    var image_dv = document.createElement('DIV');
    image_dv.className = "photoimg";
    var image = document.createElement('IMG');
    image.src = hash.photo + "?dt=" + new Date().getTime();
    image.id = "photo_id_" + hash.photo_id;
    eval("image.onclick = function(){ main_photonew(" + hash.photo_id + "); }");
    image_dv.appendChild(image);
    
    //description
    var desrc_dv = document.createElement('DIV');
    desrc_dv.className = "photodesc";
    var descr_input = document.createElement('INPUT');
    descr_input.type = "text";
    descr_input.id = "photo_desc_" + hash.photo_id;
    descr_input.name = "photo_desc_" + hash.photo_id;
    if(hash.photo_desc!=''){
        descr_input.value = hash.photo_desc;
    }
    descr_input.size = "13";
    descr_input.className = "fld";
    desrc_dv.appendChild(descr_input);
    
    //buttons
    var buttons_dv = document.createElement('DIV');
    buttons_dv.className = "photobuttons";
        
    //left
    var link = document.createElement('A');
    link.href = "#";
    link.id = "mvl" + hash.photo_id;
    eval("link.onclick = function(){ movePhoto(this, 'left');return false; }");
    copyTemplate(link, document.getElementById('dv_btn_left'));
    buttons_dv.appendChild(link);
    
    //save
    link = document.createElement('A');
    link.href= "#";
    eval("link.onclick = function(){ savePhotoDescr(" + hash.photo_id + ");return false; }");
    copyTemplate(link, document.getElementById('dv_btn_save'));
    buttons_dv.appendChild(link);
    
    //sepr
    var span = document.createElement('SPAN');
    span.style.color = "#FFFFFF";
    span.appendChild(document.createTextNode(' | '));
    buttons_dv.appendChild(span);
    
    //delete
    link = document.createElement('A');
    link.href= "#";
    eval("link.onclick = function(){ if(confirm('Do you really want to delete this photo ?')){deletePicNew(" + hash.photo_id + ");}return false; }");
    copyTemplate(link, document.getElementById('dv_btn_delete'));
    buttons_dv.appendChild(link);
    
    //right
    var link = document.createElement('A');
    link.href = "#";
    link.id = "mvl" + hash.photo_id;
    eval("link.onclick = function(){ movePhoto(this, 'right');return false; }");
    copyTemplate(link, document.getElementById('dv_btn_right'));
    buttons_dv.appendChild(link);
        

    new_ph_div.appendChild(counter_dv);
    new_ph_div.appendChild(image_dv);
    new_ph_div.appendChild(desrc_dv);
    new_ph_div.appendChild(buttons_dv);
    
    
    pDiv.appendChild(new_ph_div);
    
    step7CurrentPhoto++;
    uploaded_photos = uploaded_photos + 1;
    viewOnePhotoMes();

    if (hash.main_ph){
		document.getElementById('mainphex').style.display = 'block';
		document.getElementById('mainphnoex').style.display = 'none';
        main_photonew(hash.photo_id);   
    }
    
    if(maxCountPhotos == step7CurrentPhoto){
        document.getElementById('file_upl_area').style.display = "none";
    }else{
        document.getElementById('file_upl_area').style.display = "block";
    }

}


function savePhotoDescr(id){
    descr =	document.getElementById('photo_desc_' + id).value;
    ajaxData("/save_desrc.html",{id:id, descr: descr, house_id: document.getElementById('house_id').value},"savePhotoDescr2(req.responseJS,req.responseText, 'dv_btn_ok')");
}

function savePhotoDescr2(hash,text, pr_change){
      var dv = document.getElementById('photo_dv' + hash.id);
      var c = dv.childNodes.length;
      for(var i=0;i<c;i++){
        try{
            if(dv.childNodes[i].className == "photobuttons"){
                var c1 = dv.childNodes[i].childNodes.length;
                var cnt = 0;
                for(var i1=0;i1<c1;i1++){
                    try{
                        if(dv.childNodes[i].childNodes[i1].tagName.toLowerCase() == "a"){
                            cnt ++;
                        }
                    }
                    catch(e){}
                    if(cnt==2){
                        removeChildNodes(dv.childNodes[i].childNodes[i1]);
                        copyTemplate(dv.childNodes[i].childNodes[i1], document.getElementById(pr_change));
                        if(pr_change!="dv_btn_save"){
                            setTimeout("savePhotoDescr2({'id':'" + hash.id + "'},'', 'dv_btn_save')", 1500);
                        }
                        break;
                    }
                }	  			
                break;
            }
        }
        catch(e){}
      }
}



function deletePicNew(id){
    ajaxData("/delete_pic.html",{id:id, house_id: document.getElementById('house_id').value},"deletepicteFormNew('"+id+"',req.responseJS,req.responseText)");
}

function deletepicteFormNew(id,hash,text){
    if (text=="error"){
        if(hash.alert){
            alert(hash.alert);
        }
    }
    maxCountPhotos++;
    document.getElementById('file_tpl').style.display = "block";
	try{
		var del_url_photo = document.getElementById('photo_id_' + id).src;
    }
    catch(e){ 
     }
	var pDiv  = document.getElementById('in_pic2');
    pDiv.removeChild(document.getElementById('photo_dv' + id));
    var c = pDiv.childNodes.length;
    for(var i=1; i<=c;i++){
        pDiv.childNodes[i-1].childNodes[0].innerHTML = "Photo #" + i;
    }
	uploaded_photos=uploaded_photos-1;
    viewOnePhotoMes();
    document.getElementById('file_upl_area').style.display = "block";
	if(uploaded_photos==0){
		document.getElementById("img_main_photo").src ="http://static.fizber.com/nophoto/nophoto1.jpg";
	}
	
	 try{
    
		 var main_url_photo =  document.getElementById('img_main_photo').src; 
		 
		 var is_main = new RegExp("(.*?)\\d+x\\d+___tmb\.");
		 if (main_url_photo.match(is_main)[1]==del_url_photo.match(is_main)[1]){
			default_mainphoto();
		 };
     } catch(e){ 
     }
     
}

function default_mainphoto(){
	try{
     photo_id = $("div.photoimg > img").get(0).id.replace("photo_id_","");
	 main_photonew(photo_id);
	} catch(e){
	 document.getElementById("img_main_photo").src ="http://static.fizber.com/nophoto/nophoto1.jpg";
	}
};

function main_photonew(photo_id){
   ajaxData("/setup_main_photo.html",{id:photo_id, house_id: document.getElementById('house_id').value},"setupMainPhoto(req.responseJS,req.responseText)");
}
function setupMainPhoto(hash, text){
   var div_main_photo  = document.getElementById('main_photo');   
   div_main_photo.style.display = "block";
   document.getElementById("img_main_photo").src = hash.src + "?dt=" + new Date().getTime();
}


function movePhoto(photo_id, pr_move){
    photo_id = photo_id.id;
    photo_id = photo_id.replace("mvl", "");
    var main_div = document.getElementById('in_pic2');
    var c = main_div.childNodes.length;
    for(var i=0;i<c;i++){
        if(main_div.childNodes[i].id == 'photo_dv' + photo_id){
            var cur_child_num = i;
            break;
        }
    }
    
    if(pr_move == "left"){
        try{
            var id = main_div.childNodes[cur_child_num -1].id;
            var id2 = 'photo_dv' + photo_id;
            main_div.insertBefore(document.createElement('div'),main_div.childNodes[cur_child_num -1]);
            main_div.insertBefore(document.createElement('div'),main_div.childNodes[cur_child_num -1]);
            main_div.replaceChild(main_div.childNodes[cur_child_num +1],main_div.childNodes[cur_child_num]);
            main_div.replaceChild(main_div.childNodes[cur_child_num +1],main_div.childNodes[cur_child_num -1]);
            $.ajax({url:"/change_photos_order.html",
			       type:"GET",
				   data:{id: id.replace("photo_dv", ""), id2: id2.replace("photo_dv", ""), house_id: document.getElementById('house_id').value},
				   success: function(data, textStatus) {
				   	// do something
					}}
			);
        }
        catch(e){
        }
    }
    if(pr_move == "right"){
        try{
            var id = main_div.childNodes[cur_child_num +1].id;
            var id2 = 'photo_dv' + photo_id;
            main_div.insertBefore(document.createElement('div'),main_div.childNodes[cur_child_num ]);
            main_div.insertBefore(document.createElement('div'),main_div.childNodes[cur_child_num ]);
            main_div.replaceChild(main_div.childNodes[cur_child_num +2],main_div.childNodes[cur_child_num +1]);
            main_div.replaceChild(main_div.childNodes[cur_child_num +2],main_div.childNodes[cur_child_num ]);
            $.ajax({url:"/change_photos_order.html",
			       type:"GET",
				   data:{id: id.replace("photo_dv", ""), id2: id2.replace("photo_dv", ""), house_id: document.getElementById('house_id').value},
				   success: function(data, textStatus) {
				   	// do something
					}}
			 );		
        }
        catch(e){
        }
    }
    var c = main_div.childNodes.length;
    for(var i=1; i<=c;i++){
        main_div.childNodes[i-1].childNodes[0].innerHTML = "Photo #" + i;
    }
    return false;
}

function editHomeVal(){
    if(document.getElementById('pr_use_contact').value=='new'){
        return checkFormForErrors( edit_house_data , false)&& checkFormForErrors( cp_el , false);
    }else{
        return checkFormForErrors( edit_house_data, false);
    }
}
function selectFile(obj, type){

    if(!checkFileType(obj.value, type)){
        deleteFileElement(type);
        return;
    }
    obj.style.display = "none";
    var dv = document.getElementById('file_' + type);
    var txt = document.createTextNode(obj.value + " - ");
    var link = document.createElement('A');
    link.href="#";
    eval("link.onclick = function(){deleteFileElement('" + type + "');return false;}");
    link.appendChild(document.createTextNode('delete'));
    dv.appendChild(txt);
    dv.appendChild(link);
}
function deleteFileElement(type){
    var dv = document.getElementById('file_' + type);
    removeChildNodes(dv);
    var inpt = document.createElement('INPUT');
    inpt.type = "file";
    inpt.name = type + "_tour_source";
    eval("inpt.onchange = function(){selectFile(this,'" + type + "');return false;}");
    dv.appendChild(inpt);
}
function checkFileType(value, type){
    value = value.toLowerCase();
    value = value.split(".");
    value = value[value.length - 1];
    if(type=="audio"){
        var allow = {'mp3': 1, 'wma': 1 };
        var txt = "Error! We accept *.mp3, *.wma only.";
    }
    if(type=="video"){
        var allow = {'avi': 1, 'mpg': 1, 'wmv': 1, 'mov': 1 };
        var txt = "Error! We accept *.avi, *.mpg, *.wmv, *.mov only.";
    }
    if(!allow[value]){
        alert(txt);
        return false;
    }
    
    return true;
}

function ajaxStep1Login(){
    var url ="/user_ajax_login.html";	
    var email = document.getElementById('log_email').value;
    var password = document.getElementById('log_password').value;
    ajaxData(url, {email: email, password: password},"setBlock('login_form','logged_user_template',req.responseJS,req.responseText)");
}

function getWeather(srch,zip,city){
if (weather == 1){
return true;
}
document.getElementById('loader_weather').style.display = 'block';
ajaxData('/ajax-weather.html', {srch:srch, czip : zip, city:city}, "document.getElementById('loader_weather').style.display='none';displayWeather(req.responseJS,req.responseText);");
}
var weather = 0;
function displayWeather(data,text){
var r_div = document.getElementById("w_pic");
var l_div = document.getElementById("w_tbl");
if(text == 'error'){
l_div.style.width = '100%';
l_div.style.textAlign = 'center';
l_div.innerHTML = 'Sorry :(';
return false;
}
weather = 1;
if (data.map){
var div_map = document.createElement('DIV');
var im_map = document.createElement('IMG');
im_map.src = data.map;
//im_map.width = '380';
div_map.appendChild(im_map);
r_div.appendChild(div_map);
}
if (data.title){
var tt_div = document.createElement('DIV');
tt_div.style.textAlign = 'left';
tt_div.innerHTML = data.title;
l_div.appendChild(tt_div);
var br = document.createElement('BR');
l_div.appendChild(br);
}
if (data.weather){
var we_div = document.createElement('DIV');
we_div.id = 'we';
we_div.innerHTML = data.weather;
l_div.appendChild(we_div);
var br = document.createElement('BR');
l_div.appendChild(br);
}
var tmpRow = null;
var tmpCell = null;
var tbl = document.createElement('TABLE');
tbl.style.width='100%';
if (data.pressure){
tmpRow =tbl.insertRow(-1);
tmpCell = tmpRow.insertCell(-1);
tmpCell.className = 'bold';
tmpCell.innerHTML = 'Pressure:';
tmpCell = tmpRow.insertCell(-1);
tmpCell.innerHTML = data.pressure;
}
if (data.humidity){
tmpRow =tbl.insertRow(-1);
tmpCell = tmpRow.insertCell(-1);
tmpCell.className = 'bold';
tmpCell.innerHTML = 'Humdity:';
tmpCell = tmpRow.insertCell(-1);
tmpCell.innerHTML = data.humidity;
}
if (data.visibility){
tmpRow =tbl.insertRow(-1);
tmpCell = tmpRow.insertCell(-1);
tmpCell.innerHTML = 'Visibility:';
tmpCell.className = 'bold';
tmpCell = tmpRow.insertCell(-1);
tmpCell.innerHTML = data.visibility;
}
if (data.wind){
tmpRow =tbl.insertRow(-1);
tmpCell = tmpRow.insertCell(-1);
tmpCell.innerHTML = 'Wind:';
tmpCell.className = 'bold';
tmpCell = tmpRow.insertCell(-1);
tmpCell.innerHTML = data.wind;
}
if (data.sunrise){
tmpRow =tbl.insertRow(-1);
tmpCell = tmpRow.insertCell(-1);
tmpCell.innerHTML = 'Sunrise:';
tmpCell.className = 'bold';
tmpCell = tmpRow.insertCell(-1);
tmpCell.innerHTML = data.sunrise;
}
if (data.sunset){
tmpRow =tbl.insertRow(-1);
tmpCell = tmpRow.insertCell(-1);
tmpCell.innerHTML = 'Sunset';
tmpCell.className = 'bold';
tmpCell = tmpRow.insertCell(-1);
tmpCell.innerHTML = data.sunset;
}
if (data.climate) {
cl = document.getElementById('climate');
cl.innerHTML = data.climate;
}
l_div.appendChild(tbl);

if (data.image){
var im = document.createElement('IMG');
im.src = data.image;
l_div.appendChild(im);
}
if (data.temperature){
var sp = document.createElement('SPAN');
sp.id = 'tmpr';
sp.innerHTML = data.temperature;
l_div.appendChild(sp);
}
if (data.low && data.high){
var r_dd = document.createElement('DIV');
r_dd.style.width = '100%';
r_dd.style.textAlign = 'left';
r_dd.innerHTML = 'Low: '+data.low+'&nbsp;&nbsp;'+'High:'+data.high;
l_div.appendChild(r_dd);
}

l_div.style.display = 'block';
r_div.style.display='block';
}