﻿
/***********************************
            String Cut
************************************/
function cutStrExper( head, length )
{
    if(head == "?")
    {
        document.write("");
		return;
    }
        
   	var strLen = head.length;
	if (strLen > length)
	{
		head = head.substr(0, length+5) ;
		
		var lastIndexOfSpace = head.lastIndexOf(' ');
		
		if (lastIndexOfSpace > 0)
        {
            head = head.substr(0, lastIndexOfSpace) ;
        }
        else 
        {
            head = head.substr(0, length) ;
        }
		
		document.write(head + " ...");
		return;
	}
	else
	{
		document.write(head);		
	}		
}

String.prototype.TrimS = function() 
{ 
    var reg = new RegExp("(^(\\s|" + String.fromCharCode(12288) + ")*)|((\\s|" + String.fromCharCode(12288) + ")*$)", "g");
    //var reg = /(^\s*)|(\s*$)/g;
    
    return this.replace(reg, ""); 
}

/***********************************************************************************
Name: normalizeSpace(head)

Arguments: head, a string that is converted.

Descriptions: Returns the whitespace-normalized version of the argument string; 
                all leading and trailing whitespace gets stripped 
                and any sequences of whitespace characters 
                within the argument string get combined to one single space.

Composer: Namhh.   

Ex: head = "  test    text   "; 
    normalizeSpace(head) would rerurn: "test text".
************************************************************************************/
function normalizeSpace(head)
{
    
    // strim string.
    var trimedHead = head.TrimS();
      
    // regular expressions, for replacing sequences of whitespace characters within input-string.
    var pattern = "/ {2,}/"; 
    
    // whitespace charater.
    var replacement = " ";
    
    return trimedHead.replace(pattern, replacement);  
}

function cutStr1( head, length )
{
    // Normallie Space characters of string.
    var normalizedHead = normalizeSpace(head);
    
    // If head is empty.
    if((head == "?")||(normalizedHead == ""))
    {
        document.write("");
		return;
    }
    
    var pattern1 = new RegExp('\'', 'g');
     
    normalizedHead = normalizedHead.replace(pattern1,'"');
   	  	
   	// Get head's length.
   	var strLen = normalizedHead.length;
   	
   	// Head Processing.
	if (strLen < length)
	{
	    document.write(normalizedHead);
	}
	else
	{
	    
	    var tempHead = normalizedHead.substr(0, (length -4));
	    
	    var lastIndexOfSpace = tempHead.lastIndexOf(' ');
	    
	    var outHead = tempHead.substr(0, lastIndexOfSpace);
	    
	    outHead = outHead + " ..."
	    
	    document.write(outHead);
	    
	    return;
	}
}

/*
function hidestatus(){
window.status=''
return true
}

if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)

document.onmouseover=hidestatus
document.onmouseout=hidestatus
*/
