
/*~ functions.php
.---------------------------------------------------------------------------.
|  Software: DSWebsite - Domain registration and web hosting                |
|   Version: 2.0                                                            |
|   Contact: office@domainscan.ro                                           |
|      Info: http://www.domainscan.ro                                       |
|   Support: http://www.domainscan.ro/DSWebsite/                            |
| ------------------------------------------------------------------------- |
|   Author : Cimpean Andrei (original founder & project administrator)      |
| Copyright (c) 2007-2009, FUTURE WEB SRL. All Rights Reserved.             |
|  Address : 405200, Dej, Str. George Cosbuc, nr. 21, Jud. CLUJ             | 
|    Phone : +4 0264-223631 , fax: +4 0264-214035                           |
|  Website : www.futureweb.ro                                               |
|    Email : officeATfutureweb.ro                                           |
| ------------------------------------------------------------------------- |
|   License: Distributed under the Licence                                  |
| This program is distributed in the hope that it will be useful - WITHOUT  |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     |
| FITNESS FOR A PARTICULAR PURPOSE.                                         |
| ------------------------------------------------------------------------- |
|   ____                                     _       _                      |
|  |  __| _   _  _____  _   _  ____  ____   \ \  _  / \ ____  __            |
|  |  _| | |_| ||_   _|| |_| || --_|/ -__\  \ \_/_\_/ // -__\| -/_          |
|  |_|   |_____|  |_|  |_____||_|\_\|__\    \___/ \__/ |__\  |__-/          |
|  						the change comes inside you                         |
|                                                                           |
| ------------------------------------------------------------------------- |
| Tot continutul acestui fisier este proprietatea intelectuala FUTURE WEB . |
'---------------------------------------------------------------------------'

/**
* DSWebsite - main website interface
* NOTE: Designed for use with PHP version 5 and up
* @package PHPMailer
* @author Cimpean Andrei
* @copyright 2007 - 2009 FUTURE WEB SRL
*/


  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);
  }});

function preloadLoagingImage() {
  var image = new Image();
  image .src = "{$imagefolder}ajax-bar-loader.gif";
}
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/wait_dis.gif";

      if (popup != null) {
      image_url[10] = "http://www.domainscan.ro/js/popup/themes/alphacube/frame-left.gif";
      image_url[11] = "http://www.domainscan.ro/js/popup/themes/alphacube/frame-right.gif";
      image_url[12] = "http://www.domainscan.ro/js/popup/themes/alphacube/bottom-left-c.gif";
      image_url[13] = "http://www.domainscan.ro/js/popup/themes/alphacube/bottom-middle.gif";
      image_url[14] = "http://www.domainscan.ro/js/popup/themes/alphacube/bottom-right-c.gif";
      image_url[15] = "http://www.domainscan.ro/js/popup/themes/alphacube/left-top.gif";
      image_url[16] = "http://www.domainscan.ro/js/popup/themes/alphacube/right-top.gif";
      image_url[17] = "http://www.domainscan.ro/js/popup/themes/alphacube/top-middle.gif";
      }

       for(var i=0; i<=image_url.length; i++) 
          preload_image_object.src = image_url[i];

}

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 forgotPass(Id) {
  var action;
       if (Id == "dscustomer") { action = 'http://www.domainscan.ro/customer/forgot_password.php'; }
  else if (Id == "cpanel")     { action = 'http://server1.domainscan.ro:2082/'; }
  else if (Id == "webmail")    { action = 'http://server1.domainscan.ro:2082/'; }
  else if (Id == "ftp")        { action = 'http://server1.domainscan.ro:2082/';  }
  location.href=action;
}

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, 'ext_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, 'ext_checkboxex', 'all'); }
             }
         }
      }
  }
}

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;
        }
     }
  }
}

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(strstr(varArray, "|", true) != null) { 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('removeFromCartTransfer', '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){
  //verifying null args--------------------------------------------
  preloader = typeof(preloader) != 'undefined' ? preloader : null;

 //setam url-ul controlerului si parametrii------------------------
 var upperpath  = getRealPath();
 var url = upperpath+'controllers/ajax_controller.php';
 //alert(url);
 var params = 'load=' + load + '&varArray=' + varArray;

 //preloader start--------------------------------------------------
  if (preloader != null) { preload(preloader); }

    new Ajax.Request(url,
    {method: 'post',
    parameters: params,
    onSuccess: function(transport) {
                    if(strstr(divArray, "|", true) != null) { divs = divArray.split("|"); }
                    //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 (preloader != null) { preload("hide", preloader); }
    },
    onFailure: function(){ result.update('Error'); return 0; }
    });
}//end functionn
//========================================END AJAX MAIN CONTROLLER====================================

function getRealPath() {
     url = window.location.pathname; url = url.split("/");  url = url[1];
     if (substr(url, -4, -3) == ".") urlPath = "";
     else if (url == "controllers") urlPath = "../../";
     else urlPath = "../";
     return urlPath;
}

//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(strstr(response, "|", true) != null) {
  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 "addToCart":
             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(\'removeFromCart\', \''+divs+'|cartCount1|cartCount2|cartCount3\', \'prod_name='+resp['prod_name']+'|prod_id='+resp['prod_id']+'|registration_type='+resp['registration_type']+'\');"  style="cursor:hand; cursor:pointer">';
             }
        break;

        case "removeFromCart":
             if (divs == "cartCount1" || divs == "cartCount2" || divs == "cartCount3") {
               response = resp['count'];
             } else {
               response = '<input type="checkbox" name="C3" value="ON" '+
                          'onclick="ajax_controller(\'addToCart\', \''+divs+'|cartCount1|cartCount2|cartCount3\', \'prod_name='+resp['prod_name']+'|prod_id='+resp['prod_id']+'|qty=1|period=1|period_type=y|registration_type='+resp['registration_type']+'\');">';
             }
        break;
        
        case "paymentFees":
             if (divs == "paymentSubTotal") response = resp['total'];
             if (divs == "paymentFee") response = resp['fee'];
             if (divs == "paymentTotal") response = resp['total'];
        break;

    }
    return response;
}//end function



function setBgcolor(id, type, outBg) {
  if (type == "over") $(id).setStyle({backgroundColor: '#e8ffc7'});
  else $(id).setStyle({backgroundColor: outBg});
}//end function

function getProdNameservers(domain_name) {

   NameserversTrs = $$('#nameservers tr[id]'); var ns;
    for (var i = 0; i < NameserversTrs.length; i++) {
        ext = new Array();
        ext = NameserversTrs[i].id.split("."); 
        extLength = ext[1].length+1; 
        exten = '.'+ext[1]; 
        prodName = substr(NameserversTrs[i].id, 4, -extLength);

        //nameservers
        nameserver = $('nameserver_select'+prodName+exten);
        if(nameserver != null && domain_name == prodName+exten)
        ns = nameserver.value;
    }
    return ns;
}

function getProdMainDomains(package_name) {

    HostingTrs = $$('#hosting_packages tr[id]'); var mainDomain;
    for (var i = 0; i < HostingTrs.length; i++) {
        if (HostingTrs[i].id != 'trHost') { prodName = substr(HostingTrs[i].id, 6); }
        else prodName = null;

        if (prodName != null) {//alert('main_domain1'+prodName);
            selectbox = ($('main_domain2'+prodName).up('span').style.display == "none") ? null : $('main_domain2'+prodName);
            selectboxExt = null;

            if(selectbox == null) if($('ihave1'+prodName).up('span').style.display == "none") { selectbox = null; }
            else { selectbox = $('ihave1'+prodName); selectboxExt = $('ihave1Ext'+prodName); }

            //if(selectbox == null) selectbox = ($('main_domain2'+prodName).up('span').style.display == "none") ? null : $('main_domain2'+prodName);
    
            if(selectbox == null) if($('ihave2'+prodName).up('span').style.display == "none") { selectbox = null; }
            else { selectbox = $('ihave2'+prodName); selectboxExt = $('ihave2Ext'+prodName); }
    
            //main domains
            if(selectboxExt == null && package_name == prodName) mainDomain = selectbox.value;
            else if(selectboxExt != null && package_name == prodName) mainDomain = selectbox.value+'.'+selectboxExt.value;

        }
    }
    return mainDomain;
}

function processProdSettings() {
    ContactsTrs = $$('#contacts tr[id]');
    NameserversTrs = $$('#nameservers tr[id]');
    HostingTrs = $$('#hosting_packages tr[id]');

    prod = new Array();

    //aflam contactele-----------------------------------------------
    for (var i = 0; i < ContactsTrs.length; i++) {
        ext = new Array(); prod[i] = new Array();
        if(strstr(ContactsTrs[i].id, ".", true) != false) { ext = ContactsTrs[i].id.split("."); extLength = ext[1].length+1; exten = '.'+ext[1]; prodName = substr(ContactsTrs[i].id, 10, -extLength);}
        else { extLength = 0; ext[1] = ""; exten = ""; prodName = substr(ContactsTrs[i].id, 10); }

        prod[i]['prodName'] = prodName;

        //contact detinator
        contactDetinator = $('contactDetinator'+prodName+exten);
        if (contactDetinator.style.display != "none") {
          prod[i]['prodExt'] = ext[1];
          prod[i]['prodDetinatorId'] = contactDetinator.value;
          //gasim nameserverele
          prod[i]['prodNameserversId'] = getProdNameservers(prod[i]['prodName']+'.'+prod[i]['prodExt']);
        }  else {
          //gasim domeniile principale
          prod[i]['prodMainDomainName'] = getProdMainDomains(prod[i]['prodName']);
        }

        //contact administrativ
        contactAdmin = $('contactAdmin'+prodName+exten);
        if (contactAdmin.style.display != "none") { prod[i]['prodAdminId'] = contactAdmin.value; }

        //contact tehnic
        contactTehnic = $('contactTehnic'+prodName+exten);
        if (contactTehnic.style.display != "none") { prod[i]['prodTehnicId'] = contactTehnic.value; }

        //contact facturare
        contactFacturare = $('contactFacturare'+prodName+exten);
        if (contactFacturare.style.display != "none") { prod[i]['prodFacturareId'] = contactFacturare.value; }
        //alert(prod[i]['prodFacturareId']);
 }

    //if (sameValues['prodMainDomainName'] > 1) alert(sameValues['prodMainDomainName']);
    mergeArray = new Array(); count = 0; var prodEnum;
   for (var i = 0; i < prod.length; i++) {

   if (prod[i]['prodMainDomainName'] != null) {
      mergeArray[count] = prod[i]['prodMainDomainName'];
      count++;
   }

      prodEnum += ''+i+'prodName='+prod[i]['prodName']+
                  '|'+i+'prodExt='+prod[i]['prodExt']+
                  //'|'+i+'catId='+catId+
                  //'|'+i+'subcatId='+subcatId+
                  '|'+i+'prodDetinatorId='+prod[i]['prodDetinatorId']+
                  '|'+i+'prodAdminId='+prod[i]['prodAdminId']+
                  '|'+i+'prodTehnicId='+prod[i]['prodTehnicId']+
                  '|'+i+'prodFacturareId='+prod[i]['prodFacturareId']+
                  '|'+i+'prodNameserversId='+prod[i]['prodNameserversId']+
                  '|'+i+'prodFacturareId='+prod[i]['prodFacturareId']+
                  '|'+i+'prodMainDomainName='+prod[i]['prodMainDomainName']+
                  '|';
    }

    //BEGIN verificari-----------------------------------------------------------------------------
    matchValues = array_count_values(mergeArray);
    regExInvalidChars = /[^a-zA-Z0-9-\s.]+/;

    for (var i = 0; i < mergeArray.length; i++) {
        if (mergeArray[i] == 0 || mergeArray[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(mergeArray[i])) {
           alert('Domeniul principal introdus contine caractere invalide.'); return;
	} else if (matchValues[mergeArray[i]] > 1) {
           alert("Va rugam sa nu puneti acelasi domeniu ca domeniu principal pe doua pachete de gazduire diferite."); return;
        }
    }
    
    //ajax_controller('updateSetting', 'divtest', prodEnum);
    ajax_controller('updateSetting', null, prodEnum);

    //END verificari-------------------------------------------------------------------------------
    setTimeout('document.gopayment.submit()', 500);
    //print_r(hp);
}


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 = "trContacts"+Id;
    checkboxId = "allContactsOption"+Id;
  } 
  else if(settingType == "nameservers") {
    trId = "trNs"+Id;
    checkboxId = "allNsOption"+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++)
      {
          //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 = $$('#hosting_packages 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('nameserver_select'+Id);
       if (verification == 'onlyDomainscan') { option1 =  'mixed';    option2 = 'onlyOther'; }
       else if (verification == 'onlyOther') { option1 = 'onlyOther'; option2 = 'mixed'; }
       else if (verification == 'mixed') { option1 =  'mixed'; option2 = 'onlyOther'; }

       allSelects2 = substr(allSelects[i].id, 12);
       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 = $('nameserver_select'+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_domain2'+Id).value == 'ihave1' && action == 'in') { $('1_mixed'+Id).style.display="none"; $('2_mixed'+Id).style.display="";}
  else if (action == 'out') { $('1_mixed'+Id).style.display=""; $('2_mixed'+Id).style.display="none"; $('main_domain2'+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 "onlyDomainscan";
   else if(Values == allSelects.length * $(selectedValue).value) return "onlyOther";
   else return "mixed";
}

function verifyCheckedPaymentMethod(loc) {
    if ($('card').checked != true) {
       if ($('sms').checked != true) {
          if ($('paypal').checked != true) {
             error = 1;
          } 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.');
      }
    }
}

function verifyEmptyCart() {
    cartCount = $('cartCount3').innerHTML;
    if (cartCount == 0) {
       return false;
    } else {
       return true;
    }
}

function moveAddToCartBtn(id)
{
     for (var i = 1; i <= 6; i++)
     {
         if('addPackage'+i == id) {
           $(id).update('<img border="0" src="http://www.domainscan.ro/styles/default/imageset/ro/buttons/adauga2.gif" width="132" height="24" '+
                        'style="cursor:hand; cursor:pointer" onclick="document.packages.submit();">');
           $('add').value = i;
        } else $('addPackage'+i).update();
     }
}//end function



//window functions---------------------------------------------------
function dialogAlert(load, varArray, windowId) {
  windowId = typeof(windowId) != 'undefined' ? windowId : null;

   var params = 'load='+load+'&varArray='+varArray;
   Dialog.alert({url: "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(strstr(varArray, "|", true) != null) { 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') { Windows.closeAll(); location.reload(true); }
              else Dialog.closeInfo();
              },
     id: windowId
     });

}

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-----------------------------------------------------
function activateTab(Id, tabLength, icon) {
icon = typeof(icon) != 'undefined' ? icon : null;
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); $('trIndexTab'+i).style.display=""; }
     else if (i == 1)         { processTab(tab+i, "out", 1, 1, icon); $('trIndexTab'+i).style.display="none";}
     else if (i == tabLength) { processTab(tab+i, "out", 2, 2, icon); $('trIndexTab'+i).style.display="none";}
     else                     { processTab(tab+i, "out", 2, 1, icon); $('trIndexTab'+i).style.display="none";}
   }
}

function processTab(Id, _type, pozition1, pozition2, icon) {
    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';
}

//#END tabs functions-------------------------------------------------


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 submitVerificationForm() { if(document.verification.onsubmit()) { document.verification.submit(); windowSetSize(440,200); }}
function submitNewsletterForm() { if(document.newsletter_form.onsubmit()) { document.newsletter_form.submit(); }}
function submitDomainRenewalForm() { if(document.DomRenewalForm.onsubmit()) { $('continue').value = "true"; document.DomRenewalForm.submit(); }}
function submitHostingRenewalsForm() { if(document.host_renewals.onsubmit()) { document.host_renewals.submit(); }}
function submitBulkRegisterForm() { if(document.bulk_register.onsubmit()) { $('continue_img').src = "http://www.domainscan.ro/styles/default/imageset/ro/buttons/wait_dis.gif"; 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 DoCustomValidation() {
	$('verify').disabled = true;
        $('verify').value = 'Va rugam sa asteptati pana cand domeniile sunt verificate...';
        return true;
}

function DoCustomValidation2() {
  var descendants = $('hosting_packages').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 pachet de gazduire pentru reinoire."); 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();
	}
}

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"); setTimeout('location.href="../process_order.php?go=cart";', 500); }
}

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(strstr(tagStyle, "|", true) != null) {
    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(div){
    $(div).style.display = "";     
    $(div).update('<center><img border="0" src="http://www.domainscan.ro/styles/default/imageset/ro/ajax-loader.gif"></center>');
}
//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;
}
