/****************************************************
| Created   : 24/4/2008 | 21:31:00 GMT
| Updated   : 
| Category  : Programming Langauges (javascript)
| Title     : My admin control
| Subject   : 
| Group     : FUNCTIONS
| Author    : OJOpc E-mail: ojopc@yahoo.com
| Company   : www.iq4iq.net 2003-2008
****************************************************/
function ojopc_show_aux(parent, child){
  var p = document.getElementById(parent);
  var c = document.getElementById(child);
  var top  = (c["obj_position"] == "y") ? p.offsetHeight+2 : 0;
  var left = (c["obj_position"] == "x") ? p.offsetWidth +2 : 0;
  for (; p; p = p.offsetParent){
    top  += p.offsetTop;
    left += p.offsetLeft;
  }
  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}
function ojopc_show(){
  var p = document.getElementById(this["link_rollover"]);
  var c = document.getElementById(this["win_atshow" ]);
  ojopc_show_aux(p.id, c.id);
  clearTimeout(c["realtimeout"]);
}
function ojopc_hide(){
  var c = document.getElementById(this["win_atshow"]);
  c["realtimeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 125);
}
function ojopc_attach(parent, child, showtype, position, cursor){
  var p = document.getElementById(parent);
  var c = document.getElementById(child);
  p["link_rollover"]     = p.id;
  c["link_rollover"]     = p.id;
  p["win_atshow"]      = c.id;
  c["win_atshow"]      = c.id;
  p["obj_position"]   = position;
  c["obj_position"]   = position;
  c.style.position   = "absolute";
  c.style.visibility = "hidden";
  if (cursor != undefined) p.style.cursor = cursor;
  switch (showtype) {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = ojopc_hide;
      c.onmouseover = ojopc_show;
      c.onmouseout  = ojopc_hide;
      break;
    case "hover":
      p.onmouseover = ojopc_show;
      p.onmouseout  = ojopc_hide;
      c.onmouseover = ojopc_show;
      c.onmouseout  = ojopc_hide;
      break;
  }
}
// *******************************************************************
// ##### Office colors 2007, system colors Office 2007
// generate by ojopc@yahoo.com 
// 00:25 GMT ‎10/‎11/‎2008 
function color_Init() {
  document.body.onkeypress = color_CloseOnEsc;
}
function color_CloseOnEsc() {
  if (event.keyCode == 27) { window.close(); return; }
}
function color_View(color) {
	document.getElementById('ColorPreview').style.backgroundColor = '#' + color;
	document.getElementById('ColorHex').value = '' + color;
	document.getElementById('colorselected').style.backgroundColor = '#' + color;
}
function color_ValidateColor(string) {
  string = string || '';
  string = string + "";
  string = string.toUpperCase();
  chars = '0123456789ABCDEF';
  out   = '';
		// remove invalid color chars
  for (i=0; i<string.length; i++) {
    schar = string.charAt(i);
    if (chars.indexOf(schar) != -1) { out += schar; }
  }
		// check length
  if (out.length != 6) { return null; }
  return out;
} 
// select color
function color_Set(string) {
  color = color_ValidateColor(string);
  if (color == null) { alert("Invalid color code: " + string); 
	} else {
    color_View(color);
    window.returnValue = color;
    window.close();
  }
}
// *******************************************************************
// ##### Resize Fonts in selected Tags - like=file[0-9]
// generate by ojopc@yahoo.com 
// 10:25 GMT ‎5/12/‎2008 
var tgs = new Array('p');
var szs = new Array('x-small', 'small', 'normal', 'medium', 'large', 'x-large', 'xx-large');
var startSz = 3;
function fs( trgt, inc ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	sz += inc;
	
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
	cEl.style.fontSize = szs[ sz ];
	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}
// *******************************************************************
// ##### Set Pop Up Window 
// generate by ojopc@yahoo.com 
var win=null;
function ojopc_popwindow(mypage, myname, w, h, scroll, pos){
	if(pos=='random'){
	LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
	TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
if(pos=='center'){
LeftPosition=(screen.width)?(screen.width-w)/2:100;
TopPosition=(screen.height)?(screen.height-h)/2:100;
}
else if((pos!='center' && pos!='random') || pos==null){
LeftPosition=0;TopPosition=20
}
settings='width='+w+', height='+h+', top='+TopPosition+', left='+LeftPosition+', scrollbars='+scroll+',location=no, directories=no, status=no, menubar=no, toolbar=no, resizable=no';
win=window.open(mypage,myname,settings);
}
// ******************************[Groups]*****************************
// showHeddinContent
// generate by ojopc@yahoo.com 
// G1 
// function is work in select & any tag in html
function showContent(targetid){
	if (document.getElementById) {
     targetelement = document.getElementById(targetid);
    if (targetelement.style.display == 'none') {
			 targetelement.style.display = '';
			}
	}
}
function ojopc_otherSelect(Id, divId){
var val = document.getElementById(Id).value;
var gover = the_id;
	if(gover == val) {
			document.getElementById(gover).style.display='block';
			return true;
	} else {
			document.getElementById(gover).style.display='none';
			return false;
	}
}
function showHeddinContent(targetid){
     targetelement = document.getElementById(targetid);
    if (targetelement.style.display == 'none') {
			 targetelement.style.display = '';
			} else {
			targetelement.style.display = 'none';
		}
}
function showHeddinContent_2div(targetid, targetid2){
	if (document.getElementById) {
     targetelement = document.getElementById(targetid);
    if (targetelement.style.display == 'none') {
			 targetelement.style.display = '';
			 document.getElementById(targetid2).style.display = 'none';
			} else {
			targetelement.style.display = 'none';
			document.getElementById(targetid2).style.display = '';
		}
	}
}
// form.use in (tip in inputs form before type)..
function clear_inputvalue(targetid, lastvalue){
var field = document.getElementById(targetid).value
if (field == lastvalue)
document.getElementById(targetid).value = "";
}
// *****************************************************
// confirm,msg,alert
// function confirmation event any submit
// ======================================
function check_var() {
	if (window.confirm('هل أنت متأكد من الإجراء الحالي ؟')) 
		return true; 
		else return false;
	}
function check_exitwindow() {
	if (window.confirm('هل تريد الخروج ؟')) 
		return true; 
		else return false;
	}

// Select checkbox puts (checkAll, Uncheck)
function checkedtxtbox(theElement) {
var z = 0
var formId = theElement.form
	for(z=0; z<formId.length;z++){
		if(formId[z].type == 'checkbox' && formId[z].name != 'checkall'){
			formId[z].checked = theElement.checked;
		}
	}
}
function checkAll(form){
  for (var i = 0; i < form.elements.length; i++){
    eval("form.elements[" + i + "].checked = form.elements[0].checked");  
  } 
} 
// the limitation char for input (text, textarea)
var ns6=document.getElementById&&!document.all
function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}
function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text=' <em class="limitchar" id="'+theform.toString()+'">'+thelimit+'</em>'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}
// check inputs var empty or more, nice function (my function)
function CheckEmptyFields(formobj){
	var fieldRequired = Array('title');
	var fieldDescription = Array(' العنوان');
	var alertmsm = "خطأ في الإضافة ! .. لا يمكنك ترك الحقول المطلوبة فارغة :\n";
	var l_Msg = alertmsm.length;
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.options[obj.selectedIndex].value == ""){
					alertmsm += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertmsm += " -  " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "file":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertmsm += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertmsm += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}
	if (alertmsm.length == l_Msg){
		return true;
	}else{
		alert(alertmsm);
		return false;
	}
}
// *****************************************************
// Textarea resizeble
var ojopc_glob;
var ojopc_dash;
function resize(id, event) {
try {
		ida=id;
		ojopc_glob = document.getElementById(id).style;
		if ( !event ) var event = window.event
				ojopc_dash = event.clientY + document.body.scrollTop;
				document.onmousemove = _resize;
				document.onmouseup = _cancel;
	}
catch (err){}
}
function _cancel() {
	document.onmouseup = null;
	document.onmousemove = null;
}
function _resize(event) {
		try {
			if ( !event ) var event = window.event
				event.cancelBubble = true;
				event.returnValue = false;
			if (event.stopPropagation) event.stopPropagation();
			if (event.preventDefault) event.preventDefault();
				var move = event.clientY + document.body.scrollTop - ojopc_dash;
				ojopc_dash = event.clientY + document.body.scrollTop;
			var height = ojopc_glob.height.replace('px', '')
			if (((+height) + move) > 20) ojopc_glob.height = (+height) + move;
		}
		catch (err){}
}
// *****************************************************
// Inputs char and numbers [labs]
// Int Only My input [IE]
function maskKeyPress(objEvent)	{
var iKeyCode;  	
iKeyCode = objEvent.keyCode;			
	if(iKeyCode>=48 && iKeyCode<=57) return true;
return false;
}
// only somethink
function numbersonly(e){
	var key;
	var keychar;
	if (window.event)
	key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	else
		return false;
}
// just numbers in .000
function floatsonly(e){
	var key;
	var keychar;
	if (window.event)
	key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;
	else if ((("0123456789.").indexOf(keychar) > -1))
		return true;
	else
		return false;
}
// Get RGB color Values
function rgbvalues(e){
	var key;
	var keychar;
	if (window.event)
	key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;
	else if ((("1234567890abcdef").indexOf(keychar) > -1))
		return true;
	else
		return false;
}

var checkobj
function accept_delete(el){
checkobj=el
	if (document.all||document.getElementById){
		for (i=0;i<checkobj.form.length;i++){
			var tempobj=checkobj.form.elements[i]
			if(tempobj.type.toLowerCase()=='button') tempobj.disabled=!checkobj.checked
			
		}
	}
}





// *****************************************************
// Textarea resizeble NEW
var defsize = 200;
var miniresize = 40;
function ojopc_expand(getidname) {
    e = document.getElementById(getidname).style.height;
    e = parseInt(e.replace("px",""));
    if (isNaN(e)) {
        e = defsize;
    }
    e += miniresize;
    document.getElementById(getidname).style.height = e + "px"; 
}
function ojopc_contract(getidname) {
    e = document.getElementById(getidname).style.height;
    e = parseInt(e.replace("px",""));
    if (isNaN(e)) {
        e = defsize;
    } 
    if (e > defsize) {
        e -= miniresize;
        document.getElementById(getidname).style.height = e + "px";
    }
}
