function dumpObj(obj, name, indent, depth) 
{
    var MAX_DUMP_DEPTH = 10;
    if (depth > MAX_DUMP_DEPTH) {
        return indent + name + ": <Maximum Depth Reached>\n";
    }

    if (typeof obj == "object") {
        var child = null;
        var output = indent + name + "<br/>\n";
        indent += "&nbsp;\t";
        for (var item in obj)
        {
            try {
                child = obj[item];
            } catch (e) {
                child = "<Unable to Evaluate>";
            }
            if (typeof child == "object") {
                output += dumpObj(child, item, indent, depth + 1);
            } else {
                output += indent + item + ": " + child + "<br/>\n";
            }
        }
        return output;
    } else {
        return obj;
    }
}

function stripHtml(htstring) {
    return htstring.replace(/(<([^>]+)>)/ig,""); 
}

function isEmail(str) {
    // are regular expressions supported?
    var supported = 0;
    if (window.RegExp) {
        var tempStr = "a";
        var tempReg = new RegExp(tempStr);
        if (tempReg.test(tempStr)) supported = 1;
    }
    if (!supported) 
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    return (!r1.test(str) && r2.test(str));
}

function submitActionTarget(form, action, target) {
    form.action=action;
    form.target=target;
    form.submit();
}

function submitActionTargetByID(form, action, target) {
    var objForm = document.getElementById(form);
    objForm.action=action;
    objForm.target=target;
    objForm.submit();
}

function popupWindow(urlPath,width,height){
    popWin=window.open(urlPath, 'PopWin', 'width='+width+',height='+height+',top=0,left=50, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no');
    if(typeof(popWin)=="object"){
        popWin.focus();
        popWin.moveTo(screen.availWidth/10,90);
    }
}

function popupWindow2(url) {
    window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=320,height=370,screenX=0,screenY=0,top=0,left=0');
}

function popupWindow3(urlPath,width,height){
	window.open(urlPath, 'PopWin', 'width='+width+',height='+height+',toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');
//    popWin=window.open(urlPath, 'PopWin', 'width='+width+',height='+height+',toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');
//    if(typeof(popWin)=="object"){
//        popWin.focus();
//        popWin.moveTo(screen.availWidth/10,90);
//    }
}

function jumpToTarg(targ,urlPath){ // go to target url
    eval(targ+".location='"+urlPath+"'");
}

function historyGo(num){ // history back
    history.go(num);
}

function setUploadObjExtend(objID,startNum,endNum){	// expend upload image fieldbox
    var x;
    x=document.getElementById(objID);
    str='';
    str+="<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
    for(i=startNum;i<endNum+1;i++){
        j=i+2;
        str+="<tr>";
        str+="<td align='left' width='150'>Photo "+i+" : </td>";
        str+="<td align='left'>";
        str+="<input name='uploadImg[]' type='file' class='regitration_input_txtbox1' id='uploadImg"+i+"'> ";
        str+="<input name='ImgBtn"+j+"' type='button' id='ImgBtn"+j+"' value='OK' />";
        str+="</td>";
        str+="</tr>";
    }
    str+="</table>";
    if(x != null){
        x.innerHTML=str;
    }
    else{
        alert('setUploadImgExtend exception!');
    }
}

function showHiddenArea(sid){		// show or hide special area with sid
    document.getElementById(sid).style.display = document.getElementById(sid).style.display == "none" ? "" : "none";
}

function showHiddenField(sid){		// show or hide special area with sid
    document.getElementById(sid).style.display =  "";
}

function hideHiddenField(sid){		// show or hide special area with sid
    document.getElementById(sid).style.display =  "none";
}

function enableField(sid){		// enable special area with sid
    document.getElementById(sid).disabled =  false;
}

function disableField(sid){		// disable special area with sid
    document.getElementById(sid).disabled =  true;
}

/**
 * to control the row display attribute displayed or not displayed begin
 **/
function expandRow(rowid,parent_row,parent_row_bg,id_next_parent) 
{
    if(rowid!=''){
        obj = document.getElementById(rowid);
        obj.style.display = "";//inline;block; tried,not good. empty seems both ok in firefox and IE
    }
	
    if(parent_row!=''){
        obj_parent = document.getElementById(parent_row);
        obj_parent.style.backgroundColor=parent_row_bg; 
    }
	
    if(id_next_parent!=''){
        obj_next_parent = document.getElementById(id_next_parent);
        //obj_next_parent.className = 'bordered_top';
        obj_next_parent.style.display = "";
        //alert(obj_next_parent.id);
    }

    return false;
}

function collapseRow(rowid,parent_row,parent_row_bg,id_next_parent) 
{
    if(rowid!='')
    {
        obj = document.getElementById(rowid);
        obj.style.display = "none";
    }


    if(parent_row!=''){
        obj_parent = document.getElementById(parent_row);
        obj_parent.style.backgroundColor=parent_row_bg; 
    }

    if(id_next_parent!=''){
        obj_next_parent = document.getElementById(id_next_parent);
        obj_next_parent.style.display = "none";
    }


    return false;
}

/**
 * to control the row display attribute displayed or not displayed end
 **/

function closeWindow()
{
    window.close();
}

/**
 *compare the order of two date
 *return true if startdate < enddate
 *return true if one date is null
 *return false if startdate >= enddate
 */
function checkDateEarlier(strStart,strEnd,splitter)
{
    if (( strStart == "" ) || ( strEnd == "" ))
        return true;
    //    var arr1 = strStart.split("-");
    //    var arr2 = strEnd.split("-");
    var arr1 = strStart.split(splitter);
    var arr2 = strEnd.split(splitter);
    var date1 = new Date(arr1[2],parseInt(arr1[1].replace(/^0/,""),10) - 1,arr1[0]);
    var date2 = new Date(arr2[2],parseInt(arr2[1].replace(/^0/,""),10) - 1,arr2[0]);
    if(arr1[1].length == 1)
        arr1[1] = "0" + arr1[1];
    if(arr1[0].length == 1)
        arr1[0] = "0" + arr1[0];
    if(arr2[1].length == 1)
        arr2[1] = "0" + arr2[1];
    if(arr2[0].length == 1)
        arr2[0]="0" + arr2[0];
    var d1 = arr1[2] + arr1[1] + arr1[0];
    var d2 = arr2[2] + arr2[1] + arr2[0];
    if(parseInt(d1,10) > parseInt(d2,10))
        return false;
    else
        return true;
}//

function checkValidateForbiddenChars(str){
    var forbidden = new Array(">","<","'","\"");
    for(var k=0;k<str.length;k++){
        for(var i=0;i<forbidden.length;i++){
            if(str.charAt(k)==forbidden[i]){
                return false;
            }
        }
    }
    return true;
}

function checkCheckbox(formname,objid){
    obj = document.forms[formname].elements[objid];
    if(typeof(obj)=="object"){
        if(obj.length>0){
            //			alert(obj.valueOf());
            var tmpflag;
            if(obj[0].checked == false){
                tmpflag = true;
            }else{
                tmpflag = false;
            }

            for (i=0;i<obj.length;i++){
                obj[i].checked = tmpflag;
            }
        }
        else{
            if(obj.checked == false){
                obj.checked = true;
            }else{
                obj.checked = false;
            }
        }
    }
}

function changeClass(objId, objClassOne, objClassTwo)
{
    var obj = document.getElementById(objId);

    if (objClassTwo != '') {
        if (obj.className == objClassOne) {
            obj.className = objClassTwo;
        } else {
            obj.className = objClassOne;
        }
    } else {
        if (objClassOne != '') {
            obj.className = objClassOne;
        } else {
            // fail
        }
    }
}


function show_block(id, width, height)
{
    document.getElementById(id).style.display = "";
    document.getElementById(id).style.overflow = "";
    document.getElementById(id).style.width = width;
    document.getElementById(id).style.height = height;
}

function hide_block(id)
{
    document.getElementById(id).style.display = "block";
    document.getElementById(id).style.overflow = "hidden";
    document.getElementById(id).style.width = "0";
    document.getElementById(id).style.height = "0";
}

function hideElement(id)
{
    document.getElementById(id).style.display = 'none';
}

function showElement(id)
{
    document.getElementById(id).style.display = 'block';
}

function isIE()
{
    return (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
}

function isWin()
{
    return (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
}

function isOpera()
{
    return (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
}
