dojo.declare("Perso.DialogWithoutClose",dijit.Dialog,{
postCreate: function(){	
	this.inherited(arguments); 
	this.closeButtonNode.style.display = "none";	
    }
  }
);

/*
 * Function to check if the input string is a valid email address
 * Return : true if valid or false 
 */
function isEmail(value) {
	var re=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	return re.test(value);
}

/*
 * Function to check if the input string is a valid domain
 * Return : true if valid or false 
 */
function isDomain(value) { 
	var re=/^((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	return re.test(value);
}

/*
 * Function to check if the input string is a valid user
 * Return : true if valid or false 
 */
function isUser(value) {
	var re=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))$/;
	return re.test(value);
}

/*
 * Function to check if the input string is a valid ip
 * Return : true if valid or false 
 */
function isIp(value) {
	 var re =/^([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})(\.([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})){3}$/
	 return re.test(value);
 }
 
/*
 * Function to Show or Hid a <DIV> content
 * Using Dojo FX effect
 * Paramters : 
 * 			wipeIn : boolean true or false
 * 			container : The container name to apply effect
 * 			timer : effect time in milliseconds 
 *  
 */ 
 function showHidePanel(maximize,container,timer) {		
	if (maximize)		
        dojo.fx.wipeIn({node: container,duration: timer}).play();        	
	else		
        dojo.fx.wipeOut({node: container,duration: timer}).play();
}

function showErrorDialog(title1,content1) {			
	var dialog = new Perso.DialogWithoutClose({ title: title1 ,style :"width:250px;" });	
	dojo.connect(dialog.domNode, "onkeyup", function (evt) {				
		if(evt.keyCode == dojo.keys.ESCAPE) {
			dialog.hide();
	 		dialog.destroyRecursive();
		}
	});

	var close = function(e) {dialog.hide();
							 dialog.destroyRecursive();
							 return false;								
	                         };             
	                      	           	   	                         
	var questionDiv = dojo.create('div', { innerHTML: content1  });
	var closeButton = new dijit.form.Button({ label: 'Close', id: 'cButton', onClick: close });
		
	dialog.containerNode.appendChild(questionDiv);
	dialog.containerNode.appendChild(closeButton.domNode);
	dialog.show();        
}
 
function validateForm() {  	  	       
	if (!form.validate())    	
    	showErrorDialog(errorlabel.attr("value"),errorlabelValue.attr("value"));    	
    else
    	showSavedDialog(savedlabel.attr("value"),savedlabel.attr("value"));    	         
}

function setCatid(e){	
	storeproduct.close();	    		
	storeproduct._jsonFileUrl = "/index/getprod/cat/"+catSelector.attr('value');	    	
	storeproduct.fetch();	
	prodSelector.attr('value','');
	prodSelector.setAttribute('disabled',false);
	prodSelector.refresh;		
}
