$(document).ready(function(){
	$("#loaderdiv")
	.ajaxStart(function(){
	    $(this).show();
	})
	.ajaxComplete(function(){
	    $(this).hide();
	});
	$.ajaxSetup({
        error:function(x,e){
            if(x.status==0){
            alert('You are offline!!\n Please Check Your Network.');
            }else if(x.status==404){
            alert('Requested URL not found.');
            }else if(x.status==500){
            alert('Internel Server Error.');
            }else if(e=='parsererror'){
            alert('Error.\nParsing JSON Request failed.');
            }else if(e=='timeout'){
            alert('Request Time out.');
            }else {
            alert('Unknow Error.\n'+x.responseText);
            }
        }
    });
//	$("#menu").tabs("load",$("#menu").tabs("option","selected"));
	/*$("#menu").tabs({
			ajaxOptions: {
				error: function(xhr, status, index, anchor) {
					$(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible.");
				}
			}
	});*/
	$("#menu").tabs();
});
function $p(id) {
   return document.getElementById(id);
}
function setSelected(id, val){
    var obj = $p(id);
    for(i=0; i<obj.length; i++){
        var temp=obj[i];
        if(temp.value==val)
            temp.selected='true';
    }
}
function setSelectedObj(obj, val){
    for(i=0; i<obj.length; i++){
        var temp=obj[i];
        if(temp.value==val)
            temp.selected='true';
    }
}
function getSelectedValueObj(obj){
    for(i=0; i<obj.length; i++){
        var temp=obj[i];
        if(temp.selected==true)
            return temp.value;
    }
}
function setCurPage(value, form){
    $p('curpage').value= value;
    var fr= $p(form);
    fr.submit();
}
function setCurPageNoSubmit(k){
    $p('curpage').value= k;
}
function setAction(action){
	$p('action').value= action;
}
function postForm(form, action){
	$p('action').value= action;
    $p(form).submit();
}
function setCheckedUnchecked(ele, checked){
	var checks= ele.getElementsByTagName("input");
	if(checked=="checked")
		ch= true;
	else
		ch= false;
	for(i= 0; i< checks.length; i++){
        var check= checks[i];
        if(check.type=="checkbox"){
        	check.checked= ch;
        }
	}
}
function setCheckedUncheckedID(id, checked){
	var ele= $p(id);
	var checks= ele.getElementsByTagName("input");
	if(checked=="checked")
		ch= true;
	else
		ch= false;
	for(i= 0; i< checks.length; i++){
        var check= checks[i];
        if(check.type=="checkbox"){
        	check.checked= ch;
        }
	}
}
function conf(){
	if(confirm("Are you sure?"))
		return true;
	else
		return false;
}
function removeChilds(obj){
	not_text_child_length(obj);
}
function initFCKEditor(id, toobar){
    var sBasePath= document.location.protocol+"//"+document.location.hostname+document.location.pathname+"js/fckeditor/";
    var oFCKeditor = new FCKeditor( id );
    oFCKeditor.Height   = 400 ;
    oFCKeditor.Config["AutoDetectLanguage"] = false ;
    oFCKeditor.Config["DefaultLanguage"]    = "en" ;
    oFCKeditor.BasePath = sBasePath;
    oFCKeditor.ReplaceTextarea();
}
// called when FCKeditor is done starting..
function FCKeditor_OnComplete( editorInstance ){
        editorInstance.LinkedField.form.onsubmit = article.doAddUpdArticle;
}
function openComment(divId, moveX, moveY, resizeX, resizeY){
    var sort_order_popup = null;
    sort_order_popup = new PopupLayer(divId, "Event");
    var div= document.getElementById(divId);
    if (div) {
        div.style.display= "block";
        sort_order_popup.moveTo(moveX, moveY);
        sort_order_popup.resizeTo(resizeX, resizeY);    
        sort_order_popup.show();
    }
}
function closeComment(divId){
	var div = $p(divId);
    if (div)
        div.style.display = "none";
}

var validate = {

    isMail: function (x){
        return x.search(/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,}$/ig) != -1;
    },
    
    isEmpty: function(x){
        if(!this.isDefined(x))
            return false;
        if(this.isNumeric(x))
            return false;
        if(x=="")
            return true;
        return false;
    },
    
    isDefined: function(x){
        return typeof(x)!="undefined";
    },

    isNumeric: function(x){
        return this.isFloat(x);
    },
    
    isFloat: function(x){
        if(!this.isDefined(x))
            return false;
        return x!=""&&!isNaN(x);
    },
    
    isBlank: function(val){
        if(val==null){
            return true;
        }
        for(var i=0;i<val.length;i++){
            if((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){
                return false;
            }
        }
        return true;
    },
    
    isDigit: function(num){
        if(num.length>1){
            return false;
        }
        var string="1234567890";
        if(string.indexOf(num)!=-1){
            return true;
        }
        return false;
    },
    
    isInteger: function(val,message){
        if(validate.isBlank(val)){
            return false;
        }
        for(var i=0;i<val.length;i++){
            if(!validate.isDigit(val.charAt(i)))
                return false;
        }
        
        return true;
    }
}

