//Cosciisoft Editor
function parent_add_emoticon(src){
	//window.top.window.addEmoticon(src);
	window.opener.addEmoticonByPop(src);
	window.close();
}
function add_emoticon(src){
	addEmoticonByPop(src);
}
function setOpacity(obj) {
	obj.style.filter = "alpha(opacity=" + (0.40*100) + ")";
}
function setOpacityOff(obj){
	obj.style.filter = "alpha(opacity=" + (100) + ")";
}
//Dynamic Page
function add_image(src){
		if (editor.wyswing_box.contentWindow.document.selection)
			{
					 var sel = editor.wyswing_box.contentWindow.document.selection.createRange();
					 theParentNode = sel.parentElement();	
					if(theParentNode.nodeName.toUpperCase()!="FORM"){						
							sel.pasteHTML("<img src="+src+"  style=\"PADDING-RIGHT: 15px; PADDING-LEFT: 15px; PADDING-BOTTOM: 15px; PADDING-TOP: 15px;\" border=0 align=left>");
							sel.select();			
					}
		   }else{
					var selection = editor.wyswing_box.contentWindow.getSelection(); 
					var range = editor.wyswing_box.contentWindow.getSelection().getRangeAt(0); 
					var newNode = document.createElement('img'); 
					newNode.setAttribute('src',src);	
					newNode.setAttribute('border',0);	
					newNode.setAttribute('align',"absmiddle");			
					newNode.style.cssText="PADDING-RIGHT: 15px; PADDING-LEFT: 15px; PADDING-BOTTOM: 15px; PADDING-TOP: 15px";
					range.insertNode(newNode); 		
			}
}
function add_file_link(src,name){
	if (editor.wyswing_box.contentWindow.document.selection)
		{
				 var sel = editor.wyswing_box.contentWindow.document.selection.createRange();
				 theParentNode = sel.parentElement();	
				if(theParentNode.nodeName.toUpperCase()!="FORM"){						
						sel.pasteHTML("<a href=\"stream_file?file_name="+name+"&file_path="+src+"\" target=\"_blank\">"+name+"</a>");
						sel.select();			
				}
	   }else{
				var selection = editor.wyswing_box.contentWindow.getSelection(); 
				var range = editor.wyswing_box.contentWindow.getSelection().getRangeAt(0); 
				var newNode = document.createElement('a'); 
				newNode.setAttribute('href',"stream_file_spacial.php?file_name="+name+"&file_path="+src);	
				newNode.setAttribute('target','_blank');	
				newNode.innerHTML=name;			
				range.insertNode(newNode); 		
		}
}
//Validation
function is_null(objName){
	if(document.getElementById(objName).value==""){
		return true;	
	}else{
		return false;
	}	
}
function activeobj(objname){
	document.getElementById(objname).focus();	
	document.getElementById(objname).select();	
}
//Submit
function send_to(url){
	if(document.getElementById("CosciisoftEditor")!=null){
		editor.updateInput();	
	}
	document.form1.action=url;
	document.form1.submit();
}
function goto(url){
	window.location=url;
}
//Varities
function pop_window(url){
	var width = 700;
    var height = 500;
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2))-50;
	window.open(url,'',"scrollbars=1  resizable=1 menubar=1 width="+width+" height="+height+" left=" + left + " top=" + top );
}
function get_http_req(){
	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject){
		// code for IE6, IE5
	  	return new ActiveXObject("Microsoft.XMLHTTP");
	}	
}
function CDate(objName){
	var d = new Date();
	var currentDate=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear();
	var obj=document.getElementById(objName);
	if(obj.value=="")obj.value=currentDate;
	obj.onclick=function(){
		obj.select();			
	}	
	obj.onkeypress=function(){
		if((event.keyCode<47 || event.keyCode>57)) return false;	
		//alert(event.keyCode);
	}
	obj.onkeyup=function(){
		/*if(event.keyCode!=8){
			if(obj.value.length==2 && isNumeric(obj.value)) obj.value+="/";
			if(obj.value.length==5) obj.value+="/";
		}*/
	}
	obj.onblur=function(){
		if(obj.value.length==0 || !checkDateFormat(this)) obj.value=currentDate;
	}
}
function checkDateFormat(obj){
	var tmp=obj.value.split("/");
	var isDateFormat=true;
	if(tmp.length==3){
		if(tmp.length!=3){
			isDateFormat=false;
		}
		if(tmp[0]>31 || tmp[0]<0){
			isDateFormat=false;
		}
		if(tmp[1]>12 || tmp[1]<0){
			isDateFormat=false;
		}
		/*if(tmp[2]<1900 ){
			isDateFormat=false;
		}*/
		/*if(tmp[2].substr(0,2)>25 ||  tmp[2].substr(0,2)<25){
			isDateFormat=false;
		}*/
		if(tmp[2].length!=4){
			isDateFormat=false;
		}
		if(!isNumeric(tmp[0]) || !isNumeric(tmp[1]) || !isNumeric(tmp[2])){
			isDateFormat=false;
		}
	}else{
			isDateFormat=false;
	}
	return isDateFormat;
}
function CDateTime(objName,point_datetime){
	var obj=document.getElementById(objName);
	obj.value=point_datetime;
	obj.onclick=function(){
		obj.select();	
	}
	obj.onkeypress=function(){
		if(event.keyCode<48 || event.keyCode>57) return false;	
		//alert(event.keyCode);
	}
	obj.onkeyup=function(){
		if(event.keyCode!=8){
			if(obj.value.length==2 && isNumeric(obj.value)) obj.value+="/";
			if(obj.value.length==5) obj.value+="/";
			if(obj.value.length==10) obj.value+=" ";
			if(obj.value.length==13) obj.value+=":";
		}
	}
	obj.onblur=function(){
		if(obj.value.length==0 || !checkDateTimeFormat(this))obj.value=point_datetime;
	}
}
function checkDateTimeFormat(obj){
	var tmpx=obj.value.split(" ");
	if(tmpx.length==2){
		var tmp=tmpx[0].split("/");
		var isDateFormat=true;
		if(tmp.length==3){
			if(tmp.length!=3){
				isDateFormat=false;
			}
			if(tmp[0]>31 || tmp[0]<0){
				isDateFormat=false;
			}
			if(tmp[1]>12 || tmp[1]<0){
				isDateFormat=false;
			}
			/*if(tmp[2]<1900 ){
				isDateFormat=false;
			}*/
			/*if(tmp[2].substr(0,2)>25 ||  tmp[2].substr(0,2)<25){
				isDateFormat=false;
			}*/
			if(tmp[2].length!=4){
				isDateFormat=false;
			}
			if(!isNumeric(tmp[0]) || !isNumeric(tmp[1]) || !isNumeric(tmp[2])){
				isDateFormat=false;
			}
			tmp=tmpx[1].split(":");
			if(!isNumeric(tmp[0]) || !isNumeric(tmp[1])){
				isDateFormat=false;
			}
			if(tmp[0]>24 ||  tmp[0]<0 ||  tmp[1]>59 || tmp[1]<0 ){
				isDateFormat=false;
			}
		}else{
				isDateFormat=false;
		}
	}else{
			isDateFormat=false;
	}
	return isDateFormat;
}
function isNumeric(str){
	var valided=true;
	if(checkHaveData(str)){
	    for(j=0;j<str.length;j++){
	        if( (str.charCodeAt(j)<48) || (str.charCodeAt(j)>57) ){
	            valided=false;	
		    break;
	        }
	    }
        }else{
	     valided=false;
        }
	return valided;
}
function checkHaveData(str){
	valided=true;
	if(str.length==0){
	   valided=false;
	}
	return valided;
}
