function deleteAction(frm, insId, cfm, delObj, act){
	if(cfm=='1'){
		if(!confirm('Kayıt silinecektir. Devam etmek istiyor musunuz?'))
			return;
	}
	if(typeof(act)=='undefined')
		frm.action='../common/action/tx_cfwDelete.jsp';
	else
		frm.action=act;
	frm.pInstanceId.value=insId;	
	frm.pDeleteObjects.value=delObj;
	frm.submit();	
}

function updateAction(frm, page, insId, isPopUp, popUpW, popUpH){
	if(isPopUp=='1'){				
		if(typeof(popUpW)=='undefined'){
			popUpW = 600;
			popUpH = 400;
		}			
		openPopUp('../common/popUpHostSimple.jsp?pPageSrc='+escape(page+'?pPopUp=1&pInstanceId='+insId), popUpW, popUpH);
	}else{
		frm.action = page;
		frm.pPageId.value='';
		frm.pInstanceId.value = insId;
		frm.pDInstanceId.value = '';
		frm.submit(); 
	}
}


/******************* DATE VALIDATION **************************************/
/**************************************************************************/
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
    var dtCh= "/";
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	/*if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}*/
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}
/******************* DATE VALIDATION END **********************************/
/**************************************************************************/


function setComboDate(formName, element){
	var dateFormat = '';
	dateFormat = eval('document.'+formName+'.'+element+'_DATEFORMAT.value');		
	
	if(eval('document.'+formName+'.'+element+'_DAY.value')=='' ||
	   eval('document.'+formName+'.'+element+'_MONTH.value')=='' ||
	   eval('document.'+formName+'.'+element+'_YEAR.value')==''){
	   eval('document.'+formName+'.'+element+'.value=\'\'');
	   return;
	}		
	//regExp = /d/g;
	//dateFormat.replace(regExp, eval('document.'+formName+'.'+element+'_DAY.value'));
	//dateFormat.replace(/mm/, eval('document.'+formName+'.'+element+'_MONTH.value'));
	//dateFormat.replace(/yyyy/, eval('document.'+formName+'.'+element+'_YEAR.value'));		
	
	dateFormat = eval('document.'+formName+'.'+element+'_DAY.value')+'/';
	dateFormat = dateFormat + eval('document.'+formName+'.'+element+'_MONTH.value')+'/';
	dateFormat = dateFormat + eval('document.'+formName+'.'+element+'_YEAR.value');
	
	eval('document.'+formName+'.'+element+'.value=\''+dateFormat+'\'');			
	
	if(!isDate(eval('document.'+formName+'.'+element+'.value'))){
		eval('document.'+formName+'.'+element+'.value=\'\'');
		if(eval('document.'+formName+'.'+element+'_DAY.type')=='select-one')
			eval('document.'+formName+'.'+element+'_DAY.options[0].selected=true');
	}
	
	return;
}


function openDatePicker(elementName, elementValue, isTime){  
	window.open('../common/datePicker.jsp?elementName='+elementName+'&elementValue='+elementValue+'&isTime='+isTime,'datePicker','width=220,height=230,status=no,toolbar=no,menubar=no,directories=no,location=no,scrollbars=no,resizable=no,alwaysRaised=no,screenX=20,screenY=5,titlebar=yes');  
} 

function clearDatePicker(element) {
	element.value ='';  
} 

function getSeperatedInstanceId(instanceId, javaAlias){
	  var st = instanceId.split(':');
	  alert(instanceId+" - "+javaAlias);
	  for(var i=0; i<st.length; i++){
		  if(st[i]==javaAlias){			  
			  if(i+1<st.length)
				  return javaAlias+':'+st[i+1];
			  else
				  return '';
		  }else{
			  if(i+1<st.length)
				  i++;
			  else
				  return '';
		  }
	  }
	  return '';	  
}

function getPKValue(instanceId, javaAlias){
	  var st = instanceId.split(':');
	  
	  for(var i=0; i<st.length; i++){
		  if(st[i]==javaAlias){			  
			  if(i+1<st.length)
				  return st[i+1];
			  else
				  return '';
		  }else{
			  if(i+1<st.length)
				  i++;
			  else
				  return '';
		  }
	  }
	  return '';	  
}


function exportToExcel(frm, fileName){
	var a = frm.action;
	var tmpAct = '../common/exportToExcel.jsp';
	if(fileName!=undefined)
		tmpAct += '?pFileName='+fileName;
	frm.action = tmpAct;
	frm.submit();
	frm.action = a;
}	

function openPopUpWin(url, width, height) {  
	if(typeof(width)=='undefined' || width==''){
		width = 700;
		height = 500;
	}    
	window.open(url, '', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+width+',height='+height);
}
  
function openPopUp(url, width, height) {
	if(typeof(width)=='undefined'){
		width = 500;
		height = 400;
	}
	window.showModalDialog(url,window,'scroll:no;resizable: yes;dialogWidth:'+width+'px; dialogHeight:'+height+'px');      
}

function openRichEditEmbedded(iframename, organizationId, loadObjName, edition, mounted, usage, readonly, width, height, sizeFlag) { 
      var loadObjValue = ''; 
      var editorwidth = 0; 
      var editorheight = 0; 
      var popupwidth  = 923; 
      var popupheight = 447; 
      var extrawidth = 5; 
      var extraheight = 56; 
      if (loadObjName) {
         loadObjValue = loadObjName.value; }
      if (loadObjValue == '')    { 
         alert('load object is not selected'); 
         return; 
      } 
      if (sizeFlag == '1')   { 
         editorwidth = width; 
         editorheight = height; 
      } else { 
            if (screen.width == 640 &&  screen.height==480 )        { // it is not supported 
                  alert ('this screen resolution is not supported'); 
                  return;  
            } else if (screen.width == 800 &&  screen.height==600 )   { 
                if (edition == 'B') { 
                  editorwidth  = 200; 
                  editorheight = 100; 
                } else { 
                  editorwidth  = 550; 
                  editorheight = 350; 
                } 
            } else if (screen.width == 1024 &&  screen.height==768 )  {  
                if (edition == 'B') { 
                  editorwidth  = 200; 
                  editorheight = 100; 
                } else { 
                  editorwidth  = 700; 
                  editorheight = 400; 
                } 
            } else if (screen.width == 1152 &&  screen.height==864 )  {  
                if (edition == 'B') { 
                  editorwidth  = 200; 
                  editorheight = 100; 
                } else { 
                  editorwidth  = 700; 
                  editorheight = 400; 
                } 
            } else if (screen.width == 1280 &&  screen.height==1024 ) {   
                if (edition == 'B') { 
                  editorwidth  = 200; 
                  editorheight = 100; 
                } else { 
                  editorwidth  = 700; 
                  editorheight = 400; 
                } 
            } else if (screen.width == 1400 &&  screen.height==1050 ) {   
                if (edition == 'B') { 
                  editorwidth  = 200; 
                  editorheight = 100; 
                } else { 
                  editorwidth  = 700; 
                  editorheight = 400; 
                } 
            } 
      } 
      if (edition == 'B') { 
        extraheight = 56; 
      } else { 
        extraheight = 88; 
      } 
      popupwidth = editorwidth +  extrawidth + 10;  
      popupheight = editorheight + extraheight + 12;  
      var url = "/cfw21/richEdit/index.jsp?pIsAdmin=1&pOrganizationId="+organizationId+"&pExtraWidth="+extrawidth+"&pExtraHeight="+extraheight+"&pComposerEdition=" + edition + "&pComposerUsageMode=" + usage + "&pSizeEditorWidth=" + editorwidth + "&pSizeEditorHeight=" + editorheight + "&pMountedToolbarSet=" + mounted + "&pLoadObject=" + loadObjValue; 
      document.write('<iframe name="'+iframename+'" id="'+iframename+'" src="'+url+'" width="'+popupwidth+'" height="'+popupheight+'"></iframe>'); 
  }



function openRichEditPopup(loadObjName, edition, userId, sessionId, organizationId, isAdmin, mounted, usage, readonly, width, height, sizeFlag) { 
       var loadObjValue = ''; 
       var editorwidth = 0; 
       var editorheight = 0; 
       var popupwidth  = 923; 
       var popupheight = 447; 
       var extrawidth = 5; 
       var extraheight = 56; 
       if (loadObjName) 
          loadObjValue = loadObjName.value; 
       if (loadObjValue == '')    { 
          alert('load object is not selected'); 
          return; 
       } 
       if (sizeFlag == '1')   { 
          editorwidth = width; 
          editorheight = height; 
       } else { 
             if (screen.width == 640 && screen.height==480 )        { // it is not supported 
                   alert ('this screen resolution is not supported'); 
                   return;  
             } else if (screen.width == 800 &&  screen.height==600 )   { 
                   editorwidth  = 673; 
                   editorheight = 447; 
             } else if (screen.width == 1024 && screen.height==768 )  {  
                   editorwidth  = 923; 
                   editorheight = 595; 
             } else if (screen.width == 1152 && screen.height==864 )  {  
                   editorwidth  = 923; 
                   editorheight = 595; 
             } else if (screen.width == 1280 && screen.height==1024 ) {  
                   editorwidth  = 923; 
                   editorheight = 595; 
             } else if (screen.width == 1400 && screen.height==1050 ) {   
                   editorwidth  = 923; 
                   editorheight = 595; 
             } 
       } 
       if (edition == 'B' || edition == 'C' ) { 
         extraheight = 56; 
       } else { 
         extraheight = 88; 
       } 
        popupwidth = editorwidth +  extrawidth + 3 ; 
        popupheight = editorheight + extraheight  ; 
        extraheight = extraheight + 1;  
        var url = "/cfw21/richEdit/index.jsp?pExtraWidth="+extrawidth+"&pExtraHeight="+extraheight+"&pOrganizationId="+organizationId+"&pUserId="+userId+"&pSessionId="+sessionId+"&pIsAdmin="+isAdmin+"&pComposerEdition=" + edition + "&pComposerUsageMode=" + usage + "&pSizeEditorWidth=" + editorwidth + "&pSizeEditorHeight=" + editorheight + "&pMountedToolbarSet=" + mounted + "&pLoadObject=" + loadObjValue;  
        someWin = window.open(url,"win1","width=" + popupwidth + "px,height=" + popupheight + "px,scrollbars=no,resizable=no,menubar=no,statusbar=yes,location=no"); 
} 

function start_search(frm){
	if(frm.pIsSearch){ 
    	frm.pIsSearch.value='1';   
    }      
} 
 
function clear_search(formName){
    if (eval('document.'+formName+'.pIsSearch')) { 
      eval('document.'+formName+'.pIsSearch.value="0";');   
    }        
}
  
function GoToPage(frm, PageId) { 
	frm.pPageId.value=PageId; 
    frm.pIsSearch.value=1; 
    if(frm.pDInstanceId.value!='')
    	frm.pInstanceId.value = frm.pDInstanceId.value;
    frm.submit(); 
} 
 
function pageSorting(frm, sortName, sortType) { 
	frm.pSortName.value=sortName;     
    frm.pIsSearch.value=1;
    frm.pSortType.value=sortType;     
    if(frm.pDInstanceId.value!='')
    	frm.pInstanceId.value = frm.pDInstanceId.value;
    frm.submit();    
}
 
function clearObjectSinglePicker(formName, elementName){
	eval('document.'+formName+'.'+elementName+'_NAME.value=\"\";');
	eval('document.'+formName+'.'+elementName+'.value=\"\";');
	try {          	
    	eval('ObjPickerClear_'+elementName+'();');
    } catch(e) {}
} 
 
function openObjectSinglePicker(url, formName, elementName, objAttributeId, whereClause, lang, diaWidth, diaHeight, urlAdd){

	
	var arr=null;
    var args=new Array();        	
  	var queryStr = '';
  	
  	whereClause = escape(whereClause);
  	queryStr = '?pPopUp=1&pLangCode='+lang+'&amp;rns='+Math.random()+'&amp;pObjAttributeId='+objAttributeId+'&amp;pWhereClause='+whereClause;
  	
  	
  	
  	if(urlAdd){
  		queryStr = queryStr + urlAdd;
  	}
  	
    arr=window.showModalDialog(url+queryStr  , args, 'scrollbars:no;resizable: yes;dialogWidth:'+diaWidth+'px; dialogHeight:'+diaHeight+'px' ); 

	
    if (arr !=null) { 
    	//var argNames = null;
    	var argValues = null;
    	var vName = null;
		argValues = arr["vElementValues"];
        //argNames = arr["vElementNames"];
        vName = arr["vName"];
                 
        eval('document.'+formName+'.'+elementName+'.value=\"'+argValues+'\";');         
		eval('document.'+formName+'.'+elementName+'_NAME.value=\"'+vName+'\";'); 
        
        try {          	
            eval('ObjPickerSelect_'+elementName+'();');
        } catch(e) {}        
    }
}  

//equals ignore case icin
String.prototype.equalsIgnoreCase=myEqualsIgnoreCase;
String.prototype.equals=myEquals;
function myEquals(arg){
	return (this.toString()==arg.toString());
}

function myEqualsIgnoreCase(arg){               
	return (new String(this.toLowerCase())==(new String(arg)).toLowerCase());
}
//................................

function resetComboBox(elm){
	var opts = elm.options;
	if(opts!=null && opts.length>0)
		opts[0].selected=true;
}

function setSelect(select,value){
	try{
		var k = 0;
		for(k = 0;k < select.options.length;k++){				
			if(select.options[k].value == value){
				select.selectedIndex = k;
				break;
			}
		}
	}
	catch(err){
		select.value = value;//select değil text ise silinmesin bu satırr kritik...
	}
}

//..................................
function getElementAsArray(elm){	
	if(!elm.type && elm.length){		
		return elm;
	}else{			
		var tmpArr = new Array(1);
		tmpArr[0] = elm;
		return tmpArr;
	}	
}

function copyText(asHTML)
{
	var r3 = document.selection.createRange();
	if (r3.boundingWidth > 0) {
		var str = asHTML ? r3.htmlText : r3.text;
	    window.clipboardData.setData('Text',str);
    	document.getElementById('output').innerText = str;
    }
}

var g_rngAnchor = null;
var g_wordSelect = false;
var g_inMenu = false;
function doSelection()
{
	try {
	    var e = window.event;
	    e.cancelBubble = true;
	    e.returnValue = false;
	    // events.innerHTML = e.type + "-" + e.srcElement.tagName + " (" + e.clientX + ":" + e.clientY + ")<br/>" + events.innerHTML;
	    switch(e.type) {
	    case 'dblclick' :
	    	// Select a whole word.
	        g_rngAnchor = document.selection.createRange();
	    	if (g_rngAnchor.boundingWidth == 0) {
		        g_rngAnchor.moveToPoint(e.clientX, e.clientY);
		    	g_wordSelect = true;
	        }
        	g_rngAnchor.moveStart("word",-1);
        	g_rngAnchor.moveEnd("word");
            g_rngAnchor.select();
            break;

	    case 'mousedown' :
	    	// Set a selection point.
	        if (e.button == 1/*left*/ && !g_inMenu) {
	        	g_wordSelect = false;
		        document.selection.empty();
		        g_rngAnchor = document.selection.createRange();
		        g_rngAnchor.moveToPoint(e.clientX, e.clientY);
		        if (e.shiftKey) {
		        	g_rngAnchor.moveStart("word",-1);
		        	g_rngAnchor.moveEnd("word");
		        	g_wordSelect = true;
		        }
		    }
		    break;

	    case 'mousemove' :
	    	// Drag the selection. (SHIFT+drag to select words.)
	        if (e.button == 1 || g_wordSelect) {
	            var r2 = document.selection.createRange();
            	r2.moveToPoint(e.clientX, e.clientY);
	            if (r2.compareEndPoints('StartToStart',g_rngAnchor) == -1) {
	                r2.setEndPoint('StartToEnd',g_rngAnchor);
	                if (e.shiftKey || g_wordSelect) r2.moveStart("word",-1);
	                r2.select();
	            }
	            else {
	                g_rngAnchor.setEndPoint('EndToEnd',r2);
	                if (e.shiftKey || g_wordSelect) g_rngAnchor.moveEnd("word");
	                g_rngAnchor.select();
	            }
	        }
	        break;

	    case 'mouseup' :
	    	g_wordSelect = false;
	    }
	    // output.innerHTML = g_rngAnchor ? g_rngAnchor.boundingLeft + ":" + g_rngAnchor.boundingWidth : "null";
	}
	catch(e) {}
}



