function isEmail(inputString) {
	regexp=/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
	if (regexp.test (inputString)) return true
	else return false;
}
function isNumeric(inputString) {
	regexp=/^[0-9]+\.[0-9]+$/;
	regexpnum=/^[0-9]+$/;
	if (regexp.test (inputString) || regexpnum.test (inputString)) return true
	else return false;
}

function isEmpty (inputString) {
	if (inputString=='') return true
	else return false;
}

function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

function validateLogin() {
  	if(document.loginForm.user.value=='') {
                document.loginForm.user.focus();
                document.loginForm.user.style.border='2px solid red';
                createAlert('Please enter your username',true);
                return false;
        }

        if(document.loginForm.password.value=='') {
                document.loginForm.password.focus();
                document.loginForm.password.style.border='2px solid red';
                createAlert('Please enter your password',true);
                return false;
        }
	return true;
}
function rusure(m,url) { // message to display
      Dialog.confirm(m,
					{windowParameters: {width:300}, okLabel: "Confirm",
					buttonClass: "myButtonClass",
					id: "myDialogId",
					cancel:function(win) {return false;},
					ok:function(win) {document.location = url; return true;}
					});
}

function rusureajax(m,mod,url,target) { // message to display
	Dialog.confirm(m,
					{windowParameters: {width:300}, okLabel: "Confirm",
					buttonClass: "myButtonClass",
					id: "myDialogId",
					cancel:function(win) {return false;},
					ok:function(win) {xajax_axLoadPage(mod,url,target); return true;}
					});
}


function addproduct(categoryid) {
	var categoryid;
	var x=document.getElementById("category");

	for ($i=0;$i<x.length;$i++) {

		if (x.options[$i].value == categoryid) {
			x.selectedIndex=$i;
		}
	}
	var formik = document.getElementById( 'addproduct');
	var formtext = document.getElementById( 'addtext');

	if (formik.style.display == "block") {
		formik.style.display='none';
		formtext.innerHTML='Add product in this category.';

	} else {
		formik.style.display='block';
		formtext.innerHTML='Hide form.';
		var fck = FCKeditorAPI.GetInstance( 'description' ) ;
        if (  fck.EditMode == FCK_EDITMODE_WYSIWYG )
                fck.MakeEditable() ;
        }
}


// file multi laoder
	// <!-- Create an instance of the multiSelector class, pass it the output target and the max number of files -->
	function fsinit(i) {
		var multi_selector = new MultiSelector( document.getElementById( 'files_list' ), 10 );
		// <!-- Pass in the file element -->
		multi_selector.addElement( document.getElementById( i ) );
	}


// nested tree menu script

function toggle(id){
    ul = "ul_" + id;
    span = "span_" + id;
    ulElement = document.getElementById(ul);
    spanElement = document.getElementById(span);
    if (ulElement){
            if (ulElement.className == 'closed'){
                    ulElement.className = "open";
                    spanElement.className = "opened_img";
                    }else{
                    ulElement.className = "closed";
                    spanElement.className = "closed_img";
                    }
            }
}


/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

function showhide(id) {
	var lyr = getElemRefs(id);
	if (lyr.css.display == "none") lyr.css.display = "block";
	else lyr.css.display = "none";
}

// onresize for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr;	// holds id of currently visible layer
function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  //if (lyr && lyr.css) lyr.css.visibility = "visible";
  if (lyr && lyr.css) lyr.css.display = "block";
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  //if (lyr && lyr.css) lyr.css.visibility = "hidden";
  if (lyr && lyr.css) lyr.css.display = "none";

}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

// MOVE  ELEMETES BETWEEN SELECT
function copyToList(from,to)
{
  //fromList = eval('document.forms[0].' + from);
   fromList = document.getElementById(from);

  //toList = eval('document.forms[0].' + to);
  toList = document.getElementById(to);
  if (toList.options.length > 0 && toList.options[0].value == 'temp')
  {
    toList.options.length = 0;
  }
  var sel = false;
  for (i=0;i<fromList.options.length;i++)
  {
    var current = fromList.options[i];
    if (current.selected)
    {
      sel = true;
      if (current.value == 'temp')
      {
        alert ('You cannot move this text!');
        return;
      }
      txt = current.text;
      val = current.value;
      toList.options[toList.length] = new Option(txt,val);
      fromList.options[i] = null;
      i--;
    }
  }
  if (!sel) alert ('You haven\'t selected any options!');
}
// SELECT SCRIPT FOR MEMBERS OF GROUP IN user_management_group_edit.html
function allSelect()
{
  List = document.forms[0].members;
  //if (List.length && List.options[0].value == 'temp') return;
  for (i=0;i<List.length;i++)
  {
     List.options[i].selected = true;
  }
}

var counter = 0;
function setStyle(theObj, styleName, styleValue, priority) {
	var bSuccess = false;

	try {
		if (theObj.style && theObj.style.setProperty) {
			theObj.style.setProperty(styleName, styleValue,priority);
			bSuccess = true;
		}
	} catch (ex) {
		alert('exception caught setting style: ' + ex.message); // cannot do anything try the next method
	}
	if (!bSuccess) {
		try {
			theObj.style[styleName] = styleValue;
			bSuccess = true;
		} catch (exNext) {
			alert('exception caught setting direct style: ' + exNext.message); // cannot do anything
		}
	}
	return bSuccess;
} // end of setStyle

var gFocusItem = null;

function doFocus() {
	try {
		if (gFocusItem != null) {
			gFocusItem.focus();
			gFocusItem=null;
		}
	} catch (error) {
		alert("DEBUG: error in doFocus()");
	}
}


function createAlert(alertText, bGiveFocus) {

	Dialog.alert(alertText, {windowParameters: {
									className: "alphacube",
									width:300,
									height:100
													}, okLabel: "Ok"});
}

function OLDcreateAlert(alertText, bGiveFocus) {
	var popupDiv = document.createElement("div");
	popupDiv.setAttributeNS("http://www.w3.org/TR/xhtml2", "role", "wairole:alert");
	var divId = "alert" + counter++;
	popupDiv.setAttribute("id", divId);
	popupDiv.setAttribute("tabindex", "-1");
	popupDiv.setAttribute("class", "alert");
	setStyle(popupDiv,"display", "block", "");
	var dataNode = document.createTextNode(alertText);
	popupDiv.appendChild(dataNode);
	var close = document.createElement("a");
	close.setAttribute("onclick", "closeAlert('" +divId + "');");
	close.setAttribute("href", "#");
	var closeText = document.createTextNode("close");
	close.appendChild(closeText);
	var closeDiv = document.createElement("div");
	setStyle(closeDiv, "clear", "both","");
	setStyle(closeDiv,"text-align","right","");
	setStyle(closeDiv,"margin-top","5px","");
	closeDiv.appendChild(close);
	popupDiv.appendChild(closeDiv);
	//var contentDiv = document.getElementById("content");

	// try parenting to a div on the page rather than document.body
	var divParent = document.getElementById("alertParent");
	divParent.appendChild(popupDiv);
	//document.body.appendChild(popupDiv);
	if (bGiveFocus) {
		gFocusItem = popupDiv;
		setTimeout("doFocus();", 0);
	}
	return false; // handled
}

function closeAlert(divId) {
	var popupDiv = document.getElementById(divId);
	setStyle(popupDiv,"display", "none", "");
	var divParent = document.getElementById("alertParent");
	divParent.removeChild(popupDiv);
	//document.body.removeChild(popupDiv);
}

function addLoadEvent(func)
{
        var oldonload = window.onload;
        if (typeof window.onload != 'function'){
        window.onload = func;
        } else {
                window.onload = function(){
                oldonload();
                //eval(func);
			func();
                }
        }

}
/*global vars*/
var emod; 	/*the event model*/
var alt = false;
var ctrl = false;
var shift = false;
var key = false;

function onKeyDownH(e)
{

	switch (emod) {
		case "IE4+":
			e = window.event;
			alt = (e.altKey) ? true : false;
			ctrl = (e.ctrlKey) ? true : false;
			shift = (e.shiftKey) ? true : false;
		break;
		case "NN4":
			alt = ((e.modifiers & Event.ALT_MASK) == Event.ALT_MASK);
			ctrl = ((e.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK);
			shift = ((e.modifiers & Event.SHIFT_MASK) == Event.SHIFT_MASK);
		break;
		case "W3C":
			alt = (e.altKey) ? true : false;
			ctrl = (e.ctrlKey) ? true : false;
			shift = (e.shiftKey) ? true : false;
		break;
		default:
			if (e.target) {
			alt = (e.altKey) ? true : false;
			ctrl = (e.ctrlKey) ? true : false;
			shift = (e.shiftKey) ? true : false;
			}
		break;
		}
		if(e.keyCode) key=e.keyCode;
		return key;
}

function onloadH(e)
{
	/*get the event model*/
	emod = (e) ? (e.eventPhase) ? "W3C" : "NN4" : (window.event) ? "IE4+" : "unknown";

	/*A*/
	if (emod == "NN4") {
	document.captureEvents(Event.KEYDOWN);
	}
	document.onkeydown = onKeyDownH;
	return true;
}
// to init emod deifnation
addLoadEvent(onloadH);

// to remove del + item
function jxdelRow(id,table) {
	if (key == "68") xajax_delRow(id,table); // D + click
}

function delRow(id) {
		Fat.fade_element(id,null,700,'#FF3333');
		setTimeout("document.getElementById('" + id +"').style.display= 'none';", 800);
}

function windowPopUp (id,title,urlpath) {
	var win = new Window(id,
			{	className: "alphacube",
				title: title,
				top:40, left:160, width:900, height:580,
				resizable: true, url: urlpath, showEffectOptions: {duration:1}
			})
	win.setDestroyOnClose();
	win.showCenter(true);
	win.show();
}




function cmsbg(image) {
          var cmsImage = document.getElementById("cmsImage");
          if(image != "") {
                cmsImage.style.background = "url(" + image +") no-repeat";
          }
}


function popUp(URL,name,width,height) {
	day = new Date();
	window.open(URL,"newOne", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + width +",height=" + height);

}

function creatediv(t) {
			var tool = document.createElement('div');
			tool.innerHTML = t;
			tool.id = oldtooltip.id;
			tool.style.visibility = 'visible';
			con = document.getElementById("container");
			document.body.insertBefore(tool,con);
}

function selectit(name) {
	var v = eval('document.forms[0].' + name);

	if(v.checked) {
		v.checked = false;
	} else  {
		v.checked = true;
	}
}

function checkUncheckAll(theElement) {
   var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox'){
	  	if(theForm[z].checked)  theForm[z].checked = false;
	  	else theForm[z].checked = true;
	  }
	 }
}
/* FCK + AJAX */
function getfck(frm,id) {
	var val = get_ed_text(id);
	frm.elements[id].value = val;
}


function get_ed_text(editor_name)
{
    var oEditor = FCKeditorAPI.GetInstance(editor_name) ;
    if (oEditor.EditorDocument.body.innerHTML) {
        // Uncomment the following line for a proper XHTML return
        // return oEditor.GetXHTML();
        return oEditor.EditorDocument.body.innerHTML;
    }
    else return '';
}

