function checkCompAvailability(id){
    var frm = document.getElementById("signup-form");
    var fv = new Focus.FieldValidation(frm['compid'],{});
    //clear all validation-advice
    Ext.get(frm['compid']).parent().select('div.validation-advice').remove();    
    if(fv.validate()){
	    if(cid!=""){
	            var cid = frm['compid'].value;    
			    document.getElementById("avl_lbl").innerHTML = "Searching...";
			    Ext.Ajax.request({
			        url : 'CheckCompanyAvailability.aspx',
			        method : 'POST',
			        params : {
			            compid : cid,
			            inv_code : frm['inv_code'].value
			        },
			        success : function(o,r){
			            if(o.statusText.toLowerCase() == "ok"){
                            var responseText = o.responseText;
		                    if(responseText=="notfound"){
			                    document.getElementById("avl_lbl").innerHTML = "Available";
		                    }else{
			                    document.getElementById("avl_lbl").innerHTML = "Not Available";
		                    }			            
			            }
			        },
			        failure : function(o,r){
			            document.getElementById("avl_lbl").innerHTML = "Some Technical Problem at server side. Please refresh your page and try again.";
			        }
			    });
	    }
	}    
}

function ToggleSubmitBtn(me){
	var obj = document.getElementById("CreateBtn");
	if(me.checked){
		obj.disabled=false;
	}else{
		obj.disabled=true;
	}
}


function Signup(){
    var frm = document.getElementById("signup-form");
    var fields = [frm['compname'],frm['compid']];
    //clear all validation-advice
     Ext.select('div.validation-advice').remove();
    //select fields to send to validation
    if(frm['eemail'].value.trim().length==0){
        fields.push(frm['fname']);
        fields.push(frm['lname']);
        fields.push(frm['email']);
        fields.push(frm['pwd1']);
        fields.push(frm['pwd2']);
    }else{
        fields.push(frm['eemail']);
    }
    var fsv = new Focus.FieldSetValidation(fields,{});
    return fsv.validate();
    //if(fsv.validate()){
        //ajax hit here
    //}
}


function makeValidCompId(){
    var frm = document.getElementById("signup-form");
    var fv = new Focus.FieldValidation(frm['compid'],{});
    if(fv.validate()){
        var val = frm['compid'].value;
        //remove & and space character first 
        val = val.replace(/\&|\s/g,'');
        if(val.length>30){
            val = val.substr(0,30);
        }
        frm['compid'].value = val;
    }
}
function setCompId(){
    var frm = document.getElementById("signup-form");
    var fv = new Focus.FieldValidation(frm['compname'],{});
    if(fv.validate()){
        var val = frm['compname'].value;
        //remove & and space character first 
        val = val.replace(/\&|\s/g,'');
        if(val.length>30){
            val = val.substr(0,30);
        }
        frm['compid'].value = val;
    }
}
function setUser(){
    var frm = document.getElementById("signup-form");
    if(frm['eemail'].value.trim().length>0){
        frm['fname'].disabled = true;
        frm['lname'].disabled = true;
        frm['email'].disabled = true;
        frm['pwd1'].disabled = true;
        frm['pwd2'].disabled = true;
    }else{
        frm['fname'].disabled = false;
        frm['lname'].disabled = false;
        frm['email'].disabled = false;
        frm['pwd1'].disabled = false;
        frm['pwd2'].disabled = false;
        frm['fname'].focus();
    }
}

function newProject(){
    var frm = document.getElementById("newproj-form");
    var fields = frm.elements;
    //clear all validation-advice
    Ext.select('div.validation-advice').remove();
    var fsv = new Focus.FieldSetValidation(fields,{});
    var validate = fsv.validate();
    if(validate){
        if(frm['projid'].value.trim().length==0){
            validate = genProjId();
        }
    }
    return validate;
}

function importproj(){
    var frm = gE('importproj-form')
    var fields = frm.elements;
    //clear all validation-advice
    Ext.select('div.validation-advice').remove();
    var fsv = new Focus.FieldSetValidation(fields,{});
    var validate = fsv.validate();
    if(validate){
        if(frm['projid'].value.trim().length==0){
            validate = genProjId('importproj-form');
        }
    }
    
    return validate;
}


function genProjId(name){
    name = name || "newproj-form";
    var frm = document.getElementById(name);
    var fv = new Focus.FieldValidation(frm['projname'],{});
    if(fv.validate()){
        var val = frm['projname'].value;
        //remove & and space character first 
        val = val.replace(/\&|\s/g,'');
        if(val.length>30){
            val = val.substr(0,30);
        }
        frm['projid'].value = val;
        return true;
    }else{
        frm['projid'].value = '';
        return false;
    }
}


function changepwd(){
    var link = gE('chg_pwd');
    var is2show = link.getAttribute('show') || 'false';
    var pwd1_el = gE('changepwd1');
    var pwd2_el = gE('changepwd2');
    var frm = gE('myaccount');
    if(is2show=='false'){
        pwd1_el.style.display = '';
        pwd2_el.style.display = '';
        frm['pwd1'].disabled = false;
        frm['pwd2'].disabled = false;
        link.setAttribute('show','true');
    }else{
        pwd1_el.style.display = 'none';
        pwd2_el.style.display = 'none';
        frm['pwd1'].disabled = true;
        frm['pwd2'].disabled = true;
        link.setAttribute('show','false')
    }
}

function back2dashboard(){
    document.location.href = 'userdashboard.aspx';
}

function updateinfo(){
    var frm = gE('');
    var link = gE('chg_pwd');
    var is2show = link.getAttribute('show') || 'false';    
    var frm = gE('myaccount');
    if(!frm) return false;
    frm.method = "POST";
    //clear all validation-advice
    Ext.select('div.validation-advice').remove();    
    //validate    
    var fields = [frm['fname'],frm['lname']];
    if(is2show=='true'){
        fields.push(frm['pwd1']);
        fields.push(frm['pwd2']);
    }
    var fsv = new Focus.FieldSetValidation(fields,{});
    return fsv.validate();
}

function forgotpwd(){
    var frm = gE('forgotpwd');
    if(!frm) return false;
    frm.method = "POST";
    //clear all validation-advice
    Ext.select('div.validation-advice').remove();    
    //validate    
    var fields = [frm['email']];
    var fsv = new Focus.FieldSetValidation(fields,{});
    return fsv.validate();    
}