function Get_Cookie(name) {
	
    var start = document.cookie.indexOf(name);
    var len = start+name.length+1;
    
    if ((!start) && (name != document.cookie.substring(0,name.length))) {
		return '';
	}
    if (start == -1) {
		return '';
	}
    var end = document.cookie.indexOf(";",len);

    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));

}

function Set_Cookie(name,value,path,expires,domain,secure) {

    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure=" + secure : "");	
}


function Del_Cookie (name, path) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1); 
	var cval = Get_Cookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString() + ";path=" + path;
}


function onCheck(string) { if (string == "on") return true; return false; }

function getValue(string,elementName,object,elementType) {
// gets value of elementName from string and populates object of elementType

    var startPos = string.indexOf(elementName + "=")
    
    if (startPos > -1) {
        startPos = startPos + elementName.length + 1;
        var endPos = string.indexOf("&",startPos);
        if (endPos == -1) endPos = string.length;

        var elementValue = unescape(string.substring(startPos,endPos));
        
        if (object == "") {			
            return elementValue;
        } else {
            if (elementType == "text")     object.value = elementValue;
            if (elementType == "password") object.value = elementValue;	    
            if (elementType == "select")   {
                for (i=0; i<object.length; i++)	{
                    if (object[i].value == elementValue) {		
                        object.selectedIndex = i;						
                    }
                }
            }
            if (elementType == "checkbox") object.checked = onCheck(elementValue);
            if (elementType == "radio") {
                for (i=0; i<object.length; i++) {							
                    if (object[i].value == elementValue ) {					
                        object[i].checked = true;					
                    }		   
                }
            }
        }
    }
}

function Win_Project(page, flag) {
	
	var intW = 400;
	var intH = 500;
	var url = "../common/project.asp" 
	var objWin;	

    if(flag == '2'){  
		var KeyCode = event.keyCode	
			
		if (KeyCode==13) {
			
////            document.myPage.txtPJT_Seq.value = "";
////            document.myPage.txtPJT_Desc.value = "";

            url = url + "?txtPJT=" + document.myPage.txtPJT_No.value;	

			objWin = window.open(url,'POP_PROJECT', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');			
	    	objWin.focus();
		}
	}
	else{         
		url = url;
	
		objWin = window.open(url,'POP_PROJECT', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');
	    objWin.focus();	            
	}	
}


function Win_SUB_Project(flag) {
	
	var intW = 400;
	var intH = 500;
	var url = "../common/sub_project.asp"; 
    var objWin;
	
    if(flag == '2'){  
		var KeyCode = event.keyCode	
			
		if (KeyCode==13) {
			
            document.myPage.txtPJT_Desc.value = "";

            url = url + "?txtPJT=" + document.myPage.txtPJT_No.value;	

			var objWin = window.open(url,'POP_PROJECT', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');
	    	objWin.focus();
		}
	}
	else{         
	
		var objWin = window.open(url,'POP_PROJECT', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');
	    objWin.focus();	            
	}	

}


function On_mouseover(obj){
	obj.style.backgroundColor = "#FFF7D9"; 	
	obj.style.cursor ='hand';
} 
function On_mouseout(obj){
	obj.style.backgroundColor = "#F6F6F6"; 
}

function func_CursorOver(obj){
	obj.style.backgroundColor = "#F0F0F0"; 	
	obj.style.cursor ='hand';
} 
function func_CursorOut(obj){
	obj.style.backgroundColor = "#FFF7D9"; 
}

function makeArray(n) {
    this.length = n;

    for (var i = 1 ; i <= n ; i++)
        this[i] = "0";

    return this;
}

function redimArray(obj, n) {	
	
	var aa = obj.length+1 
	
    obj.length = n;

    for (var i = aa ; i <= n ; i++)
        obj[i] = "0";    
}

function replace(string,text,by) {
// Replaces text with by in string

    var i = string.indexOf(text);

    while (i != -1) {
        string = string.replace(text, by);
        i = string.indexOf(text);   
    }
    return string;
}

function Open_Menual(url, strName) {
		var objWin = window.open(url,strName, 'width=770,height=600,top=100,left=100, scrollbars=yes, resizable=yes');
	    objWin.focus();		
}

function Open_Menual2(url, strName) {
		var objWin = window.open(url,strName, 'width=950, height=705,top=100,left=100, scrollbars=yes, resizable=yes');
	    objWin.focus();		
}

function Open_Win(url, name, intW, intH) {

        var objWin = window.open(url, name, 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');
	    objWin.focus();	 	
}

function Win_Vendor(flag) {
	
	var intW = 400;
	var intH = 500;
	var url = "../common/vendor_search.asp" 
	var objWin	

    if(flag == '2'){  
		var KeyCode = event.keyCode	
			
		if (KeyCode==13) {

			if (document.myPage.txtVendName.value=='')
			{
				alert('Vendor name is required!');
				document.myPage.txtVendName.focus();
				return false;
			}

            url = url + "?strVendorName=" + document.myPage.txtVendName.value;	

			var objWin = window.open(url,'POP_VENDOR', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');			
	    	objWin.focus();
		}
	}
	else{         
		url = url;
	
		var objWin = window.open(url,'POP_VENDOR', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');
	    objWin.focus();	            
	}	
}

function Win_Inspector(flag) {
	
	var intW = 400;
	var intH = 500;
	var url = "../inspection/inspector_search.asp" 
	var objWin	

    if(flag == '2'){  
		var KeyCode = event.keyCode	
			
		if (KeyCode==13) {

			if (document.myPage.strInspector.value=='')
			{
				alert('Inspector name is required!');
				document.myPage.strInspector.focus();
				return false;
			}

            url = url + "?strSearchName=" + document.myPage.strInspector.value;	

			var objWin = window.open(url,'POP_INSPECTOR', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');			
	    	objWin.focus();
		}
	}
	else{         
		url = url;
	
		var objWin = window.open(url,'POP_INSPECTOR', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');
	    objWin.focus();	            
	}	
}

function Win_VendorInspection(flag) {
	
	var intW = 400;
	var intH = 500;
	var url = "../common/vendor_search.asp?strVendorType=INS" 
	var objWin	

    if(flag == '2'){  
		var KeyCode = event.keyCode	
			
		if (KeyCode==13) {

			if (document.myPage.strVendorName.value=='')
			{
				alert('Vendor name is required!');
				document.myPage.strVendorName.focus();
				return false;
			}

            url = url + "?strVendorName=" + document.myPage.strVendorName.value;	

			var objWin = window.open(url,'POP_VENDOR_INSPECTION', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');			
	    	objWin.focus();
		}
	}
	else{         
		url = url;
	
		var objWin = window.open(url,'POP_VENDOR_INSPECTION', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');
	    objWin.focus();	            
	}	
}

function Win_Register(flag) {
	
	var intW = 400;
	var intH = 500;
	var url = "../inspection/pia_Register_search.asp" 
	var objWin	

    if(flag == '2'){  
		var KeyCode = event.keyCode	
			
		if (KeyCode==13) {

			if (document.myPage.strRegister.value=='')
			{
				alert('Register name is required!');
				document.myPage.strRegister.focus();
				return false;
			}

            url = url + "?strSearchName=" + document.myPage.strRegister.value;	

			var objWin = window.open(url,'POP_Register', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');			
	    	objWin.focus();
		}
	}
	else{         
		url = url;
	
		var objWin = window.open(url,'POP_Register', 'width=' + intW + ',height=' + intH + ',top=100,left=100, scrollbars=yes, resizable=yes');
	    objWin.focus();	            
	}	
}