
function trim (s)
{
	var i, j, str;
	lng = s.length;	
	i = 0;
	

	if (lng == 0)
		return "";
		
	while (s.substr(i, 1) == " " && i < lng)
		i ++;

	if (i>0) {
		s = s.substr (i);
		lng = lng - i;
		}
		
	j = lng - 1;	
	
	while (s.substr(j, 1) == " " && j > 0)
		j --;		
			
	if (j < lng - 1) 	
		s = s.substr(0, j + 1);
			
	return s;
}

function isNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
function isInt(sText){
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
         }
      }
   return IsNumber;
   
}


function GetElementById(ename)
{
	var obj;
	
	if (document.all)
	{
		eval("obj = document.all[\"" + ename + "\"]");
	}
	else if (document.layers)
	{		
		eval("obj = document.layers[\"" + ename + "\"]");
	}
	else if (document.getElementById)
	{	
		eval("obj = document.getElementById (\"" + ename + "\")");		
	}
	else	
		obj = undefined;

	return obj;
}



function formCheck(formobj, fieldRequired, fieldDescription, alertMsg){
	var l_Msg = alertMsg.length;
    for (var i = 0; i < fieldRequired.length; i++){
        var obj = formobj.elements[fieldRequired[i]];
        if (obj){
            if (obj.type == null){
                var blnchecked = false;
                for (var j = 0; j < obj.length; j++){
                    if (obj[j].checked){
                        blnchecked = true;
                    }
                }
                if (!blnchecked){
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
                continue;
            }

            switch(obj.type){
	            case "select-one":
	                if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].value == ""){
	                    alertMsg += " - " + fieldDescription[i] + "\n";
	                }
	                break;
	            case "select-multiple":
	                if (obj.selectedIndex == -1){
	                    alertMsg += " - " + fieldDescription[i] + "\n";
	                }
	                break;
	            case "text":
	            case "password":
	            case "textarea":
	                if (obj.value == "" || obj.value == null){
	                    alertMsg += " - " + fieldDescription[i] + "\n";
	                }
	                break;
	            default:
            }
        }
    }

    if (alertMsg.length == l_Msg){
        return true;
    }else{
        alert(alertMsg);
        return false;
    }
}

function showElement(elem){
	var obj = GetElementById(elem);
	
	if (obj){
		obj.style.display = "";
	}
}

function hideElement(elem){
	var obj = GetElementById(elem);
	
	if (obj){
		obj.style.display = "none";
	}
}

	function rememberPassword(backref){
		var objEmail = GetElementById('customers_email');
		
		if (objEmail && objEmail.value != ''){
			document.location.href = 'login.php?action=remember-password&email=' + objEmail.value + '&backref=' + backref;
		}
		else {
			alert('Completati adresa de email pentru care doriti reamintirea parolei.');
			return false;
		}
	}

	
	function checkMail(field) {
		var obj = GetElementById(field);
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(obj.value)) {
			return true
		}
		else {
			alert("Va rugam introduceti o adresa de email valida.");
			return false;
		}
		
	}













function switch_tabs(index){
	if (index=="fiz"){
		var c=GetElementById('tab_acc_juridic');
		var o=GetElementById('tab_acc_fizica');
	}
	else{
		var c=GetElementById('tab_acc_fizica');
		var o=GetElementById('tab_acc_juridic');
		
	}

	if (c){
		c.style.display = "none";
	}
	
	if (c){
		o.style.display = "";
	}
}

function GetElementByIdPopup(ename)
{
	var obj;

	if (window.opener.document.all)
		{
		eval("obj = window.opener.document.all[\"" + ename + "\"]");
		}
	else if (window.opener.document.layers)
	{		
		eval("obj = window.opener.document.layers[\"" + ename + "\"]");
	}
	else if (window.opener.document.getElementById)
	{	
		eval ("obj = window.opener.document.getElementById (\"" + ename + "\")");		
	}
	else	
		obj =  undefined;

	return obj;
}

function GetInputByName (ename)
{
		
	var f = document.forms [fname];
	
	return f[ename];
	
}

function PopupWindow(File,Name)
{
	window.open(File,'' + Name,'width=500,height=450, scrollbars=yes,screenX=0,left=0,screenY=0,top=0');
}

function PopupWindowEx(File, Name, width, height)
{
	window.open(File,'' + Name,'width=' + width + ',height=' + height + ', scrollbars=yes,screenX=0,left=0,screenY=0,top=0');
}

function CheckLength(ob,maxLength,objSpan)
{ 
	var objSp = GetElementById(objSpan)
	var val = maxLength - ob.value.length;
	objSp.innerHTML = "Mai aveti " + val + " caractere disponibile.";
	if (ob.value.length > maxLength)
	{ 
		objSp.innerHTML = "You have 0 characters left.";
		temp1=ob.value; ob.value="";ob.value = temp1.substring(0, maxLength);
		alert("Puteti introduce maxim " +maxLength+ " caractere!"); 
	} 
}

		
function SetFocus(elName)	
{
	var objElement = GetInputByName(elName)
	objElement.focus();
}

function ChangeClass(newClass, oldClass, objElement)
{
	if (newClass != "")
	{
		if (objElement.className != "rowSelected")
			objElement.className = newClass;
	}
	else
	{
		if (objElement.className == "rowMouseOver")
			objElement.className = oldClass;
	}
}

function ReplaceChar( strIn, strCharIn, strCharOut )
{
	while (strIn.indexOf(strCharIn) > 0)
		strIn = strIn.replace (strCharIn, strCharOut);
	return strIn;
}

function formatNumber(nStr){
		
	nStr = nStr.toFixed(2);
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}

function returnPrice(nrKg, envelopePrice, parcelPrice, extraKgValue, asigValue, asigProcent)
{
	var price = 0;
	if ((nrKg > 0) && (nrKg < 0.5))
		price = envelopePrice;
	else if ((nrKg >= 0.5) && (nrKg < 1))
		price = parcelPrice;
	else if (nrKg >= 1)
	{
		price = parcelPrice;
		var exKg = nrKg -1;
		price += exKg * extraKgValue;
	}
	
	if ((asigValue > 0) && (nrKg > 0))
	{
		asigValue = (asigValue * asigProcent) / 100;
		price += asigValue;
	}
	
	return price;
}

function randomString() 
	{
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}


function OpenTabs(tab)
{
	var objTd = document.frames[0].tdLeftColumn;
	var objComand = document.frames[0].spComand;
	var objOper = document.frames[0].spOper;
	
	if (tab == "operation")
	{
		objTd.style.display = "";
		objOper.style.display = "";
		
		GetElementById("spShowOperation").style.display="none";
	}
	else
	{
		objTd.style.display = "";
		objComand.style.display = "";
		GetElementById("spShowComand").style.display="none";
	}
}

function CloseTabs(tab, IsVisible)
{
	if (IsVisible)
		tabIsVisible = "";
	else
		tabIsVisible = "none";
		
	var objTd = GetElementById("tdLeftColumn");
	var objComand = GetElementById("spComand");
	var objOper = GetElementById("spOper");
	
	if (objTd && objComand )//&& objOper)
	{
		var comandVisible = objComand.style.display;
		var operVisible = "";
		if (objOper)
			operVisible = objOper.style.display;
		
		if (tab == "operation")
		{
			objOper.style.display = tabIsVisible;
			if (comandVisible == tabIsVisible)
				objTd.style.display = tabIsVisible;
			
			parent.spShowOperation.style.display = "";
		}
		else
		{
			objComand.style.display = tabIsVisible;
			if (objOper)
			{
				if (operVisible == tabIsVisible)
					objTd.style.display = tabIsVisible;
			}
			else
			{
				objTd.style.display = tabIsVisible;
			}
			
			parent.spShowComand.style.display = "";
		}
	}
}

function OpenWebDialog(page, width, height)
{
	if (checkIt('msie'))
		window.showModalDialog(page, null,'status:no;dialogWidth:'+ width +'px;dialogHeight:' + height + 'px;dialogHide:true;help:no;scroll:no');
	else
		PopupWindowEx(page, "DialogForm", width, height);
}

/*var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";
*/

function checkIt(string)
{
	var detect = navigator.userAgent.toLowerCase();
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function SwitchAdvancedSearch(advSearch)
{
	var objAdvSearch = GetElementById("advancedSearch");
	var objAdvSearchFields = GetElementById("advancedSearchFields");
	var objBasicSearch = GetElementById("basicSearch");
	
	if (advSearch)
	{
		objAdvSearch.style.display = "none";
		objBasicSearch.style.display = "";
		objAdvSearchFields.style.display = "";
	}
	else
	{
		objAdvSearch.style.display = "";
		objBasicSearch.style.display = "none";
		objAdvSearchFields.style.display = "none";
	}
}

function LaunchPrintExtended(pageUrl, popName, width, height, qs)
{
	var objChkTotals = GetElementById("chkTotals");
	var objChkListing = GetElementById("chkListing");
	var type = "all";
	if 	((objChkTotals) && (objChkListing))
	{
		if ((objChkTotals.checked) && (!objChkListing.checked))
			type = "total";
		if ((!objChkTotals.checked) && (objChkListing.checked))
			type = "listing";
		if ((!objChkTotals.checked) && (!objChkListing.checked))
		{
			alert("Pentru a putea printa aceasta pagina trebuie selectat cel putin unul din cele 2 criterii de printare(Totaluri/Lista)!");
			objChkTotals.focus();
			return;
		}
	}	
	
	if (width == null)
		width = 950;
		
	if (popName == null)
		popName = "Fereastra_Printare";
		
	if (height == null)
		height = 650;		
		
	if (qs == null)
		pageUrl += "?printType=" + type;
	else
		pageUrl += "&printType=" + type;
	window.open(pageUrl, popName, "width=" + width + ",height=" + height + ",scrollbars=yes,screenX=0,left=0,screenY=0,top=0");
}

function LaunchPrint(pageUrl, popName, width, height)
{
	if (width == null)
		width = 950;
		
	if (popName == null)
		popName = "Fereastra_Printare";
		
	if (height == null)
		height = 650;		
		
	window.open(pageUrl, popName, "width=" + width + ",height=" + height + ",scrollbars=yes,screenX=0,left=0,screenY=0,top=0");
}

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function CheckCookieEnabled()
{
	var cookieEnabled=(navigator.cookieEnabled)? true : false

	//if not IE4+ nor NS6+
	if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
	document.cookie="testcookie"
	cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
	}

	if (cookieEnabled) 
		return true;
	else
		return false;
	
}

function GeneralSubmit(action, isSubmit, hiddenName)
{
	var objHidden = GetElementById(hiddenName);
	if (objHidden)
		objHidden.value = action;
	else
		return false;
	
	if (!isSubmit)
		objForm.submit();
	else
		return true;
}

function hasJavaScript(){
	return true;
}

function verifyJavaScript(){
	if (!hasJavaScript()){
		document.location.href = "enable-js.php";
	}
}


function submitFilter(){
	var obj = GetElementById('promotion_filter');
	if (obj){
		obj.submit();
	}
}
function validateSearch(){
	var objValue = GetElementById("q");
	if (objValue && objValue.value != ""){
		return true;
	}
return false;
}

var myWidth = 0, myHeight = 0;
function getSize() {

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

}
function reinitializeTot(){
	getSize();
	
	if(myWidth<1025){
		document.getElementById('tot').style.width="1050px";
	}else{
		document.getElementById('tot').style.width="100%";
	}
}
function reinitializeBoxes(){
	
	try{
		for(i=1;i<=ids;i++){
			
			var elm = document.getElementById('ob_contentRow_'+i);
			var x =elm.offsetHeight;
			elm.style.height=x+"px";
			
			//document.getElementById('contentRow_'+ids[i]).style.height=x+"px";
			document.getElementById('ob_middleLeft_'+i).style.height=x+"px";
			document.getElementById('ob_middleRight_'+i).style.height=x+"px";	
		}
	}catch(e){
	}
}
function reinitializeBox(idBox){
		try{
		
		var elm = document.getElementById('ob_contentRow_'+idBox);
		
		var x =elm.offsetHeight;
		
		elm.style.height=x+"px";
			

		document.getElementById('ob_middleLeft_'+idBox).style.height=x+"px";
		document.getElementById('ob_middleRight_'+idBox).style.height=x+"px";	
		
	}catch(e){
	}
}
function reinitializeBoxHeight(idBox,Height){
		try{
		
		var elm = document.getElementById('ob_contentRow_'+idBox);
		
		elm.style.height=Height+"px";
			

		document.getElementById('ob_middleLeft_'+idBox).style.height=Height+"px";
		document.getElementById('ob_middleRight_'+idBox).style.height=Height+"px";	
		
	}catch(e){
	}
}
function reinitializeThisBox(Container,BoxId){
	setTimeout('reinitializeBoxHeight('+BoxId+','+document.getElementById(Container).offsetHeight+')',300);
	//reinitializeBoxHeight(BoxId,document.getElementById(Container).offsetHeight);
	//alert(document.getElementById(Container).offsetHeight+' '+BoxId);
}
