
/*
.----------------------------------------------------------------------------.
|  Software : DSWebsite, DSCustomer, DsAdmin                                 |
|   Version : 3.0                                                            |
|   Contact : office@domainscan.ro                                           |
| DSWebsite : http://www.domainscan.ro                                       |
|DSCustomer : http://www.domainscan.ro/customer/                             |
|   DSAdmin : http://www.domainscan.ro/admin/                                |
| -------------------------------------------------------------------------- |
|    Author : Cimpean Andrei (original founder & project administrator)      |
| Copyright : (c) 2007-2020, HOST LAYER SRL. All Rights Reserved.            |
|   Address : 407260, Cuzdrioara, Str.Mihai Eminescu, Nr. 191/A, Jud. CLUJ   |
|     Phone : +40-740-453636 , fax: +40-264-214035                           |
|   Website : www.hostlayer.ro                                               |
|     Email : office@hostlayer.ro                                            |
| -------------------------------------------------------------------------- |
|   License : Distributed under the Licence                                  |
| -------------------------------------------------------------------------- |
|   ____                                     _       _                       |
|  |  __| _   _  _____  _   _  ____  ____   \ \  _  / \ ____  __             |
|  |  _| | |_| ||_   _|| |_| || --_|/ -__\  \ \_/_\_/ // -__\| -/_           |
|  |_|   |_____|  |_|  |_____||_|\_\|__\    \___/ \__/ |__\  |__-/           |
|  				                      the change comes inside you            |
|                                                                            |
| -------------------------------------------------------------------------- |
| The content of this file is HOST LAYER SRL property.                       |
.----------------------------------------------------------------------------.
*/


  Element.addMethods({
  append: function(element, tagName, tagId, tagStyle, tagClass, tagHTML) {
    element = $(element);
    tagId = typeof(tagId) != 'undefined' ? tagId : null;
    tagStyle = typeof(tagStyle) != 'undefined' ? tagStyle : null;
    tagClass = typeof(tagClass) != 'undefined' ? tagClass : null;
    tagHTML = typeof(tagHTML) != 'undefined' ? tagHTML : null;

    var wrapper = document.createElement(tagName);
        wrapper.id = tagId;
        wrapper.setStyle({'position': tagStyle['position'], 'z-index': tagStyle['z-index']});
        wrapper.className = tagClass;
        wrapper.innerHTML = tagHTML;
    element.appendChild(wrapper);
    return Element.extend(wrapper);
  }});

  /*
Effect.BlindRight = function(element) {
  element = $(element);
  var elementDimensions = element.getDimensions();
  return new Effect.Scale(element, 100, Object.extend({
    scaleContent: false,
    scaleY: false,
    scaleFrom: 0,
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
    restoreAfterFinish: true,
    afterSetup: function(effect) {
      effect.element.makeClipping().setStyle({width: '0px'}).show();
    },  
    afterFinishInternal: function(effect) {
      effect.element.undoClipping();
    }
  }, arguments[1] || { }));
};

Effect.BlindLeft = function(element) {
  element = $(element);
  element.makeClipping();
  return new Effect.Scale(element, 0,
    Object.extend({ scaleContent: false,
      scaleY: false,
      restoreAfterFinish: true,
      afterFinishInternal: function(effect) {
        effect.element.hide().undoClipping();
      }
    }, arguments[1] || { })
  );
};
*/

function preloadLoagingImage() {
  var image = new Image();
  image.src = "{$imagefolder}ajax-bar-loader.gif";
}
function preloadPayNowImages() {
  preload_image_object = new Image();
  image_url = new Array();

  image_url[0] = "http://www.domainscan.ro/styles/default/imageset/ro/buttons/pay_now.png";
  image_url[1] = "http://www.domainscan.ro/styles/default/imageset/ro/buttons/pay_now_over.png";
  image_url[2] = "http://www.domainscan.ro/styles/default/imageset/ro/buttons/pay_now_down.png";

  for(var i=0; i<=image_url.length; i++) preload_image_object.src = image_url[i];
}
function preloadImages(popup) {
      popup = (typeof(popup) != 'undefined') ? popup : null;
      preload_image_object = new Image();
      // info box
      image_url = new Array();
      image_url[0] = "http://www.domainscan.ro/styles/default/imageset/ro/div_styles/2/bottom_left.gif";
      image_url[1] = "http://www.domainscan.ro/styles/default/imageset/ro/div_styles/2/bottom_middle.gif";
      image_url[2] = "http://www.domainscan.ro/styles/default/imageset/ro/div_styles/2/bottom_right.gif";
      image_url[3] = "http://www.domainscan.ro/styles/default/imageset/ro/div_styles/2/right_middle.gif";
      image_url[4] = "http://www.domainscan.ro/styles/default/imageset/ro/div_styles/2/top_left2.gif";
      image_url[5] = "http://www.domainscan.ro/styles/default/imageset/ro/div_styles/2/top_left.gif";
      image_url[6] = "http://www.domainscan.ro/styles/default/imageset/ro/div_styles/2/top_middle.gif";
      image_url[7] = "http://www.domainscan.ro/styles/default/imageset/ro/div_styles/2/top_right.gif";
      image_url[8] = "http://www.domainscan.ro/styles/default/imageset/ro/div_styles/2/left_middle.gif";
      image_url[9] = "http://www.domainscan.ro/styles/default/imageset/ro/buttons/please_wait_disabled.png";

      if (popup != null) {
          image_url[10] = "http://www.domainscan.ro/js/popup/themes/alphacube/frame-left.png";
          image_url[11] = "http://www.domainscan.ro/js/popup/themes/alphacube/frame-right.png";
          image_url[12] = "http://www.domainscan.ro/js/popup/themes/alphacube/bottom-left-c.png";
          image_url[13] = "http://www.domainscan.ro/js/popup/themes/alphacube/bottom-middle.png";
          image_url[14] = "http://www.domainscan.ro/js/popup/themes/alphacube/bottom-right-c.png";
          image_url[15] = "http://www.domainscan.ro/js/popup/themes/alphacube/left-top.png";
          image_url[16] = "http://www.domainscan.ro/js/popup/themes/alphacube/right-top.png";
          image_url[17] = "http://www.domainscan.ro/js/popup/themes/alphacube/top-middle.png";
      }

       for(var i=0; i<=image_url.length; i++) preload_image_object.src = image_url[i];

}

/** APELATA DIN
 * @header.tpl //aprox. line: 30
 * @index.tpl //aprox. line: 128
 * @dom_bulk_register.tpl //aprox. line: 128
 */
function repune(_text, textfield, type) {
    _text = str_replace("<br>","\n", _text);
    //verificam daca e textarea
    if (textfield.type == 'textarea') {
        if (type == "off") textfield.className = 'medium_textarea_black';
        else textfield.className = 'medium_textarea';
    }
    if (type == "on") { if ($(textfield).value == '') $(textfield).value = _text; }
    else if ($(textfield).value == _text) $(textfield).value = '';
}//end function

function popup(url,width,height) { window.open(url,null,'width='+width+',height='+height+',toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no'); }

function windowSetSize(width,height) {
         if (window.outerWidth) { window.outerWidth = width; window.outerHeight = height; }
	 else if (window.resizeTo) { window.resizeTo(width,height); }
	 else return;
}

function resetAuctionsSearchForm() {
    $('category_type').value='all';
    $('auction_price').value='all';
    $('selling_type').value='all';
    $('add_date').value='all';
    $('sld_length').value='all';
    $('exclude_hypens').checked=false;
    $('exclude_numbers').checked=false;
    $('exclude_idn').checked=true;
    $('search_what').value='all';
    $('auction_views').value='all';
    $('sort_by').value='alfabetic_order';
    $('results_per_page').value='50';
    $('language').value='all';
    $('sld_string_position1').checked=false;
    $('sld_string_position2').checked=true;
    $('sld_string_position3').checked=false;
}

/** APELATA DIN
 * @domains.tpl //aprox. line: 94
 */
function checkAll(Id, insidediv, selection) {
  var descendants = $(insidediv).descendants();
  for (var i = 0; i < descendants.length; i++)
  {
      if (descendants[i].type == "checkbox")
      {
         if (selection == "all") {
            descendants[i].checked = true;
            $(Id).innerHTML = "Selecteaza standard";
            $(Id).onclick = function() { checkAll(Id, 'tld_checkboxex', 'standard'); }
         } else {
             if(descendants[i].id != "com"  && descendants[i].id != "net" && descendants[i].id != "org" && descendants[i].id != "eu" && descendants[i].id != "info") {
                 descendants[i].checked = false;
                 $(Id).innerHTML = "Selecteaza toate";
                 $(Id).onclick = function() { checkAll(Id, 'tld_checkboxex', 'all'); }
             }
         }
      }
  }
}

/** APELATA DIN
 * @index.tpl
 */
function changeBg(id, idnr, side) {
     if (side == 'left') nr = parseFloat($(idnr).innerHTML) - 1;
     else if (side == 'right') nr = parseFloat($(idnr).innerHTML) + 1;

     if (nr == 1) newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/week_offer.png)";
     else if (nr == 2) newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/week_offer2.png)";
     else if (nr == 3) newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/week_offer3.png)";

     else if (nr < 1) { nr = 1; newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/week_offer.png)"; }
     else if (nr > 3) { nr = 3; newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/week_offer3.png)"; }

     //Effect.Fade(id, { duration: 0.3 });
     //setTimeout(function() {$(id).style.backgroundImage = newImage; Effect.Shake(id, { duration: 0.5 })} , 300);

     Effect.Fade(id, { duration: 0.3 });
     setTimeout(function() {Effect.Appear(id, { duration: 0.3 });} , 400);
     setTimeout(function() {$(id).style.backgroundImage = newImage;} , 300);

     $(idnr).innerHTML = nr;

     //alert(newImage);
}

/** APELATA DIN
 * @index.tpl
 */
function init_glinder() {
featuredcontentglider.init({
	gliderid: "main_offers", //ID of main glider container
	contentclass: "glidecontent", //Shared CSS class name of each glider content
	togglerid: "p-select1", //ID of toggler container
	remotecontent: "", //Get gliding contents from external file on server? "filename" or "" to disable
	selected: 0, //Default selected content index (0=1st)
	persiststate: true, //Remember last content shown within browser session (true/false)?
	speed: 500, //Glide animation duration (in milliseconds)
	direction: "leftright", //set direction of glide: "updown", "downup", "leftright", or "rightleft"
	autorotate: true, //Auto rotate contents (true/false)?
	autorotateconfig: [6000, 2] //if auto rotate enabled, set [milliseconds_btw_rotations, cycles_before_stopping]
})
}

/** APELATA DIN
 * @index.tpl
 */
function init_glinder2() {
featuredcontentglider.init({
	gliderid: "week_offers", //ID of main glider container
	contentclass: "glidecontent2", //Shared CSS class name of each glider content
	togglerid: "p-select2", //ID of toggler container
	remotecontent: "", //Get gliding contents from external file on server? "filename" or "" to disable
	selected: 0, //Default selected content index (0=1st)
	persiststate: true, //Remember last content shown within browser session (true/false)?
	speed: 500, //Glide animation duration (in milliseconds)
	direction: "leftright", //set direction of glide: "updown", "downup", "leftright", or "rightleft"
	autorotate: true, //Auto rotate contents (true/false)?
	autorotateconfig: [6000, 2] //if auto rotate enabled, set [milliseconds_btw_rotations, cycles_before_stopping]
})
}

/** APELATA DIN
 * @index.tpl
 */
function init_glinder3() {
featuredcontentglider.init({
	gliderid: "servers_offers", //ID of main glider container
	contentclass: "glidecontent3", //Shared CSS class name of each glider content
	togglerid: "p-select", //ID of toggler container
	remotecontent: "", //Get gliding contents from external file on server? "filename" or "" to disable
	selected: 0, //Default selected content index (0=1st)
	persiststate: true, //Remember last content shown within browser session (true/false)?
	speed: 500, //Glide animation duration (in milliseconds)
	direction: "leftright", //set direction of glide: "updown", "downup", "leftright", or "rightleft"
	autorotate: true, //Auto rotate contents (true/false)?
	autorotateconfig: [3000, 2] //if auto rotate enabled, set [milliseconds_btw_rotations, cycles_before_stopping]
})
}

/** APELATA DIN
 * @index.tpl
 */
function changeMainBg(_this, id, type) {
     if (type == 'dedicated_servers') newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/dedicated_servers_summary.png)";
     else if (type == 'vps_servers') newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/vps_servers_summary.png)";
     else if (type == 'domains_auctions') newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/domains_auctions_summary.png)";
     else if (type == 'web_hosting') newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/web_hosting_summary.png)";
     else if (type == 'storage_hosting') newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/storage_hosting_summary.png)";
     else if (type == 'domains') newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/domains_summary.png)";
     else if (type == 'ssl_certificates') newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/ssl_certificates_summary.png)";
     else if (type == 'resellers') newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/resellers_summary.png)";
     else if (type == 'affiliates') newImage = "url(http://www.domainscan.ro/styles/default/imageset/ro/affiliates_summary.png)";

     Effect.Fade(id, { duration: 0.3 });
     setTimeout(function() {Effect.Appear(id, { duration: 0.3 });} , 400);
     setTimeout(function() {$(id).style.backgroundImage = newImage;} , 300);
     //pref = substr(_this.id , 0, -4);

     for(i=0; i<9; i++) {
       if (i == 0) pref = 'dedicated_servers';
       else if (i == 1) pref = 'vps_servers';
       else if (i == 2) pref = 'domains_auctions';
       else if (i == 3) pref = 'web_hosting';
       else if (i == 4) pref = 'storage_hosting';
       else if (i == 5) pref = 'domains';
       else if (i == 6) pref = 'ssl_certificates';
       else if (i == 7) pref = 'resellers';
       else if (i == 8) pref = 'affiliates';

       if (pref == type) { setTimeout(function() {$(type+'_btn').src = 'http://www.domainscan.ro/styles/default/imageset/ro/buttons/'+type+'_over_btn.gif'} , 1000);  }
       else { $(pref+'_btn').src = 'http://www.domainscan.ro/styles/default/imageset/ro/buttons/'+pref+'_btn.gif' ;}
       //alert(pref+' == '+type);
       }

     //alert('http://www.domainscan.ro/styles/default/imageset/ro/buttons/'+type+'_over_btn.gif');

}


/** APELATA DIN
 * @host_renewal.tpl //aprox. line: 128
 */
function checkAll2(Id, check_type, div) {
  var descendants = $(div).descendants();
  for (var i = 0; i < descendants.length; i++) {
     if (check_type == "checkboxes") {
        if (descendants[i].type == "checkbox") {
            if ($(Id).checked == true) descendants[i].checked = true;
            else descendants[i].checked = false;
        }
     }
  }
}
/** APELATA DIN
 * @divTransferCodes.php //aprox. line: 18
 */
function confirmation(type) {
  if (type == 'removeFromCart') {
     return confirm("Esti sigur ca doresti sa stergi acest produs din cart?");
  }
}

/** APELATA DIN
 * @divTransferCodes.php //aprox. line: 18
 */
function ConfirmAction(type, question, varArray) {
varArray = typeof(varArray) != 'undefined' ? varArray : null;
var answer = confirm(question, "Da", "Nu");
//fac split la raspuns
Arr = new Array();
if(varArray != null) {
  if(varArray.indexOf("|") != '-1') { varArray2 = varArray.split("|");
    for (var i = 0; i < varArray2.length; i++) { varArraySplit = varArray2[i].split("="); Arr[varArraySplit[0]] = varArraySplit[1]; }
  }
}
if (answer) {
   switch(type) {
       case "emptyCart": $('delete').value = 'all'; document.cart.submit(); break;
       case "emptyCartTransfer": ajax_controller('removeTransferDomainsFromCart', 'divTransferCodes', 'remove_type=alltransfer'); break;
       case "deleteProfile":
         ajax_controller('popupInfo', null, 'infoType='+Arr['what']+'|action=delete|id='+Arr['id']);
         Windows.closeAll(); 
         dialogAlert('popupInfo','infoType='+Arr['what']+'|action=edit_delete', 'edit_delete_'+Arr['what']); 
         break;
}} else
       return void(0);
}

//========================================AJAX MAIN CONTROLLER========================================
function ajax_controller(load, divArray, varArray, preloader, preloaderType, preloaderStyle, redirectUrl){

  //verifying null args--------------------------------------------
  preloader = (typeof(preloader) != 'undefined' && $(preloader) != null) ? preloader : null;
  preloaderType = typeof(preloaderType) != 'undefined' ? preloaderType : 1;
  preloaderStyle = typeof(preloaderStyle) != 'undefined' ? preloaderStyle : 1;
  redirectUrl = typeof(redirectUrl) != 'undefined' ? redirectUrl : null;

 //setam url-ul controlerului si parametrii------------------------
 var upperpath  = getRealPath();
 var url = upperpath+'controllers/ajax_controller.php';
 var params = 'load=' + load + '&varArray=' + varArray;


 //preloader start--------------------------------------------------
  if (preloader != null) { preload(preloader, 'on', preloaderStyle); }

    new Ajax.Request(url,
    {method: 'post',
    parameters: params,
    onSuccess: function(transport) {
                    var divs = new Array();
                    if(divArray.indexOf("|") != '-1') { divs = divArray.split("|"); } else divs[0] = divArray;
                    //facem update la div-uri--------------------------------------------
                    if (divs.length == 1) {
                         var response = $(divArray);
                         response.update(transport.responseText);
                    } else if (divs.length > 1) {
                        for (var i = 0; i < divs.length; i++) {
                            //apelam functia de verificare
                            var procResponse = distributeResponses(load, divs[i], transport.responseText);
                            var response = $(divs[i]);
                            response.update(procResponse);
                        }
                    }

               //preloader end--------------------------------------
               if (preloaderType == 2) { preload(preloader, 'off', preloaderStyle); }

    },
    onFailure: function(){ result.update('Error'); return 0; },
    onComplete: function(){ if (redirectUrl != null) { window.location=redirectUrl; } }
    });

}//end functionn

function getRealPath() {
     url = window.location.pathname; url = url.split("/"); 
     
     //url = url[4]; //localhost
     url = url[1]; //domainscan.ro

     if (substr(url, -4, -3) == ".") urlPath = "";
     else if (url == "controllers") urlPath = "../../";
     else urlPath = "../";
     //alert(urlPath);
     return urlPath;
}
//========================================END AJAX MAIN CONTROLLER====================================



//functia returneaza id-ul divului in functie de raspunsul primit sub forma de array
function distributeResponses(load, divs, response) {
var resp = new Array();

//fac split la raspuns
if(response.indexOf("|") != '-1') {
  response = response.split("|");
  for (var i = 0; i < response.length; i++) {
    response_split = response[i].split("=");
    resp[response_split[0]] = response_split[1];
  }
}
    switch(load) {
        case "addDomainsToCart":
             if (divs == "cartCount1" || divs == "cartCount2" || divs == "cartCount3") {
               response = resp['count'];
             } else {
               response = '<img border="0" src="http://www.domainscan.ro/styles/default/imageset/ro/smallcart_remove.gif" '+
                          'onclick="ajax_controller(\'removeDomainsFromCart\', \''+divs+'|cartCount1|cartCount2|cartCount3\', \'sld='+resp['sld']+'|tld='+resp['tld']+'|prod_id='+resp['prod_id']+'|cart_id='+resp['cart_id']+'|registration_type='+resp['registration_type']+'\');"  style="cursor:hand; cursor:pointer">';
             }
        break;

        case "removeDomainsFromCart":
             if (divs == "cartCount1" || divs == "cartCount2" || divs == "cartCount3") {
               response = resp['count'];
             } else {
               response = '<input type="checkbox" name="C3" value="ON" '+
                          'onclick="ajax_controller(\'addDomainsToCart\', \''+divs+'|cartCount1|cartCount2|cartCount3\', \'sld='+resp['sld']+'|tld='+resp['tld']+'|prod_id='+resp['prod_id']+'|quantity=1|registration_type='+resp['registration_type']+'\');">';
             }
        break;
/*
        case "calculateCartTotal":
             if (divs == "paymentSubTotal") response = resp['total'];
             if (divs == "paymentFee") response = resp['fee'];
             if (divs == "paymentTotal") response = resp['total'];
        break;
*/
    }
    return response;
}//end function


/** APELATA DIN
 * @index_tab1.tpl //aprox. line: 49
 */
function setBgcolor(id, type, outBg) {
  if (type == "over") $(id).setStyle({backgroundColor: '#e8ffc7'});
  else $(id).setStyle({backgroundColor: outBg});
}//end function


function switchPaymentTypeDiv(payment_type) {

  if (payment_type == 'card') {
  
     $('validation_card').style.display='';
     $('validation_sms').style.display='none';
     $('validation_paypal').style.display='none';
     $('validation_credits').style.display='none';
     $('validation_phone').style.display='none';

  } else if (payment_type == 'sms') {
  
     $('validation_card').style.display='none';
     $('validation_sms').style.display='';
     $('validation_paypal').style.display='none';
     $('validation_credits').style.display='none';
     $('validation_phone').style.display='none';

  } else if (payment_type == 'paypal') {

     $('validation_card').style.display='none';
     $('validation_sms').style.display='none';
     $('validation_paypal').style.display='';
     $('validation_credits').style.display='none';
     $('validation_phone').style.display='none';

  } else if (payment_type == 'credits') {

     $('validation_card').style.display='none';
     $('validation_sms').style.display='none';
     $('validation_paypal').style.display='none';
     $('validation_credits').style.display='';
     $('validation_phone').style.display='none';

  } else if (payment_type == 'phone') {

     $('validation_card').style.display='none';
     $('validation_sms').style.display='none';
     $('validation_paypal').style.display='none';
     $('validation_credits').style.display='none';
     $('validation_phone').style.display='';

  }

}


/** APELATA DIN
 * @index_tab1.tpl //aprox. line: 49
 */
function getProdNameservers(cartId) {

   NameserversTrs = $$('#nameservers tr[id]'); var ns;
    for (var i = 0; i < NameserversTrs.length; i++) {
        if (cartId == substr(NameserversTrs[i].id, 6)) {
        //nameservers
        nameserver = $('ns_profile_'+cartId);
        if(nameserver != null) ns = nameserver.value;
        }
    }
    //alert(ns);
    return ns;
}

/** APELATA DIN
 * @index_tab1.tpl //aprox. line: 49
 */
function getProdMainDomains(cartId, type) {
    var mainDomain;
    if ($('tr_'+type+'_'+cartId) != null) {
      //alert($('mixed_1_'+cartId).style.display);
      if ($('only_domainscan_'+cartId) != null) {
        if ($('only_domainscan_'+cartId).style.display == 'none') {
           if ($('only_other_'+cartId) != null) {
             if ($('only_other_'+cartId).style.display == 'none') {
               if ($('mixed_'+cartId) != null) {
                  if ($('mixed_'+cartId).style.display != 'none') {
                    if ($('mixed_1_'+cartId) != null) {
                       if ($('mixed_1_'+cartId).style.display == 'none') {
                           mainDomain = $('ihave_2_sld_'+cartId).value+'.'+$('ihave_2_tld_'+cartId).value;
                       } else {
                           mainDomain = $('main_domain_2_'+cartId).value;
                       }
                     } else mainDomain = null;
                  }
                } else mainDomain = null;
             } else { mainDomain = $('ihave_1_sld_'+cartId).value +'.'+ $('ihave_1_tld_'+cartId).value; }
           } else mainDomain = null;
        } else { mainDomain = $('main_domain_1_'+cartId).value; }
      } else mainDomain = null;


    } else mainDomain = null;
    //alert(mainDomain);
    return mainDomain;

}

/** APELATA DIN
 * @index_tab1.tpl //aprox. line: 49
 */
function getProdHostname(cartId) {
    var hostname;
    ServersTrs = $$('#servers tr[id]');
    for (var i = 0; i < ServersTrs.length; i++) {
        if (cartId == substr(ServersTrs[i].id, 11)) {
        //nameservers
        hostnameTxt = $('hostname_'+cartId);
        if(hostnameTxt != null && hostnameTxt.style.display != 'none') hostname = hostnameTxt.value; else hostname = null;
        }
    }

    return hostname;
}

/** APELATA DIN
 * @index_tab1.tpl //aprox. line: 49
 */
function getEppCode(cartId) {
    var code;
    DomainsTrs = $$('#nameservers tr[id]');
    for (var i = 0; i < DomainsTrs.length; i++) {
        if (cartId == substr(DomainsTrs[i].id, 6)) {
        //nameservers
        eppTxt = $('epp_code_'+cartId);
        if(eppTxt != null && eppTxt.style.display != 'none') code = eppTxt.value; else code = null;
        }
    }
    //alert(ns);
    return code;
}

/** APELATA DIN
 * @index_tab1.tpl //aprox. line: 49
 */
function getProdCSR(cartId) {
    var csr;
    SSLCertificates = $$('#ssl_certificates tr[id]');
    for (var i = 0; i < SSLCertificates.length; i++) {
        if (cartId == substr(SSLCertificates[i].id, 20)) {
        //nameservers
        csrTxtarea = $('csr_'+cartId);
        if(csrTxtarea != null && csrTxtarea.style.display != 'none') csr = csrTxtarea.value; else csr = null;
        }
    }
    //alert(ns);
    return csr;
}

/** APELATA DIN
 * @index_tab1.tpl //aprox. line: 49
 */
function processProdSettings() {
    ContactsTrs = $$('#contacts tr[id]');
    NameserversTrs = $$('#nameservers tr[id]');
    WebHostingTrs = $$('#web_hosting tr[id]');
    StorageHostingTrs = $$('#storage_hosting tr[id]');
    ServersTrs = $$('#servers tr[id]');
    SSLCertificates = $$('#ssl_certificates tr[id]');
    Resellers = $$('#resellers tr[id]')

    prod = new Array();

    //aflam contactele-----------------------------------------------
    for (var i = 0; i < ContactsTrs.length; i++) {  //alert(i);

        cartId = substr(ContactsTrs[i].id, 12);
        prod[i] = new Array();

        prod[i]['cartId'] = cartId;

        //contact detinator
        ownerContact = $('owner_contact_'+cartId);
        if (ownerContact.style.display != "none") {
          prod[i]['ownerContactId'] = ownerContact.value;
          //gasim nameserverele
          prod[i]['nameserversId'] = getProdNameservers(cartId);
        }

        //contact administrativ
        adminContact = $('admin_contact_'+cartId);
        if (adminContact.style.display != "none") { prod[i]['adminContactId'] = adminContact.value; }

        //contact tehnic
        techContact = $('tech_contact_'+cartId);
        if (techContact.style.display != "none") { prod[i]['techContactId'] = techContact.value; }

        //contact facturare
        billContact = $('bill_contact_'+cartId);
        if (billContact.style.display != "none") { prod[i]['billContactId'] = billContact.value; }
        //alert(prod[i]['prodFacturareId']);

        //hostname-uri la servere
        prod[i]['eppCode'] = getEppCode(cartId);

        //gasim domeniile principale la web hosting
        prod[i]['webHostingMainDomainName'] = getProdMainDomains(cartId, 'web_hosting');   //alert(cartId+' '+prod[i]['WebHostingMainDomainName']);

        //gasim domeniile principale la storage hosting
        prod[i]['storageHostingMainDomainName'] = getProdMainDomains(cartId, 'storage_hosting');   //alert(cartId+' '+prod[i]['WebHostingMainDomainName']);

        //hostname-uri la servere
        prod[i]['serverHostname'] = getProdHostname(cartId);  //alert(prod[i]['serverHostname']);

        //csr-urile la certificatele SSL
        prod[i]['csr'] = getProdCSR(cartId);

        //gasim domeniile principale la resellers
        prod[i]['resellerMainDomainName'] = getProdMainDomains(cartId, 'resellers');   //alert(cartId+' '+prod[i]['resellerMainDomainName']);

 }

   //if (sameValues['prodMainDomainName'] > 1) alert(sameValues['prodMainDomainName']);
   mergeArrayWebHosting = new Array(); count = 0;
   mergeArrayStorageHosting = new Array(); count2 = 0;
   mergeArrayServerHostname = new Array(); count3 = 0;
   mergeArrayCsr = new Array(); count4 = 0;
   mergeArrayResellers = new Array(); count5 = 0;
   mergeArrayDomains = new Array(); count6 = 0;

   var prodEnum;
   for (var i = 0; i < prod.length; i++) {

   if (prod[i]['webHostingMainDomainName'] != null) { mergeArrayWebHosting[count] = prod[i]['webHostingMainDomainName']; count++; }
   if (prod[i]['storageHostingMainDomainName'] != null) { mergeArrayStorageHosting[count2] = prod[i]['storageHostingMainDomainName']; count2++; }
   if (prod[i]['serverHostname'] != null) { mergeArrayServerHostname[count3] = prod[i]['serverHostname']; count3++; }
   if (prod[i]['csr'] != null) { mergeArrayCsr[count4] = prod[i]['csr']; count4++; }
   if (prod[i]['resellerMainDomainName'] != null) { mergeArrayResellers[count5] = prod[i]['resellerMainDomainName']; count5++; }
   if (prod[i]['eppCode'] != null) { mergeArrayDomains[count6] = prod[i]['eppCode']; count6++; }

      prodEnum += '|'+i+':cartId='+prod[i]['cartId']+
                  '|'+i+':ownerContactId='+prod[i]['ownerContactId']+
                  '|'+i+':adminContactId='+prod[i]['adminContactId']+
                  '|'+i+':techContactId='+prod[i]['techContactId']+
                  '|'+i+':billContactId='+prod[i]['billContactId']+
                  '|'+i+':nameserversId='+prod[i]['nameserversId']+
                  '|'+i+':eppCode='+prod[i]['eppCode']+
                  '|'+i+':webHostingMainDomainName='+prod[i]['webHostingMainDomainName']+
                  '|'+i+':storageHostingMainDomainName='+prod[i]['storageHostingMainDomainName']+
                  '|'+i+':serverHostname='+prod[i]['serverHostname']+
                  '|'+i+':csr='+prod[i]['csr']+
                  '|'+i+':resellerMainDomainName='+prod[i]['resellerMainDomainName']+
                  '|';

    }

    //BEGIN verificari-----------------------------------------------------------------------------
    matchValues1 = array_count_values(mergeArrayWebHosting);
    matchValues2 = array_count_values(mergeArrayStorageHosting);
    matchValues3 = array_count_values(mergeArrayServerHostname);
    matchValues4 = array_count_values(mergeArrayCsr);
    matchValues5 = array_count_values(mergeArrayResellers);
    matchValues6 = array_count_values(mergeArrayDomains);
    regExInvalidChars = /[^a-zA-Z0-9-\s.]+/;

    for (var i = 0; i < mergeArrayDomains.length; i++) {
        if (mergeArrayDomains[i] == 0 || mergeArrayDomains[i] == "Introduceti codul EPP.") {
           alert("Va rugam sa introduceti codul EPP pentru domeniul dvs."); return;
        }
    }
    for (var i = 0; i < mergeArrayWebHosting.length; i++) {
        if (mergeArrayWebHosting[i] == 0 || mergeArrayWebHosting[i] == "introduceti domeniul dvs..ext") {
           alert("Va rugam sa selectati domeniul principal pentru care doriti sa fie activat pachetul de gazduire."); return;
        } else if (regExInvalidChars.test(mergeArrayWebHosting[i])) {
           alert('Domeniul principal introdus contine caractere invalide.'); return;
	} else if (matchValues1[mergeArrayWebHosting[i]] > 1) {
           alert("Va rugam sa nu puneti acelasi domeniu ca domeniu principal pe doua pachete de gazduire diferite."); return;
        }
    }
    for (var i = 0; i < mergeArrayStorageHosting.length; i++) {
        if (mergeArrayStorageHosting[i] == 0 || mergeArrayStorageHosting[i] == "introduceti domeniul dvs..ext") {
           alert("Va rugam sa selectati domeniul principal pentru care doriti sa fie activat pachetul de gazduire storage."); return;
        } else if (regExInvalidChars.test(mergeArrayStorageHosting[i])) {
           alert('Domeniul principal introdus contine caractere invalide.'); return;
	} else if (matchValues2[mergeArrayStorageHosting[i]] > 1) {
           alert("Va rugam sa nu puneti acelasi domeniu ca domeniu principal pe doua pachete de gazduire storage diferite."); return;
        }
    }
    for (var i = 0; i < mergeArrayServerHostname.length; i++) {
        if (mergeArrayServerHostname[i] == 0 || mergeArrayServerHostname[i] == "Introduceti hostname-ul.") {
           alert("Va rugam sa introduceti hostname-ul pentru serverul dvs."); return;
        }
    }
    for (var i = 0; i < mergeArrayCsr.length; i++) {
        if (mergeArrayCsr[i] == 0 || mergeArrayCsr[i] == "Introduceti CSR-ul.") {
           alert("Va rugam sa introduceti CSR-ul pentru certificatele SSL."); return;
        }
    }
    for (var i = 0; i < mergeArrayResellers.length; i++) {
        if (mergeArrayResellers[i] == 0 || mergeArrayResellers[i] == "introduceti domeniul dvs..ext") {
           alert("Va rugam sa selectati domeniul principal pentru care doriti sa fie activat pachetul de reseller."); return;
        } else if (regExInvalidChars.test(mergeArrayResellers[i])) {
           alert('Domeniul principal introdus contine caractere invalide.'); return;
	} else if (matchValues5[mergeArrayResellers[i]] > 1) {
           alert("Va rugam sa nu puneti acelasi domeniu ca domeniu principal pe doua pachete de reseller diferite."); return;
        }
    }

    //ajax_controller('updateSetting', 'divtest', prodEnum);
    ajax_controller('updateProductsServicesSettings', null, prodEnum, 'preloadSettings', 2, 2, 'process_order.php?go=payment');

    //END verificari-------------------------------------------------------------------------------
    //setTimeout('document.gopayment.submit()', 3000);
}



/** APELATA DIN
 * @renewals.php //aprox. line: 128
 */
function moveSelectedDomains(domainsFrom,domainsTo)
{
	var iOptionsLength = domainsFrom.options.length
	
	//Move
	for (var x=0; x<iOptionsLength; x++)
	{
		var objFrom1 = domainsFrom.options[x];
		if (objFrom1.selected)
			domainsTo.options[domainsTo.options.length] = new Option(objFrom1.text, objFrom1.value, false, false);
	}
	
	//Delete
	for (var x=(iOptionsLength-1); x>=0; x--)
	{
		var objFrom2 = domainsFrom.options[x];
		if (objFrom2.selected)
			domainsFrom.options[x] = null;
	}
	
        domainsFrom.selectedIndex = -1;
	domainsTo.selectedIndex = -1;

	var renewOpts	= document.DomRenewalForm.renew_domains_left.options.length;
	var selectedOpts = document.DomRenewalForm.renew_domains_right.options.length;
	
	//reset display
	//document.getElementById('renewal_display').update(renewOpts);
	document.getElementById('selected_display').innerHTML = selectedOpts;

}

function moveEveryDomain(domainsFrom,domainsTo)
{
	var iOptionsLength = domainsFrom.options.length;
	
	if (iOptionsLength > 500)
	{
		iOptionsLength = 500;
	}
		
	for (var x=0; x<iOptionsLength; x++)
	{
		domainsFrom.options[x].selected = true;
	}
		
	moveSelectedDomains(domainsFrom,domainsTo);
}



function sameSettingToAll(settingType, Id) {
  trSelects = new Array();
  formSelects = new Array();

  if (settingType == "contacts") {
    trId = "tr_contacts_"+Id;
    checkboxId = "all_contacts_"+Id;
  }
  else if(settingType == "nameservers") {
    trId = "tr_ns_"+Id;
    checkboxId = "all_ns_"+Id;
  }

  //selectam toate selecturile din form
  formDescendants = $(settingType).descendants();
  trDescendants = $(trId).descendants();

  if($(checkboxId).checked == true) {

     count = 0;
     for (var i = 0; i < trDescendants.length; i++)
     {
         if (trDescendants[i].type == 'select-one') {
            trSelects[count] = trDescendants[i];
            count++;
         }
     }

      count2 = 0;
      for (var j = 0; j < formDescendants.length; j++)
      {
         if (formDescendants[j].type == 'select-one') {
             formSelects[count2] = formDescendants[j];
             count2++;
         } else if (formDescendants[j].type == 'checkbox') {
              //facem disable la celelalte checkboxuri
              if(formDescendants[j].id != checkboxId) { formDescendants[j].checked = false; }
         }
      }

      //din 4 in 4 selecturi de form punem valoarea unui select de tr
      for (var k = 0; k < formSelects.length; k++)
      {      //alert(trSelects[k].value);
          //switch setting type
          if(settingType == "contacts") {
            if (k % 4 == 0) {
                formSelects[k].value  = trSelects[0].value;
                formSelects[k+1].value  = trSelects[1].value;
                formSelects[k+2].value  = trSelects[2].value;
                formSelects[k+3].value  = trSelects[3].value;
            }
          } else if(settingType == "nameservers") { formSelects[k].value = trSelects[0].value; }
            //facem disable la toate selectboxurile
            formSelects[k].disabled = true;
      }
      //facem enable la tr-ul cel bun
      for (var l = 0; l < trSelects.length; l++) { trSelects[l].disabled = false; }

  }  else {
  
     for (var j = 0; j < formDescendants.length; j++) {
         if (formDescendants[j].type == 'select-one') { formDescendants[j].disabled = false; }
        }
  }
}//end function

function distributeDomainNames(Id) {
   //selectam toate selectboxurile din acel form
   var allSelects = $$('#web_hosting select');
   var Selects = new Array();

   //parcurg toate selecturile si in functie de optiuni le modific
   for(var i = 0; i < allSelects.length; i++) {
       verification = verifyOption('ns_profile_'+Id);
       if (verification == 'only_domainscan') { option1 =  'mixed';    option2 = 'only_other'; }
       else if (verification == 'only_other') { option1 = 'only_other'; option2 = 'mixed'; }
       else if (verification == 'mixed') { option1 =  'mixed'; option2 = 'only_other'; }

       allSelects2 = substr(allSelects[i].id, 13);
       //alert(allSelects2);
       if (allSelects2 != "") {
       //refresh la selectboxes
         if($(verification+'_'+allSelects2) != null) {
           descendants = $('mixed_'+allSelects2).descendants();
           for (var k = 0; k < descendants.length; k++) {
                 if(descendants[k].type == 'select-one' && descendants[k].id != '') {
                   for (var n = 0; n < descendants[k].length; n++) {
                   IdProfil = $('ns_profile_'+Id).value;
                   valoareDreapta = descendants[k][n].value;
                   valoareStanga = Id;
                   //alert('Stanga:'+valoareStanga+'  Dreapta:'+valoareDreapta+'  IdProfil:'+IdProfil);
                   if(valoareStanga == valoareDreapta) {
                           if(IdProfil != 1) descendants[k][n].style.display = "none";
                           if(IdProfil == 1) descendants[k][n].style.display = "block";
                   }
                 }
               }
            }
         }
         //alert("Daca optiunea este: '"+verification+allSelects2+"' atunci aratam div-ul: '"+option1+allSelects2+"' si ascundem div-ul: '"+option2+allSelects2+"'");
         $(option1+allSelects2).style.display = ""; 
         $(option2+allSelects2).style.display = "none";
       }
   }

//aceleasi setari pentru storage hosting

   //selectam toate selectboxurile din acel form
   var allSelects = $$('#storage_hosting select');
   var Selects = new Array();

   //parcurg toate selecturile si in functie de optiuni le modific
   for(var i = 0; i < allSelects.length; i++) {
       verification = verifyOption('ns_profile_'+Id);
       if (verification == 'only_domainscan') { option1 =  'mixed';    option2 = 'only_other'; }
       else if (verification == 'only_other') { option1 = 'only_other'; option2 = 'mixed'; }
       else if (verification == 'mixed') { option1 =  'mixed'; option2 = 'only_other'; }

       allSelects2 = substr(allSelects[i].id, 13);
       //alert(allSelects2);
       if (allSelects2 != "") {
       //refresh la selectboxes
         if($(verification+'_'+allSelects2) != null) {
           descendants = $('mixed_'+allSelects2).descendants();
           for (var k = 0; k < descendants.length; k++) {
                 if(descendants[k].type == 'select-one' && descendants[k].id != '') {
                   for (var n = 0; n < descendants[k].length; n++) {
                   IdProfil = $('ns_profile_'+Id).value;
                   valoareDreapta = descendants[k][n].value;
                   valoareStanga = Id;
                   //alert('Stanga:'+valoareStanga+'  Dreapta:'+valoareDreapta+'  IdProfil:'+IdProfil);
                   if(valoareStanga == valoareDreapta) {
                           if(IdProfil != 1) descendants[k][n].style.display = "none";
                           if(IdProfil == 1) descendants[k][n].style.display = "block";
                   }
                 }
               }
            }
         }
         //alert("Daca optiunea este: '"+verification+allSelects2+"' atunci aratam div-ul: '"+option1+allSelects2+"' si ascundem div-ul: '"+option2+allSelects2+"'");
         $(option1+allSelects2).style.display = ""; 
         $(option2+allSelects2).style.display = "none";
       }
   }

//aceleasi setari pentru resellers

   //selectam toate selectboxurile din acel form
   var allSelects = $$('#resellers select');
   var Selects = new Array();

   //parcurg toate selecturile si in functie de optiuni le modific
   for(var i = 0; i < allSelects.length; i++) {
       verification = verifyOption('ns_profile_'+Id);
       if (verification == 'only_domainscan') { option1 =  'mixed';    option2 = 'only_other'; }
       else if (verification == 'only_other') { option1 = 'only_other'; option2 = 'mixed'; }
       else if (verification == 'mixed') { option1 =  'mixed'; option2 = 'only_other'; }

       allSelects2 = substr(allSelects[i].id, 13);
       //alert(allSelects2);
       if (allSelects2 != "") {
       //refresh la selectboxes
         if($(verification+'_'+allSelects2) != null) {
           descendants = $('mixed_'+allSelects2).descendants();
           for (var k = 0; k < descendants.length; k++) {
                 if(descendants[k].type == 'select-one' && descendants[k].id != '') {
                   for (var n = 0; n < descendants[k].length; n++) {
                   IdProfil = $('ns_profile_'+Id).value;
                   valoareDreapta = descendants[k][n].value;
                   valoareStanga = Id;
                   //alert('Stanga:'+valoareStanga+'  Dreapta:'+valoareDreapta+'  IdProfil:'+IdProfil);
                   if(valoareStanga == valoareDreapta) {
                           if(IdProfil != 1) descendants[k][n].style.display = "none";
                           if(IdProfil == 1) descendants[k][n].style.display = "block";
                   }
                 }
               }
            }
         }
         //alert("Daca optiunea este: '"+verification+allSelects2+"' atunci aratam div-ul: '"+option1+allSelects2+"' si ascundem div-ul: '"+option2+allSelects2+"'");
         $(option1+allSelects2).style.display = ""; 
         $(option2+allSelects2).style.display = "none";
       }
   }


}//end function



function changeSelectPrimaryType(Id, action) {
  if ($('main_domain_2_'+Id).value == 'ihave_1' && action == 'in') { $('mixed_1_'+Id).style.display="none"; $('mixed_2_'+Id).style.display="";}
  else if (action == 'out') { $('mixed_1_'+Id).style.display=""; $('mixed_2_'+Id).style.display="none"; $('main_domain_2_'+Id).value = '0'; }
}


function verifyOption(selectedValue) {
   var allSelects = $$('#nameservers select');
   var Values = 0;
   for(var i = 0; i < allSelects.length; i++) Values += parseFloat(allSelects[i].value);

   if(Values == allSelects.length) return "only_domainscan";
   else if(Values == allSelects.length * $(selectedValue).value) return "only_other";
   else return "mixed";
}

function verifyCheckedPaymentMethod(loc) {
    if ($('card').checked != true) {
       if ($('sms').checked != true) {
          if ($('paypal').checked != true) {
             if ($('credits').checked != true) {
               if ($('phone').checked != true) {
                  error = 1;
               } else error = 0;
             } else error = 0;
          } else error = 0;
       } else error = 0;
    } else error = 0;

    if (error == 1) alert('Va rugam sa selectati o modalitate de plata!');
    else { 
      if (verifyEmptyCart() == true) {
          document.payment_method.submit(); IElocation = '?go='+loc;
          setTimeout("window.location.href = IElocation", 0);
      } else {
          alert('Pentru a continua trebuie sa aveti cel putin un produs in cart.');
      }
    }
}
/** APELATA DIN
 * @hosting.tpl //aprox. line: 128
 */
function jumpStep(type, link) {
   if (type == 'servers') {
      //location.href = link;
      setTimeout(function() {location.href = link;} , 1000);
   }
}

function verifyEmptyCart() {
    if ($('cart_count').value == 0) {
       return false;
    } else {
       return true;
    }
}

/** APELATA DIN
 * @hosting.tpl //aprox. line: 128
 */
function moveAddToCartBtn(div, id, _length, _type, form_name, server_id, button_type) {
    _length = typeof(_length) != 'undefined' ? _length : 6;
    _type = typeof(_type) != 'undefined' ? _type : 'packages_add';
    form_name = typeof(form_name) != 'undefined' ? form_name : 'packages';
    server_id = typeof(server_id) != 'undefined' ? server_id : null;
    button_type = typeof(button_type) != 'undefined' ? button_type : 'add_to_cart';

    if (button_type == 'add_to_cart') {
      _name = 'adauga2';
    } else {
      _name = 'configure';
    }

     for (var i = 1; i <= _length; i++)
     {
         if(div+i == div+id) {
           $(div+id).update('<img border="0" src="http://www.domainscan.ro/styles/default/imageset/ro/buttons/'+_name+'.png" width="136" height="30" '+
                            'style="cursor:hand; cursor:pointer" onclick="$(\''+substr(_type, 0, -4)+'_enabled\').value=\'true\'; document.'+form_name+'.submit();">');
           $(_type).value = i;
           if (server_id != null) $('server_id').value=server_id;
        } else $(div+i).update('');
     }
}//end function


/** APELATA DIN
 * @hosting.tpl //aprox. line: 128
 */
function moveServersAddToCartBtn(div, id, _length, form_name, server_id, button_type) {

    _length = typeof(_length) != 'undefined' ? _length : 3;
    form_name = typeof(form_name) != 'undefined' ? form_name : 'order_servers';
    button_type = typeof(button_type) != 'undefined' ? button_type : 'configure';
    
    if (button_type == 'add_to_cart') {
      _name = 'adauga2';
    } else {
      _name = 'configure';
    }


     for (var i = 1; i <= _length; i++)
     {
         if(div+i == div+id) {

           $(div+id).update('<img border="0" src="http://www.domainscan.ro/styles/default/imageset/ro/buttons/'+_name+'.png" width="136" height="30" '+
                            'style="cursor:hand; cursor:pointer" onclick="document.'+form_name+'.submit();">');
           $('server_id').value=server_id;  
           //alert(server_id);
        } else $(div+i).update('');
     }
}//end function




function showHideAuctionSearch(action, divToHide) {
   if (action == 'hide') {
       $(divToHide).style.display='none';
       $('hide_show_search').style.display='';
   } else {
       $(divToHide).style.display='';
       $('hide_show_search').style.display='none';
   }
}

//window functions---------------------------------------------------
function dialogAlert(load, varArray, windowId) {
  windowId = typeof(windowId) != 'undefined' ? windowId : null;

   var params = 'load='+load+'&varArray='+varArray;
   var upperpath  = getRealPath();

   Dialog.alert({url: upperpath+"controllers/ajax_controller.php", options: {method: 'post', parameters: params}}, {
     className: "alphacube",
     width:350,
     okLabel: "Inchide fereastra",
     onOk: function() {
              //fac split la raspuns
              Arr = new Array();
              if(varArray.indexOf("|") != '-1') { varArray2 = varArray.split("|");
                for (var i = 0; i < varArray2.length; i++) { varArraySplit = varArray2[i].split("="); Arr[varArraySplit[0]] = varArraySplit[1]; }
              }
              if (Arr['action'] == 'edit_delete') location.reload(true);
              else if (Arr['action'] == 'edit') {
                if (Arr['infoType'] == "contacts") { Windows.closeAll(); dialogAlert('popupInfo','infoType=contacts|action=edit_delete', 'edit_delete_contacts'); }
                else if (Arr['infoType'] == "nameservers") { Windows.closeAll(); dialogAlert('popupInfo','infoType=nameservers|action=edit_delete', 'edit_delete_ns'); }
              }
              else if (Arr['action'] == 'add') {
                if (Arr['infoType'] == "contacts") { Windows.closeAll(); location.reload(true); }
                else if (Arr['infoType'] == "nameservers") { Windows.closeAll(); location.reload(true); }
                else if (Arr['infoType'] == "auction_watchlist") { Windows.closeAll(); }
                else if (Arr['infoType'] == "send_message_to_seller") { Windows.closeAll(); }
                else { Windows.closeAll(); location.reload(true); }
              }
              else if (Arr['action'] == 'view') {
                if (Arr['infoType'] == "auction_bids") { Windows.closeAll(); }
              }
              else Dialog.closeInfo();
              },
     id: windowId
     });

}

function textCounter(textarea, counterID, maxLen) {
    cnt = $(counterID);
    if (textarea.value.length > maxLen) {
        textarea.value = textarea.value.substring(0,maxLen);
    }
    cnt.innerHTML = maxLen - textarea.value.length;
    count = maxLen - textarea.value.length;
    if (count <= 0) alert("Va rugam sa nu depasiti 500 de caractere!");
}

function popupAction(Id, form, actionType) {
    Id = $(Id);
    //Id.disabled=true;
    var formSerialization = str_replace('&', '|', $(form).serialize());
    switch(form) {
      case "save_edit":
        ajax_controller('popupInfo', 'divVerification', 'infoType='+actionType+'|action='+form+'|'+formSerialization, 'divVerification'); //Id.value='Salveaza!'; //dimension = Windows.getFocusedWindow().getSize(); currentHeight = dimension['height']; //Windows.getFocusedWindow().setSize(null, 446+209);
      break;

      case "save_add":
        ajax_controller('popupInfo', 'divVerification', 'infoType='+actionType+'|action='+form+'|'+formSerialization, 'divVerification'); //Id.value='Adaugat!';
      break;

    }
}


//#END window functions----------------------------------------------



//tabs functions-----------------------------------------------------

/** APELATA DIN
 * @index_tab1.tpl //aprox. line: 7
 * @dom_tab1.tpl //aprox. line: 7
 */
function activateTab(Id, tabLength, icon, tabName, orientation) {
icon = typeof(icon) != 'undefined' ? icon : null;
tabName = typeof(tabName) != 'undefined' ? tabName : 'Index';
orientation = typeof(orientation) != 'undefined' ? orientation : 'orizontal';

var pos = substr(Id, -1);
if (pos == 1) {pozition1 = 3; pozition2 = 2;}
else if (pos == tabLength) {pozition1 = 4; pozition2 = 3;}
else {pozition1 = 4; pozition2 = 2;}

var tab = substr(Id, 0, -1);
   for (var i = 1; i <= tabLength; i++) {
     if ($(tab+i) == $(Id))   { processTab(tab+i, "in", pozition1, pozition2, icon, orientation, tabLength); $('tr'+tabName+'Tab'+i).style.display=""; }
     else if (i == 1)         { processTab(tab+i, "out", 1, 1, icon, orientation, tabLength); $('tr'+tabName+'Tab'+i).style.display="none";}
     else if (i == tabLength) { processTab(tab+i, "out", 2, 2, icon, orientation, tabLength); $('tr'+tabName+'Tab'+i).style.display="none";}
     else                     { processTab(tab+i, "out", 2, 1, icon, orientation, tabLength); $('tr'+tabName+'Tab'+i).style.display="none";}
   }
}



function activateTabCustom(Id, tabLength) {

var tab = substr(Id, 0, -1);
   for (var i = 1; i <= tabLength; i++) {
     if ($(tab+i) == $(Id))   { $(tab+i).className = "tabIVin";  $('trAuctionsSearch'+i).style.display=""; }
     else if (i == 1)         { $(tab+i).className = "tabIVout"; $('trAuctionsSearch'+i).style.display="none"; }
     else if (i == tabLength) { $(tab+i).className = "tabIVout"; $('trAuctionsSearch'+i).style.display="none"; }
     else                     { $(tab+i).className = "tabIVout"; $('trAuctionsSearch'+i).style.display="none"; }
   }
}

function activateTabCustom2(Id, tabLength) {

var tab = substr(Id, 0, -1);
   for (var i = 1; i <= tabLength; i++) {
     if ($(tab+i) == $(Id))   { $(tab+i).className = "tabVin";  $('trAuctions'+i).style.display=""; }
     else if (i == 1)         { $(tab+i).className = "tabVout"; $('trAuctions'+i).style.display="none"; }
     else if (i == tabLength) { $(tab+i).className = "tabVout"; $('trAuctions'+i).style.display="none"; }
     else                     { $(tab+i).className = "tabVout"; $('trAuctions'+i).style.display="none"; }
   }
}

function activateTabCustom3(Id, tabLength, aux) {

var tab = substr(Id, 0, -1);
   for (var i = 1; i <= tabLength; i++) {
     if ($(tab+i) == $(Id))   { $(tab+i).className = "tabVin";  $('tr_'+aux+'_'+i).style.display=""; }
     else if (i == 1)         { $(tab+i).className = "tabVout"; $('tr_'+aux+'_'+i).style.display="none"; }
     else if (i == tabLength) { $(tab+i).className = "tabVout"; $('tr_'+aux+'_'+i).style.display="none"; }
     else                     { $(tab+i).className = "tabVout"; $('tr_'+aux+'_'+i).style.display="none"; }
   }
}

/** APELATA DIN
 * @this->activateTab()
 */
function processTab(Id, _type, pozition1, pozition2, icon, orientation, tabLength) {
    orientation = typeof(orientation) != 'undefined' ? orientation : 'orizontal';

    var pos = substr(Id, -1);
    //alert(pos);

    if (orientation == 'orizontal') {
      
      if (icon == null) { middle1 = 2; middle2 = 4; middle3 = 5; left = 3; right = 6; }
      else { middle1 = 2; middle2 = 4; middle3 = 11; left = 3; right = 12; }

      $(Id).down(middle1).setStyle({backgroundImage: 'url(http://www.domainscan.ro/styles/default/imageset/ro/tabs/middle_'+_type+'.gif)'});
      $(Id).down(middle2).setStyle({backgroundImage: 'url(http://www.domainscan.ro/styles/default/imageset/ro/tabs/middle_'+_type+'.gif)'});
      $(Id).down(middle3).setStyle({backgroundImage: 'url(http://www.domainscan.ro/styles/default/imageset/ro/tabs/middle_'+_type+'.gif)'});
      $(Id).down(left).src = 'http://www.domainscan.ro/styles/default/imageset/ro/tabs/left_'+_type+pozition1+'.gif';
      $(Id).down(right).src = 'http://www.domainscan.ro/styles/default/imageset/ro/tabs/right_'+_type+pozition2+'.gif';
    
    } else {

       if (pos < tabLength) pozition = ''; else pozition = '2';

      $(Id).down(3).src = 'http://www.domainscan.ro/styles/default/imageset/ro/headings/design6/style2/top_left_'+_type+'.gif';
      $(Id).down(4).setStyle({backgroundImage: 'url(http://www.domainscan.ro/styles/default/imageset/ro/headings/design6/style2/top_middle_'+_type+'.gif)'});
      $(Id).down(5).src = 'http://www.domainscan.ro/styles/default/imageset/ro/headings/design6/style2/top_middle_'+_type+'.gif';
      $(Id).down(7).src = 'http://www.domainscan.ro/styles/default/imageset/ro/headings/design6/style2/top_right_'+_type+'.gif';
      $(Id).down(9).setStyle({backgroundImage: 'url(http://www.domainscan.ro/styles/default/imageset/ro/headings/design6/style2/left_middle_'+_type+'.gif)'});
      if (_type == 'in') $(Id).down(10).setStyle({backgroundColor: '#FFFFFF'}); else $(Id).down(10).setStyle({backgroundColor: '#F7F7F7'});
      $(Id).down(17).setStyle({backgroundImage: 'url(http://www.domainscan.ro/styles/default/imageset/ro/headings/design6/style2/right_middle_'+_type+'.gif)'});
      $(Id).down(20).src = 'http://www.domainscan.ro/styles/default/imageset/ro/headings/design6/style2/bottom_left_'+_type+pozition+'.gif';
      $(Id).down(21).setStyle({backgroundImage: 'url(http://www.domainscan.ro/styles/default/imageset/ro/headings/design6/style2/bottom_middle_'+_type+pozition+'.gif)'});
      $(Id).down(22).src = 'http://www.domainscan.ro/styles/default/imageset/ro/headings/design6/style2/bottom_middle_'+_type+pozition+'.gif';
      $(Id).down(24).src = 'http://www.domainscan.ro/styles/default/imageset/ro/headings/design6/style2/right_bottom_'+_type+pozition+'.gif';


    }
}

//#END tabs functions-------------------------------------------------

function loadFlowPlayer() {

//flowplayer("player", "http://www.domainscan.ro/flv/flowplayer/flowplayer-3.2.7.swf");

flowplayer("player", "http://www.domainscan.ro/flv/flowplayer/flowplayer-3.2.7.swf", {

	// change the default controlbar to modern
	plugins: {
		controls: {
			url: 'flowplayer.controls-3.2.5.swf',
			
			buttonColor: 'rgba(0, 0, 0, 0.9)',
			buttonOverColor: '#000000',
			backgroundColor: '#D7D7D7',
			backgroundGradient: 'medium',
			sliderColor: '#FFFFFF',
			
			sliderBorder: '1px solid #808080',
			volumeSliderColor: '#FFFFFF',
			volumeBorder: '1px solid #808080',
			
			timeColor: '#000000',
			durationColor: '#535353'
		}
	},
	clip: {
    	autoPlay: true /*,
    	scaling: 'orig'*/
    }
	
});


}

function displayInfo(id, posY, posX, width, height) {

posY = typeof(posY) != 'undefined' ? posY : 20;
posX = typeof(posX) != 'undefined' ? posX : -20;
width = typeof(width) != 'undefined' ? width : 200;
height = typeof(height) != 'undefined' ? height : 100;


var div = $('info_div');
//schimbam vizibilitatea meniului
if (div.className == "hide") div.className = "show";
else { div.className = "hide"; document.body.removeChild(div); }

//pozitia unde sa fie afisat meniul
var x = findPosX($(id));
var y = findPosY($(id));

//determinam pozitia meniului
div.style.left = (x+posX)+'px'; div.style.top = (y+posY)+'px';
div.style.width =  width+'px';  div.style.height = height+'px';

//setam durata si vizibilitatea meniului
//div.onmouseover = function() { div.className = "show"; }
//div.onmouseout = function() { div.className = "hide"; }

}// end function

function submitValidationForm(_type) {

  if (_type == 'card') {

    if(document.validation_card_form.onsubmit()) {
      document.validation_card_form.submit();
    }

  } else if (_type == 'sms') {

    if(document.validation_sms_form.onsubmit()) { 
      document.validation_sms_form.submit(); 
    }

  } else if (_type == 'paypal') {

      if(document.validation_paypal_form.onsubmit()) {
      document.validation_paypal_form.submit();
    }

  } else if (_type == 'credits') {

  if(document.validation_credits_form.onsubmit()) {
      document.validation_credits_form.submit();
    }

  } else if (_type == 'phone') {

    if(document.validation_phone_form.onsubmit()) {
      document.validation_phone_form.submit();
    }

  }

}

function submitValidationSmsForm() { if(document.validation_sms_form.onsubmit()) { document.validation_sms_form.submit(); /*windowSetSize(440,200);*/ }}
function submitValidationPhoneForm() { if(document.validation_phone_form.onsubmit()) { document.validation_phone_form.submit(); /*windowSetSize(440,200);*/ }}
function submitNewsletterForm() { if(document.newsletter_form.onsubmit()) { document.newsletter_form.submit(); }}
function submitPaymentForm() { document.payment.submit(); /*if(document.payment.onsubmit()) { document.payment.submit(); }*/ }
function submitDomainRenewalForm() { if(document.DomRenewalForm.onsubmit()) { $('continue').value = "true"; document.DomRenewalForm.submit(); }}
/** APELATA DIN
 * @host_renewal.tpl //aprox. line: 128
 */
function submitHostingRenewalsForm() { if(document.host_renewals.onsubmit()) { document.host_renewals.submit(); }}
function submitResellersRenewalsForm() { if(document.resellers_renewals.onsubmit()) { document.resellers_renewals.submit(); }}
function submitResellersUpgradeDowngradeForm() { if(document.resellers_upgrade_downgrade.onsubmit()) { document.resellers_upgrade_downgrade.submit(); }}
/** APELATA DIN
 * @host_upgrade_downgrade.tpl //aprox. line: 128
 */
function submitHostingUpgradeDowngradeForm() { if(document.host_upgrade_downgrade.onsubmit()) { document.host_upgrade_downgrade.submit(); }}
function submitServersRenewalsForm() { if(document.serv_renewals.onsubmit()) { document.serv_renewals.submit(); }}
/** APELATA DIN
 * @ssl_renewals.tpl
 */
function submitSSLCertificatesRenewalsForm() { if(document.ssl_certificates_renewals.onsubmit()) { document.ssl_certificates_renewals.submit(); }}
function submitBulkRegisterForm() { if(document.bulk_register.onsubmit()) { $('continue_img').src = "http://www.domainscan.ro/styles/default/imageset/ro/buttons/please_wait_disabled.png"; setTimeout("document.bulk_register.submit()", 600); }}
//function submitBulkTransferForm() { if(document.bulk_transfer.onsubmit()) { setTimeout("document.bulk_transfer.submit()", 600); }}

function submitWeekOfferForm() { if(document.week_offer.onsubmit()) {
  if ($('offerOrderDomain').innerHTML != 'nici un domeniu in comanda...') {
     document.week_offer.submit();
 } else {
     alert('Va rugam sa adaugati un domeniu la comanda dvs.!');
}}}

function validateCCForm() {

	 var vdt = new Validator("payment");

	 vdt.addValidation("card_number","minlen=16", "Lungimea numarului cardului trebuie sa fie de 16 de caractere. Nu inserati spatii intre numere.");
	 vdt.addValidation("card_number","maxlen=16", "Lungimea numarului cardului trebuie sa fie de 16 de caractere. Nu inserati spatii intre numere.");
	 vdt.addValidation("card_number","req", "Campul 'numar card' este obligatoriu!");
	 vdt.addValidation("card_number","numeric", "Numarul de card trebuie sa contina doar cifre!");

	 vdt.addValidation("card_fullname","maxlen=50", "Lungimea numelui si prenumelui nu trebuie sa depaseasca 50 de caractere.");
	 vdt.addValidation("card_fullname","req", "Campul 'nume complet' este obligatoriu!");
	 vdt.addValidation("card_fullname","alphabetic_space", "Numele si prenumele dvs. nu este corect!");

	 vdt.addValidation("card_exp_date_month","dontselect=00", "Selectati 'luna expirarii cardului'!");

	 vdt.addValidation("card_exp_date_year","dontselect=0000", "Selectati 'anul expirarii cardului'!");

	 vdt.addValidation("card_cvv2","minlen=3", "Lungimea numarului CVV2-ului trebuie sa fie de 3 caractere. Nu inserati spatii intre numere.");
	 vdt.addValidation("card_cvv2","maxlen=3", "Lungimea numarului CVV2-ului trebuie sa fie de 3 caractere. Nu inserati spatii intre numere.");
	 vdt.addValidation("card_cvv2","req", "Campul 'CVV2' este obligatoriu!");
	 vdt.addValidation("card_cvv2","numeric", "Numarul CVV2 trebuie sa contina doar cifre!");

}

function DoCustomValidation() {
	$('verify').disabled = true;
        $('verify').value = 'Va rugam sa asteptati pana cand domeniile sunt verificate...';
        return true;
}
/*
function DoCustomValidation2(_type, div) {
  var descendants = $(div).descendants();
  var result = 0;
  for (var i = 0; i < descendants.length; i++) {
        if (descendants[i].type == "checkbox") {
            if (descendants[i].checked == true) result = 1;
        }
  }
  if (result != 1) { 
    if (_type == 'domains_renewals') alert("Va rugam sa selectati cel putin un domeniu pentru reinoire.");
    else if (_type == 'hosting_renewals') alert("Va rugam sa selectati cel putin un pachet de gazduire pentru reinoire.");
    else if (_type == 'hosting_upgrade_downgrade') alert("Va rugam sa selectati cel putin un pachet de gazduire pentru upgradare / downgradare.");
    else if (_type == 'servers_renewals') alert("Va rugam sa selectati cel putin un server pentru reinoire.");
    else if (_type == 'ssl_certificates_renewals') alert("Va rugam sa selectati cel putin un certificat SSL pentru reinoire.");
    else if (_type == 'resellers_renewals') alert("Va rugam sa selectati cel putin un pachet de reseller pentru reinoire.");
    return false;
   } else return true;
}
*/

function DoCustomValidation2() {
  var descendants = $('customer_products_services').descendants();
  var result = 0;
  for (var i = 0; i < descendants.length; i++) {
        if (descendants[i].type == "checkbox") {
            if (descendants[i].checked == true) result = 1;
        }
  }
  if (result != 1) { alert("Va rugam sa selectati cel putin un produs pentru a continua."); return false; }
  else return true;
}


function SubmitBulkRenewals()
{
	var frm = document.DomRenewalForm;
	var bSubmitForm = true;

	var iOptionsLength = frm.renew_domains_right.options.length;
	if (iOptionsLength < 501) {
		for (var x=0; x<iOptionsLength; x++) {
			frm.renew_domains_right.options[x].selected = true;
		}
	} else {
		alert('Poti selecta maxim 500 de domenii pentru reinoire.');
		bSubmitForm = false;
	}
	if ((frm.renew_domains_right.value=='') && (bSubmitForm)) {
		alert('Te rugam sa selectezi domeniile pe care doresti sa le reinoiesti.');
		bSubmitForm = false;
	}
	if (bSubmitForm) {
		submitDomainRenewalForm();
	}
}
/** APELATA DIN
 * @ssl_products.tpl //aprox. line: 128
 */
 function showResellerTypes() {

  var descendants = $('reseller_packages').descendants();
  for (var i = 0; i < descendants.length; i++) {
        if (descendants[i].type == "checkbox" && descendants[i].id != "all") {
            if (descendants[i].checked == true) { /*alert('true-'+descendants[i].id);*/ $(descendants[i].id+'_resellers').style.display = '';}
            else { /*alert('false-'+descendants[i].id);*/ $(descendants[i].id+'_resellers').style.display = 'none'; }
     }
  }
 }

/** APELATA DIN
 * @ssl_products.tpl //aprox. line: 128
 */
function showSubmenus(type) {
    for (var i = 1; i <= 3; i++) {
        if (i == 1) submenu = 'dedicated_servers';
        else if (i == 2) submenu = 'virtual_dedicated_servers';
        else if (i == 3) submenu = 'server_administration';
        
        if (submenu == type) {
          if ($('submenu_'+submenu).style.display == 'none') { $('arrow_'+submenu).src = 'http://www.domainscan.ro/styles/default/imageset/ro/arrows/arrow.gif'; effect('BlindDown', 'submenu_'+submenu, 0.5); ajax_controller('serversMenu', null, 'menu='+type); }
          else { $('arrow_'+submenu).src = 'http://www.domainscan.ro/styles/default/imageset/ro/arrows/arrow3.gif'; effect('BlindUp', 'submenu_'+submenu, 0.5); ajax_controller('serversMenu', null, 'menu=none'); }
        }
        else { $('arrow_'+submenu).src = 'http://www.domainscan.ro/styles/default/imageset/ro/arrows/arrow3.gif'; effect('BlindUp', 'submenu_'+submenu, 0.5); }
    }
}

/** APELATA DIN
 * @ssl_products.tpl //aprox. line: 128
 */
function showSubmenus2(type) {
    //alert(type);
    for (var i = 1; i <= 6; i++) {
        if (i == 1) submenu = 'domains';
        else if (i == 2) submenu = 'web_hosting';
        else if (i == 3) submenu = 'storage_hosting';
        else if (i == 4) submenu = 'servers';
        else if (i == 5) submenu = 'ssl_certificates';
        else if (i == 6) submenu = 'resellers';

        if (submenu == type) {
                              
          if ($('submenu_'+submenu).style.display == 'none') {
            $('arrow_'+submenu).src = 'http://www.domainscan.ro/styles/default/imageset/ro/arrows/arrow7.gif';
            effect('BlindDown', 'submenu_'+submenu, 0.5);
            //ajax_controller('serversMenu', null, 'menu='+type);
          
          } /*else {
            $('arrow_'+submenu).src = 'http://www.domainscan.ro/styles/default/imageset/ro/arrows/arrow8.gif';
            effect('BlindUp', 'submenu_'+submenu, 0.5);
            //ajax_controller('serversMenu', null, 'menu=none');
          }*/
        } else {
          $('arrow_'+submenu).src = 'http://www.domainscan.ro/styles/default/imageset/ro/arrows/arrow8.gif';
          effect('BlindUp', 'submenu_'+submenu, 0.5);
        }
    }
}

function effect(type, div, duration_length) {
  //scriptaculous
  switch(type) {
  case "BlindDown":  Effect.BlindDown(div, {duration:duration_length}); break;
  case "BlindUp":  Effect.BlindUp(div, {duration:duration_length}); break;
  case "BlindLeft":  Effect.BlindLeft(div); break;
  case "BlindRight":  Effect.BlindRight(div); break;
  }

  //jquery
/*  switch(type) {
  case "BlindDown":  $j('#'+div).slideDown(); break;
  case "BlindUp":  $j('#'+div).slideUp(); break;
  }*/
}

/** APELATA DIN
 * @server_applications.php //aprox. line: 128
 */
function showServDetails(id) {
    var tbody = $('tbody_'+id);
    if (tbody.style.display == 'none') {
        tbody.style.display = '';
      $('img_'+id).src='http://www.domainscan.ro/styles/default/imageset/ro/minus.gif';
    }
    else {
      tbody.style.display = 'none'; 
      $('img_'+id).src='http://www.domainscan.ro/styles/default/imageset/ro/plus.gif'; 
    }
}

/** APELATA DIN
 * @dom_domain_transfer.php //aprox. line: 128
 */
function verifyTransferCodes() {
 var txt = $$('#divTransferCodes input[id]');
 var result = 0;
 var codes = "";
     for (var i = 0; i < txt.length; i++) {
         if (txt[i].type == "text") {
            if (txt[i].value == "") result = 1;
            codes += "code"+substr(txt[i].id, 4)+"="+txt[i].value+"|";
         }
     }
     if (result == 1) { alert("Va rugam sa introduceti codul de transfer pentru fiecare domeniu."); }
     else if ($('agree').checked == false) { alert("Pentru a continua trebuie sa fiti de acord cu termenii si conditiile noastre."); }
     else {  ajax_controller('updateTransferDomain', null, codes+"action=update_code", null, 1, 1, '../process_order.php?go=cart'); }
}

function createEl(to, el, tagId, tagStyle, tagClass, tagHTML)
{
    to = typeof(to) != 'undefined' ? to : null;
    tagId = typeof(tagId) != 'undefined' ? tagId : null;
    tagStyle = typeof(tagStyle) != 'undefined' ? tagStyle : null;
    tagClass = typeof(tagClass) != 'undefined' ? tagClass : null;
    tagHTML = typeof(tagHTML) != 'undefined' ? tagHTML : null;

//fac split la style
if (tagStyle != null) {
  if(tagStyle.indexOf("|") != '-1') {
    tagStyle = tagStyle.split("|");
    for (var i = 0; i < tagStyle.length; i++)
    {
      tagStyle_value = tagStyle[i].split("=");
      tagStyle[tagStyle_value[0]] = tagStyle_value[1];
    }
  }
}
    $(to).append(el, tagId, tagStyle, tagClass, tagHTML);
}


//php equivalent functions-------------------------------------------
function strstr( haystack, needle, bool ) {
    var pos = 0;

    haystack += '';
    pos = haystack.indexOf( needle );
    if( pos == -1 ){
        return false;
    } else{
        if( bool ){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}

function array_count_values( array ) {

    var tmp_arr = {}, key = '', t = '';
    
    var __getType = function(obj) {
        // Objects are php associative arrays.
        var t = typeof obj;
        t = t.toLowerCase();
        if (t == "object") {
            t = "array";
        }
        return t;
    }    
 
    var __countValue = function (value) {
        switch (typeof(value)) {
            case "number":
                if (Math.floor(value) != value) {
                    return;
                }
            case "string":
                if (value in this) {
                    ++this[value];
                } else {
                    this[value] = 1;
                }
        }
    };
    
    t = __getType(array);
    if (t == 'array') {
        for ( key in array ) {
            __countValue.call(tmp_arr, array[key]);
        }
    } 
    return tmp_arr;
}

function substr( f_string, f_start, f_length ) {
    f_string += '';
 
    if(f_start < 0) {
        f_start += f_string.length;
    }
 
    if(f_length == undefined) {
        f_length = f_string.length;
    } else if(f_length < 0){
        f_length += f_string.length;
    } else {
        f_length += f_start;
    }
 
    if(f_length < f_start) {
        f_length = f_start;
    }

    return f_string.substring(f_start, f_length);
}


function array_merge() {

    var args = Array.prototype.slice.call(arguments);
    var retObj = {}, k, j = 0, i = 0;
    var retArr;
    
    for (i=0, retArr=true; i < args.length; i++) {
        if (!(args[i] instanceof Array)) {
            retArr=false;
            break;
        }
    }
    
    if (retArr) {
        return args;
    }
    var ct = 0;
    
    for (i=0, ct=0; i < args.length; i++) {
        if (args[i] instanceof Array) {
            for (j=0; j < args[i].length; j++) {
                retObj[ct++] = args[i][j];
            }
        } else {
            for (k in args[i]) {
                if (is_int(k)) {
                    retObj[ct++] = args[i][k];
                } else {
                    retObj[k] = args[i][k];
                }
            }
        }
    }
    
    return retObj;
}


function str_replace(search, replace, subject) {

    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}

function sleep(seconds) {

    var start = new Date().getTime();
    while (new Date() < start + seconds*1000);
    return 0;
}

function print_r( array, return_val ) {

    var output = "", pad_char = " ", pad_val = 4;
 
    var formatArray = function (obj, cur_depth, pad_val, pad_char) {
        if (cur_depth > 0) {
            cur_depth++;
        }
 
        var base_pad = repeat_char(pad_val*cur_depth, pad_char);
        var thick_pad = repeat_char(pad_val*(cur_depth+1), pad_char);
        var str = "";
 
        if (obj instanceof Array || obj instanceof Object) {
            str += "Array\n" + base_pad + "(\n";
            for (var key in obj) {
                if (obj[key] instanceof Array) {
                    str += thick_pad + "["+key+"] => "+formatArray(obj[key], cur_depth+1, pad_val, pad_char);
                } else {
                    str += thick_pad + "["+key+"] => " + obj[key] + "\n";
                }
            }
            str += base_pad + ")\n";
        } else if(obj == null || obj == undefined) {
            str = '';
        } else {
            str = obj.toString();
        }
 
        return str;
    };
 
    var repeat_char = function (len, pad_char) {
        var str = "";
        for(var i=0; i < len; i++) { 
            str += pad_char;
        };
        return str;
    };
    output = formatArray(array, 0, pad_val, pad_char);

    if (return_val !== true) {
        document.write("<pre>" + output + "</pre>");
        return true;
    } else {
        return output;
    }
}

function array_count_values( array ) {
    var tmp_arr = {}, key = '', t = '';
    
    var __getType = function(obj) {
        // Objects are php associative arrays.
        var t = typeof obj;
        t = t.toLowerCase();
        if (t == "object") {
            t = "array";
        }
        return t;
    }    
 
    var __countValue = function (value) {
        switch (typeof(value)) {
            case "number":
                if (Math.floor(value) != value) {
                    return;
                }
            case "string":
                if (value in this) {
                    ++this[value];
                } else {
                    this[value] = 1;
                }
        }
    };
    
    t = __getType(array);
    if (t == 'array') {
        for ( key in array ) {
            __countValue.call(tmp_arr, array[key]);
        }
    } 
    return tmp_arr;
}



//#END php equivalent functions--------------------------------------


//preloaders----------------------------------------------------------
function preload(divArray, preloaderAction, preloaderStyle) {
  //alert(div+' '+preloaderType);
  var divs = new Array();
  if (preloaderStyle == 1) { var preloaderHTML = '<div style="height: 100%; width: 100%;" align="center"><img border="0" src="http://www.domainscan.ro/styles/default/imageset/ro/ajax-loader.gif"></div>'; }
  else if (preloaderStyle == 2) { var preloaderHTML = '<table cellpadding="0" cellspacing="0" class="smallmedium_txt_black_b"><tr><td>Se incarca...&nbsp;&nbsp;</td><td><img border="0" src="http://www.domainscan.ro/styles/default/imageset/ro/ajax-loader.gif"></td></tr></table>'; }

      if (preloaderAction == 'on') {
        if(divArray.indexOf("|") != '-1') {
          divs = divArray.split("|");
          for (var i = 0; i < divs.length; i++) {
            $(divs[i]).style.display = "";
            $(divs[i]).update(preloaderHTML);
          }
        } else {
            divs[0] = divArray;
            $(divs[0]).style.display = "";
            $(divs[0]).update(preloaderHTML);

        }
      } else {
          if(divArray.indexOf("|") != '-1') {
            divs = divArray.split("|");
            for (var i = 0; i < divs.length; i++) {
              $(divs[i]).update('');
            }
        } else {
            divs[0] = divArray;
            $(divs[0]).update('');
        }
      }

}
//end function preloader

function GetWidth() {
    var x = 0;
    if (self.innerHeight) { x = self.innerWidth; }
    else if (document.documentElement && document.documentElement.clientHeight) { x = document.documentElement.clientWidth; }
    else if (document.body) { x = document.body.clientWidth; }
    return x;
}

function GetHeight() {
    var y = 0;
    if (self.innerHeight) { y = self.innerHeight; }
    else if (document.documentElement && document.documentElement.clientHeight) { y = document.documentElement.clientHeight; }
    else if (document.body) { y = document.body.clientHeight; }
    return y;
}

//functii pentru determinarea pozitiei unui obiect
function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {
		posTop += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return posTop;
}
function findPosX(obj) {
	var posLeft = 0;
	while (obj.offsetParent) {
		posLeft += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return posLeft;
}
