Event.observe(window, 'load', function() {
    if ($('warranty') != null) {
        ResetWarrantyForm();
        NewAddPrdTable();
    }
    if ($('warranty_renew') != null) {
        ResetWarrantyRenewForm();
        NewAddPrdTableRenew();
    }
});   


// for brand and category start
var brand_with_cate = [];
function change_brand(brand_field, cate_field) {
    var brand = $(brand_field);
    var cate = $(cate_field);
    
    var cate_opt = cate.options;
    var cate_opt_l = cate_opt.length;
	for(var i=cate_opt_l; i>1; i--) {
	    cate_opt[i - 1] = null;
	}	    
	
	if (brand.value != "" && brand.value != "0") {
	    var cate_obj = brand_with_cate["brand"+brand.value];
	    for(i = 0; i < cate_obj.length; i++) {
    	    cate_opt[cate_opt.length] = new Option(cate_obj[i].cate_name, cate_obj[i].cate_id);
    	}
    }
}
// for brand and category end


var warranty_obj = 
{
    'Lang' : "en",  
    'LabelEdit' : "Edit",  
    'LabelDelete' : "Delete", 
    'LabelUpdate' : "Update", 
    'LabelCancel' : "Cancel",
    'LabelPleaaeInputProduct' : "Pleaae Input Product",
    'LabelUpdateProductQuestion' : "Update Product?"
}

function delete_all_prd() {
    var all_prd = $('all_prd_id').value;
    var all_prd_arr = all_prd.split(",");

    for (var i=0; i<all_prd_arr.length-1; i++) {
        delete_prd_data_row(all_prd_arr[i]);
    }
    
    $('all_prd_id').value = "";
    $('prd_current_id').value = 0;
    $('current_prd_div').value = 0;
    $('prd_number').value = 0;
}

function delete_all_prd_renew() {
    var all_prd = $('all_prd_id').value;
    var all_prd_arr = all_prd.split(",");

    for (var i=0; i<all_prd_arr.length-1; i++) {
        delete_prd_data_row_renew(all_prd_arr[i]);
    }
    
    $('all_prd_id').value = "";
    $('prd_current_id').value = 0;
    $('current_prd_div').value = 0;
    $('prd_number').value = 0;
}

function delete_prd_data_row(id) {
    var row_id = "main_prd_display_table_new_row_" + id;
    var all_tr = $('main_prd_display_table').rows.length;
    var delete_idx = "";

    for (var i=0; i < all_tr; i++) {
        var temp_row_id = $('main_prd_display_table').rows[i].id;
        if (row_id == temp_row_id) {
            delete_idx = i;
            break;
        }
    }
	        
    if (delete_idx != "") {
        if ($("current_prd_div").value == id) {
            cancel_update_prd_data(id);
        }
        
        var data_action_type = $('prd_table_status_' + id).value;
        if (data_action_type == "insert") {
            $('prd_table_status_' + id).value = "cancel";
        } else if (data_action_type == "update") {
            $('prd_table_status_' + id).value = "delete";
        }
        
        $('main_prd_display_table').deleteRow(delete_idx);
        //$("update_table_data").removeChild($("update_table_data_" + id));
        //$('all_prd_id').value = $('all_prd_id').value.replace(id+',','');
        
        $('brand_id_'+id).removeAttribute("check");
        $('prd_id_'+id).removeAttribute("check");
        $('model_'+id).removeAttribute("check");
        $('verify_model_no_'+id).removeAttribute("check");
        $('sn_'+id).removeAttribute("check");
        $('warranty_num_'+id).removeAttribute("check");
        $('purchaseDate_'+id).removeAttribute("check");
        $('dealer_'+id).removeAttribute("check");
        $('invoice_num_'+id).removeAttribute("check");

        $('prd_number').value = $('main_prd_display_table').rows.length - 1;
    }
}

function delete_prd_data_row_renew(id) {
    var row_id = "main_prd_display_table_new_row_" + id;
    var all_tr = $('main_prd_display_table').rows.length;
    var delete_idx = "";

    for (var i=0; i < all_tr; i++) {
        var temp_row_id = $('main_prd_display_table').rows[i].id;
        if (row_id == temp_row_id) {
            delete_idx = i;
            break;
        }
    }
	        
    if (delete_idx != "") {
        if ($("current_prd_div").value == id) {
            cancel_update_prd_data(id);
        }
        
        var data_action_type = $('prd_table_status_' + id).value;
        if (data_action_type == "insert") {
            $('prd_table_status_' + id).value = "cancel";
        } else if (data_action_type == "update") {
            $('prd_table_status_' + id).value = "delete";
        }
        
        $('main_prd_display_table').deleteRow(delete_idx);
        //$("update_table_data").removeChild($("update_table_data_" + id));
        //$('all_prd_id').value = $('all_prd_id').value.replace(id+',','');
        
        $('brand_id_'+id).removeAttribute("check");
        $('prd_id_'+id).removeAttribute("check");
        $('model_'+id).removeAttribute("check");
        $('verify_model_no_'+id).removeAttribute("check");
        $('sn_'+id).removeAttribute("check");
        $('warranty_num_'+id).removeAttribute("check");
        $('warrantyDate_'+id).removeAttribute("check");

        $('prd_number').value = $('main_prd_display_table').rows.length - 1;
    }
}

function update_prd_data(id) {  

    if (validation_tag($("core_table_"+id))) {
        var data_action_type = $('prd_table_status_' + id).value;
        if (data_action_type == "insert" || data_action_type == "edit") {
            var prd_value = $("prd_id_"+id).value;
            var prd_index = $("prd_id_"+id).selectedIndex;
            var prd_text = $("prd_id_"+id)[prd_index].innerHTML;   
            $("span_prd_id_" + id).value = prd_value;
            $("span_prd_id_" + id).innerHTML = prd_text;
            $('span_model_' + id).value = $("model_" + id).value;
            $('span_model_' + id).innerHTML = $("model_" + id).value.toUpperCase();
            $("span_sn_" + id).value = $('sn_' + id).value;
            $("span_sn_" + id).innerHTML = $('sn_' + id).value.toUpperCase();
        
            $("hidden_brand_id_" + id).value = $('brand_id_' + id).value;
            $("hidden_prd_id_" + id).value = $('prd_id_' + id).value;
            $('hidden_model_' + id).value = $("model_" + id).value.toUpperCase();
            $("hidden_sn_" + id).value = $('sn_' + id).value.toUpperCase();
            $("hidden_warranty_num_" + id).value = $('warranty_num_' + id).value.toUpperCase();
            $("hidden_purchaseDate_" + id).value = $('purchaseDate_' + id).value;
            $("hidden_dealer_" + id).value = $('dealer_' + id).value;
            $("hidden_invoice_num_" + id).value = $('invoice_num_' + id).value.toUpperCase();
        }    
        $("update_table_data_"+id).style.display = "none";
        $("input_table_data").style.display = "block";
        $("current_prd_div").value = 0;
    }
}

function update_prd_data_renew(id) {  
    if (validation_tag($("core_table_"+id))) {
        var data_action_type = $('prd_table_status_' + id).value;
        if (data_action_type == "insert" || data_action_type == "edit") {
            var prd_value = $("prd_id_"+id).value;
            var prd_index = $("prd_id_"+id).selectedIndex;
            var prd_text = $("prd_id_"+id)[prd_index].innerHTML;   
            $("span_prd_id_" + id).value = prd_value;
            $("span_prd_id_" + id).innerHTML = prd_text;
            $('span_model_' + id).value = $("model_" + id).value;
            $('span_model_' + id).innerHTML = $("model_" + id).value.toUpperCase();
            $("span_sn_" + id).value = $('sn_' + id).value;
            $("span_sn_" + id).innerHTML = $('sn_' + id).value.toUpperCase();
        
            $("hidden_brand_id_" + id).value = $('brand_id_' + id).value;
            $("hidden_prd_id_" + id).value = $('prd_id_' + id).value;
            $('hidden_model_' + id).value = $("model_" + id).value.toUpperCase();
            $("hidden_sn_" + id).value = $('sn_' + id).value.toUpperCase();
            $("hidden_warranty_num_" + id).value = $('warranty_num_' + id).value.toUpperCase();
            $("hidden_warrantyDate_" + id).value = $('warrantyDate_' + id).value;
        }    
        $("update_table_data_"+id).style.display = "none";
        $("input_table_data").style.display = "block";
        $("current_prd_div").value = 0;
    }
}

function cancel_update_prd_data(id) {  
    var data_action_type = $('prd_table_status_' + id).value;
    if (data_action_type == "insert" || data_action_type == "edit") {
        $('brand_id_' + id).value = $("hidden_brand_id_" + id).value;
        $('prd_id_' + id).value = $("hidden_prd_id_" + id).value;
        $("model_" + id).value = $('hidden_model_' + id).value;
        $('sn_' + id).value = $("hidden_sn_" + id).value;
        $('warranty_num_' + id).value = $("hidden_warranty_num_" + id).value;
        $('purchaseDate_' + id).value = $("hidden_purchaseDate_" + id).value;
        $('dealer_' + id).value = $("hidden_dealer_" + id).value;
        $('invoice_num_' + id).value = $("hidden_invoice_num_" + id).value;
        
        verify_model_no_value("brand_id_" + id,"prd_id_" + id,"model_" + id,"verify_model_no_icon_" + id,"verify_model_no_" + id);
    }    
    $("update_table_data_"+id).style.display = "none";
    $("input_table_data").style.display = "block";
    $("current_prd_div").value = 0;
}

function cancel_update_prd_data_renew(id) {  
    var data_action_type = $('prd_table_status_' + id).value;
    if (data_action_type == "insert" || data_action_type == "edit") {
        $('brand_id_' + id).value = $("hidden_brand_id_" + id).value;
        $('prd_id_' + id).value = $("hidden_prd_id_" + id).value;
        $("model_" + id).value = $('hidden_model_' + id).value;
        $('sn_' + id).value = $("hidden_sn_" + id).value;
        $('warranty_num_' + id).value = $("hidden_warranty_num_" + id).value;
        $('warrantyDate_' + id).value = $("hidden_warrantyDate_" + id).value;
        
        verify_model_no_value("brand_id_" + id,"prd_id_" + id,"model_" + id,"verify_model_no_icon_" + id,"verify_model_no_" + id);
    }    
    $("update_table_data_"+id).style.display = "none";
    $("input_table_data").style.display = "block";
    $("current_prd_div").value = 0;
}

function create_span_text(id, name, value, text) {
    var dummy = document.createElement("span");
    dummy.id = name + "_" + id;
    dummy.name = name + "_" + id;
    dummy.value = value;
    dummy.innerHTML = text;
		    
    return dummy;
}

function create_text_input(id, name, value, type, input_size, max_length) {
    var dummy = document.createElement("input");
    dummy.id = name + "_" + id;
    dummy.name = name + "_" + id;
    dummy.type = type;
    dummy.value = value;
    
    if (input_size != null) {
        dummy.size = input_size;
    }
    if (max_length != null) {
        dummy.maxLength = max_length;
    }

    return dummy;
}

function create_prd_edit_href(target_id, text) {
    /*
    var dummy = document.createElement("a");
    dummy.innerHTML = text;
    dummy.href = "javascript:edit_prd_data_open('" + target_id + "');";
    */
    
    var dummy = document.createElement("a");
    dummy.href = "#";
    dummy.onclick = function() { edit_prd_data_open(target_id);return false; }
    
    var dummy_img = document.createElement("img");
    dummy_img.src = "/templates/alpha/"+warranty_obj.Lang+"/images/icon_edit.gif";
    
    dummy.appendChild(dummy_img);
    
    return dummy;
}

function create_prd_edit_href_renew(target_id, text) {
    /*
    var dummy = document.createElement("a");
    dummy.innerHTML = text;
    dummy.href = "javascript:edit_prd_data_open('" + target_id + "');";
    */
    
    var dummy = document.createElement("a");
    dummy.href = "#";
    dummy.onclick = function() { edit_prd_data_open_renew(target_id);return false; }
    
    var dummy_img = document.createElement("img");
    dummy_img.src = "/templates/alpha/"+warranty_obj.Lang+"/images/icon_edit.gif";
    
    dummy.appendChild(dummy_img);
    
    return dummy;
}
	    
function create_prd_delete_href(target_id, text) {
    /*
    var dummy = document.createElement("a");
    dummy.innerHTML = text;
    dummy.href = "javascript:delete_prd_data_row('" + target_id + "');";
    */
    
    var dummy = document.createElement("a");
    dummy.href = "#";
    dummy.onclick = function() { delete_prd_data_row(target_id);return false; }
    
    var dummy_img = document.createElement("img");
    dummy_img.src = "/templates/alpha/"+warranty_obj.Lang+"/images/icon_delete.gif";
    
    dummy.appendChild(dummy_img);
    
    return dummy;
}

function create_prd_delete_href_renew(target_id, text) {
    /*
    var dummy = document.createElement("a");
    dummy.innerHTML = text;
    dummy.href = "javascript:delete_prd_data_row('" + target_id + "');";
    */
    
    var dummy = document.createElement("a");
    dummy.href = "#";
    dummy.onclick = function() { delete_prd_data_row_renew(target_id);return false; }
    
    var dummy_img = document.createElement("img");
    dummy_img.src = "/templates/alpha/"+warranty_obj.Lang+"/images/icon_delete.gif";
    
    dummy.appendChild(dummy_img);
    
    return dummy;
}

function edit_prd_data_open(id) {
    var current_div = $("current_prd_div").value;
    if (current_div == "0") {
    } else {
        cancel_update_prd_data(current_div);
    }
    
    $("current_prd_div").value = id;
    $("input_table_data").style.display = "none";
    $("update_table_data_" + id).style.display = "block";    
}

function edit_prd_data_open_renew(id) {
    var current_div = $("current_prd_div").value;
    if (current_div == "0") {
    } else {
        cancel_update_prd_data_renew(current_div);
    }
    
    $("current_prd_div").value = id;
    $("input_table_data").style.display = "none";
    $("update_table_data_" + id).style.display = "block";    
}

function ResetWarrantyForm() {
    delete_all_prd();
    $('warranty').reset();
}

function ResetWarrantyRenewForm() {
    delete_all_prd_renew();
    $('warranty_renew').reset();
}

function NewAddPrdTable() {
    var next_prd_id = parseInt($('prd_current_id').value,10) + 1;
    var temp_html = $('core_table_data').innerHTML;
    temp_html = temp_html.replace(/#no#/g,next_prd_id)
    
    var dummy_div = document.createElement("div");
    dummy_div.id = "input_table_data_" + next_prd_id;
    dummy_div.name = "input_table_data_" + next_prd_id;
    dummy_div.innerHTML = temp_html;
    
    $('input_table_data').appendChild(dummy_div);
    $('prd_current_id').value = next_prd_id;
}

function NewAddPrdTableRenew() {
    var next_prd_id = parseInt($('prd_current_id').value,10) + 1;
    var temp_html = $('core_table_data').innerHTML;
    temp_html = temp_html.replace(/#no#/g,next_prd_id)
    
    var dummy_div = document.createElement("div");
    dummy_div.id = "input_table_data_" + next_prd_id;
    dummy_div.name = "input_table_data_" + next_prd_id;
    dummy_div.innerHTML = temp_html;
    
    $('input_table_data').appendChild(dummy_div);
    $('prd_current_id').value = next_prd_id;
}


function AddNewPrd(prd_id) {

    if (validation_tag($("core_table_"+prd_id))) { 

        // append new table start
        var dummy_div = document.createElement("div");
        dummy_div.id = "update_table_data_" + prd_id;
        dummy_div.name = "update_table_data_" + prd_id;
        dummy_div.style.display = "none";

        dummy_div.appendChild($('input_table_data_'+prd_id));    
        $('update_table_data').appendChild(dummy_div);
        // append new table end
        
        // update display table start
        $('all_prd_id').value = $('all_prd_id').value + prd_id + ",";
     
        var new_row = $('main_prd_display_table').insertRow($('main_prd_display_table').rows.length);
        new_row.id = "main_prd_display_table_new_row_" + prd_id;
        var cell0 = new_row.insertCell(0);
        var cell1 = new_row.insertCell(1);
        var cell2 = new_row.insertCell(2);
        var cell3 = new_row.insertCell(3);
        
        var brand_value = $("brand_id_"+prd_id).value;
        var prd_value = $("prd_id_"+prd_id).value;
        var prd_index = $("prd_id_"+prd_id).selectedIndex;
        var prd_text = $("prd_id_"+prd_id)[prd_index].innerHTML;
        var model_value = $("model_"+prd_id).value;
        var sn_value = $("sn_"+prd_id).value;
        var warranty_num_value = $("warranty_num_"+prd_id).value;
        var purchaseDate_value = $("purchaseDate_"+prd_id).value;
        var dealer_value = $("dealer_"+prd_id).value;
        var invoice_num_value = $("invoice_num_"+prd_id).value;
    	    
        cell0.appendChild(create_span_text(prd_id,'span_prd_id',prd_value,prd_text));
        cell1.appendChild(create_span_text(prd_id,'span_model',model_value,model_value.toUpperCase()));
        cell1.appendChild(create_span_text('','','','&nbsp;'));
        cell2.appendChild(create_span_text(prd_id,'span_sn',sn_value,sn_value.toUpperCase()));
        cell2.appendChild(create_span_text('','','','&nbsp;'));

        cell3.appendChild(create_prd_edit_href(prd_id,warranty_obj.LabelEdit));
        cell3.appendChild(create_span_text('','','','&nbsp;'));
        cell3.appendChild(create_prd_delete_href(prd_id,warranty_obj.LabelDelete));
        
        $('hidden_brand_id_'+prd_id).value = brand_value;
        $('hidden_prd_id_'+prd_id).value = prd_value;
        $('hidden_model_'+prd_id).value = model_value.toUpperCase();
        $('hidden_sn_'+prd_id).value = sn_value.toUpperCase();
        $('hidden_warranty_num_'+prd_id).value = warranty_num_value.toUpperCase();
        $('hidden_purchaseDate_'+prd_id).value = purchaseDate_value;
        $('hidden_dealer_'+prd_id).value = dealer_value;
        $('hidden_invoice_num_'+prd_id).value = invoice_num_value.toUpperCase();
            
        $('brand_id_'+prd_id).writeAttribute("check","check_select_empty_zero");
        $('prd_id_'+prd_id).writeAttribute("check","check_select_empty_zero");
        $('model_'+prd_id).writeAttribute("check","check_empty;check_normal_char_no_space");
        $('verify_model_no_'+prd_id).writeAttribute("check","verify_data");
        $('sn_'+prd_id).writeAttribute("check","check_empty;check_normal_char_no_space");
        $('warranty_num_'+prd_id).writeAttribute("check","check_empty;check_normal_char_no_space");
        $('purchaseDate_'+prd_id).writeAttribute("check","check_empty;check_date;check_90_today");
        $('dealer_'+prd_id).writeAttribute("check","check_empty;check_normal_char");
        $('invoice_num_'+prd_id).writeAttribute("check","check_empty;check_normal_char_no_space");

        $('prd_number').value = $('main_prd_display_table').rows.length - 1;
        // update display table end
            
        // change edit cancel btn start
        $('prd_button_add_'+prd_id).style.display = "none";
        $('prd_button_edit_'+prd_id).style.display = "block";
        // change edit cancel btn end
            
        // add new input table start
        NewAddPrdTable();
        // add new input table end
    
    }
}

function AddNewPrdRenew(prd_id) {

    if (validation_tag($("core_table_"+prd_id))) { 
    
        // append new table start
        var dummy_div = document.createElement("div");
        dummy_div.id = "update_table_data_" + prd_id;
        dummy_div.name = "update_table_data_" + prd_id;
        dummy_div.style.display = "none";

        dummy_div.appendChild($('input_table_data_'+prd_id));    
        $('update_table_data').appendChild(dummy_div);
        // append new table end
        
        // update display table start
        $('all_prd_id').value = $('all_prd_id').value + prd_id + ",";
     
        var new_row = $('main_prd_display_table').insertRow($('main_prd_display_table').rows.length);
        new_row.id = "main_prd_display_table_new_row_" + prd_id;
        var cell0 = new_row.insertCell(0);
        var cell1 = new_row.insertCell(1);
        var cell2 = new_row.insertCell(2);
        var cell3 = new_row.insertCell(3);
        
        var brand_value = $("brand_id_"+prd_id).value;
        var prd_value = $("prd_id_"+prd_id).value;
        var prd_index = $("prd_id_"+prd_id).selectedIndex;
        var prd_text = $("prd_id_"+prd_id)[prd_index].innerHTML;
        var model_value = $("model_"+prd_id).value;
        var sn_value = $("sn_"+prd_id).value;
        var warranty_num_value = $("warranty_num_"+prd_id).value;
        var warrantyDate_value = $("warrantyDate_"+prd_id).value;
    	    
        cell0.appendChild(create_span_text(prd_id,'span_prd_id',prd_value,prd_text));
        cell1.appendChild(create_span_text(prd_id,'span_model',model_value,model_value.toUpperCase()));
        cell1.appendChild(create_span_text('','','','&nbsp;'));
        cell2.appendChild(create_span_text(prd_id,'span_sn',sn_value,sn_value.toUpperCase()));
        cell2.appendChild(create_span_text('','','','&nbsp;'));

        cell3.appendChild(create_prd_edit_href_renew(prd_id,warranty_obj.LabelEdit));
        cell3.appendChild(create_span_text('','','','&nbsp;'));
        cell3.appendChild(create_prd_delete_href_renew(prd_id,warranty_obj.LabelDelete));
        
        $('hidden_brand_id_'+prd_id).value = brand_value;
        $('hidden_prd_id_'+prd_id).value = prd_value;
        $('hidden_model_'+prd_id).value = model_value.toUpperCase();
        $('hidden_sn_'+prd_id).value = sn_value.toUpperCase();
        $('hidden_warranty_num_'+prd_id).value = warranty_num_value.toUpperCase();
        $('hidden_warrantyDate_'+prd_id).value = warrantyDate_value;
            
        $('brand_id_'+prd_id).writeAttribute("check","check_select_empty_zero");
        $('prd_id_'+prd_id).writeAttribute("check","check_select_empty_zero");
        $('model_'+prd_id).writeAttribute("check","check_empty;check_normal_char_no_space");
        $('verify_model_no_'+prd_id).writeAttribute("check","verify_data");
        $('sn_'+prd_id).writeAttribute("check","check_empty;check_normal_char_no_space");
        $('warranty_num_'+prd_id).writeAttribute("check","check_empty;check_normal_char_no_space");
        $('warrantyDate_'+prd_id).writeAttribute("check","check_empty;check_date;check_30_today_after");

        $('prd_number').value = $('main_prd_display_table').rows.length - 1;
        // update display table end
            
        // change edit cancel btn start
        $('prd_button_add_'+prd_id).style.display = "none";
        $('prd_button_edit_'+prd_id).style.display = "block";
        // change edit cancel btn end
            
        // add new input table start
        NewAddPrdTableRenew();
        // add new input table end
        
    }
}

function ValidationWarrantyForm(form_obj) {
    var re = true;

    if (parseInt($('prd_number').value,10) <= 0) {
        alert(warranty_obj.LabelPleaaeInputProduct);
        re = false;
    } else if ($('current_prd_div').value != "0") {
        alert(warranty_obj.LabelUpdateProductQuestion);
        re = false;
    } else if (!validation(form_obj)) {
        re = false;
    }

    return re;
}

function ValidationWarrantyRenewForm(form_obj) {
    var re = true;

    if (parseInt($('prd_number').value,10) <= 0) {
        alert(warranty_obj.LabelPleaaeInputProduct);
        re = false;
    } else if ($('current_prd_div').value != "0") {
        alert(warranty_obj.LabelUpdateProductQuestion);
        re = false;
    } else if (!validation(form_obj)) {
        re = false;
    }

    return re;
}


// verify model number start
function verify_model_no_value(brand_id, cate_id, model_id, icon_id, verify_id) {
    $(icon_id).src = "/templates/alpha/images/spacer_15_15.gif";
    $(verify_id).value = "";
    var brand_value = $(brand_id).value;
    var cate_value = $(cate_id).value;
    var model_value = $(model_id).value;
    model_value = MyTrim(model_value);
    
    if (brand_value != "0" && cate_value != "0" && model_value != "") {
        var url = '/services/verify_model_no.html';

        var params= Object.extend({ 
                b:brand_value,
                c:cate_value,
			    no:model_value,
			    rand:Math.floor(Math.random()*10000000)
        });

        var myAjax = new Ajax.Request(
            url,
            {
                method: 'post',
                parameters: params,
                onComplete: function(originalRequest) {
                                //alert(originalRequest.responseText);
		  	  	                var Verify = originalRequest.responseText.evalJSON(true);
    		  	  	            
		  	  	                //alert(Verify.Verify);
		  	  	                if (Verify.Verify == "true") {
		  	  	                    $(icon_id).src = "/templates/alpha/images/spacer_15_15.gif";
		  	  	                    $(verify_id).value = "true";
		  	  	                } else {
		  	  	                    $(icon_id).src = "/templates/alpha/images/verify_false_"+warranty_obj.Lang+".gif";
		  	  	                    $(verify_id).value = "false";
		  	  	                }
                            }
            }
        );
    } else {
        //$(icon_id).src = "/templates/alpha/images/verify_false_"+warranty_obj.Lang+".gif";
        $(verify_id).value = "false";
    }
}

// Trim start
function MyLTrim(str){ 
    var i;
    
    for(i=0;i<=str.length-1;i++){
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ") 
            break;
    }
    
    str = str.substring(i,str.length);
    
    return str;
}

function MyRTrim(str){
    var i;
    
    for(i=str.length-1;i>=0;i--){
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ") 
            break;
    }
    
    str = str.substring(0,i+1);
    
    return str;
}

function MyTrim(str){ 
    return MyLTrim(MyRTrim(str)); 
}
// Trim end
// verify model number end


// add by evans 20100325 start 
function validation_tag(v_tag){
    var re = true;
    var have_check = true;
    
	for(var i=0;i<v_tag.childNodes.length;i++){	

	    var input=v_tag.childNodes[i];
	    
	    var check = "";
	    try {
            check=getAttrValue(input,"temp_check");
        } catch(ex) {
            have_check = false;
        }

        if(typeof(check)=='undefined') have_check = false;;
        if(check=="") have_check = false;
		
		if (have_check) {
            if(validation_check(v_tag,input,check)==false){
                if(input.focus && input.type!="hidden") {
                    try {
                        input.focus();
                    } catch(ex){}
                }			
    			
                re = false;
                break;
            }
        }
	    
	    //alert(input.childNodes.length + "\n" + input.innerHTML);
        if (input.childNodes.length > 0) {            
            re = validation_tag(input);
            if (!re) {
                break;
            }
        }
		
	}
	
	return re;	
}
// add by evans 20100325 end
