function writeContent(Url, TargetId) {
  dojo.xhrGet ({
    url: Url,       
    load: function (data) { dojo.byId(TargetId).innerHTML = data; },
    handleAs: "text",
    preventCache: true,
    timeout: 10000,
    error: function (data) { console.error('Error: ', data); }
  });  
}  
  
function clickPlusMinus(id,children) {
  if(dojo.byId('a_'+id).className!="active"){
      dojo.byId('a_'+id).className="active";
      var url = "?ViewAction=ViewSubCategoriesSnipplet&ObjectID="+id+"&menu=1";
        if(children) url+="&children=yes";    
      
      writeContent(url,'s_'+id);
      dojo.byId('s_'+id).style.height = "auto";    
  } else {
      dojo.byId('a_'+id).className = "";
      dojo.byId('s_'+id).style.height = "0em";
      dojo.byId('s_'+id).innerHTML = "";
  }    
  return false; 
}


var st1;
function prepData(form){
	var data = {};
	var formObj = dojo.formToObject(form);
	
	var productParams = new Array('ChangeObjectID','ProductID','VoucherProduct_Name','VoucherProduct_Email');
	
	for(var i=0;i<productParams.length;i++){
		data[productParams[i]] = eval("formObj."+productParams[i]);
	}

	var quantity = parseInt(formObj.Quantity);
	if (!quantity) 
		quantity = 1;
	data['Quantity'] = quantity;
	
	return data;
}

function appendProductURL(formular){
  var urlstr = "";
  var productParams = new Array('ChangeObjectID','ProductID','Quantity');
  for(var i=0;i<productParams.length;i++){
    urlstr += "&"+productParams[i]+"="+eval("formular."+productParams[i]+".value");  
  }
  return urlstr;
}

function divpopup_del(url,formular,id){
	url+=appendProductURL(formular);
	writeContent(url,'divbasketpopup');
	window.setTimeout(function () {writeContent('?ViewAction=ViewBasketBox','basket');},1000);
	dojo.byId(id).innerHTML='\<div style="text-align:center;height:28px"\>\<img src="\/WebRoot\/Laptopbags24\/SF\/img\/del.gif" style="margin-top: 7px;" alt="" \/>\<\/div\>';
}

function divpopup(url,form){
	var rurl = WebServerScriptUrlSSL+url;	
	//dojo.byId('divbasketpopup_container').style.display = 'block';
	dojo.byId('divbasketpopup_container').style.display = 'block';
	dojo.byId("divbasketpopup").innerHTML = '<div><img id="loader" src="/WebRoot/Laptopbags24/SF/img/loader.gif" alt="" /></div>';
	
	dojo.xhrPost({
		url: rurl,
		method: "post",
		content: prepData(form),
		preventCache: true,
		load: function (data) {
                dojo.byId("divbasketpopup").innerHTML = data;
             },
		error: function (data) {
			dojo.byId('divbasketpopup').innerHTML = "<p>An error has occurred! Please try again later.</p>";		
		},
		mimetype:'text/html'
	});	

	window.clearTimeout(st1);
	st1 = undefined;
	st1=window.setTimeout(function () {closedivpopup();},5000);
}

function writeToBasket(url){
	var rurl = WebServerScriptUrlSSL+url;	
	
	dojo.xhrPost({
		url: rurl,
		method: "post",
		preventCache: true,
		load: function (data) {
                dojo.byId("basket").innerHTML = data;
             },
		mimetype:'text/html'
	});	
}


function closedivpopup(){
	dojo.byId('divbasketpopup_container').style.display = 'none';
 // dojo.byId('divbasketpopup_container').style.display = 'none';  
}

function validate_voucher_form(id)
{
   var myForm = dojo.byId(id);
   var flag=1;
   var flag2=1;
   var voucher_name = myForm.VoucherProduct_Name.value;
   var voucher_email = myForm.VoucherProduct_Email.value;
   var voucher_email_cofirm = myForm.VoucherProduct_EmailConfirm.value;
   
   if(voucher_name.length == 0 && voucher_email == 0 && voucher_email_cofirm == 0)
   {
      myForm.submit();
   }
   else
   {
     if (voucher_name.length == 0)
     {
       myForm.VoucherProduct_Name.className = "Text DialogError";
       flag=0;
       if(flag2&&!flag){
         dojo.byId('Err_voucher').innerHTML = "Bitte f&uuml;llen Sie die rot markierten Felder aus.";
         dojo.byId('Err_voucher').className = "DialogMessage MessageWarning";
         myForm.VoucherProduct_Name.focus();
         flag2=0;
       }
     }
     else
     {
        myForm.VoucherProduct_Name.className = "Text";
     }
     
     
    
     //check email
     email = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))$/;
    
     if (voucher_email.length == 0 || !email.test(voucher_email))
     {
       myForm.VoucherProduct_Email.className = "Text DialogError";
       flag=0;
       if(flag2&&!flag){
         dojo.byId('Err_voucher').innerHTML = "Bitte f&uuml;llen Sie die rot markierten Felder aus.";
         dojo.byId('Err_voucher').className = "DialogMessage MessageWarning";
         myForm.VoucherProduct_Email.focus();
         flag2=0;
       }
     }
     else
     {
        myForm.VoucherProduct_Email.className = "Text";
     }
     
     if(voucher_email != voucher_email_cofirm)
     {
         myForm.VoucherProduct_EmailConfirm.className = "Text DialogError";
         flag=0;
         if(flag2&&!flag){
           dojo.byId('Err_voucher').innerHTML = "Bitte f&uuml;llen Sie die rot markierten Felder aus.";
           dojo.byId('Err_voucher').className = "DialogMessage MessageWarning";
           myForm.VoucherProduct_EmailConfirm.focus();
           flag2=0;
         }
     }
     else
     {
        myForm.VoucherProduct_EmailConfirm.className = "Text";
     } 
    
     
     if(!flag)
     return false;
   
     myForm.submit();
   }
   
}
