/** Function to fix IE6 menu dropdown **/

/** End **/

/** Function to fix IE6 png **/

/** End **/

function limitStr(str,limitNum){
	var end=' ...'
	document.write(str.substr(0,limitNum) + end);
}

function isInteger(s) {
	var i;
	if (isEmpty(s))
	if (isInteger.arguments.length == 1) return 0;
	else return (isInteger.arguments[1] == true);

	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (!isDigit(c) || (i==0 && c=="0")) return false;
	}
	return true;
}

function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}

function isDigit (c) {
	return ((c >= "0") && (c <= "9"))
}

function validateIntAdd(pid)
{	
	var o = document.getElementById('_cart_nr');
	switch (isInteger(o.value)) {
		case true:
				if(pid > '0')
				{
					document.getElementById('cart_pid').value=pid;
					document.getElementById('_cartForm').action="/cos_cumparaturi.aspx";
					document.getElementById('_cartForm').submit();

				}
			break;
		case false:
			document.getElementById('_cartForm').action="/cos_cumparaturi.aspx";
			alert("Trebuie sa adaugati minim un produs")
	}
}	

function itemUpdate(x) {
	var id=document.getElementById('itemid_'+x).value;
	var q=document.getElementById('itemnr_'+x).value;
	
	document.getElementById('_cart_action').value="Update";
	document.getElementById('_cart_item_id').value=id;
	document.getElementById('_cart_item_nr').value=q;
	document.getElementById('_cart_item_index').value=x;
	document.getElementById('cartForm').submit();
}


function itemDelete(x) {
var id=document.getElementById('itemid_'+x).value;
document.getElementById('_cart_action').value="Delete";
document.getElementById('_cart_item_id').value=id;
document.getElementById('_cart_item_index').value=x;
document.getElementById('cartForm').submit();

}

function UpdateTotalSum() {
document.getElementById('_cart_action').value="UpdateTotal";
document.getElementById('cartForm').submit();
}

function goUp(x){
	var temp=eval(document.getElementById('itemnr_'+x).value);
	document.getElementById('itemnr_'+x).value=temp + 1;
}

function goDown(x){
	document.getElementById('itemnr_'+x).value=document.getElementById('itemnr_'+x).value-1;
	if(document.getElementById('itemnr_'+x).value==0){
		alert('Cantitatea minima obligatorie este 1!');
		document.getElementById('itemnr_'+x).value=1;
	}
}

function DoCommand(msg1,msg2,msg3){
	var sw=0;	
	if((!verifyRadio("box1")) && (sw==0)){
		alert(msg1);
		sw=1;
	}
	if((!verifyRadio("box2")) && (sw==0)){
		alert(msg2);
		sw=1;
	}	
	if((!verifyRadio("box3")) && (sw==0)){
		alert(msg3);
		sw=1;
	}
	if(sw==0){	
  		document.getElementById('_cart_action').value="Command";
  		document.getElementById('cartForm').submit();
	}
}
  
function submiteaza(){
	document.getElementById('cartForm').submit();
}

function verifyRadio(checkid){
  	var checkedElements = document.getElementById(checkid).getElementsByTagName('input');
  	var ischecked=false;
  	for(i=0; i<checkedElements.length; i++)
	{
  		if((checkedElements[i].type=="radio") &&  checkedElements[i].checked)
  		ischecked=true;		
  	}
  	return ischecked; 	
}
  
function verifyType(element){
	if (element.checked){
		if(element.id == 'persoana fizica'){
			alert("Fizica");
		}
		if(element.id == 'persoana juridica'){
			alert("Juridica");
		}
	}
}  	

function limitText(id, limitNum){
	limitField=document.getElementById(id);
	if (limitField.value.length > limitNum) 
	{
		limitField.value = limitField.value.substring(0, limitNum);
	} 
}

function showPage(id){
	var totalNumberOfPages = 1;
	for(i=1; i<=totalNumberOfPages; i++) {
		if(document.getElementById('page' + i))
		document.getElementById('page' + i).style.display = 'none';
	}
	if(document.getElementById('page' + id))
		document.getElementById('page' + id).style.display = 'block';
}

function showPageName(id){
	var totalNumberOfPages = 1;
	for(i=1; i<=totalNumberOfPages; i++) {
		if(document.getElementById('pageName' + i))
		document.getElementById('pageName' + i).style.display = 'none';
	}
	if(document.getElementById('pageName' + id))
		document.getElementById('pageName' + id).style.display = 'block';
}

var birthDateE = '$!util.GetString("Param:_account_birth_date")';
var bDate = new Array();

bDate = birthDateE.split("/");

var day1 = bDate[1];
var month1 = bDate[0];
var year1 = bDate[2];


function writeDay(){
	for (var i=1;i<=31;i++) {
		document.write('<option '+ (day1==i ? (' selected="selected" value="'+i+'" ') : ('value="'+ i +'"') ) +'>'+i+'</option>');
	}
}
function writeMonth(){
	var months = new Array("Luna", "Ianuarie", "Februarie", "Martie", "Aprilie", "Mai", "Iunie", "Iulie", "August", "Septembrie", "Octombrie", "Noiembrie", "Decembrie");
	for (var m=1;m<=12;m++) {
		document.write('<option '+ (month1==m ? ' selected="selected" value="'+m+'" ' : 'value="'+m+'"') +'>'+months[m]+'</option>');
	}
}
function writeYear(){
	for (var y=1940;y<=2000;y++) {
		document.write('<option '+ (year1==y ? ' selected="selected" value="'+y+'" ' : 'value="'+y+'"') +'>'+y+'</option>');
	}
}

function checkAge()
{
	
	var now = new Date();

	var day=document.getElementById('_account_day').value;
	var month=document.getElementById('_account_month').value;
	var year=document.getElementById('_account_year').value;
	var birthdate=day+'/'+month+'/'+year;
	var birthdate2=month+'/'+day+'/'+year;
	
	document.getElementById('_acc_date_div').innerHTML = '<input type="hidden" name="_account_birth_date" id="_account_birth_date" value='+birthdate2+' />';
	
	var date_comp = birthdate.split('/');
	var birthday = new Date(date_comp[2],date_comp[1],date_comp[0]);
	
	if(Math.floor((now.getTime()-birthday.getTime())/(365*24*3600*1000)) < 18)
	{
	alert("Data introdusa nu corespunde\nTrebuie sa aveti 18 ani pentru a va crea cont");
	document.getElementById('over_18').checked=false;
	return false;
	}
}

function changeToOn(){
	if(document.getElementById('account_newsletter').value == 0) {
		document.getElementById('account_newsletter').value="on";
	} else {
		document.getElementById('account_newsletter').value = 0;
	}
}

function validate_required(field,alerttxt) {
	field.value = (field.value).replace(/^\s*|\s*$/g,'');
	with (field) {
		if (value==null||value=="") {
			alert(alerttxt);
			return false;
		}
		else {
			return true;
		}
	}
}

function validate_email(field,alerttxt) {
	with (field) {
		var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	    if (document.accountForm._account_email.value.search(emailRegEx) == -1) {
			alert(alerttxt);
			return false;
	    }
		else {
			return true;
		}
	}
}

function validate_passwd(field,alerttxt,alerttxt2) {
	with (field) {
		if (document.accountForm._account_password.value.length < 6 ) {
			alert(alerttxt);
			return false;
	    }
		else if (document.accountForm._account_password.value !== document.accountForm._account_password2.value ){
			alert(alerttxt2);
			return false;
		}
		else {
			return true;
		}
	}
}

function validate_check(field,alerttxt,alerttxt2) {
	with (field) {
		if (document.accountForm._approve.checked == false) {
			alert(alerttxt);
			return false;
		}
		else if (document.accountForm._over_18.checked == false){
			alert(alerttxt2);
			return false;
		}
		else {
			return true;
		}
	}
}

function validate_form(thisform,msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9,msg10,msg11,msg12,msg13,msg14,msg15,msg16,msg17,msg18,msg20,msg21,msg22) 
{
	with (thisform) {
		if (validate_required(_account_username,msg1)==false) {
			_account_username.focus();
			return false;
		}
		if (validate_required(_account_password,msg2)==false) {
			_account_password.focus();
			return false;
		}
		if (validate_required(_account_password2,msg3)==false) {
			_account_password2.focus();
			return false;
		}
		if (validate_passwd(_account_password,msg4,msg5)==false) {
			_account_password.focus();
			return false;
		}
		if (validate_required(_account_email,msg8)==false) {
			_account_email.focus();
			return false;
		}
		if (validate_email(_account_email,msg9)==false) {
			_account_email.focus();
			return false;
		}
		if (validate_required(_account_lastname,msg7)==false) {
			_account_lastname.focus();
			return false;
		}
		if (validate_required(_account_firstname,msg6)==false) {
			_account_firstname.focus();
			return false;
		}
		if (validate_required(_account_day,"Va rugam selectati ziua!")==false) {
			_account_day.focus();
			return false;
		}
		if (validate_required(_account_month,"Va rugam selectati luna!")==false) {
			_account_month.focus();
			return false;
		}
		if (validate_required(_account_year,"Va rugam selectati anul!")==false) {
			_account_year.focus();
			return false;
		}
		if (validate_required(_account_telephone,msg22)==false) {
			_account_telephone.focus();
			return false;
		}
		if (validate_required(_account_address1,msg15)==false) {
			_account_address1.focus();
			return false;
		}
		if (validate_required(_account_town,msg16)==false) {
			_account_town.focus();
			return false;
		}	
		if (validate_required(_account_region,msg17)==false) {
			_account_region.focus();
			return false;
		}

		if (validate_check(_approve,msg13,msg14)==false) {
			_approve.focus();
			return false;
		}
				
		if(!verify('check'))
		
		{
			alert('Campurile marcate cu \' * \' sunt obligatorii!');
			return false;
		}
	}
}

function verify(checkid){
var send = true;
var mesaj = '';
var focus;
var checkedElements = $('*', document.getElementById(checkid));

	for(i=0; i<checkedElements.length; i++)
	{
	
		if (checkedElements[i].tagName.toLowerCase() == 'input') 
		{ 
			if(checkedElements[i].getAttribute('rel'))
			{					
				if (checkedElements[i].getAttribute('rel').toLowerCase().indexOf("notblank") != -1)
				{	if(checkedElements[i].value == '')
					{	
						checkedElements[i].className="borderRosu";
						if(send) focus = checkedElements[i];
						send = false;
					}
				}
			}
		}
	}
	return send;
}

function SearchString() {
	document.getElementById('searchForm').action = "/produse_cautate.aspx?orderBy=2&orderType=asc";
	document.getElementById('searchForm').submit();
}   

function doSearchHitEnter(e){
	var keynum;
	if(window.event) // IE
	{
	keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	keynum = e.which;
	}
	if (keynum == 13){
	SearchString();
	return false;
	}
	return true;
} 

function SearchStringInstr() {
	document.getElementById('searchFormInstr').action = "/search_instr.aspx?orderBy=2&orderType=asc";
	document.getElementById('searchFormInstr').submit();
}   

function doSearchHitEnterInstr(e){
	var keynum;
	if(window.event) // IE
	{
	keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	keynum = e.which;
	}
	if (keynum == 13){
	SearchStringInstr();
	return false;
	}
	return true;
} 

function isEmail(string){
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
	else
	return false;
}

function doComment(msg1,msg2,msg3,msg4) {
	var sw=0;
	
	if (((document.getElementById('name').value.length == 0) || (document.getElementById('name').value=='Nume'))&&(sw==0)){
		alert(msg1);
		document.getElementById('name').focus();
		sw=1;
	} 
	if (document.getElementById('subscription_email3').value.length == 0){
		alert('sss');
		document.getElementById('subscription_email3').focus();
		sw=1;
	} 
	if ((document.getElementById('subscription_email3').value == 'e-mail')&&(sw==0)){
		alert(msg2);
		document.getElementById('subscription_email3').focus();
		sw=1;
	} 		 
	if ((isEmail(document.getElementById('subscription_email3').value) == false)&&(sw==0)){
		alert(msg3);
		document.getElementById('subscription_email3').focus();
		sw=1;
	}
	if (((document.getElementById('comentariu').value.length == 0) || (document.getElementById('comentariu').value=='Comentariu'))&&(sw==0))
	{
		alert(msg4);
		document.getElementById('comentariu').focus();
		sw=1;
	}
	if (sw==0)
	 {	 document.getElementById('cactType').value="comment";

		 document.getElementById('productcomment').submit();	    
	 }
}

/** editeaza cont **/

function validate_form_edit(thisform,msg6,msg7,msg8,msg9,msg13,msg14,msg15,msg16,msg17,msg18,msg20,msg21,msg22) 
{
	with (thisform) {

		if (validate_required(_account_firstname,msg6)==false) {
			_account_firstname.focus();
			return false;
		}
		if (validate_required(_account_lastname,msg7)==false) {
			_account_lastname.focus();
			return false;
		}
		if (validate_required(_account_email,msg8)==false) {
			_account_email.focus();
			return false;
		}
		if (validate_email(_account_email,msg9)==false) {
			_account_email.focus();
			return false;
		}

		if (validate_check(_approve,msg13,msg14)==false) {
			_approve.focus();
			return false;
		}
		if (validate_required(_account_address1,msg15)==false) {
			_account_address1.focus();
			return false;
		}
		if (validate_required(_account_town,msg16)==false) {
			_account_town.focus();
			return false;
		}	
		if (validate_required(_account_region,msg17)==false) {
			_account_region.focus();
			return false;
		}
		if (validate_required(_account_country,msg18)==false) {
			_account_country.focus();
			return false;
		}		
		if (validate_required(_account_telephone,msg22)==false) {
			_account_telephone.focus();
			return false;
		}
				
		if(!verify('check'))
		
		{
			alert('Campurile marcate cu \' * \' sunt obligatorii!');
			return false;
		}
	}
}

/** end editeaza cont **/

function newsletter(msg2,msg1)
{ 		
	var sw=0;

	if (document.getElementById('subscription_email').value.length == 0)
	{
		alert(msg2);
		document.getElementById('subscription_email').focus();
		sw=1;
	} 
	if ((document.getElementById('subscription_email').value == 'adresa de e-mail')&&(sw==0))
	{
		alert(msg1);
		document.getElementById('subscription_email').focus();
		sw=1;
	} 		 
	if ((isEmail(document.getElementById('subscription_email').value) == false)&&(sw==0))
	{
		alert(msg2);
		document.getElementById('subscription_email').focus();
		sw=1;
	}
if (sw==0)
{	
	location.href='/newsletter.aspx?subscription_email='+document.getElementById('subscription_email').value+'&subscription_name='+document.getElementById('subscription_name').value;
}
} 

function EditUser(msg1,msg2,msg3,msg4,msg5)    //aici incepe functia pentru "editarea de adresa" din vm-ul "luxury_delivery_addresses_edit"
{

		var sw=0;
		
    if ((document.getElementById('_addressname').value.length == 0)&&(sw==0))
		{
			alert(msg1);
			document.getElementById('_addressname').focus();
			sw=1;
		}  
		if ((document.getElementById('_address').value.length == 0)&&(sw==0))
		{
			alert(msg2);
			document.getElementById('_address').focus();
			sw=1;
		}
	
		if ((document.getElementById('_town').value.length == 0)&&(sw==0))
		{
			alert(msg3);
			document.getElementById('_town').focus();
			sw=1;
		}
		if ((document.getElementById('_region').value.length == 0)&&(sw==0))
		{
			alert(msg4);
			document.getElementById('_region').focus();
			sw=1;
		}
		if ((document.getElementById('_country').value.length == 0)&&(sw==0))
		{
			alert(msg5);
			document.getElementById('_country').focus();
			sw=1;
		}
		if (sw==0)
		{
			document.getElementById('_action').value="Edit";
			document.getElementById('deliv_address').submit();
				
		}
  }
  function DeleteUser(id)
  
  {
 		document.getElementById('_action').value="Delete";
		document.getElementById('deliv_address').submit();
	
  }

function Submite() {
		document.getElementById('order_mess').submit();
	}