preload_image_object = new Image();
image_url = new Array();
image_url[0] = "../images/ajax-loader.gif";
image_url[1] = "../images/msg.gif";
var i = 0;
for(i=0; i<=1; i++){preload_image_object.src = image_url[i];}

var clostptable='<form method=\"POST\" name=\"cflostp\" onsubmit=\"makeRequest(\'lostp.php?email=\'+document.cflostp.email.value,1);return false;\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"8\" width=\"100%\"><tr><td align=\"center\"><div class=\"infotext\">In cazul in care ai uitat parola, te rugam sa introduci mai jos adresa ta de e-mail (cea folosita la creearea contului) si vei primi in scurt timp un mesaj cu numele de utilizator si parola.</div></td></tr><tr><td align=\"center\"><br><table border=\"0\" cellpadding=\"2\" cellspacing=\"0\"><tr><td><b>E-mail:</b></td><td><input type=\"text\" name=\"email\" size=\"20\"></td><td><input type=\"submit\" style=\"cursor: pointer; background-image: url(\'../images/bok.gif\'); background-repeat: no-repeat; background-color:#FFFFFF; width: 30px; height: 21px; border: none;\" name=\"B1\" value=\"\"></td><td><input type=\"image\"  BORDER=\"0\" SRC=\"../images/bcancel.gif\" name=\"B2\" onclick=\"clearTxt(\'lostpdiv\');\"></td></tr></table><br>&nbsp;</td></tr></table></form>';
var chgpw='<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"\"><tr><td>Parola veche:</td><td><input type=\"password\" name=\"pold\" size=\"20\"></td><td></td><td></td></tr><tr><td>Parola noua:</td><td><input type=\"password\" name=\"pnew\" size=\"20\"></td><td><input type=\"submit\" value=\"Ok\" name=\"B3\"></td><td><input type=\"button\" value=\"Renunta\" name=\"B4\" onclick=\"clearTxt(\'divchg\');\"></td></tr></table>';

var picerr='<img border=\"0\" src=\"../images/msg.gif\" align=\"absmiddle\" width=\"34\" height=\"34\">';
var loadpic='<center><img border=\"0\" src=\"../images/ajax-loader.gif\" align=\"absmiddle\" width=\"20\" height=\"20\"> Va rugam asteptati...</center>';



function populateTxt(txt,ndiv) { 
   obj=document.getElementById(ndiv);
   obj.innerHTML=txt;
}
function clearTxt(ndiv){
  obj=document.getElementById(ndiv);
  obj.innerHTML='';
}

function modiq(pid,q,o,k){
 bucform='<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"right\"><b>Cantitate noua:</b> <input type=\"text\" name=\"q\" size=\"2\" value=\"'+q+'\"><input type=\"button\" value=\"Actualizeaza\" name=\"bAct\" onclick=\"fcart.pid.value=\''+pid+'\'; fcart.opt.value=\''+o+'\';fcart.action=\'cos-actualizeaza.htm\'; fcart.submit();\"><input type=\"button\" value=\"Renunta\" name=\"bRst\" onclick=\"clearTxt(\'modibuc\');cOut('+k+');\"></td></tr></table><br>&nbsp;';
 clearTxt('modibuc');
 populateTxt(bucform,'modibuc');
}

function dialog(s,u){
     if (s.length>0){
          string = s.split( "|" );
           if (string[0]=='1'){
           	if (confirm(string[1])){document.location.href='cont.htm?burl='+document.location.href;}
           }
           else{
           	alert(string[1]);
	        if((u != '')&&(string[2]=='1')){document.location.href=u;}
           }	

       }

}

var http_request;

function makeRequest(url,n) {
        http_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/html');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        switch (n){
        case 1: http_request.onreadystatechange = function1;break;
        case 2: http_request.onreadystatechange = function2;break;
        case 3: http_request.onreadystatechange = function3;break;
        default: http_request.onreadystatechange = ContentsTxt;break;
        }

        if (url.indexOf("?") == -1){
	url+='?dummy=' + new Date().getTime();
        }
        else{		
             url+='&dummy=' + new Date().getTime();
        }
        http_request.open('GET', url, true);
        http_request.send(null);
 }

function test_form(theFormName) {
  currentForm = document.getElementById(theFormName);
  eInputs = currentForm.getElementsByTagName("input");
  var t=true;
  for (i=0;i<currentForm.elements.length;i++) {

        if((currentForm.elements[i].name != 'B1')&&(currentForm.elements[i].name != 'B2')){
        if (document.forms[theFormName].elements[currentForm.elements[i].name].value=='') {  
             //alert(currentForm.elements[i].name);   
	document.forms[theFormName].elements[currentForm.elements[i].name].className="cf_error";
              t=false;
         }
          else{
	document.forms[theFormName].elements[currentForm.elements[i].name].className="cf_ok";
            }
        }

    }
  if (! t){ alert('Formular incomplet !\nTe rugam sa verifici datele introduse...\nCampurile nefolosite pot fi completate cu -\nMultumim !');}
  return t;
}


function send_form(theFormName,url) {
  theForm = document.getElementById(theFormName);
    var qs = '';
    for (e=0;e<theForm.elements.length;e++) {
        if (theForm.elements[e].name!='') {
            var name = theForm.elements[e].name;
            if (qs.indexOf('?')==-1){qs+='?';}
	else{qs+='&';}	
            qs+= name+'='+escape(theForm.elements[e].value);
        }
    }
    qs+="\n";
  //  return qs ;
  //alert(url+qs);
  makeRequest(url+qs);
  return true;
}



function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@._-";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}


function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.length-email.lastIndexOf(".") > 4){
        return false;  
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.lastIndexOf("@") == email.length-1) {  // @ must not be the last character
        return false;
    } else if (email.lastIndexOf(".") == email.length-1) {  // . must not be the last character
        return false;
    }

	
    return true;
}



//-------------modificare dimensiuni TEXTAREA -------------------
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));

var is_regexp = (window.RegExp) ? true : false;

var vbDOMtype = '';
if (document.getElementById)
{
vbDOMtype = "std";
}
else if (document.all)
{
vbDOMtype = "ie4";
}
else if (document.layers)
{
vbDOMtype = "ns4";
}

var vBobjects = new Array();

function fetch_object(idname, forcefetch)
{
  if (forcefetch || typeof(vBobjects[idname]) == "undefined")
  {
  switch (vbDOMtype)
  {
  case "std":
  {
  vBobjects[idname] = document.getElementById(idname);
  }
  break;
  
  case "ie4":
  {
  vBobjects[idname] = document.all[idname];
  }
  break;
  
  case "ns4":
  {
  vBobjects[idname] = document.layers[idname];
  }
  break;
  }
  }
  return vBobjects[idname];
}

function alter_box_height(boxid, pixelvalue)
{
var box = fetch_object(boxid);
var boxheight = parseInt(box.style.height);
var newheight = boxheight + pixelvalue;
if (newheight > 0)
{
box.style.height = newheight + "px";
}
return false;
}
//-----------END----------------------

function valButton(btn) {
var cnt = -1;
for (var i=btn.length-1; i > -1; i--) {
   if (btn[i].checked) {cnt = i; i = -1;}
   }
if (cnt > -1) return btn[cnt].value;
else return null;
} 

//-----------------------------------------
function divShow(n){
 obj=document.getElementById(n);
 obj.style.visibility='visible';
 obj.style.display='block';
}
function divHide(n){
 obj=document.getElementById(n);
 obj.style.visibility='hidden';
 obj.style.display='none';
}

function highlight(idlink) {
for (i=1;i<=6;i++){
 obj=document.getElementById('l'+i);
 if (i==idlink){
   obj.style.backgroundColor='white';
 }
 else{
   //obj.style.backgroundColor='#FFE8E8';
 }

}
}
function offlight(idex){
for (i=1;i<=6;i++){
  if(idex != i){
    obj=document.getElementById('l'+i);
    obj.style.backgroundColor='#FFE8E8';
  }
}
}

function tabclass(obj){
  var lk=document.getElementById("pnav").getElementsByTagName("a");
   for (i = 0; i < lk.length; i++) {
      lk[i].className="taboff";
   }
   if (isNaN(obj)){
     obj.className="tabon";
   }
   else{ 
     lk[obj].className="tabon";
   }
   
}

function loadTab(obj,url,msg,div){
	tabclass(obj);
	populateTxt(msg,div);
	if(url != ''){makeRequest(url);}
}
function loadTab1(obj,msg1,div1,msg,div){
	tabclass(obj);
	populateTxt(msg,div);
	populateTxt(msg1,div1);
}

function showTab(cur) { 
   obj=document.getElementById(cur);
   obj1=document.getElementById("pviz");
   obj1.innerHTML=obj.innerHTML;
}

function urlparamselect(tabinterfaceid){
  var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL
  return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
}



function lostpass(p){
 var popup = window.open("", "Popup",'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
 popup.location = 'lostpopup.php?email='+p;
}

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}