/*****************************************************************
** Use there function to invoke iframe script from main page
**
******************************************************************/
function defaultFrameAction(thisFrame,actionName) {
	var method = "on"+actionName+"()";
	try {
		execFrameAction(thisFrame,method);
		return true;
	} catch (e) {
        return true;
	}
}
function execFrameAction(frame,action) {
	frame.document.getElementById("actionExecutor").value=action;
	frame.document.getElementById("actionExecutor").click();
}
function invokeFrameAction(button){
	var method = button.value;
    try {
        eval(method);
    } catch (e) {
        alert(method+" may not be defined in frame page."+e);
    }
}


/*****************************************************************
** modal dialog return value
**
******************************************************************/
function modalDlgReturn(aid,aname){
      parent.window.returnValue=aid+'|^|'+aname;
      parent.window.close();
}

function uploadDlgReturn(aid){
      parent.window.returnValue=aid;
      parent.window.close();
}




/*****************************************************************
** To forbid some key and click events
**
******************************************************************/
//forbid body
function forbidMenuAndSelect() {
    var str = event.srcElement.tagName.toLowerCase();
    if (str=="input" || str=="textarea") {
        return true;
    }
    return false;
}

//forbid special key
function forbidSpecialKey() {

    if ((event.keyCode==116)||(event.ctrlKey && event.keyCode==82)){
        event.returnValue=false;//Ctrl+R ,F5
    }
    if ((event.ctrlKey)&&(event.keyCode==78)) // Ctrl+n
        event.returnValue=false;
    if ((event.shiftKey)&&(event.keyCode==121)) // shift+F10
        event.returnValue=false;
    if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
        window.event.returnValue = false; //shift+left click

    if ((window.event.altKey)&&(window.event.keyCode==37)||(window.event.altKey)&&(window.event.keyCode==39)){
        window.event.returnValue = false; //alt+> alt+<
    }
}



/*****************************************************************
** post form it's important function
**
******************************************************************/
//refresh
function invokeRefresh(action){
    if (action!=-1){
        window.location.href=''; //solve progressbar problem
        document.all.action_field.value='S'+action;
        document.all.action_btn.click();
    }
}




/*****************************************************************
** website page's location and redirect
**
******************************************************************/
//open page with parammeters
function openExternalPage(linkPage,parameters,newWindow,width,height){
    var url = "app?service=external/"+linkPage+"&amp;sp=S"+parameters;
    if (newWindow==true) {
        openNewWindow(url,width,height);
    } else {
        window.location = url;
    }
}
//forward
function forwardLocate(linkPage,parameters){
    if (parameters==undefined) parameters = "";
    var url = "app?service=external/"+linkPage+"&amp;sp=S"+parameters;
    window.location = url;
}





/*****************************************************************
** others
**
******************************************************************/

//open a new window in center
function openNewWindow(dourl,width,height){
	var viewOnlyStr="";
	var str = "height=" + height + "px,innerHeight=" + height + "px";
	str += ",width=" + width + "px,innerWidth=" + width+"px,status=yes,scrollbars=yes,resizable=yes,dependent";
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}
    window.open(dourl,"",str);
}


//replace all
function replaceStr(str,re,ne){
    while ( str.indexOf(re)!=-1 ) {
        str = str.replace(re,ne);
    }
    return str;
}

function formatReturnString(str){
    str = replaceStr(str,"&amp;","&");
    str = replaceStr(str,"&quot;","\"");
    str = replaceStr(str,"&lt;","<");
    str = replaceStr(str,"&gt;",">");
    str = replaceStr(str,"&nbsp;"," ");
    str = replaceStr(str,";","!");
    return str;
}

function reloadPageForSessionTimeOut(){
    parent.parent.window.location = "app?service=page/webApp:Logout";
}





/*****************************************************************
** validation
**
******************************************************************/
function v_isEmpty(str){
	var isN;
	if (str == "" || str == null){
        isN = true;
    } else {
        isN = false;
    }
	return isN;
}

//new window
function v_openNewWindow(url,width,height){
    var features = "dialogHeight:"+height+"px;dialogWidth:"+width+"px;resizable:yes ;help:no;status:no;";
    window.showModalDialog(url,0,features);

}









