var passwortlenth=6;
var mode='';
var confirmeremovefromwishlist='';
var timeout=5000;
var BLANK_URL = 'js/blank.html'; 
var BLANK_IMG = 'js/spacer.gif';
var ACTIVECHECKOUT='';
var HIDEADDRESSLIST=true;
var openwin;
var url=location.pathname;
var errorMessages =new Array();
var delay=500;
var hidetimeout=2000;
var hideSearcResult=false;
var maxAddRecipient=0;
var AddedRecipient=1;
var lableSenderName='Name';
var lableSenderEmail='Email';
var RemoveIcon='images/list_remove_btn.gif'
var DefaultArtNummber=false;
var DefaultAmount=false;
var addresstype=0;
function getErrorMessage(name){
    

	 try{
		return errorMessages[name];
    }
    catch(e){}
}



function getElById(id){
	return(document.getElementById==null) ?
   (document.all==null ? null : document.all[id]) : document.getElementById(id);
}

function setRedirect(path){
 setTimeout('setDocumentLocation(\''+path+'\',false)',timeout);	
}


function getInputData(id){
	if(getElById(id)){
		return getElById(id).value;
	}
	
}
function getData(id){
	if(getElById(id)){
		return getElById(id).value;
	}
	
}

function getIntData(id){
	if(getElById(id)){
		return parseInt(getElById(id).value);
	}
	
}

function setData(id,val){
	if(getElById(id)){
		return getElById(id).value=val;
	}	
	
}

function setIntData(id,val){
	if(getElById(id)){
		return getElById(id).value=parseInt(val);
	}	
	
}

function setElementMode(id,mode){
	if(getElById(id)){
		getElById(id).disabled=mode;
	}
}

function HideProgressDiv(){
		div1=getElById('overlayer');
		div2=getElById('working');	
		if(div1){
			div1.style.display='none';
		}
		if(div2){
			div2.style.display='none';
		}		
}

function ShowProgressDiv(parent){
	  pa=getElById(parent);
	  h='100px';
	  if(pa){
	  	h=pa.offsetHeight+'px'
	  }
		div1=getElById('overlayer');
		div2=getElById('working');


		if(div1){
			div1.style.height=h;
			div1.style.display='block';
		}
		if(div2){
			div2.style.display='block';
		}	
}


function setFormAction(action,field,form){
	if(getElById(field)){
		getElById(field).value=action;
		document.forms[form].submit();
	}
	return false;
}


function resetForm(name){
  document.forms[name].reset();
}

function setDocumentLocation(path,addvalue){
  if(addvalue && addvalue!='undefined'){
		if(path.lastIndexOf('?')==-1){
			path+='?'+addvalue;
		}
		else{
			path+='&'+addvalue;
		}
	}
 	document.location.href=path;
 
}



function changeCurrency(obj,path){
  cur=obj.value;
  
  setDocumentLocation(path,'__currency='+cur);
}

function selectAllRelated(txt){
	if (relatedProductsCheckFlag == false) {
	 $$('.related-checkbox').each(function(elem){
	 elem.checked = true;
	 });
	 relatedProductsCheckFlag = true;
	 txt.innerHTML="unselect all";
	 } else {
	 $$('.related-checkbox').each(function(elem){
	 elem.checked = false;
	 });
	 relatedProductsCheckFlag = false;
	 txt.innerHTML="select all";
	 }
	 addRelatedToProduct();
}

function addRelatedToProduct(){
	 var checkboxes = $$('.related-checkbox');
	 var values = [];
	 for(var i=0;i<checkboxes.length;i++){
	 if(checkboxes[i].checked) values.push(checkboxes[i].value);
	 }
	 if($('related-products-field')){
	 $('related-products-field').value = values.join(',');
	 }
}


 function setPasswordForm(arg){
	 if(arg){
		 $('current_password').up(3).show();
		 $('current_password').addClassName('required-entry');

		 
		 $('password').addClassName('required-entry');
		 $('confirmation').addClassName('required-entry');
		 setData('accountmode','changepass');
	
	 }else{
		 $('current_password').up(3).hide();
		 $('current_password').removeClassName('required-entry');

		 $('password').removeClassName('required-entry');
		 $('confirmation').removeClassName('required-entry');
		 setData('accountmode','account');
	 }
 }


function validatePollAnswerIsSelected(){
 var options = $$('input.poll_vote');
 for( i in options ) {
	 if( options[i].checked == true ) {
		 return true;
	 }
 }
 return false;
}


function Reorder(id){
	setData('reorder',id);

	
	setFormAction('reorderaction','reorderaction','form-reorder');
	
}


function AddToCompareList(name,id,group,icon,number){
	setData('compareproduct',id);
	setData('comparegroup',group);
	setData('compareproductname',name);
	setData('compareproductimage',icon);
	setData('compareproductnumber',number);
	setFormAction('addtocompate','compareaction','compare-form-list');
	
}
function AddToWhislistList(name,id,group,sympol,price,mode,target){
	setData('productid',id);
	setData('productname',name);
	setData('productgroup',group);
	setData('productprice',price);
	setData('productsymbol',sympol);

	switch(mode){
		case 1:
	  var f=getElById('form-chart');
		  if(target=='TRUE'){
		  	
				f.action='/wishlist';
		  }		
		
			setFormAction('addtowhislist','productaction','form-chart');		
		break;
		default:
			var f=getElById('form-productgroup');
		  if(target=='TRUE'){
		  	
				f.action='/wishlist';
		  }	
		
			setFormAction('addtowhislist','productpaction','form-productgroup');		
		break;
	}

	
}

function RemoveFromCompareList(name,id,mode){
	conf=NormalizeOutput(confirmremovefromcompareList);

	if(mode=='one' && confirm(NormalizeOutput(confirmremovefromcompareList.replace(/%NAME%/,name)))){
		setData('compareproduct',id);
		
		setData('compareproductname',name);
		
		setFormAction('removefromcompare','compareaction','compare-form-list');		
	}
	if(mode=='all' && confirm(NormalizeOutput(confirmremoveallfromcomparelist.replace(/%NAME%/,name)))){
		setFormAction('removeallfromcompare','compareaction','compare-form-list');		
	}	
}


function CompareProducts(){
	if(openwin && close){
		openwin.close();
	}	
	page='/compare';
	
	var para='top=50,left=50,width=800,height=600,location=no,resizable=yes,scrollbars=yes';
	openwin=window.open(page,'DOCUMENTPRINT',para);
  if(openwin){
  	openwin.opener.name = "opener";
  	openwin.focus();
  }		
}

function SetCompareLocation(id){
	
	if(opener){
		opener.location.href='/'+id;
		opener.focus();
	}
	
	
}

function ReLoadOpener(){
	if(opener){
		opener.location.href=opener.location.href;
		
	}
	
}

function AddToBasket(mode ,article,target){
	
	switch(mode){
		
		case 1:
		  
		  setData('productid',article);
		  if(target=='TRUE'){
		  	var f=getElById('form-chart');
				f.action='/chart';
		  }
			setFormAction('addtocharsingle','productaction','form-chart');		  
		break;
		case 0:
		default:

		  setData('productid',article);
		  if(target=='TRUE'){
		  	var f=getElById('form-productgroup');
				f.action='/chart';
		  }
			setFormAction('addtocharsingle','productpaction','form-productgroup');
		break;
	}
	
	
}

function RemoveCharitem(id,name){
conf=NormalizeOutput(confirmdeletepos);

	if(confirm(conf.replace(/%NAME%/,name))){
		setData('productid',id);
		setFormAction('deleteitem','productaction','form-chart');

	}
	
	
return false;
}

function UpdateBasketdata(){
	
	alert(1);
}



function NormalizeOutput(value){
	
	value=value.replace(/&ouml;/,'ö');
	value=value.replace(/&Ouml;/,'Ö');
	value=value.replace(/&auml;/,'ä');
	value=value.replace(/&Auml;/,'Ä');
  value=value.replace(/&uuml;/,'ü');
  value=value.replace(/&Uuml;/,'Ü');
	value=value.replace(/&nbsp;/,' ');
	
	
	return value;
	
}

function saveSession(){

	if(window.XMLHttpRequest){
  	saveframe=new XMLHttpRequest();
  }
  else if(window.ActiveXObject){
  	saveframe=new ActiveXObject("Microsoft.XMLHTTP");
  }	
   var jetzt = new Date();
 		path='/reload?ser='+(jetzt.getTime());
	if(saveframe){
  	saveframe.onreadystatechange=function(){
    outputReload();
      return false;
  	}
  }
  saveframe.open("GET",path,true);
  saveframe.send(null); 
	
	
}
function outputReload(){
  if(saveframe.readyState==4){
    if(saveframe.status==200){
     
    	setTimeout('saveSession();',60000);
    }
  }	
	
}

function focusComment(obj,defaultvalue){
 if( obj.value == defaultvalue ) {
  obj.value = ''; 
 } else if( obj.value == '' ) {
 obj.value = defaultvalue;
 }	
	
}
function confirmRemoveWishlistItem(item,name){
	conf=NormalizeOutput(confirmeremovefromwishlist);
	if(confirm(conf.replace(/%NAME%/,name))){
		setData('productid',item);
		setData('productname',name);
		setFormAction('removefromwhislist','productpaction','form-wishlist');
		
	}
	return false;
}

function confirmRemoveWishlistAuxItem(item,name){
	conf=NormalizeOutput(confirmeremovefromwishlist);
	if(confirm(conf.replace(/%NAME%/,name))){
		setData('artid',item);
		setData('artname',name);
		setFormAction('removefromwhislist','whishaction','form-wishlist');
		
	}
	return false;
}

function confirmRemoveCartAuxItem(item,name){
	conf=NormalizeOutput(confirmeremovefromCartAux);
	if(confirm(conf.replace(/%NAME%/,name))){
		setData('basketproductid',item);
		setData('basketproductname',name);
		setFormAction('deleteitem','basketaction','form-chart-aux');
		
	}
	return false;	
}

function MoveToChartItem(item){
	
	return false;
}

function ProductToChart(){
	
	setFormAction('addtocharsingle','productpaction','form-product');
}

function MoveAllToChart(){
	alert('coming soon ');
	
}

function UpdateWishList(){
	setFormAction('updatewishlist','productpaction','form-wishlist');
}

function LoadPostForm(formname,actionname,actiontarget,modename,modetarget){
	setData(modetarget,modename);

	setFormAction(actionname,actiontarget,formname);
	return false;
	
}

function ConfirmDeleteAddress(name){
	conf=NormalizeOutput(confirmdeleteaddress);
	if(confirm(conf.replace(/%NAME%/,name))){
		
		LoadPostForm('form-address','deleteaddress','addressaction','deleteaddress','addressmode');
	}
	
	return false;
}


function CreateNewAddress(){
	LoadPostForm('form-address','newaddress','addressaction','newaddress','addressmode');
}



function SwitchSchippingAddressMode(box){
	
	if( box.value == 1 ) {
		$('shipping_addressall').show();
		$('pShipForm').hide();
		$('cShipForm').show();
	}else if( box.value == 0 ) {
		$('shipping_addressall').show();
		$('pShipForm').show();
		$('cShipForm').hide();
	}
	
	return;
	
	if(parentdiv=getElById('shipping_addressall')){
		Show('shipping_addressall');
	}
	if(box.value==1){
		try {
			$('shipping_salutation').removeClassName('validate-select');
			$('shipping_salutation').removeClassName('validation-failed');
		}catch(e) {}

		$('shipping_company').addClassName('required-entry');
		$('shipping_company').removeClassName('validation-failed');	
		$('shipping_name').removeClassName('required-entry');
		$('shipping_name').removeClassName('validation-failed');

		
		Hide('shipping_addresssalutation');
		Show('shipping_addresslegalform');
		Show('shipping_addresscompanyname');
		Show('shipping_addressperson');
		Show('shipping_uidlist');
		Hide('shipping_addressname');
		addresstype=1;
		CheckForUid(getData('state'),1);
		
	
	}
	else{
		try {
			$('shipping_salutation').addClassName('validate-select');
		}catch(e) {}
		
		$('shipping_company').removeClassName('required-entry');

		$('shipping_name').addClassName('required-entry');
		$('shipping_name').removeClassName('validation-failed');	
	
		Show('shipping_addresssalutation');
		Show('shipping_addressname');
		Hide('shipping_addresslegalform');
		Hide('shipping_addresscompanyname');
		Hide('shipping_uidlist');
		Hide('shipping_addressperson');
		addresstype=0;
		

	}	
	
}

function SubmitForm(form,next) {
	var f = new VarienForm(form);
	console.log(Form.request(form));
	
	
	return;
	f.submit = function() {
		if( this.validator.validate() ) {
			SetCheckOutStep(next,true);
			var url = '/docheckout';
			var h = getFormData(post);
			new Ajax.Request(url, {
			  method: 'post',
			  parameters: h,
  			onSuccess: function(transport) {
    			var notice = $('notice');
  			}
			});
		}
	}.bind(f);
	return f;
//	ACTIVECHECKOUT='opc-billing-checkout-step';
//	HIDEADDRESSLIST=false;
//	switchBillingAddressselect($('billing-address-select').value);
	
//	var USERISLOGED='YES';
}


function getFormData(value) {
	var l = c(value);
	var h = new Hash();
	l.each(function(v,i){
		try {
			h.set($(v).name,$(v).value);
		}catch(e) {}
	});
	return h;
}

function c(value) {
	return value.split(" ");
}

function SwitchBillingAddressMode(box){


	if( box.value == 1 ) {
		$('billing_addressall').show();
		$('pBillForm').hide();
		$('cBillForm').show();
		if($('cBill[uid][active]').checked) {
			$('uidForm').show();	
			$('uidDesc').show();	
		}else{
			$('uidForm').hide();
			$('uidDesc').hide();
		}
	}else if( box.value == 0 ) {
		$('billing_addressall').show();
		$('pBillForm').show();
		$('cBillForm').hide();
	}
	
	$('cBill[uid][active]').observe("click",function(){
		if($('cBill[uid][active]').checked){
			$('uidForm').show();
			$('uidDesc').show();
		}else{
			$('uidForm').hide();
			$('uidDesc').hide();
		}
	});
	

	
	return;

	if(parentdiv=getElById('billing_addressall')){
		Show('billing_addressall');
	}
	
	/*extraaddressdata*/
	if(box.value==1){
		try {
			$('billing_salutation').removeClassName('validate-select');
			$('billing_salutation').removeClassName('validation-failed');
		}catch(e){}

		$('billing_company').addClassName('required-entry');
		$('billing_company').removeClassName('validation-failed');	
		$('billing_name').removeClassName('required-entry');
		$('billing_name').removeClassName('validation-failed');

		
		Hide('billing_addresssalutation');
		Show('billing_addresslegalform');
		Show('billing_addresscompanyname');
		Show('billing_addressperson');
		//Hide('billing_uidlist');
		Show('billing_uid_field');
		Hide('billing_addressname');
		Show('billingsentto');
		Show('billingaddresssave');
		addresstype=1;
		CheckForUid(getData('billing_state'),1);
		 Hide('extraaddressdata');
		 if(getData('billing_personname')==''){
		 	
		 	setData('billing_personname',getData('billingfirst')+' '+getData('billinglast'));
		 }		
		
	
	}
	else{
		try {
			$('billing_salutation').addClassName('validate-select');
		}catch(e){}
		$('billing_company').removeClassName('required-entry');

		$('billing_name').addClassName('required-entry');
		$('billing_name').removeClassName('validation-failed');	
	
		Show('billing_addresssalutation');
		Show('billing_addressname');
		Hide('billing_addresslegalform');
		Hide('billing_addresscompanyname');
		//Hide('billing_uidlist');
		Hide('billing_uid_field');
		Hide('billing_addressperson');
		Show('billingsentto');
		Show('billingaddresssave');
		 Hide('extraaddressdata');
		 if(getData('billing_name')==''){
		 	
		 	setData('billing_name',getData('billingfirst')+' '+getData('billinglast'));
		 }		
		addresstype=0;
		

	}
	//alert(getData('billing_personname'));
	switch(mode){
		case 'guest':

		break;
		default:
		 Show('extraaddressdata');
		 
		 if(getData('billing_personname')==''){
		 	setData('billing_personname',getData('billingfirst')+' '+getData('billinglast'));
		 }		 
		break;
		
		
	}	
	
}


function SwitchAddressMode(box){
	if(parentdiv=$('addressall')){
		Show('addressall');
	}
	if(box.value==1){
		$('salutation').removeClassName('validate-select');
		$('salutation').removeClassName('validation-failed');

		$('cname').removeClassName('required-entry');
		$('cname').removeClassName('validation-failed');	
		$('company').addClassName('required-entry');
		$('company').removeClassName('validation-failed');

		d=$('advice-validate-select-salutation');
		if(d){
			d.outerHTML='';
		}		
		Hide('addresssalutation');
		Show('addresslegalform');
		Show('addresscompanyname');
		Show('addressperson');
		Show('uidlist');
		Hide('addressname');
		addresstype=1;
		CheckForUid(getData('state'),1);
	}
	else{
		$('salutation').addClassName('validate-select');
		$('cname').addClassName('required-entry');

		$('company').removeClassName('required-entry');
		$('company').removeClassName('validation-failed');	
		$('legal_form').removeClassName('validation-failed');		
		Show('addresssalutation');
		Show('addressname');
		Hide('addresslegalform');
		Hide('addresscompanyname');
		Hide('uidlist');
		Hide('addressperson');
		addresstype=0;
		d=$('advice-validate-select-legal_form');
		if(d){
			d.outerHTML='';
		}			
	}
}

function CheckForUid(val,id){
	obj=$('uid_country_list');
	if(id=='undefined'){
		id=0;
	}
	if(obj){
		hide=true;
		for(i=0;i<obj.options.length;i++){
			v=obj.options[i].value;
			
			if(v==val){
				hide=false;
				setData('uid_country_list',val);
				break;
			}
		}
	
		if(hide){
			Hide('uidlist');
		}
		else{
			if(id==1){
			Show('uidlist');
			}
		}
	}
	else{
		return;
	}
}


function UpdateRegion(id,target){
	CheckForUid(id,addresstype);
	if(window.XMLHttpRequest){
  	reload=new XMLHttpRequest();
  }
  else if(window.ActiveXObject){
  	reload=new ActiveXObject("Microsoft.XMLHTTP");
  }	
  var jetzt = new Date();
 	path='/axjaxrequest?mode=LoadCountryList&state='+id+'&ser='+(jetzt.getTime());
	if(reload){
  	reload.onreadystatechange=function(){
    renderCountrySelect(target);
      return false;
  	}
  }
  reload.open("GET",path,true);
  reload.send(null);	
  d=$('advice-validate-select-'+target);
  c=$(target);
  if(c && c.removeClassName){
  	c.addClassName('validate-select');
  	c.removeClassName('validation-failed');

  }
	if(d){
		d.outerHTML='';
	}
	
}

function renderCountrySelect(target){
	
  if(reload.readyState==4){
    if(reload.status==200){
    	HideProgressDiv();
    	opts=NormalizeOutput(reload.responseText);
      objTargetSelect=getElById(target);	
      mandator=getElById('required_'+target);
      objTargetSelect.disabled=false;
    	if(opts!='' && opts.length>1){
	      if(document.all){
					opts = '<option>ie hack</option>' + opts;
				}
				objTargetSelect.innerHTML = opts;
				if(document.all) { // Or any IE testing
					objTargetSelect.outerHTML = objTargetSelect.outerHTML;
				}
			  if(mandator){
				  mandator.style.display='inline';	 
				  objTargetSelect.addClassName('validate-select');
		  
			  }		
    	}
    	else{
				objTargetSelect.innerHTML = '';
        objTargetSelect.disabled=true;
        if(mandator){
				  mandator.style.display='none';	
					
					objTargetSelect.removeClassName('validate-select');
					
        }
				   		
    	}
    }
  }
  	
}


function SwapMainImage(id,timeoute){
	container=getElById('imageid');
	if(container){
		container.style.cssText='';
		container.src="loadthumbnail.php?id="+id;
		product_zoom = new Product.Zoom('imageid', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
	  if(timeoute){
	  	 setTimeout('SwapMainImage('+id+',false)',500);	
	  }
	}
}


function UpdateMutationAndPrice(obj,targetobj,aid){
	ShowProgressDiv('product-order');
	setData('productid',DefaultArticleId);
	setButtonEnableMode(false,'send2');
	if(window.XMLHttpRequest){
  	reload=new XMLHttpRequest();
  }
  else if(window.ActiveXObject){
  	reload=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  val='';
  if(getElById(targetobj)){	
  	val=getElById(targetobj).value;	
  }
  var jetzt = new Date();
 	path='/axjaxrequest?mode=LoadMutationList&article='+aid+'&mutation='+obj+'&target='+val+'&targetid='+targetobj+'&ser='+(jetzt.getTime());	

	if(reload){
  	reload.onreadystatechange=function(){
    renderMutationSelect(targetobj,aid);
      return false;
  	}
  }
  reload.open("GET",path,true);
  reload.send(null);	 

  d=getElById('advice-validate-select-MutationGroup1List');
  $('MutationGroup1List').removeClassName('validation-failed');
	if(d){
		d.outerHTML='';
	} 
  d=getElById('advice-validate-select-MutationGroup2List');
  if(d){
  	$('MutationGroup2List').removeClassName('validation-failed');
		d.outerHTML='';
	} 	
	getElById('product-price-2').innerHTML=DefaultPrice;
	getElById('product-price-1').innerHTML=DefaultPrice;	

	if(DefaultArtNummber){
		getElById('artidnumber').innerHTML=DefaultArtNummber;
	}
	if(DefaultAmount){
		getElById('in-stock').innerHTML= DefaultAmount;
	}
	
}

function renderMutationSelect(targetobj,aid){
  if(reload.readyState==4){
    if(reload.status==200){
    	opts=NormalizeOutput(reload.responseText);
    	
      if(objTargetSelect=getElById(targetobj)){	
    	if(opts!='' && opts.length>1){
	      if(document.all){
					opts = '<option>ie hack</option>' + opts;
				}
				objTargetSelect.innerHTML = opts;
				if(document.all) { // Or any IE testing
					objTargetSelect.outerHTML = objTargetSelect.outerHTML;
				}
    	}
    }
  	if(getData('MutationGroup1List')!='' && getData('MutationGroup2List')!=''){
      LoadMutationArticlePrice(aid,getData('MutationGroup1List'),getData('MutationGroup2List'));	
  	}else{
  		LoadArticleImageList();
  	}
   }
  }		

}

function LoadArticleImageList(){
	art=getData('productid');
	if(art!=''){
		if(window.XMLHttpRequest){
	  	areload=new XMLHttpRequest();
	  }
	  else if(window.ActiveXObject){
	  	areload=new ActiveXObject("Microsoft.XMLHTTP");
	  }	
	
	  var jetzt = new Date();
	 	path='/axjaxrequest?mode=LoadArticleImageList&article='+art+'&ser='+(jetzt.getTime());		
		if(areload){
		  areload.onreadystatechange=function(){
		    renderArticleImagelist();
		      return false;
	  	}			
			
		}
  areload.open("GET",path,true);
  areload.send(null);			
	}
}


function LoadMutationArticlePrice(article,group1,group2){
	ShowProgressDiv('product-order');
	if(window.XMLHttpRequest){
  	reload=new XMLHttpRequest();
  }
  else if(window.ActiveXObject){
  	reload=new ActiveXObject("Microsoft.XMLHTTP");
  }	

  var jetzt = new Date();
 	path='/axjaxrequest?mode=LoadMutationPrice&article='+article+'&group1='+group1+'&group2='+group2+'&ser='+(jetzt.getTime());	

	if(reload){
  	reload.onreadystatechange=function(){
    renderArticlePrice();
      return false;
  	}
  }
  reload.open("GET",path,true);
  reload.send(null);	
	
}


function renderArticleImagelist(){
  if(areload.readyState==4){
    if(areload.status==200){
    	
    	if(areload.responseText!=''){
    		
    		getElById('return-image-box').innerHTML=areload.responseText
    		SwapMainImage(getData('BigImageFrom'),true);
    		
    	}
      HideProgressDiv();
    	
    }
  }	
	
}

function renderArticlePrice(){
	
  if(reload.readyState==4){
    if(reload.status==200){
    	opts=NormalizeOutput(reload.responseText);
    	var data=opts.split("|");
   
    	HideProgressDiv();
      if(opts!=''){
      	getElById('product-price-1').innerHTML=data[1];
      	getElById('product-price-2').innerHTML=data[1];
      	setData('productid',data[0]);
        LoadArticleImageList();
				if(DefaultArtNummber){
					
					getElById('artidnumber').innerHTML=data[2];
				} 
				if(DefaultAmount){
          getElById('in-stock').innerHTML=data[3];
				}   	
      }
      enable=true;
      if(data[4]=='FREE_93'){
      	enable=false;
      }
      setButtonEnableMode(enable,'send2');
   }
  }		
	
}

function SetCheckOutStep(step,check){
  ResetValidationerrors();

  switch(step){
		case 'opc-login':
		   if(processpayment && processpayment.location){
		   	processpayment.location.href='about:blank';
		   }
		   ShowElement(step+'-checkout-step');
		   RemoverFunction('opc-login-header');
		   RemoverFunction('opc-billing-header');
		   RemoverFunction('opc-shipping-header');
		   RemoverFunction('opc-shipping_method-header');
		   RemoverFunction('opc-payment-header');
		   RemoverFunction('opc-review-header');
		 

		 	 RemoveDTData('TIT_15');
		 	 RemoveDTData('TIT_16');
		 	 RemoveDTData('TIT_17');
		 	 RemoveDTData('TIT_18');	
		break;
		
		case 'opc-billing':
		  if(processpayment && processpayment.location){
		   	processpayment.location.href='about:blank';
		  }	
		  	
		  mode=false;
	    if(check){
		   	Hide('billing-new-address-form');
		   	Hide('userBillingSalutation');
		   	Hide('userBillingUsername');
		   	Hide('userPersonemail');
		   	Hide('userBillingname');
		   	Hide('billingaddresssave');	
		   	Hide('newBillingemail');
		   	Hide('billingsentto');
	    }		   
		  if(HIDEADDRESSLIST){
			   Hide('userBillingaddress');

		   }
		   else{
			   Show('userBillingaddress');
	   	 }
		   if(getElById('login:guest') && getElById('login:register')){
		   	
			   if(getElById('login:guest').checked && !getElById('login:register').checked){
			   	 mode='guest';
			   	 Hide('creatpasswd');
			   	 Hide('loginSektion');
			   } 
			   else if(!getElById('login:guest').checked && getElById('login:register').checked){
			   	mode='regsiter';
			   	Show('creatpasswd');
			   	Show('loginSektion');
			   }
			   else{
			   	 alert(choice_checkout_as_anon);
			   	 return false;
			   }
			   setData('checkoutas',mode);
			   setFormAction('checkoutas','checkoutloginaction','checkout-form-login');
		   }
		   else if(!getElById('login:guest') && getElById('login:register')){
			   	mode='regsiter';
			   	Show('creatpasswd');
			   setData('checkoutas',mode);
			   setFormAction('checkoutas','checkoutloginaction','checkout-form-login');			   			   	
		   }
		   else if(getElById('login:guest') && !getElById('login:register')){
			   	 mode='guest';
			   	 Hide('creatpasswd');	
			   setData('checkoutas',mode);
			   setFormAction('checkoutas','checkoutloginaction','checkout-form-login');			   	 	   	
		   }		
		   switch(mode){
		   	case 'guest':
		   	Hide('extraaddressdata');
		   	break;
		   	default:
		   	Show('extraaddressdata');
		   	break;
		   	
		   	
		   	
		   }		      
		   if(check){
		   
		    ShowCheckOutProgess('opc-billing-please-wait');
		   }
		   ShowElement(step+'-checkout-step');
		   AddFunction('opc-login-header','opc-login');
		   RemoverFunction('opc-billing-header');
		   RemoverFunction('opc-shipping-header');
		   RemoverFunction('opc-shipping-method-header');
		   RemoverFunction('opc-payment-header');
		   RemoverFunction('opc-review-header');
		 	 RemoveDTData('TIT_15');
		 	 RemoveDTData('TIT_16');
		 	 RemoveDTData('TIT_17');
		 	 RemoveDTData('TIT_18');			   
		   if(check && mode!=false){
			   	Show('billing-new-address-form');
			   	Show('userBillingSalutation');
			   	Show('userBillingUsername');
			   	Show('userPersonemail');	
			   	Show('newBillingemail');	   
		   }
              
		break;
		 	if(processpayment && processpayment.location){
		   	processpayment.location.href='about:blank';
		   }		
		case 'opc-shipping':
		   if(check){
			 	t=getData('billing-address-select');
			 	
			 	if(t=='new' && !$('billing_is_pr').checked && !$('billing_is_cr').checked){
			 		d=$('newbillingaddressnotify'); 
					if(d){
						d.innerHTML='<ul class="messages"><li class="error-msg"><ul><li>'+notifytext+'</li></ul></li></ul>';
					}   	
			   	Show('newbillingaddressnotify');
			 		return false;		
			 	}  
			 	 Hide('newbillingaddressnotify'); 	
		   	 ShowCheckOutProgess('opc-billing-please-wait');
			   if($('use_for_shipping_yes').checked){
			   	 setFormAction('sameaddrress','checkoutbillingaction','checkout-form-billing');
				 /*  ShowElement('opc-shipping-method-checkout-step');
				   ShowCheckOutProgess('opc-shipping-method-please-wait');*/
				  
				   AddFunction('opc-billing-header','opc-billing');	
				   AddFunction('opc-shipping-header','opc-shipping');	 
				   //if(getData('billing-address-select')!='new'){  	
				   //	setData('shipping-address-select',getData('billing-address-select'));
				   //}
				   $('shipping-address-select').value = $('billing-address-select').value;
				   if($('billing-address-select').value=='new' && $('use_for_shipping_yes').checked ) {
				   	 
				   	 $('shipping_is_pr').checked = $('billing_is_pr').checked;
				   	 $('shipping_is_cr').checked = $('billing_is_cr').checked;
				   	 if( $('shipping_is_pr').checked ) {
				   	 	SwitchSchippingAddressMode($('shipping_is_pr'));
				   	 }else if( $('shipping_is_cr').checked ){
				   	 	SwitchSchippingAddressMode($('shipping_is_cr'));
				   	 }
				   	 
				   	 setData('shipping_salutation',getData('billing_salutation'));
					   setData('shipping_legal_form',getData('billing_legal_form'));
					   setData('shipping_company',getData('billing_company'));
					   setData('shipping_name',getData('billing_name'));
					   setData('shipping_personname',getData('billing_personname'));
					   setData('shipping_street',getData('billing_street'));
					   setData('shipping_number',getData('billing_number'));
					   setData('shipping_addressaddon',getData('billing_addressaddon'));
					   setData('shipping_zip',getData('billing_zip'));
					   setData('shipping_state',getData('billing_state'));	
					   setData('shipping_city',getData('billing_city'));
					   try{
					   	setData('shipping_country_id',getData('billing_country_id'));
					   }catch(e) {}
					   setData('shipping_uid_country_list',getData('billing_uid_country_list'));
					   setData('shipping_uid_number',getData('billing_uid_number'));
					   setData('shipping_phone',getData('billing_phone'));
					   setData('shipping_fax',getData('billing_fax'));
					   setData('shipping_email',getData('billing_email'));
				   }
				   				   	 	
			   }
			   else{ // Shipping different no copy of Data
			   	 setFormAction('differentaddress','checkoutbillingaction','checkout-form-billing');
				/*	 ShowElement(step+'-checkout-step');
				   ShowCheckOutProgess(step+'-please-wait');*/
				   AddFunction('opc-billing-header','opc-billing');	
				   if(getData('shipping-address-select')==''){
				   	setData('shipping-address-select','new');
				   }
				   //$('shipping-address-select').value = $('billing-address-select').value;
				   
			   	 //setData('shipping_salutation',getData('billing_salutation'));
				   //setData('shipping_legal_form',getData('billing_legal_form'));
				   //setData('shipping_company',getData('billing_company'));
				   //setData('shipping_name',getData('billing_name'));
				   //setData('shipping_personname',getData('billing_personname'));
				   //setData('shipping_street',getData('billing_street'));
				   //setData('shipping_number',getData('billing_number'));
				   //setData('shipping_addressaddon',getData('billing_addressaddon'));
				   //setData('shipping_zip',getData('billing_zip'));
				   //setData('shipping_state',getData('billing_state'));	
				   //setData('shipping_city',getData('billing_city'));
				   try{
				   	//setData('shipping_country_id',getData('billing_country_id'));
				   }catch(e) {}
				   //setData('shipping_uid_country_list',getData('billing_uid_country_list'));
				   //setData('shipping_uid_number',getData('billing_uid_number'));
				   //setData('shipping_phone',getData('billing_phone'));
				   //setData('shipping_fax',getData('billing_fax'));
				   //setData('shipping_email',getData('billing_email'));   	
			   }
		   }
		   else{
		   	ShowElement(step+'-checkout-step');
		   }
		  if(HIDEADDRESSLIST){
			   Hide('userShippingaddress');

		   }
		   else{
			   Show('userShippingaddress');
	   	 }
	   	 if(!check){
	   	 	RemoverFunction('opc-shipping-header');
	   	 }
		   RemoverFunction('opc-shipping-method-header');
		   RemoverFunction('opc-payment-header');
		   RemoverFunction('opc-review-header');
		   
		 	 RemoveDTData('TIT_16');
		 	 RemoveDTData('TIT_18');			   
       if(check){
       	if(getData('shipping-address-select')=='new'){
       		Show('shipping-new-address-form');
       	}
       	else{
       		Hide('shipping-new-address-form');
       		
       	}
       }	 		
		break;
		case 'opc-shipping-method':
		 if(processpayment && processpayment.location){
		   	processpayment.location.href='about:blank';
		 }		
		 if(check){
		 	t=getData('shipping-address-select');
		 	
		 	if(t=='new' && !getElById('shipping_is_pr').checked && !getElById('shipping_is_cr').checked){
		 		d=getElById('newaddressnotify'); 
				if(d){
					d.innerHTML='<ul class="messages"><li class="error-msg"><ul><li>'+notifytext+'</li></ul></li></ul>';
				}   	
		   	Show('newaddressnotify');
		 		return false;		
		 	} 		 	
   	 	setFormAction('saveaddress','checkoutshippingaction','checkout-form-shipping');
   	  /*ShowCheckOutProgess('opc-shipping-method-please-wait');*/
   	  ShowCheckOutProgess('opc-shipping-please-wait');
   	  Hide('newaddressnotify');
		 }
		 else{
		   ShowElement(step+'-checkout-step');
		 }
	   
	   
	   AddFunction('opc-billing-header','opc-billing');	
	   AddFunction('opc-shipping-header','opc-shipping');	   	
	
		 RemoveDTData('TIT_16');
		 RemoverFunction('opc-shipping-method-header');
		 RemoverFunction('opc-payment-header');
		 RemoverFunction('opc-review-header');		 
		break;
		case 'opc-payment':
		   if(processpayment && processpayment.location){
		   	processpayment.location.href='about:blank';
		   }		
			 if(check){
			  var box=document.forms['checkout-form-shipping-method'].elements['shipping_method'];
			  
			  var checked=false;
			  if(box!='undefined'){
			  	if(box.checked==true){
			  		checked=box.checked;
			  	
			  	}
			  	else{
					for(i=0; i< box.length;i++){
							if(box[i].checked==true){
								checked=true;
								break;
							}
					}		  	 
			  	}
			  }
			  if(!checked){
			  	alert(wsCheckoutChooseVersandart);
				  if(getElById('BUT_21')){
		  			getElById('BUT_21').disabled=false;
		 		 	}
		 		 	return false;
			  }
			  else{
			  	setFormAction('saveshippingnethod','checkoutshipping-methodaction','checkout-form-shipping-method');
			  }
			  ShowCheckOutProgess('opc-shipping-method-please-wait');
			 
			 }
			 else{
			 	ShowElement('checkout-payment-step');
			 }
	    
	    
	    AddFunction('opc-billing-header','opc-billing');	
	    AddFunction('opc-shipping-header','opc-shipping');
	    AddFunction('opc-shipping-method-header','opc-shipping-method');	 			 
		  RemoverFunction('opc-payment-header');
		  RemoverFunction('opc-review-header');		
		break;
		case 'opc-review':
		   if(processpayment && processpayment.location){
		   	processpayment.location.href='about:blank';
		   }		
			 if(check){
			  var box=document.forms['checkout-form-payment'].elements['paymentmethod'];
			  var checked=false;
			  if(box!='undefined'){
					for(i=0; i< box.length;i++){
							if(box[i].checked==true){
								checked=true;
								break;
							}
					}		  	 
			  	
			  }
			  if(!checked){
			  	alert(AlertSelectPaymentMethod);
				  if(getElById('BUT_21_PAYMENT')){
		  			getElById('BUT_21_PAYMENT').disabled=false;
		 		 	}
		 		 	return false;
			  }
			  else{
			  	setFormAction('savepayment','checkoutpaymentaction','checkout-form-payment');
			  }
			 }		
      ShowCheckOutProgess('opc-payment-please-wait');			 
			RemoverFunction('opc-review-header');
		break;
		
		
		case 'opc-dopay':
		  ShowCheckOutProgess('opc-review-please-wait');
		 
		  processpayment.location.href='/payment?init=true';
		  /*processpayment*/
		break;
		case 'opc-savepayedorder':
		 setFormAction('savepayedorder','checkoutpaymentaction','checkout-form-payment');
		break;
		default:
		
		break;
		
		
		
	}
}


function setButtonEnableMode(mode,but){

	s=getElById(but);
	if(s){
		s.disabled=!mode;
		if(!mode){
			if(s.addClassName){
			s.addClassName('disabled');
			}
		}
		else{
			if(s.removeClassName){
		  s.removeClassName('disabled');
			}
		}
	}
}

function SetButtonAccept(box){
	if(box.disabled){
		return;
	}

	s=getElById('BUT_21_PREVIEW');
	p=getElById('BUT_59_PREVIEW');	
	if(s){
		s.disabled=!box.checked;
	}
	if(p){
		p.disabled=!box.checked;
	}
	
	
}


function switchAddressselect(mode){
	ResetValidationerrors();
	if(mode=='new'){
		Show('billing-new-address-form');
		Hide('userBillingUsername');
		Hide('userPersonemail');
		
		Hide('userBillingSalutation');
		Show('userBillingname');
		Hide('newBillingemail');

		
		Hide('creatpasswd');
	}
	else{
		Hide('billing-new-address-form');
		Hide('userBillingname');
		Hide('userBillingUsername');
		Hide('userPersonemail');	
		Hide('userBillingSalutation');
		Hide('newBillingemail');

		Hide('creatpasswd');		
	}
}

function switchBillingAddressselect(mode){
	ResetValidationerrors();
	
	if(mode=='new'){
		Show('billing-new-address-form');
		d=getElById('newbillingaddressnotify');
		if(d){
			d.innerHTML='<ul class="messages"><li class="notice-msg"><ul><li>'+notifytext+'</li></ul></li></ul>';
		}

   	
   	Show('newbillingaddressnotify');			
	}
	else{
		Hide('billing-new-address-form');
		Hide('newbillingaddressnotify');
	
	
		if(d=getElById('newbillingaddressnotify')){
			d.innerHTML='';
		}			
	}
}


function switchShippingAddressselect(mode){
	ResetValidationerrors();
	
	if(mode=='new'){
		Show('shipping-new-address-form');
		d=getElById('newaddressnotify');
		if(d){
			d.innerHTML='<ul class="messages"><li class="notice-msg"><ul><li>'+notifytext+'</li></ul></li></ul>';
		}   	
   	Show('newaddressnotify');		
		/*if(getData('shippingname')==''){
	   if(HIDEADDRESSLIST){
		 setData('shippingname',getData('billingfirst')+'  '+getData('billinglast'));
	   }
	   else{
	    setData('shippingname',getData('billingname'));
	   }
 
   	setData('shippingcompanyname',getData('billingcompanyname'));
   	setData('shippingstreet',getData('billingstreet'));
   	setData('shippingnumber',getData('billingnumber'));
   	setData('shippingaddressaddon',getData('addressaddon'));
   	setData('shippingzip',getData('billingzip'));
   	setData('shippingstate',getData('billingstate'));
   	setData('shippingcity',getData('billingcity'));
   	setData('shippingcountry_id',getData('billingcountry_id'));
   	setData('shippingphone',getData('billingphone'));	
   	setData('shippingfax',getData('billingfax'));	
		}	*/

	}
	else if(mode=='check'){
		if(USERISLOGED=='YES'){
			/*switchShippingAddressselect(getData('billing-address-select'));*/
		}
    /*setData('shipping-address-select',getData('billing-address-select'));*/
	}
	else{
		Hide('shipping-new-address-form');
		if(getElById('usebilling_address')){
			getElById('usebilling_address').checked=false;
		}
		Hide('shipping-new-address-form');
		Hide('newaddressnotify');
		if(d=getElById('newaddressnotify')){
			d.innerHTML='';
		}		
   /* setData('shippingfirst','');
    setData('shippinglast','');
    setData('shippingcompanyname','');
    setData('shippingstreet','');
    setData('shippingnumber','');
    setData('shippingaddressaddon','');
    setData('shippingzip','');
    setData('shippingstate','');
    setData('shippingcity','');
    setData('shippingcountry_id','');
    setData('shippingphone','');	
    setData('shippingfax','');	*/	
		
	}
}

function switchMethodPayment(mode){
	ResetValidationerrors();
	obj=getElById('opc-dopay');
	s=getElById('BUT_21_PREVIEW');
	p=getElById('BUT_59_PREVIEW');
	if(mode=='TRUE'){
		 obj.style.display='block';
		 s.style.display='none';
		 p.style.display='block';
		 /*getElById('ccsave_cc_owner').addClassName('required-entry');
		 getElById('ccsave_cc_type').addClassName('validate-select');
		 getElById('ccsave_cc_number').addClassName('required-entry');
		 getElById('ccsave_cc_number').addClassName('validate-cc-number');
		 getElById('ccsave_cc_number').addClassName('validate-cc-type');
		 getElById('ccsave_expiration').addClassName('validate-select');
		 getElById('ccsave_expiration').addClassName('validate-validate-cc-exp');
		 
		 getElById('ccsave_expiration_yr').addClassName('validate-select');
		 getElById('ccsave_cc_cid').addClassName('required-entry');
		 getElById('ccsave_cc_cid').addClassName('validate-cc-cvn');*/
		  
		 
	
		  
	}
	else{
		obj.style.display='none';
		 s.style.display='block';
		 p.style.display='none';		
		/* getElById('ccsave_cc_owner').removeClassName('required-entry');
	   getElById('ccsave_cc_type').removeClassName('validate-select');
		 getElById('ccsave_cc_number').removeClassName('required-entry');
		 getElById('ccsave_cc_number').removeClassName('validate-cc-number');
		 getElById('ccsave_cc_number').removeClassName('validate-cc-type');
		 getElById('ccsave_expiration').removeClassName('validate-select');
		 getElById('ccsave_expiration').removeClassName('validate-validate-cc-exp');
		 getElById('ccsave_expiration_yr').removeClassName('validate-select');		
		 getElById('ccsave_cc_cid').removeClassName('required-entry');
		 getElById('ccsave_cc_cid').removeClassName('validate-cc-cvn'); */	 		 
		
	}
	
}

function ToolTop(name,mode){
	obj=getElById(name);
	if(mode){
		obj.style.display='block';
	}
	else{
		obj.style.display='none';
	}	
	
}


function AddFunction(name,id){
	
obj=getElById(name);
	if(obj){
	  obj.style.cursor='hand' ;
		obj.onclick=function(){SetCheckOutStep(id,false)};
		
	}
}

function RemoverFunction(name){
	obj=getElById(name);
	if(obj){
		obj.style.cursor='default' ;
		obj.onclick=function(){return false};
	}
 	
}

function RemoveDTData(name){
	obj=getElById(name);

	if(obj){
		switch(name){
			case 'TIT_15':
			  obj.innerHTML='';

		  
			break;
			case 'TIT_16':
			 obj.innerHTML='';
			break;
			case 'TIT_17':
			 obj.innerHTML='';
			break;
			case 'TIT_18':
			 obj.innerHTML='';
			break;						
			
		}
	}
}

function AddDTData(name,header,text){
	obj=getElById(name);
	cobj=getElById(name+'_CONT')
	if(obj && cobj){
			  obj.innerHTML=header;

			  cobj.innerHTML=text;
			  cobj.style.display='block';		

	}
}


function ResizeParentrame(id,target){
	obj=getElById(id);
	
	if(parent && parent.getElById){
		tobj=parent.getElById(target);
		if(tobj){
			tobj.style.height=(obj.offsetHeight+100)+'px'
		}
	}
	

}
function ResizeParentrameFix(id){

	
	if(parent && parent.getElById){
		tobj=parent.getElById(id);
		tobj.style.height='500px'
	}
	

}

function ShowElement(name){
	if(getElById(name)){

		getElById(name).style.display='block';
		getElById(ACTIVECHECKOUT).style.display='none';
		ACTIVECHECKOUT=name;
	}
}
function Hide(name){
	return ;
	if(!getElById(name)){
		return;
	}
	getElById(name).style.display='none';
	switch(name){
		 case 'creatpasswd':
		   getElById('password').removeClassName('required-entry');
		   getElById('password').removeClassName('validate-password');
		   getElById('confirmationid').removeClassName('required-entry');
		   getElById('confirmationid').removeClassName('validate-cpassword');		   
		 break;
   	 case 'userBillingname':
   	   getElById('billingname').removeClassName('required-entry');
  	 break;	
  	 case 'billing-new-address-form':
			 getElById('billing_street').removeClassName('required-entry');
  	   getElById('billing_number').removeClassName('required-entry');
  	   getElById('billing_zip').removeClassName('required-entry');
  	   
  	   getElById('billing_zip').removeClassName('validate-zip-international');  
  	   getElById('billing_state').removeClassName('validate-select');
  	   
  	   getElById('billing_city').removeClassName('required-entry');
  	   
  	   
  	 break;
  	 case 'userBillingUsername':
  	   getElById('billingfirst').removeClassName('required-entry');
  	   getElById('billinglast').removeClassName('required-entry');
  	   getElById('person_email').removeClassName('required-entry');
  	   getElById('person_email').removeClassName('validate-email');
  	 break;
  	 case 'userBillingSalutation':
  	   getElById('billingsex').removeClassName('validate-select');
  	 break;
     case 'shipping-new-address-form':
   

       
			 
			 getElById('shipping_street').removeClassName('required-entry');
  	   getElById('shipping_number').removeClassName('required-entry');
  	   getElById('shipping_zip').removeClassName('required-entry');
  	   
  	   getElById('shipping_zip').removeClassName('validate-zip-international');  
  	   getElById('shipping_state').removeClassName('validate-select');
  	   
  	   getElById('shipping_city').removeClassName('required-entry');
  	 	
  	           
     break;
		default:
		break;
	}
	
	
}
function Show(name){
	if(!getElById(name)){
		return;
	}	
	getElById(name).style.display='block';
	
	switch(name){
		 case 'creatpasswd':
		   getElById('password').addClassName('required-entry');
		   getElById('password').addClassName('validate-password');
		   getElById('confirmationid').addClassName('required-entry');
		   getElById('confirmationid').addClassName('validate-cpassword');		   
		 break;		 
   	 case 'userBillingname':
   	   getElById('billingname').addClassName('required-entry');
   	 
   	 break;	
  	 case 'billing-new-address-form':
       getElById('billing_street').addClassName('required-entry');
       getElById('billing_number').addClassName('required-entry');
  	   getElById('billing_zip').addClassName('required-entry');
  	   getElById('billing_zip').addClassName('validate-zip-international');  
  	   getElById('billing_state').addClassName('validate-select');
  	   getElById('billing_city').addClassName('required-entry'); 	 
  	 break;
  	 case 'userBillingUsername':
  	   getElById('billingfirst').addClassName('required-entry');
  	   getElById('billinglast').addClassName('required-entry');
  	   getElById('person_email').addClassName('required-entry');
  	   getElById('person_email').addClassName('validate-email');  	   
  	 break;
  	 case 'userBillingSalutation':
  	   getElById('billingsex').addClassName('validate-select');
  	 break;
     case 'shipping-new-address-form':

       getElById('shipping_street').addClassName('required-entry');
       getElById('shipping_number').addClassName('required-entry');
  	   getElById('shipping_zip').addClassName('required-entry');
  	   getElById('shipping_zip').addClassName('validate-zip-international');  
  	   getElById('shipping_state').addClassName('validate-select');
  	   getElById('shipping_city').addClassName('required-entry'); 
  	        
     break;  	    	    		
		default:
		break;
	}	
	
}
function ShowCheckOutProgess(name){
	if(getElById(name)){
		getElById(name).style.display='block';
	}
	
}
function HideCheckOutProgess(name){
	if(getElById(name)){
		getElById(name).style.display='none';
	}
}

function ResetValidationerrors(){
	return;
/*	e=getElById('shipping-error');
	if(e){
		e.innerHTML='';
	}
	e=getElById('billing-error');
	if(e){
		e.innerHTML='';
	}	*/
	var l=document.forms.length;
	for(i=0;i<l;i++){
		obj=document.forms[i];

		for (x=0; x<obj.getElementsByTagName("input").length; x++) {
			cur=obj.getElementsByTagName("input")[x];
			if(cur.removeClassName){
				cur.removeClassName('validation-failed');
				id=cur.getAttribute('id');
				if(d=getElById('advice-required-entry-'+id)){
					d.outerHTML='';
				}
			}
		}
		for (x=0; x<obj.getElementsByTagName("select").length; x++) {
			cur=obj.getElementsByTagName("select")[x];
			if(cur.removeClassName){
				cur.removeClassName('validation-failed');
				id=cur.getAttribute('id');
				if(d=getElById('advice-validate-select-'+id)){
					d.outerHTML='';
				}			
			}
		}
	}
}



function CaluculateCartShipping(){
	var checked=false;
	if(getData('productcharge')!=''){
		checked=true;
	}
	if(!checked){
		alert(wsCheckoutChooseVersandart);
	
		return false;
	}
	else{
		setFormAction('calculatetotal','productaction','form-chart');
	}
}

function InitMoveTo(){
	id=getData('movtoid');
	obj=getElById('mt_'+id);
	if(obj){
		move_to(id, obj);
	}
	
	
}


function horizScroller(opt)
{
   var d = 0;
   opt.delay = opt.delay || 50;
   opt.dist = opt.dist || 2;
  
   opt.leftEl.onmouseover = function() { d = -opt.dist; scroll(); }
   opt.leftEl.onmouseout = function() { d = 0 }
   opt.rightEl.onmouseover = function() { d = opt.dist; scroll(); }
   opt.rightEl.onmouseout = function() { d = 0 }
   
    function scroll(){
    
       if (!d) return;

       var x = opt.contentEl.scrollLeft+d;
       stop = false;
       rightBoundary = opt.contentEl.scrollWidth-opt.contentEl.offsetWidth;
       
       if (x<0) {
           addClassName(opt.leftEl, 'disabled');
           x = 0;
           stop = true;
       } else {
           removeClassName(opt.leftEl, 'disabled');
       }
       if (x>=rightBoundary) {
           addClassName(opt.rightEl, 'disabled');
           x = rightBoundary;
           stop = true;
       } else {
           removeClassName(opt.rightEl, 'disabled');
       }
       opt.contentEl.scrollLeft = x;

       if (stop) return;
       window.setTimeout(scroll, opt.delay);
   }
   
   function addClassName(el, className){
       el.className = el.className.replace(new RegExp(' ?'+className+'|$'), ' '+className);
   }
   
   function removeClassName(el, className){
       el.className = el.className.replace(new RegExp(' ?'+className+'( |$)'), '$1');
   }
}

function SelectCheckBoxes(mode){
/*	var box=document.forms['checkout-form-payment'].elements['related_products[]'];*/

	/*'related_products[]'*/
	var box=document.getElementsByName('related_products[]');
	var data='';
	if(box){
		 for(i=0;i<box.length;i++){
		 	 box[i].checked=mode;
		 	 if(mode){
		 	 	data+=(data.length>0?',':'')+box[i].value;
		 	 }
		 }
		 
	
	}
	setData('related-articles',data);
}
function CheckSelectAll(){
	var box=document.getElementsByName('related_products[]');
	var data='';
	if(box){
		var l=0;
		for(i=0;i<box.length;i++){
			if(box[i].checked==true){
				data+=(data.length>0?',':'')+box[i].value;
				l++;
			}
		}
		if(l==0){
			Show('selectallitems');
			Hide('unselectallitems');	
		}
		else if(l==box.length){
			Hide('selectallitems');
			Show('unselectallitems');			
		
		}
	}

	setData('related-articles',data);
}

function printDocument(id){
	
	if(openwin && close){
		openwin.close();
	}	
	page='/'+id+'?print=true';
	
	var para='top=10,left=10,width=800,height=600,location=no,resizable=yes,scrollbars=yes';
	openwin=window.open(page,'DOCUMENTPRINT',para);
  if(openwin){
  	openwin.focus();
  }	
	
}

function EditMyTag(id){
	setData('productid',id);
	setFormAction('edit','productpaction','form-productgroup');
	return false;	
}
function RemoveMyTag(id,name){
	if(confirm(confirmremoveTag.replace(/%NAME%/,name))){
		setData('productid',id);
		var f=getElById('form-productgroup');
		if(f){
			f.action='/mytags';
		}		
		setFormAction('removetag','productpaction','form-productgroup');
	
	}
	return false;
	
}


function UpdateTage(){
		var f=getElById('addTagForm');
		if(f){
			f.action='/mytags';
		}		
	setFormAction('apply','productpaction','addTagForm');
}


function checkVotecomplete(){
	
	var box=document.getElementsByName('question[]');
	var dovote=0;
	for(i=0;i<box.length;i++){
		id=box[i].value;
		radios=document.getElementsByName('choice_'+id);
		for(x=0;x<radios.length;x++){
			if(radios[x].checked==true){
				dovote++;
			}
		}
	}
	
  if(dovote==box.length){
  	setFormAction('dovote','pollaction','pollForm');
  }
}

function SetCheckOutMultiStep(step){
	
	setData('checkoutstep',step);
	setFormAction('nextstep','checkoutaction','form-checkout');
}

function RemoveMultiCharitem(item,name){
  conf=NormalizeOutput(confirmdeletepos);
	if(confirm(conf.replace(/%NAME%/,name))){
		setData('position',item);
		setFormAction('removeposition','checkoutaction','form-checkout');
	}
	
	return false;
}
function SplitMultiCharitem(item){
	setData('posid',item);
	setFormAction('splitposition','checkoutaction','form-checkout');
	
}

function CheckIsOneSplitPosSelected(){
	var box=document.getElementsByName('split_position[]');
	var disabled=true;
	for(i=0;i<box.length;i++){
		if(box[i].checked==true){
			disabled=false;
			break;
		}
	}
	setElementMode('BUT_57',disabled);
}

function checkMultipleCheckOutShipping(step){
	 var box=document.getElementsByName('shipping_address[]');
	 var all=new Array();
	 var submitform=true;
	 for(i=0;i<box.length;i++){
	 	 all[i]=box[i].value;
	 }
   for(i=0;i<all.length;i++){
   	 id=all[i];
   	 Hide('advice_'+id);
   	 radio=document.getElementsByName('shipping_method_'+id);
   	 checked=false;
   	 for(x=0;x<radio.length;x++){
   	 	 if(radio[x].checked==true){
   	 	 	 checked=true;
   	 	 }
   	 }
   	 if(checked==false){
   	 	Show('advice_'+id);
   	 	if(submitform==true){
   	 		submitform=false;
   	 	}
   	 }
   } 	 
   if(submitform==true){
		setData('checkoutstep',step);
		setFormAction('saveshippingdata','checkoutaction','form-checkout');
   }
}

 
function RemoveMultiAddressitem(item,name){
	name=NormalizeOutput(name);
  conf=NormalizeOutput(confirmdeletShippingaddress);
	if(confirm(conf.replace(/%NAME%/,name))){
		setData('address',item);
		setFormAction('removeaddress','checkoutaction','form-checkout');
	}
	
	return false;
}

function CheckOutMultipleBilling(step){

	Hide('advice_payment');
	//var box=document.getElementsByName('paymentmethod');
	var box=$$('input[name="paymentmethod"]');
	var submitform=false;
  for(i=0;i<box.length;i++){
  	if(box[i].checked==true){
  		submitform=true;
  		break;
  	}
  }
  if(!submitform){
  	Show('advice_payment');
  	return;
  }
	/*
	obj=getElById('payment_form_save');
	if(obj.style.display=='block'){
		
	}*/
	
   
		setData('checkoutstep',step);
		setFormAction('savebillingdata','checkoutaction','form-checkout');
   	
}

function finalizeMultipleShipping(){
		var agb = $('review[agb]');
		if(!agb.checked) {
			return;
		}
		setData('checkoutstep',5);
		setFormAction('finalize','checkoutaction','form-checkout');	
	
}
function finalizeMultipleShippingandPay(){
		setData('checkoutstep',4);
		setFormAction('pay','checkoutaction','form-checkout');		
	
}


function ForwardAddRecipient(){
   ul = $('recipients_options'); 
   i=AddedRecipient+1;
   var li_mail = Element.extend(document.createElement("LI"));
   li_mail.setAttribute('id','recipients_name'+i); 
   li_mail.addClassName('add-row'); 
   
	 li_mail.innerHTML = '<div align="right" style="padding-top:10px"><a href="deleteemail" onclick="ForwardRemoveRecipient('+i+');return false"><img src="'+RemoveIcon+'" /></a></div>'
   li_mail.innerHTML += '<div class="left"><label for="recipients_name">'+lableSenderName+'<span class="required"> *</span></label><br/><input type="hidden" name="recipients[]" value="'+i+'" /><input name="recipientsname'+i+'" type="text" class="input-text required-entry" id="recipients_name'+i+'" style="width:350px;"/><br /><br /></div>';
   li_mail.innerHTML += '<div class="right"><label for="recipients_email">'+lableSenderEmail+'<span class="required"> *</span></label><br/><input name="recipientsemail'+i+'" value="" title="Email Address" id="recipients_email'+i+'" type="text" class="input-text required-entry validate-email" style="width:350px;"/></div>';    
	 AddedRecipient++;
   if(AddedRecipient>=maxAddRecipient || maxAddRecipient == 0) {
	 $('add_recipient_button').hide();
	 $('max_recipient_message').show();
	 }
	 ul.appendChild(li_mail);    
   
   
}

function ForwardRemoveRecipient(i){
 $('recipients_name'+i).remove();
 AddedRecipient--;
 if(AddedRecipient<maxAddRecipient || maxAddRecipient == 0) {
 $('add_recipient_button').show();
 $('max_recipient_message').hide();
 }
 return false; 	
	
}

function DoSearchAdvanced(){

  Hide('advice-validate-number-price_from');
  Hide('advice-validate-number-price_to');
  $('price_from').removeClassName('validation-failed');
  $('price_to').removeClassName('validation-failed');
 	Hide('globsearcherror');
 	Hide('globsearcherrorbottom');
 	error=false;
 
	if(!checkInputSearch(getData('price_from'))){
		Show('advice-validate-number-price_from');
		$('price_from').addClassName('validation-failed');
		error=true;
		
	}
	if(!checkInputSearch(getData('price_to'))){
		Show('advice-validate-number-price_to');
		$('price_to').addClassName('validation-failed');
		error=true;
	} 	
	
	if(!error){
		if(Validation.get('IsEmpty').test(getData('name')) &&  Validation.get('IsEmpty').test(getData('shortdesc')) && Validation.get('IsEmpty').test(getData('desc')) 
		&& Validation.get('IsEmpty').test(getData('number')) &&  Validation.get('IsEmpty').test(getData('price_from')) && Validation.get('IsEmpty').test(getData('price_to')) && !isOneOptionSelect()){
		  error=true;
		 	Show('globsearcherror');
		 	Show('globsearcherrorbottom');		  
		}
	}
	if(!error){
		/*document.forms['form-validate'].submit();*/
		lc='';
		var lc='/adresult?q=true';
		if(!Validation.get('IsEmpty').test(getData('name'))){
			lc+='&name='+Url.encode(getData('name'));
		}
		if(!Validation.get('IsEmpty').test(getData('shortdesc'))){
			lc+='&shortdesc='+Url.encode(getData('shortdesc'));
		}
		if(!Validation.get('IsEmpty').test(getData('desc'))){
			lc+='&desc='+Url.encode(getData('desc'));
		}
		if(!Validation.get('IsEmpty').test(getData('number'))){
			lc+='&number='+Url.encode(getData('number'));
		}
		if(!Validation.get('IsEmpty').test(getData('price_from'))){
			lc+='&price_from='+Url.encode(getData('price_from'));
		}
		if(!Validation.get('IsEmpty').test(getData('price_to'))){
			lc+='&price_to='+Url.encode(getData('price_to'));
		}	
    /*document.location.href=lc;*/
		obj=document.forms['form-validate'];
		for (x=0; x<obj.getElementsByTagName("select").length; x++) {
			cur=obj.getElementsByTagName("select")[x];
			n=cur.name;
			
      if(cur && cur.options.length>0 && !Validation.get('IsEmpty').test(cur.value)){
      	for(i=0;i<cur.options.length;i++){
      		s=cur.options[i];
      		if(s.selected==true){
      		  lc+='&'+n+'='+s.value;
      		}
      		
      	}
      }
		} 

	 if(lc!=''){
	 
	 	/*lc=Url.encode(lc);*/

	 	document.location.href=lc;
	 }		
	}
	
}

function isOneOptionSelect(){
	
	obj=document.forms['form-validate'];
	for (x=0; x<obj.getElementsByTagName("select").length; x++) {
		cur=obj.getElementsByTagName("select")[x];
		if(cur && !Validation.get('IsEmpty').test(cur.value)){
			return true;
		}	
	}
	return false;
}


function checkInputSearch(v){
	
	return Validation.get('IsEmpty').test(v) || (!isNaN(parseNumber(v)) && !/^\s+$/.test(parseNumber(v)));	
	
}


var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

function switchCardType(id){
	ShowCheckOutProgess('opc-dopay-please-wait');
	setData('step',1);
	setFormAction('loadfields','action','paymentForm');
	
}

function setPaymentWait(){
	ShowCheckOutProgess('opc-dopay-please-wait');
	document.location.href='/payment?step=wait';
}


function SubmitCheckoutForm(form) {
	var f = new VarienForm(form);
	var _f = form;
	f.submit = function() {
		if( this.validator.validate() ) {
				_f.request({evalJS:'force',onLoading:function(transport){$$('.please-wait').invoke('show');},onComplete:function(transport){$$('.please-wait').invoke('hide');}});
		}
	}.bind(f);
	return f;
}

function SelectAddress(obj,type) {
	var c = {};
	switch(type) {
		case 'ship':
			c.type = 'Ship';
			c.select = 'select_address_id_ship';
			c.def = 'default_shipping';
			c.pr = 'shipping_is_pr';
			c.cr = 'shipping_is_cr';
			break;
		default:
			c.type = 'Bill';
			c.select = 'select_address_id';
			c.def = 'default_billing';
			c.pr = 'billing_is_pr';
			c.cr = 'billing_is_cr';
			break;
	} 
	if(obj.value != 'new') {
		$(c.select).value = obj.value;
		$(c.type+'Type').hide();
		$(c.def).show();
		SelectAddressType(null,c.type);
	}else{
		$(c.select).value = '';
		$(c.type+'Type').show();
		$(c.def).hide();
		if( $(c.pr).checked ) {
			SelectAddressType($(c.pr),c.type);
		}
		if( $(c.cr).checked ) {
			SelectAddressType($(c.cr),c.type);
		}
	}
}

function SelectAddressType(obj,type) {
	var value = '';
	try{
		value = obj.value;
	}catch(e) {}
	
	switch(value) {
		case 'company':
			$('p'+type+'Form').hide();
			$('c'+type+'Form').show();
			break;
		case 'private':
			$('p'+type+'Form').show();
			$('c'+type+'Form').hide();
			break;
		default:
			$('p'+type+'Form').hide();
			$('c'+type+'Form').hide();
			break;
	}
}

function isUidActive(obj) {
	if( obj.checked ) {
		$('uidForm1').show();
		$('uidForm2').show();
		$('uidDesc').show();
	}else{
		$('uidForm1').hide();
		$('uidForm2').hide();
		$('uidDesc').hide();
	}
}

function goToStep(step) {
	var steps = $$('div.step');
	steps.each(Element.hide);
	$(step).show();
}




function SwitchAddressModeNew(value) {
	switch(value) {
		case 1:
		case '1':
			$('private[form]').hide();
			$('company[form]').show();
			break;
		case 0:
		case '0':
			$('private[form]').show();
			$('company[form]').hide();
			break;
		default:
			$('private[form]').hide();
			$('company[form]').hide();
			break;
	}
}



