﻿function openPopup(url,w,h,name,returnid){
	var str = 'height=' + h + '; width=' + w + '; top=0; left=0; toolbar=0; menubar=0; scrollbars=1, resizable=1;location=0; status=1';
	//var str = 'dialogHeight=' + h + 'px;'; //dialogWidth=' + w + 'px; dialogLeft: 20; dialogTop:20;';
	//alert(str);
	//alert(url);
	//var str = 'dialogHeight=' + h + 'px; dialogWidth=' + w + 'px; edge:raised; center: yes; resizable: no; status: yes; scroll=yes;';
	//window.showModalDialog(url,"",str)
	var retval=window.showModalDialog(url,"",str);
	//var retval=window.showModalDialog(url);
	if (retval=="undefined" || retval==null)
	    return false;
	else if ( returnid != '' ){
	    var id = document.getElementById(returnid);
	    if(id != "undefined")
	    {
	        id.value = retval;
	    }
	}
	return true;		
}
function openPopupWindow(url,w,h,name){
	var str = 'height=' + h + ', width=' + w + ', top=0, left=0, toolbar=0, menubar=0, scrollbars=1, resizable=0,location=0, status=0';
	var win=window.open(url,name,str);
	if (win=="undefined" || win==null)
	    alert("Your browser is having pop-up blocker, you have to allow the pop-ups to use our website");		
}
function hasChecked(findStr,confirmMsg,alertMsg) { 
	// loop through all elements
	var frm = document.forms[0];
	for (i=0; i<frm.length; i++) 
	{
		// Look for our checkboxes only
		if (frm.elements[i].name.indexOf(findStr) !=-1) 
		{
			// If any are checked then confirm alert, otherwise nothing happens
			if(frm.elements[i].checked) 
			{
				//return confirm ('Are you sure you want to delete your selection(s)?')
				if(confirmMsg!=''){
				    return confirm(confirmMsg);
				}
				else{
				    return true;
				}
			}
		}
	}
	if(alertMsg != ''){
	    alert(alertMsg);
	}
	    
	return false;
}
function checkAll(ctrl,findStr) { 
	// loop through all elements
	var frm = document.forms[0];
	var checked = ctrl.checked;
	
	for (i=0; i<frm.length; i++) 
	{
		// Look for our checkboxes only
		if (frm.elements[i].name.indexOf(findStr) !=-1) 
		{
			frm.elements[i].checked = checked;
		}
	}
}
function wordCount(msgid,displayid,displayid2,allowedLength){
    var msg = document.getElementById(msgid);
    var display = document.getElementById(displayid);
    var display2 = document.getElementById(displayid2);
    
    var result = getWordCount(msg.value);
    
    //if(length>allowedLength){
    //   msg.value = msg.value.substring(0,allowedLength);
    //    length = allowedLength;
    //    alert('You have exceed the Maximum Number of Characters allowed.');
    //}
    if (typeof(display)=="text")
        display.value = result[0];
    else
        display.innerHTML = result[0];
    
    if (typeof(display2)=="text")
        display2.value = result[1];
    else
        display2.innerHTML = result[1];    
}
function getWordCount(content){
    var count = 0;
    var result = new Array();
    result[0] = 0;
    result[1] = 1;
    
    var i = 0;
    if(content!=''){
        for(j=0;j<content.length;j++)
        {
            i = content.charCodeAt(j);
            if(i == 12 || i == 94 || i == 123 || i == 125 || i == 92 || i == 91 || i == 126 || i == 93 || i == 124 || i == 164)
            {
                count = count + 2;
            }
            else
            {
                count = count + 1;
            }
        }
        result[0] = count;
        if(count<=160)
            result[1] = 1;
        else
            result[1] = Math.ceil(1.0 * count / 152);
    }
    
    return result;
}

