if(typeof(Page)=='undefined'){
 	var Page = {};
}

Page.SelectRender = function() {};
Page.SelectRender.prototype = {
	initialize :  function(container,params) {
	    this.setParams(params);
	    this.container = container;
	    this.start();
	 },
	start : function(){
	    if($(this.container)==null){
	    	return ;
	    }
		new Ajax.Request(this.params.actionUrl,{method :  'get', parameters : this.params, onComplete : this.render.bind(this)});
 	}, 
    render : function(req) {
		var jsonData = eval(req.responseText);
		//alert(req.responseText);
		$(this.container).options.length = 0;
		if(jsonData==null || jsonData.length==0)
		   return ;
	 	if(this.params.selTip != ''){
	 		$(this.container).appendChild(SelectHelper.builderOption(this.params.selTip, "", false));
	 	}
		for(i=0; i < jsonData.length; i++){
		   var text = jsonData[i].text;
		   var value = jsonData[i].value;
		   var isSel = (this.params.defaultValue == value);
		   $(this.container).appendChild(SelectHelper.builderOption(text, value, isSel));
	 	}
     } 
}


Page.JobFunction = Class.create();
Page.JobFunction.prototype = Object.extend(new Page.SelectRender(),{
  	 setParams :  function(params){
	    this.params = {
	    actionUrl : '/static/helper.do',
	    action : 'getFieldData',
	    fieldName : 'jobFunc',
	    defaultValue : '',
	    selTip : '-------------------'
	    };
	    Object.extend(this.params, params || {});
	 } 
});

Page.IndustryCategory = Class.create();
Page.IndustryCategory.prototype = Object.extend(new Page.SelectRender(),{
	 setParams :  function(params){
	    this.params = {
	    actionUrl : '/static/helper.do',
	    action : 'getFieldData',
	    fieldName : 'industryCategory',
	    defaultValue : '',
	    selTip : '-------------------'
	    };
	    Object.extend(this.params, params || {});
	 }
});

Page.IndustryType = Class.create();
Page.IndustryType.prototype = Object.extend(new Page.SelectRender(),{
	 setParams :  function(params){
	    this.params = {
	    actionUrl : '/static/helper.do',
	    action : 'getFieldData',
	    fieldName : 'industryType',
	    defaultValue : '',
	    categoryId : '',
	    selTip : '-------------------'
	    };
	    Object.extend(this.params, params || {});
	 }
});

Page.Country = Class.create();
Page.Country.prototype = Object.extend(new Page.SelectRender(),{
	 setParams :  function(params){
	    this.params = {
	    actionUrl : '/static/helper.do',
	    action : 'getFieldData',
	    fieldName : 'country',
	    name : '',
	    defaultValue : '',
	    selTip : '-------------------'
	    };
	    Object.extend(this.params, params || {});
	 }  
});

var SelectHelper = {
	 builderOptionHTML : function(text,value,isSel) {
	    var optionHTML = "<option value=" + value;
	    if(isSel){
	      optionHTML+= "selected";
	   	}
	   	optionHTML+= "\">" + text + "</option>";
	 	return optionHTML;
     }, 
      builderOption : function(text,value,isSel) {
	    var oOption = document.createElement("option");
	    oOption.appendChild(document.createTextNode(text));
	    oOption.setAttribute("value",value);
	    if(isSel){
	   	 oOption.setAttribute("selected","selected");
	    }
	 	return oOption;
     }      
};

function changeIndustryCategory(name,categoryId){
	new Page.IndustryType(name,{'categoryId' : categoryId});
}

function validForm(form){
    var errorNum = 0;
	Form.getInputs(form).each(function(e){ 
	     if(e.name.substring(0,1)=='*'){
		   var errName = "ERR_" + e.name.substring(1);
		   if($(errName) != null){
		      if(e.value == ''){
		      	$(errName).style.display = '';
		      	errorNum ++;
		      }else{
		      	$(errName).style.display = 'none';
		      }
		  }
	    }
	 });
	return (errorNum == 0);
}
