var baseURL = "http://www.luanababymall.com/";

function stergeComandaUser(x) {
    if (confirm("Are you sure you want to delete the selected order ?")) {
       document.location=baseURL+"myorders/?do=del&id="+x;
    }
}

function votePic(care,vcc) {
  
  var cc = document.getElementById("checkcode"+care).value;

  if (cc=="" || cc==null) {
    alert("Enter the security code from the image");
  } else if (cc!=vcc) {
    alert("The security code you entered does not match the security code from the image");
  } else {
      document.activeForm.action.value="voteazapoza";
      document.activeForm.selpic.value=care;
      document.activeForm.submit();
  }
}

function showPicVoteDiv(care) {
    document.getElementById("votepic"+care).style.display = "block";
}

function hidePicVoteDiv(care) {
    document.getElementById("votepic"+care).style.display = "none";
}

function checkFormPic() {
     var fisier = document.activeForm.new_file.value;
     var numecopil =  document.activeForm.onew_nume.value;
     var anicopil = document.activeForm.onew_ani.value;
     var lunicopil = document.activeForm.onew_luni.value;
     var descriere = document.activeForm.onew_desc.value;
     if (fisier=="" || fisier==null) {
           alert("Browse for an image");
     } else {
         var extensia = fisier.substring(fisier.length-3,fisier.length).toLowerCase();
         if (extensia!="jpg" && extensia!="jpeg" && extensia!="gif") {
            alert("The selected image is not in GIF or JPEG format");
         } else {
             if (numecopil=="" || numecopil==null || descriere=="" || descriere==null) {
                 alert("Fill all the fields");
             } else {
                 if (anicopil==0 && lunicopil==0) {
                    alert("Enter the child age");
                 } else {
                     if (anicopil==4 && lunicopil>0) {
                         alert("The maximum age is 4 years");
                     } else {
                         document.activeForm.action.value="uploadfile";
                         document.activeForm.submit();
                     }
                 }
             }
         }
      }
}

function uploadContestPic(x) {
   if (x==0) {
      alert("You must login to upload an image");
      document.location=baseURL+"login/";
   } else {
      document.location=baseURL+"concurs-participa/";
   }
}

function addForumMsg(x) {
   if (x==0) {
      alert("You must login to post forum messages");
      document.location=baseURL+"login/";
   } else {

	window.scrollTo(0,0);
    var objBody = document.getElementsByTagName("body").item(0);
    var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() { myLightbox.end(); }
	objBody.appendChild(objOverlay);

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
	if (!e) var e = window.event;
	   var clickObj = Event.element(e).id;
		if ( clickObj == 'lightbox') {
			myLightbox.end();
		}
	};
	objBody.appendChild(objLightbox);

	hideSelectBoxes();
	hideFlash();

	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);

        new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: 0.8 });
	document.getElementById("div-forum-mesaj").style.display = "block";
   }
}

function addArtMsg(x) {
   if (x==0) {
      alert("You must login to post product messages");
   } else {

	window.scrollTo(0,0);
    var objBody = document.getElementsByTagName("body").item(0);
    var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() { myLightbox.end(); }
	objBody.appendChild(objOverlay);

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
	if (!e) var e = window.event;
	   var clickObj = Event.element(e).id;
		if ( clickObj == 'lightbox') {
			myLightbox.end();
		}
	};
	objBody.appendChild(objLightbox);

	hideSelectBoxes();
	hideFlash();

	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);

        new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: 0.8 });
	document.getElementById("div-articol-mesaj").style.display = "block";
   }
}


function showContestRules() {

    window.scrollTo(0,0);
    var objBody = document.getElementsByTagName("body").item(0);
    var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() { myLightbox.end(); }
	objBody.appendChild(objOverlay);

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
	if (!e) var e = window.event;
	   var clickObj = Event.element(e).id;
		if ( clickObj == 'lightbox') {
			myLightbox.end();
		}
	};
	objBody.appendChild(objLightbox);

	hideSelectBoxes();
	hideFlash();

	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);

    new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: 0.8 });
	document.getElementById("div-concurs-regulament").style.display = "block";
}

function showPage(x) {
    document.activeForm.crntPage.value=x;
    document.activeForm.submit();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openPage(page_name,x,y,scroll,target) {

    window.open(''+page_name+'', ''+target+'', 'width='+x+',height='+y+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');

    //return false;

}


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 isDateTime(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 validEmail(address) {

if (address.length==0) {
  return (true);
}
else
{
if (address.length>=6) {
if (address.indexOf("@")>0) {
if ((address.indexOf("@")+1)<address.lastIndexOf(".")) {
if (address.lastIndexOf(".")<(address.length-2)) {
return (true);
}
}
}
}
}
return (false);
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }



function isDate (date2check) {

    if (date2check.length!=10) return false;

    var year = date2check.substr(0,4);

    var month = date2check.substr(5,2);

    var day = date2check.substr(8,2);

    var today = new Date();

    year = ((!year) ? y2k(today.getYear()):year);

    month = ((!month) ? today.getMonth():month-1);

    if (!day) return false

    var test = new Date(year,month,day);

    if ( (y2k(test.getYear()) == year) &&

         (month == test.getMonth()) &&

         (day == test.getDate()) )

        return true;

    else

        return false

}



function isTime (time2check) {

    if (time2check.length!=8) return false;

    var hour = time2check.substr(0,2);

    var min = time2check.substr(3,2);

    var sec = time2check.substr(6,2);

    if ((hour>=0 && hour<=24 ) && (min>=0 && min<=60) && (sec>=0 && sec<=60))

	     return true;

	   else

	     return false;

}



String.prototype.capitalize = function() {

    return this.replace(/\w+/g, function(a){

        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();

    });

};

function add2Cart(x) {
    var buc = document.getElementById("qty").value;
    var size_prod = 0;
    var color_prod = 0;
    var tmp = "";
    var stoc_art = 0;
    for (var i=0; i<document.activeForm.length; i++) {

	    n = document.activeForm[i].name;
	    v = document.activeForm[i].value;

	    if (n=="size_prod" && document.activeForm[i].checked) {
               size_prod = v;
	    }
	    if (n=="color_prod" && document.activeForm[i].checked) {
               tmp = v.split('-');
	    }
    }

    color_prod = tmp[0];
    stoc_art = tmp[1];

    if (!isNumeric(buc) || buc==0 || buc==null || buc=="" || buc<0) {
       alert("Please enter a numeric positive value as quantity");
    } else if (size_prod==0) {
       alert("Pick a size");
    } else if (color_prod==0) {
       alert("Pick a color");
    } else if (buc>stoc_art) {
         alert("The available quantity for your selection is "+stoc_art+" pcs.");
    } else {
      add2CartDO(x,buc,size_prod,color_prod);
    }

}

function delFromCart(x) {
   if (confirm("Are you sure you want to delete the selected product from the cart ?")) {
       document.activeForm.action.value="delfromcart";
       document.activeForm.selid.value=x;
       document.activeForm.submit();
   }
}

function delAllFromCart() {
   if (confirm("Are you sure you want to delete all the products from the cart ?")) {
       document.activeForm.action.value="delallfromcart";
       document.activeForm.submit();
   }
}

function checkRegisterForm() {
    var err;
    err="";

    if (!validEmail(document.activeForm.onew_email.value)) {
       err = "The email address is not valid";
    }

    var parola = document.activeForm.onew_parola.value;
    var parola2 = document.activeForm.onew_parola2.value;

    if (parola.length<6) {
       err = "The password must be at least 6 characters long.";
    }

    if (parola!=parola2) {
       err = "The password and the confirmation does not match.";
    }

    for (var i=0; i<document.activeForm.length; i++) {

	    n = document.activeForm[i].name;
	    v = document.activeForm[i].value;

	    if ((v=="" || v==null) && n.substr(0,5)=="onew_")
		    err="Fill all the  fields.";
    }

    if (err=="") {
        document.activeForm.action.value="register";
        document.activeForm.submit();
    } else {
        alert(err);
    }
}

function checkUpdatePswdForm() {
    var err;
    err="";

    var parola = document.activeForm.onew_parola.value;
    var parola2 = document.activeForm.onew_parola2.value;

    if (parola.length<6) {
       err = "The new password must be at least 6 characters long.";
    }

    if (parola!=parola2) {
       err = "The new password and the confirmation does not match.";
    }

    for (var i=0; i<document.activeForm.length; i++) {

	    n = document.activeForm[i].name;
	    v = document.activeForm[i].value;

	    if ((v=="" || v==null) && n.substr(0,5)=="onew_")
		    err="Fill all the fields.";
    }

    if (err=="") {
        document.activeForm.action.value="changepswd";
        document.activeForm.submit();
    } else {
        alert(err);
    }
}

function checkUpdateAccountForm() {
    var err;
    err="";

    if (!validEmail(document.activeForm.onew_email.value)) {
       err = "The email address is not valid";
    }

    for (var i=0; i<document.activeForm.length; i++) {

	    n = document.activeForm[i].name;
	    v = document.activeForm[i].value;

	    if ((v=="" || v==null) && n.substr(0,5)=="onew_")
		    err="Fill all the fields";
    }

    if (err=="") {
        document.activeForm.action.value="updatemyaccount";
        document.activeForm.submit();
    } else {
        alert(err);
    }
}

function checkEnter(e){
var characterCode;// literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e;
characterCode = e.which; //character code is contained in NN4's which property
}
else{
e = event;
characterCode = e.keyCode; //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
login(); //submit the form
return false;
}
else{
return true;
}

}

function checkEnterS(e){
var characterCode;// literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e;
characterCode = e.which; //character code is contained in NN4's which property
}
else{
e = event;
characterCode = e.keyCode; //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
searchSite(); //submit the form
return false;
}
else{
return true;
}

}

function checkEnterN(e){
var characterCode;// literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e;
characterCode = e.which; //character code is contained in NN4's which property
}
else{
e = event;
characterCode = e.keyCode; //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
newsletterSubscribe(); //submit the form
return false;
}
else{
return true;
}

}

function login(){

var username = document.getElementById("login_username").value;
var parola = document.getElementById("login_parola").value;


if (username=="" || username==null || parola=="" || parola==null) {
    alert("Enter your e-mail and password");
} else {
    document.activeForm.action.value="login";
    document.activeForm.submit();
}

}

function finishOrder(x) {
   if (x==0) {
      alert("Add at least one product in your shopping cart.");
   } else {
   if (confirm("Are you sure you want to finish the order ?")) {
       window.location=baseURL+"send-order";
   }
   }
}

function nlfocus() {
  if (document.getElementById("newslettermail").value=="your email") {
      document.getElementById("newslettermail").value="";
  }
}

function nlblur() {
  if (document.getElementById("newslettermail").value=="") {
      document.getElementById("newslettermail").value="your email";
  }
}

function sfocus() {
  if (document.getElementById("searchtxt").value=="site search") {
      document.getElementById("searchtxt").value="";
  }
}

function sblur() {
  if (document.getElementById("searchtxt").value=="") {
      document.getElementById("searchtxt").value="site search";
  }
}

function searchSite() {
   var stxt = document.getElementById("searchtxt").value;
   if (stxt=="" || stxt==null || stxt.length<3 || stxt=="site search") {
       alert("Enter a text at least 3 characters long");
   } else {
      window.location=baseURL+"search/index.php?stxt="+stxt;
   }
}

function closeOrderDetails() {
    document.getElementById("detaliicomanda").style.display="none";
}
