﻿var isCurrencyvalid;
isCurrencyvalid = true;
var blnChrome;
blnChrome = true;

function onKeyEventCounter(field,MAXCHAR,dispField){
// Added for NRT-226 / Open-ended text box size specification
 if(field){
    var i;
    var len = 0;
    var extraLen = 0;
    var arrString = new Array;
    arrString = field.value.split('');
    
    for (i=0;i<=arrString.length-1;i++){
        if(arrString[i] == '\n') {
           extraLen +=1;
        }
	}
	len = field.value.length + extraLen;

    if ( len > MAXCHAR ){
        	
        field.value=field.value.substring(0,field.value.length+MAXCHAR-len);
        dispField.value = 0;
        field.focus();
    }
    else{
        dispField.value = (MAXCHAR - len);
    }
  }
}

function onKeyEventCounterSubmit(field,MAXCHAR,dispField){
// Added for NRT-226 / Open-ended text box size specification
  if(field){
    var len = 0;
	len = field.value.length;
    if ( len > MAXCHAR ){

		alert("The maximum number of characters that can be entered is" + 
        	" " + MAXCHAR +". You have entered" +
        	" " + len + " " + "characters."); 
        	
//       	strTxtLimMsg = strTxtLimMsg + " The maximum number of characters that can be entered is" +         	" " + MAXCHAR +". You have entered" +        	" " + len + " " + "characters.\n";
        field.value=field.value.substring(0,field.value.length+MAXCHAR-len);
        dispField.value = 0;
        field.focus();
        return false;
    }
    else{
        dispField.value = (MAXCHAR - len);
    }
  }
  return true;
}

function survey_preview(url)
{
	var opWin = window.open(url,'Ms','toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=400,height=500')
}
function OpenWin(strUrl){
		var opWin = window.open(strUrl,"","");
}





function GoLang(strRedirect)
{
	window.location.href = strRedirect;
}

var counter = 0;

var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS4 = (bName == "Netscape" && bVer >= 4);
 var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
 var blnAutosave = false;

function setAutosaveMode() {
    blnAutosave = true;
}
var i = 0;
if (NS4 || IE4) {
 if (navigator.appName == "Netscape") {
 layerStyleRef="layer.";
 layerRef="document.layers";
 styleSwitch="";
 }else{
 layerStyleRef="layer.style.";
 layerRef="document.all";
 styleSwitch=".style";
 }
}



//window.onload = startBlink;
//window.onload = Blink("blink_hint");

// Participation Validations ..
// Sanjeev Menon..
var valstring,intSubTime, intErr
var separator,posMonth,posDate,posYear,lenYear, ValString

var NoOfDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
var formerrormsg="You\'ve attempted to submit the survey multiple times.\n Please reload the page to resubmit the survey."
var weekend = [0,6];
var p_qtype = 0;
var do_submit = 0;
var weekendColor = "#e0e0e0";
var fontface = "Verdana";
var fontsize = 8;
var gNow = new Date();
var ggWinCal;
var vDx,vMx,vYx;
var do_chk;

// isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
// isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

Calendar.Months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function CheckDelete(){

//	if (confirm('You have changed the answer to a saved question. All previously saved responses will be lost. Do you wish to continue?'))
	if (confirm('You have modified the answer to a question which leads to branching. Responses for questions in succeeding pages will be lost. Do you wish to continue?'))
	{
		document.forms[0].action =document.forms[0].action + "&del=1";
	}else
	{
		document.forms[0].action =document.forms[0].action + "&del=2";
	}
	document.forms[0].submit();
}

function strtrim() 
{
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
String.prototype.trim = strtrim;

function ValidateConstraint(qno,ctrlid,optcnt,ctype,ccnt,qtype,intOther){
var obj;
var obj_OT;
var obj_Text;
var iSelCount=0;

if (ctype==0){return true;}

if (qtype=='C'){
	for (i=0;i<=optcnt;i++){
	//obj = eval("document.forms[0]."+ ctrlid+'_C_'+i);
	obj = document.getElementById(ctrlid + '_C_' + i);
		if(obj){
			if(obj.checked){
				iSelCount++;
			}
		}
	}
if(intOther==1)	{
//obj_OT = eval("document.forms[0]."+ ctrlid+'__OT');
obj_OT =document.getElementById(ctrlid+'__OT');
//obj_Text = eval("document.forms[0]."+ ctrlid+'_C_OT');
obj_Text = document.getElementById(ctrlid+'_C_OT');
if(obj_OT)
{
		if(obj_OT.value.trim() !='' && obj_Text.checked){
			iSelCount++;
		}
}

}	
}

if (qtype=='ML'){
	//obj = eval("document.forms[0]."+ ctrlid + "_ML");
	obj = document.getElementById(ctrlid + "_ML");
	for (i=0;i<=optcnt;i++){
		if(obj.options[i].selected){
			iSelCount++;
		}
	}

if(intOther==1)	{
//obj_OT = eval("document.forms[0]."+ ctrlid+'_OT');
obj_OT = document.getElementById(ctrlid+'_OT');
if(obj_OT)
{
		if(obj_OT.value.trim() !=''){
			iSelCount++;
		}
}

}	
	
}

if (iSelCount==0){return true;}

// Validations ..	
	if (ctype==1){
		if (iSelCount==ccnt){return true;}	
		alert("Select exactly " + ccnt + " options.")//  for Question No " + qno)
	}
	else if (ctype==2){
		if (iSelCount>=ccnt){return true;}	
		alert("Select atleast " + ccnt + " options.") // for Question No " + qno)
	}
	else if (ctype==3){
		if (iSelCount<=ccnt){return true;}	
		alert("Select at the most " + ccnt + " options.") // for Question No " + qno)
	}
	return false;
}

function ValidateConstraintAns(qno,ctrlid,optcnt,ctype,ccnt,qtype,intOther,error_msg){
var obj;
var obj_OT;
var obj_Text;
var iSelCount=0;

//if (ctype==0){return true;}

    if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }	   
    }

if (qtype=='C'){
	for (i=0;i<=optcnt;i++){
	//obj = eval("document.forms[0]."+ ctrlid+'_C_'+i);
	obj = document.getElementById(ctrlid+'_C_'+i);
		if(obj){
			if(obj.checked){
				iSelCount++;
			}
		}
	}
if(intOther==1)	{
//obj_OT = eval("document.forms[0]."+ ctrlid+'__OT');
obj_OT = document.getElementById(ctrlid+'__OT');
if(obj_OT==null){   obj_OT = document.getElementById(ctrlid+'_OT');    }
//obj_Text = eval("document.forms[0]."+ ctrlid+'_C_OT');
obj_Text = document.getElementById(ctrlid+'_C_OT');
if(obj_Text==null){ obj_Text = document.getElementById(ctrlid+'_COT'); }
if(obj_OT)
{
		if(obj_Text.checked){
			iSelCount++;
		}
}

}	
}

if (qtype=='ML'){
	//obj = eval("document.forms[0]."+ ctrlid + "_ML");
	obj = document.getElementById(ctrlid + "_ML");
	for (i=0;i<=optcnt;i++){
		if(obj.options[i].selected){
			iSelCount++;
		}
	}

if(intOther==1)	{
//obj_OT = eval("document.forms[0]."+ ctrlid+'_OT');
obj_OT = document.getElementById(ctrlid+'_OT');
if(obj_OT)
{
		if(obj_OT.value.trim() !=''){
			iSelCount++;
		}
}

}	
	
}

if (iSelCount==0){return true;}

// Validations ..	
	if (ctype=='='){
		if (iSelCount==ccnt){return true;}	
		alert(error_msg)
		if (qtype=='C')
			//obj = eval("document.forms[0]."+ ctrlid+'_C_0');
			obj = document.getElementById(ctrlid+'_C_0');
		obj.focus();
		//alert("Select exactly " + ccnt + " options.")//  for Question No " + qno)
	}
	else if (ctype=='>='){
		if (iSelCount>=ccnt){return true;}	
		alert(error_msg)
		if (qtype=='C')
			//obj = eval("document.forms[0]."+ ctrlid+'_C_0');
			obj = document.getElementById(ctrlid+'_C_0');
		obj.focus();
		//alert("Select atleast " + ccnt + " options.") // for Question No " + qno)
	}
	else if (ctype=='<='){
		if (iSelCount<=ccnt){return true;}	
		alert(error_msg)
		if (qtype=='C')
			//obj = eval("document.forms[0]."+ ctrlid+'_C_0');
			obj = document.getElementById(ctrlid+'_C_0');
		obj.focus();
		//alert("Select at the most " + ccnt + " options.") // for Question No " + qno)
	}
	return false;
}

function ValidateDate(objTextBox,intDateFormat,strErrMsg,isAutosaveEnabled)
{    
    if(objTextBox == null) {    return true;    } //For CQ when page is not loaded, check for NULL/
    blnChrome=true;
	strDate = objTextBox.value

	if(strDate == "")
	{
	    if(isAutosaveEnabled=='true') {
           setAutosaveFlag();
        }
		return true;
	}

    if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }
    }

	setDateVariables(intDateFormat)

	arrDate = strDate.split(separator)
	
	if (arrDate.length != 3)
	{
	    blnChrome=false;
		alert(strErrMsg)
		objTextBox.value=""
		//objTextBox.focus()
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false
	}
	if (arrDate[0]=="" || arrDate[1]=="" || arrDate[2]=="" || arrDate[posMonth].length > 2 || arrDate[posDate].length > 2 || arrDate[posYear].length != lenYear || arrDate[posYear] < 1)
	{
	    blnChrome=false;
		alert(strErrMsg)
		objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false
	}
	for(i=0;i<arrDate.length;i++)
	{
		strTemp = arrDate[i]
		
		for (j=0;j<strTemp.length;j++)
		{
			if ((strTemp.substring(j,j+1) == " ") || (isNaN(strTemp.substring(j,j+1))))
			{
			    blnChrome=false;
				alert(strErrMsg)
				objTextBox.value=""
				validationx=objTextBox ;
		setTimeout("validationf1();",250);
				return false
			}
		}
	}
	
	if ((arrDate[posMonth] > 12) || (arrDate[posMonth] < 1))
	{
	    blnChrome=false;
		alert(strErrMsg)
		objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false
	}

	if (arrDate[posMonth] != 2)
	{
		if ((arrDate[posDate] > NoOfDays[arrDate[posMonth]-1]) || (arrDate[posDate] < 1))
		{
		    blnChrome=false;
			alert(strErrMsg)
			objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
			return false
		}
	}
	else
	{
		if (isLeapYear(arrDate[posYear]))
		{
			if (arrDate[posDate] > 29 || (arrDate[posDate] < 1))
			{
			    blnChrome=false;
				alert(strErrMsg)
				objTextBox.value=""
				validationx=objTextBox ;
		setTimeout("validationf1();",250);
				return false
			}
		}
		else
		{
			if (arrDate[posDate] > 28 || (arrDate[posDate] < 1))
			{
			    blnChrome=false;
				alert(strErrMsg)
				objTextBox.value=""
				validationx=objTextBox ;
		setTimeout("validationf1();",250);
				return false
			}
		}
	}
if(isAutosaveEnabled=='true') {
    setAutosaveFlag();
}
return true;
}
function ValidateINTZIP(objTextBox,strErrMsg) 
{
	varZip = objTextBox.value

	if(varZip == "")
	{
		return true;
	}
	
	//var valid = "0123456789";
    
//	if (varZip.length) 
//	{
//		alert(strErrMsg)
//		objTextBox.value=""
//		validationx=objTextBox ;
//		setTimeout("validationf1();",250);
//		return false;
//	}

    if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }
    }
    
	for (var i=0; i < varZip.length; i++) 
	{
	    var TB= varZip.toString().charAt(i)                 
        var characters = TB.match(/^[a-zA-Z]*$/)            
        var numbers = TB.match(/^[0-9]*$/)  
		if (characters == null && numbers== null) 
		{
			alert(strErrMsg)
			objTextBox.value=""
			validationx=objTextBox ;
		    setTimeout("validationf1();",250);
			return false;
		}
	}
	return true;
}
function ValidateShortZIP(objTextBox,strErrMsg) 
{
    blnChrome=true;
	varZip = objTextBox.value

	if(varZip == "")
	{
		return true;
	}
	
	var valid = "0123456789";

    if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }
    }
    
	if (varZip.length!=5) 
	{
	    blnChrome=false;
		alert(strErrMsg)
		objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false;
	}

	for (var i=0; i < varZip.length; i++) 
	{
		temp = "" + varZip.substring(i, i+1);
		
		if (valid.indexOf(temp) == "-1") 
		{
		    blnChrome=false;
			alert(strErrMsg)
			objTextBox.value=""
			validationx=objTextBox ;
		setTimeout("validationf1();",250);
			return false;
		}
	}
	return true;
}

function ValidateLongZIP(objTextBox,strErrMsg) 
{
    blnChrome=true;
	varZip = objTextBox.value

	if(varZip == "")
	{
		return true;
	}
	
	var valid = "0123456789-";
	var hyphencount = 0;

    if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }
    }
    
	if (varZip.length!=5 && varZip.length!=9 && varZip.length!=10) 
	{
	    blnChrome=false;
		alert(strErrMsg)
		objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false;
	}

	for (var i=0; i < varZip.length; i++) 
	{
		temp = "" + varZip.substring(i, i+1);
		if (temp == "-") hyphencount++;
		
		if (valid.indexOf(temp) == "-1") 
		{
		    blnChrome=false;
			alert(strErrMsg)
			objTextBox.value=""
			validationx=objTextBox ;
		setTimeout("validationf1();",250);
			return false;
		}
		
		if ((hyphencount > 1) || ((varZip.length==10) && ""+varZip.charAt(5)!="-") || ((varZip.length==5) && hyphencount!=0)) 
		{
		    blnChrome=false;
			alert(strErrMsg)
			objTextBox.value=""
			validationx=objTextBox ;
		setTimeout("validationf1();",250);
			return false;
		}
	}
	return true;
}
function ValidateEmail(objTextBox,strErrMsg) 
{
    blnChrome = true;
   if(objTextBox)
   {
	    varEmail = objTextBox.value

	    if(varEmail == "")
	    {
		    return true;
	    }
	    var regex = /^([a-zA-Z0-9_\.\'\-])+\@(([a-zA-Z0-9\-\'])+\.)+([a-zA-Z])+$/;
	    if(isAssessment == true)
	    {
	        if( hours==0 && mins==0 && secs==0)
	        {	        
	            return true
	        }	   
        }
        
        if (!regex.test(varEmail))
        {
            blnChrome = false;
            alert(strErrMsg)
            objTextBox.value=""
            validationx=objTextBox ;
            setTimeout("validationf1();",250);
            return false
        }
    }
	return true;
}
function ValidateSSN(objTextBox,strErrMsg) 
{
    blnChrome=true;
	ssn = objTextBox.value

	if(ssn == "")
	{
		return true;
	}
	
	if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }
    }
	
	var matchArr = ssn.match(/^(\d{3})-?\d{2}-?\d{4}$/);
	var numDashes = ssn.split('-').length - 1;
	if (matchArr == null || numDashes == 1) 
	{
	    blnChrome=false;
		alert(strErrMsg)
		objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false;
	}
	else 
		if (parseInt(matchArr[1],10)==0) 
		{
		    blnChrome=false;
			alert(strErrMsg)
			objTextBox.value=""
			validationx=objTextBox ;
		setTimeout("validationf1();",250);
			return false;	
		}
		return true;
}
function ValidateNumber(objTextBox,xmin,xmax,strErrMsg)
{
    blnChrome=true;
	if(objTextBox)
	{
	    intNum = objTextBox.value
	    if(intNum == "" )
	    {
		    return true;
	    }
    	
	    if(isAssessment == true)
	    {
	        if( hours==0 && mins==0 && secs==0)
	        {	        
	            return true;
	        }
        }
    	
	    if (intNum.indexOf(" ")!=-1 || isNaN(intNum) || (intNum).indexOf("e") != -1 || (intNum).indexOf("E") != -1)
	    {
	        blnChrome=false;
		    alert(strErrMsg)
		    objTextBox.value=""
		    validationx=objTextBox ;
		    setTimeout("validationf1();",250);
		    return false;
	    }
    	
    	
	    if (xmin != "NA" && parseFloat(intNum) < parseFloat(xmin) )
	    {
	        blnChrome=false;
		    alert(strErrMsg)
		    objTextBox.value=""
		    validationx=objTextBox ;
		    setTimeout("validationf1();",250);
		    return false;
	    }
	    if (xmax != "NA" && parseFloat(intNum) > parseFloat(xmax))
	    {
	        blnChrome=false;
		    alert(strErrMsg)
		    objTextBox.value=""
		    validationx=objTextBox ;
		    setTimeout("validationf1();",250);
		    return false;
	    }
	}
	return true;
}
function ValidatePercentage(objTextBox,xmin,xmax,strErrMsg)
{
    blnChrome=true;
	intNum = objTextBox.value

	if(intNum == "")
	{
		return true;
	}
	
	if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }
    }
	
	if (intNum.indexOf(" ")!=-1 || isNaN(intNum) || (intNum).indexOf("e") != -1 || (intNum).indexOf("E") != -1)
	{
	    blnChrome=false;
		alert(strErrMsg)
		objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false;
	}
	else
	{
		objTextBox.value = parseInt(intNum * 100)/100
	}
	
	if (xmin != "NA" && parseFloat(intNum) < parseFloat(xmin) )
	{
	    blnChrome=false;
		alert(strErrMsg)
		objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false;
	}
	if (xmax != "NA" && parseFloat(intNum) > parseFloat(xmax))
	{
	    blnChrome=false;
		alert(strErrMsg)
		objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false;
	}
	return true;
}

function ValidateCurrency_Submit(objTextBox,xmin,xmax,strErrMsg)
{
    return isCurrencyvalid;
}

//
var validationx;
function validationf1()
{
validationx.focus();

}
function ValidateCurrency(objTextBox,xmin,xmax,strErrMsg)
{
    blnChrome=true;
	strNumber = objTextBox.value	

    //Removed for NRT 7183	
    //	if (strNumber.indexOf(",") != -1)
    //	{
    //		alert(strErrMsg)
    //		objTextBox.value=""
    //		objTextBox.focus()
    //		return false;
    //	}
	
	if(strNumber == "")
	{
		return true;
	}
	
	
	
	var arrDot,arrNum
	
	if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }
    }
	if (strNumber.indexOf(" ") != -1 || (strNumber).indexOf("e") != -1 || (strNumber).indexOf("E") != -1)
	{
	    blnChrome = false;
		alert(strErrMsg)
		objTextBox.value=""
		//objTextBox.focus()
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		
		isCurrencyvalid = false;
		return false;
	}
	
	
	
	arrDot = strNumber.split(".")

	if (arrDot.length > 2)
	{
	    blnChrome = false;
		alert(strErrMsg)
		objTextBox.value=""
	    validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false;
	}
	
	arrNum = arrDot[0].split(",")
		
	if(arrNum[0]=="" || isNaN(arrNum[0]))
	{
	    blnChrome = false;
		alert(strErrMsg)
		objTextBox.value=""
        validationx=objTextBox ;
		setTimeout("validationf1();",250);	
			return false;
	}
	
	for (i=1;i<arrNum.length;i++)
	{
		if(arrNum[i]=="" || isNaN(arrNum[i]) || arrNum[i] < 0)
		{
		    blnChrome = false;
			alert(strErrMsg)
			objTextBox.value=""
			validationx=objTextBox ;
		    setTimeout("validationf1();",250);
			return false;
		}
	}

	if (arrDot.length > 1)
	{
		if (arrDot[1]=="" || isNaN(arrDot[1]) || arrDot[1] < 0)
		{
		    blnChrome = false;
			alert(strErrMsg)
			objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
			return false;
		}
	}
	
	var re=new RegExp(',','gi')
	intTemp = strNumber.replace(re,"")
	
	if (xmin != "NA" && parseFloat(intTemp) < parseFloat(xmin) )
	{
	    blnChrome = false;
		alert(strErrMsg)
		objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false;
	}
	if (xmax != "NA" && parseFloat(intTemp) > parseFloat(xmax))
	{
	    blnChrome = false;  
		alert(strErrMsg)
		objTextBox.value=""
			validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false;
	}
	
	//NRT 7183.... Inserting comma in currency
	strNumber = strNumber.replace(/,/g,'');
	if(strNumber.length>3){	
	    
	    var strIndexOf = strNumber.indexOf(".")	    
	    if(strIndexOf > 0)
	    {
	        var strbeforeDot = strNumber.substring(0, strIndexOf)
	        var strafterDot = strNumber.substring(strIndexOf, strNumber.length)
	        strNumber=strbeforeDot
	        strNumber = '' + strNumber;	    	        
	    }
	    else {
	        strNumber = '' + strNumber;	    
        }	        
	    
//        if (strNumber.length > 3) 
//        {
            var mod = strNumber.length % 3;
            
            var output = (mod > 0 ? (strNumber.substring(0,mod)) : '');
            
                for (i=0 ; i < Math.floor(strNumber.length / 3); i++) {
                    if ((mod == 0) && (i == 0)) {
                            output +=  strNumber.substring(mod+ 3 * i, mod + 3 * i + 3);                           
                            
                        }
                        else{
                            output+= ',' + strNumber.substring(mod + 3 * i, mod + 3 * i + 3);                                                         
                        }
                }                         
//        }        
        if(strIndexOf > 0){
            output = output+strafterDot
        }            
        objTextBox.value = output        
        return objTextBox.value
     }
     else
     {
        return objTextBox.value
     }
	return true
	
}

function ValidatePhone(objTextBox,strErrMsg) 
{
	blnChrome=true;
	phone = objTextBox.value

	if(phone == "")
	{
		return true;
	}
	
	var matchArr1 = phone.match(/^(\d{10})$/);
	var matchArr2 = phone.match(/^(\d{3})-?\d{3}-?\d{4}$/);
	var matchArr3 = phone.match(/^(\d{3})-?\d{7}$/);
	var matchArr4 = phone.match(/^\(\d{3}\)\s\d{3}-\d{4}$/);
	
	
	if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }
    }
	
	if (matchArr1 != null || matchArr2 != null || matchArr3 != null || matchArr4 != null) 
	{
		if(matchArr4 == null)
		{
			phone = phone.replace(/-/g,'');
		    phone = '(' + phone.substring(0,3) + ') ' + phone.substring(3,6) + '-' + phone.substring(6,10);
		}
		objTextBox.value = phone ;
		return true;
	}
	else {
	    blnChrome=false;
		alert(strErrMsg)
		objTextBox.value=""
		validationx=objTextBox ;
		setTimeout("validationf1();",250);
		return false;		

	}
}

//function VCF(Tboxvalue,strErrMsg,custom_format)
//{
//    if(Tboxvalue.length>0 && Tboxvalue.length==custom_format.length) {
//        for(var i=0; i<custom_format.length; i++)
//        {
//            var characters = Tboxvalue[i].match(/^[a-zA-Z]*$/)
//            var numbers = Tboxvalue[i].match(/^[0-9]*$/)          
//            
//            if((characters == null && custom_format[i]=="@") || (numbers==null && custom_format[i]=="#")) 
//            {            
//                var j =true
//                 alert('c')
//                break;
//            }
//            else if((characters!=null && custom_format[i]=="@") || (numbers!=null && custom_format[i]=="#"))
//            {                
//            }                   
//            else if(Tboxvalue[i]==custom_format[i])
//            {                   
//            }  
//            else if(Tboxvalue[i]==" ")
//            {                
//                if(custom_format[i]==" ")
//                {
//                }
//                else if(custom_format[i].match(/^[a-zA-Z]*$/)==null && custom_format[i].match(/^[0-9]*$/)==null)
//                {
//                    counter = counter+1
//                    
//                    var abc = Tboxvalue[i].replace(Tboxvalue[i], custom_format[i])                    
//                    //Tboxvalue[i] = abc
//                    var strLeft = Tboxvalue.substring(0,i);                    
//                    var strRight = Tboxvalue.substring(i+1);                    
//                    var str = strLeft + abc + strRight    
//                    Tboxvalue=str                             
//                }
//                else if(custom_format[i]!=" ")
//                {
//                    var j=true
//                    break;
//                }
//            }
//            else
//            {
//                var j=true
//                break;
//            }
//        }                
//    }
//    else
//    {
//        var j=true
//    }           
//    if(j==true)
//    {
//        alert(strErrMsg)
//        Tboxvalue=""        
//    }     
//    return Tboxvalue
//}

function VCF(Tboxvalue,strErrMsg,custom_format,row)
{                            
    if(Tboxvalue.length>0 && Tboxvalue.length==row.length) 
    {               
        for(var i=0; i<row.length; i++)  
        {
            var TB= Tboxvalue.toString().charAt(i)                 
            var characters = TB.match(/^[a-zA-Z]*$/)            
            var numbers = TB.match(/^[0-9]*$/)  
                    
            var RowIndex = row.toString().charAt(i)
            if((characters == null && RowIndex=="@") || (numbers==null && RowIndex=="#")) 
            {                            
                var j =true                 
                break;
            }
            else if((characters!=null && RowIndex=="@") || (numbers!=null && RowIndex=="#"))
            {                
            }                   
            else if(TB==RowIndex)
            {                   
            }              
            else
            {
                var j=true
                break;
            }
        }                
    }
    else if(Tboxvalue.length==0)
    {             
        Tboxvalue=""
        return Tboxvalue   
    }   
    else if(Tboxvalue.length==custom_format.length)
    {
        for(var i=0; i<custom_format.length; i++)
        {
            var TB= Tboxvalue.toString().charAt(i)                 
            var characters = TB.match(/^[a-zA-Z]*$/)            
            var numbers = TB.match(/^[0-9]*$/)  
                    
            var RowIndex = custom_format.toString().charAt(i)
            if((characters == null && RowIndex=="@") || (numbers==null && RowIndex=="#")) 
            {                            
                var j =true                 
                break;
            }
            else if((characters!=null && RowIndex=="@") || (numbers!=null && RowIndex=="#"))
            {                
            }                   
            else if(TB==RowIndex)
            {                   
            }              
            else
            {
                var j=true
                break;
            }
        }
    }
    else
    {        
        var j=true
    }       
    
    if(j==true) 
    {
//        alert(strErrMsg)
//        Tboxvalue=""   
        return strErrMsg  

    }    
    else if(Tboxvalue.length!=0)
    {        
        var Custom = CustomForm(custom_format,Tboxvalue)            
        return Custom

    }             
}


function CustomForm(custom_format,Tboxvalue)
{    
    for(var k=0; k<custom_format.length; k++)
    {
        var CustomFormatIndex = custom_format.toString().charAt(k)
        if((Tboxvalue.length!=custom_format.length)&&(CustomFormatIndex.match(/^[a-zA-Z]*$/)==null && CustomFormatIndex.match(/^[0-9]*$/)==null))
        {
            if (CustomFormatIndex!="@" && CustomFormatIndex!="#")
            {
                var abc = CustomFormatIndex;                                                       
                var strLeft = Tboxvalue.substring(0,k);                                 
                var strRight = Tboxvalue.substring(k,custom_format.length);                    
                var str = strLeft + abc + strRight    
                Tboxvalue= str                        
            }                       


        }     
    }




    return Tboxvalue

}    


function ValidateCustomFormat(objTextBox,strErrMsg,custom_format,row)
{    
    blnChrome=true;
     var Tboxvalue = objTextBox.value 
    if(objTextBox.value=="" && row=="")
    {
        objTextBox.value=custom_format                          
        return true
    }
    if(objTextBox.value=="")
    {
        return true
    }
    
    if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }
    }
    
    var fnValidate = VCF(Tboxvalue,strErrMsg,custom_format,row)      
    if(fnValidate==strErrMsg)                  
    {
        blnChrome=false;
        alert(strErrMsg)
        objTextBox.value=""
        validationx=objTextBox ;
		setTimeout("validationf1();",250);
        return false
    }
    else
    {
        objTextBox.value = fnValidate                 
        return true
    }                
    


}


function setDateVariables(intDateFormat)
{
	switch(intDateFormat)
	{
		case 1 :
			separator = "/"
			posDate = 1
			posMonth = 0
			posYear = 2
			lenYear = 4
			break;
		case 2 :
			separator = "/"
			posDate = 0
			posMonth = 1
			posYear = 2
			lenYear = 4
			break;
	}
}
function isLeapYear(year)
{
	return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? true : false;
}
var isEnabledStatus=0;
function MatrixBranch(enable,varqtype,varqno,varqid,vartotanswers,id,name,isRun)
{
    var counter;
    var blnenable;
    var qtype,qno,qid,totanswers;
    var totGrids;
    var arrqtype,arrqno,arrqid,arrtotanswers;
    arrqtype=varqtype.split(',');
    arrqno=varqno.split(',');    
    arrqid=varqid.split(',');
    arrtotanswers=vartotanswers.split(',');
    //strQno=id.split('_')
   
    if(isRun==1) {
        var theRadio = document.getElementById(id);
            toggleAllRadioCheck_New(theRadio, name);
            if(theRadio.getAttribute("isChecked")=="true"){
                theRadio.checked = false;
                theRadio.setAttribute("isChecked","false");
                isEnabledStatus=1;
            } 
            else {
                theRadio.setAttribute("isChecked","true");
                isEnabledStatus=0;
           }
    }

if (enable==1) {isEnabledStatus=1} else {enable=isEnabledStatus}

    for(totGrids=0;totGrids<arrqtype.length;totGrids++)
    {
        qtype=arrqtype[totGrids];
        qno=arrqno[totGrids];
        qid=arrqid[totGrids];
        totanswers=arrtotanswers[totGrids];
        
        if(enable==1)
            blnenable=true;
        else
            blnenable=false;  
        if(qtype=="GR" || qtype=="RW1" || qtype=="RG")
        {          
            for(counter=1;counter<=totanswers;counter++)
            {
                document.getElementById(qno + "_" + qid + "_" + counter).disabled=blnenable; 
                if(blnenable)   
                    document.getElementById(qno + "_" + qid + "_" + counter).checked=false;
            }
        }
        else if(qtype=="T")      
        {
            document.getElementById(qno + "_" + qid + "_T").disabled=blnenable;
            if(blnenable)
                document.getElementById(qno + "_" + qid + "_T").value='';
        }
        else if(qtype=="RW2")      
        {
            document.getElementById(qno + "_" + qid + "_RW").disabled=blnenable;
            if(blnenable)
                document.getElementById(qno + "_" + qid + "_RW").options[0].selected=true;
        }
        else if(qtype=="GD")      
        {
            document.getElementById(qno + "_" + qid + "_GD").disabled=blnenable;
            if(blnenable)
                document.getElementById(qno + "_" + qid + "_GD").options[0].selected=true;
        }
        else if(qtype=="GC")
        {
            for(counter=0;counter<=totanswers-1;counter++)
            {
                document.getElementById(qno + "_" + qid + "_GC_" + counter).disabled=blnenable;                
                if(blnenable)
                    document.getElementById(qno + "_" + qid + "_GC_" + counter).checked=false;    
            }
        }
    }   
}
function MatrixBranchFormat(enable,varqtype,varqid,vartotanswers,rowposition,clientid,TargetGroups,StrColor)
{
    var counter;
    var blnenable;

    if(enable==1)
        blnenable=true;
    else
        blnenable=false;
    
    if(isEnabledStatus==1) { blnenable=true; }
    
    var qtype,qid,totanswers;
    var totGrids=0;
    var arrqtype,arrqid,arrtotanswers,arrGroups;
    arrqtype=varqtype.split(',');
    arrqid=varqid.split(',');
    arrtotanswers=vartotanswers.split(',');    
    arrGroups=TargetGroups.split(',');
    for(totGrids=0;totGrids<arrqtype.length;totGrids++)
    {
        qtype=arrqtype[totGrids];
        qid=arrqid[totGrids];
        totanswers=arrtotanswers[totGrids];
        if(blnenable){
            if(document.getElementById(clientid + "_tdrow2_" + arrGroups[totGrids])==null) {
            
            }
            else {
                document.getElementById(clientid + "_tdrow2_" + arrGroups[totGrids]).className="disable";
            }
        }
        else {
            if(document.getElementById(clientid + "_tdrow2_" + arrGroups[totGrids])==null) {    
            
            }
            else {
          

            //document.getElementById(clientid + "_tdrow2_" + arrGroups[totGrids]).color=StrColor;
      document.getElementById(clientid + "_tdrow2_" + arrGroups[totGrids]).className="enablequest";
            }
        }
        if(qtype=="GR" || qtype=="RW1" || qtype=="GC" || qtype=="RG")
        {          
            for(counter=0;counter<=totanswers-1;counter++)
            {
                if(blnenable)            
                    {
                        document.getElementById(clientid + "_td_" + qid + "_" + counter).className="disable";
                        document.getElementById(clientid + "_td_" + qid + "_" + counter).style.cursor='';
                        document.getElementById(clientid + "_tdrow3_" + arrGroups[totGrids] + "_" + counter).className="disable";                        
                    }
                else
                {
                    if(rowposition==0)
                    {                
                        document.getElementById(clientid + "_td_" + qid + "_" + counter).className="enableeven";
                        document.getElementById(clientid + "_td_" + qid + "_" + counter).style.cursor='pointer';
                        document.getElementById(clientid + "_tdrow3_" + arrGroups[totGrids] + "_" + counter).className="enableodd";
                    }
                     else
                     {
                        document.getElementById(clientid + "_td_" + qid + "_" + counter).className="enableodd";
                        document.getElementById(clientid + "_td_" + qid + "_" + counter).style.cursor='pointer';
                        document.getElementById(clientid + "_tdrow3_" + arrGroups[totGrids] + "_" + counter).className="enableodd";
                     }
                 }
            }
        }
        else if(qtype=="T" || qtype=="RW2" || qtype=="GD")      
        {
            if(blnenable)
            {            
                    document.getElementById(clientid + "_td_" + qid + "_0" ).className="disable";                            
                    document.getElementById(clientid + "_tdrow3_" + arrGroups[totGrids] + "_0").className="disable";
            }        
            else
            {
                if(rowposition==0)                
                {
                    document.getElementById(clientid + "_td_" + qid + "_0").className="enableeven";
                    document.getElementById(clientid + "_tdrow3_" + arrGroups[totGrids] + "_0").className="enableodd";
                }
                 else
                 {
                    document.getElementById(clientid + "_td_" + qid + "_0").className="enableodd";
                    document.getElementById(clientid + "_tdrow3_" + arrGroups[totGrids] + "_0").className="enableodd";
                  }  
             }
        }                
    }
}

function chkclk(){
	do_chk = 1;	
}
function unchkclk(){
	do_chk = 0;	
}
function ctrlClick(ctrlid,ctrl_type)
{
	if(do_chk) { 
			do_chk = 0;
		return; 
	}
	//obj = eval("document.forms[0]."+ ctrlid)
	obj = document.getElementById(ctrlid)
	if (ctrl_type == 'C')
	{
		if (obj.checked) {
			obj.checked = false;	
		}
		else {
			obj.checked = true;
		}
	}else if (ctrl_type == 'R' || ctrl_type == 'RS')
	{
		if(obj.disabled) {  }
	    else { obj.checked = true; }	}
}
function RK_ChkSame(total,strid)
{ //  total : no of dropdowns

	var i = 0;
	for(i=0;i<total;i++)
	{
		//obj = eval("document.forms[0]."+ strid + i) // Pass each dropdowns to function
		obj =document.getElementById(strid + i) // Pass each dropdowns to function
		
		if (!RK_ChkValid(obj,total,i,strid)) return false;
	
	}
	return true;	
}

function RK_ChkSelected(total,strid,count,ctype)
{

	var j = 0;
	for(i=0;i<total;i++)
	{
		//obj = eval("document.forms[0]."+ strid + i)
		obj = document.getElementById(strid + i)
		if(obj){
			if (obj.selectedIndex > 0){ // compare with other options only ..
				j++;
				obj1 = obj;
			}	
		}
		
	}

	if(count != 0) // 
	 	{
	 		if (ctype==0){
				if (j >0 && j < count) 
				{
					alert("Please rank  "+  count  +" options")
					obj1.focus()
					return false;
				}
				return true;
	 		}	 	
	 		else if (ctype==1){
				if (j >0 && j != count) 
				{
					alert("Please rank  "+  count  +" options")
					obj1.focus()
					return false;
				}
				return true;
	 		}
			else if (j >0 && ctype==2){
				if (j < count) 
				{
					alert("Please rank atleast "+  count  +" options")
					obj1.focus()
					return false;
				}
				return true;
			}
			else if (j >0 && ctype==3){
				if (j > count) 
				{
					alert("Please rank at the most "+  count  +" options")
					obj1.focus()
					return false;
				}
			}	 	
	}
	else
	{
		if (j > 0 && j != total) 
		{
			//alert("Please rank all options")
			alert(JVParticipation_RankAll)
			obj1.focus()
			return false;
		}
	}
	return true;
}
function RK_ChkSelected_New(total,strid,count,ctype,strMess)
{//PRT : 6490 Dilip Changed on 10-6-08
    if(strMess=="")
    {
        return RK_ChkSelected(total,strid,count,ctype);
    }
	var j = 0;
	for(i=0;i<total;i++)
	{
		//obj = eval("document.forms[0]."+ strid + i)
		obj = document.getElementById(strid + i)
		if(obj){
			if (obj.selectedIndex > 0){ // compare with other options only ..
				j++;
				obj1 = obj;
			}	
		}
		
	}

	if(count != 0) // 
	 	{
	 		if (ctype==0){
				if (j >0 && j < count) 
				{
					//alert("Please rank  "+  count  +" options")
					return CheckForAssessment(obj1, strMess)
				}
				return true;
	 		}	 	
	 		else if (ctype==1){
				if (j >0 && j != count) 
				{
				   return CheckForAssessment(obj1, strMess)
				}
				return true;
	 		}
			else if (j >0 && ctype==2){
				if (j < count) 
				{
				  return  CheckForAssessment(obj1, strMess)
				}
				return true;
			}
			else if (j >0 && ctype==3){
				if (j > count) 
				{
                 return   CheckForAssessment(obj1, strMess)
				}
			}	 	
	}
	else
	{
		if (j > 0 && j != total) 
		{		    		    
		  return  CheckForAssessment(obj1, strMess)                                               
		}
	}
	return true
}

function CheckForAssessment(obj1, strMess)
{
       if(isAssessment == true)
        {
		        if(hours==0 && mins==0 && secs==0)
		        {
		            return true
		        }
		        else
		        {
		            alert(strMess);
		            StartTimer();
			        //alert("Please rank all options")
			        obj1.focus()
			        return false;
                }			    
        }
       else
        {
                alert(strMess);		            
		        //alert("Please rank all options")
		        obj1.focus()
		        return false;
        }             
}

function RK_ChkValid(selObj,total,j,strid)
{
	
	do_submit = 0 // added by Sanjeev - for Netscape Submit
	selLen = selObj.length
	if(selObj.selectedIndex == 0)	{ return true;	}  // do not process if [ not selected ] ..
	var i=0;
	var i1=0;
	var obj;

		for(i=0;i<total;i++)
		{
			//obj = eval("document.forms[0]."+ strid + i)
			obj = document.getElementById(strid + i)
			if (obj) {

				if ((i != j)&&(obj.selectedIndex > 0)) // dont compare with self and unselected ones
					{
				
						if (obj.selectedIndex == selObj.selectedIndex) // check duplicate
						{	
							do_submit = 1 // added by Sanjeev - for Netscape Submit	
							
					        alert(JVParticipation_AlreadyRanked.replace("<N>",selObj.options[selObj.selectedIndex].text))			
							//alert("You have already assigned " + selObj.options[selObj.selectedIndex].text + " to another option")
							do_submit = 0 // added by Sanjeev - for Netscape Submit
							selObj.options[0].selected=true
							selObj.focus()						
							return false
						}
					}
				}
		}

	return true
}	

function CS_CheckTotal(qno,intMax,total,strid,errMsg)
{
    if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }	   
    }
	CS_AddToTotal(total,strid)	
	//objTotal = eval("document.forms[0]." + strid + "T")
	objTotal=document.getElementById(strid + "T");
    
    if(objTotal){
        if (intMax != "NA"){
		    if (!(objTotal.value == intMax||objTotal.value == "")) //  && intErr > 0
		    {
			    alert(errMsg)

	            var i,j;
	            var obj;
	            j==0;
	            for(i=1;i<=total;i++){
		            //obj = eval("document.forms[0]." + strid + i)
		            obj=document.getElementById(strid + i);
		            if (obj){
			            obj.focus();
			            break;
		            }
	            }



    //			obj = eval("document.forms[0]." + strid + "1")
    //			obj.focus()
    //			obj.select()
			    return false
		    }
	    }
    }	
return true
}	

function CS_AddToTotal(total,strid)
{
    if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }	   
    }
    
	intSum = 0
	intSomeVal = 0
	intErr = 0
	
	for (i=1;i<=total;i++)
	{
	
		//obj = eval("document.forms[0]." + strid + i)
		obj=document.getElementById(strid + i);
		if(obj){
			if (obj.value == "" || isNaN(obj.value) || (obj.value).indexOf(" ") != -1 || (obj.value).indexOf("e") != -1 || (obj.value).indexOf("E") != -1)
			{
				obj.value = ""
			}
			else
			{
				obj.value = Math.round(parseFloat(obj.value)*100)/100
				intSum += parseFloat(obj.value)
				
				// Changed by Imran For PRT 7725
				//if (parseFloat(obj.value)> 0) 
				if (parseFloat(obj.value)>= 0) 
				{ // found some text
					intErr = 1;
				}
			}
		}
	}
	
	
	//objTotal = eval("document.forms[0]." + strid + "T")
	objTotal = document.getElementById(strid + "T")
	if(objTotal){
	    objTotal.value = ""
	    objTotal.value = parseFloat(Math.round(intSum*100)/100)
	    if (intErr == 0 && intSum == 0) { // no text + sum/count = 0
		    objTotal.value = ""	
	    }
	}
}
function CS_AddToTotalNotValidate(total,strid)
{
    if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }	   
    }
    
	intSum = 0
	intSomeVal = 0
	intErr = 0
	
	for (i=1;i<=total;i++)
	{
	
		//obj = eval("document.forms[0]." + strid + i)	
		obj = document.getElementById(strid + i)	
		if(obj){
			if (obj.value == "" || isNaN(obj.value) || (obj.value).indexOf(" ") != -1 || (obj.value).indexOf("e") != -1 || (obj.value).indexOf("E") != -1)
			{
				obj.value = ""
			}
			else
			{
				obj.value = Math.round(parseFloat(obj.value)*100)/100				
			}			
		}
		
	}
	
}
function CS_Countzero(total,strid,errMsg)
{
    if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }	   
    }
	intSum = 0
	//intSomeVal = 0
	//intErr = 0
	//objTotal = eval("document.forms[0]." + strid + "T")
	objTotal = document.getElementById(strid + "T")
	for (i=1;i<=total;i++)
	{
	
		//obj = eval("document.forms[0]." + strid + i)				
		obj = document.getElementById(strid + i)				
		if(obj){
			if (obj.value == 0  )//"" || isNaN(obj.value) || (obj.value).indexOf(" ") != -1 || (obj.value).indexOf("e") != -1 || (obj.value).indexOf("E") != -1)
			{
				intSum++;
			}
		}
		
	}
	
	
	//objTotal = eval("document.forms[0]." + strid + "T")
	//objTotal.value = ""
	//objTotal.value = parseFloat(Math.round(intSum*100)/100)
	if ( intSum == total && objTotal.value=="") { // no text + sum/count = 0
			for (i=1;i<=total;i++)
			{
	
				//obj = eval("document.forms[0]." + strid + i)				
				obj = document.getElementById(strid + i)				
				//alert(obj.value)
				obj.value = ""
		
			}
		}
		return true;
}

function RK_Chkmax(total,strid,count)// Added by Ashish Acharya to check how much Opetion is selected and it should be in a sequesnce in Ranking
{
if(isAssessment == true)
	{
	    if( hours==0 && mins==0 && secs==0)
	    {	        
	        return true
	    }	   
    }
var k = 0;
var m=0;
var l=0;
for(j=0;j< total;j++)
	{
		//obj = eval("document.forms[0]."+ strid + j)
		obj = document.getElementById(strid + j)
		if (obj){
			if (obj.selectedIndex > 0 ){ // compare with other options only ..
				m++;
			}else
			{
				obj1 = obj;
			}
		}
	}

	//alert(m)
	for(i=0;i<total;i++)
	{
	
		//obj = eval("document.forms[0]."+ strid + i)
		obj = document.getElementById(strid + i)
		if (m < count && obj)
		{
			if (obj.selectedIndex > 0 &&  obj.selectedIndex > count)
			{
				k++			
			}
		}
		else if (obj)
		{
			if (obj.selectedIndex > 0 &&  obj.selectedIndex > m )
			{ // compare with other options only ..
				l++;
			}
		}
	}
	
	
	
	if(count != 0)
	{
	if (k >  0 )
	{
		//alert("1" + k)
		
		alert(" Please rank the options in numerical order")
		obj1.focus()
		return false;
		
	}
	if (l >  0 )
	{
		//alert("1" + k)
		
		alert("Please rank the options in numerical order")
		obj1.focus()
		return false;
		
	}
	
	}
	return true;
}


function populate2(d){
	var selectedDay;
	selectedDay	= d.selectedIndex;
	for (var i = 0; i < d.length; i++) 
	{
		d.options[0] = null;
	}
	for (var i = 0; i < 31; i++) 
	{
		d.options[i] = new Option(i+1);
		
	}
	d.options[selectedDay].selected = true;
}
function populate1(d,m,y,selectIndex) 
{
    //PRT 9381
    d=document.getElementById(d);
    m=document.getElementById(m);
    y=document.getElementById(y);
    selectIndex=document.getElementById(selectIndex).selectedIndex;
    
	timeA = new Date(y.options[y.selectedIndex].text, m.options[m.selectedIndex].value,1);
	
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	var daysInMonth = timeB.getDate();
	var selectedDay;
	selectedDay	= d.selectedIndex;
	if(d.length == daysInMonth)
	{
		return false;
	}
	
	for (var i = 0; i < d.length; i++) 
	{
		d.options[0] = null;
	}
	for (var i = 0; i < daysInMonth; i++) 
	{
		d.options[i] = new Option(i+1);
	}
	if (i > selectedDay)
	{
		d.options[selectedDay].selected = true;
	}
	else
	{
		d.options[daysInMonth-1].selected = true;
	}
}
function populate_embed(d,m,y,selectIndex) 
{

	timeA = new Date(y.options[y.selectedIndex].text, m.options[m.selectedIndex].value,1);
	
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	var daysInMonth = timeB.getDate();
	var selectedDay;
	selectedDay	= d.selectedIndex;
	if(d.length == daysInMonth)
	{
		return true;
	}
	
	for (var i = 0; i < d.length; i++) 
	{
		d.options[0] = null;
	}
	for (var i = 0; i < daysInMonth; i++) 
	{
		d.options[i] = new Option(i+1);
	}
	if (i > selectedDay)
	{
		d.options[selectedDay].selected = true;
	}
	else
	{
		d.options[daysInMonth-1].selected = true;		
		alert("Invalid Date!");		
		d.focus()
		return false;
	}
	return true;
}
function disableEnterKey(e) 
{
	if (window.event) 
	{ 
	    return(!(window.event.keyCode == 13))
	}
	else
	{ 
        return(!(e.which == 13))	    
	}
}

function checksubmit(submitbtn) {
	checksubmit=blocksubmit;
}
function blocksubmit(){
	if (typeof formerrormsg!="undefined")
	{
		alert(formerrormsg);
		return false;
	}
	else
	{
		return true;
	}
}


		
		
// CALENDER POP-UP WINDOW CODE :

function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
	if ((p_month == null) && (p_year == null))	return;

	if (p_WinCal == null)
		this.gWinCal = ggWinCal;
	else
		this.gWinCal = p_WinCal;
	
	if (p_month == null) {
		this.gMonthName = null;
		this.gMonth = null;
		this.gYearly = true;
	} else {
		this.gMonthName = Calendar.get_month(p_month);
		this.gMonth = new Number(p_month);
		this.gYearly = false;
	}

	this.gYear = p_year;
	this.gFormat = p_format;
	this.gBGColor = "white";
	this.gFGColor = "black";
	this.gTextColor = "black";
	this.gHeaderColor = "black";
	this.gReturnItem = p_item;
	this.gReturnItem_New = p_item.substring(9);
}

Calendar.get_month = Calendar_get_month;
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
Calendar.calc_month_year = Calendar_calc_month_year;
Calendar.print = Calendar_print;

function Calendar_get_month(monthNo) {
	return Calendar.Months[monthNo];
}

function Calendar_get_daysofmonth(monthNo, p_year) {
	/* 
	Check for leap year ..
	1.Years evenly divisible by four are normally leap years, except for... 
	2.Years also evenly divisible by 100 are not leap years, except for... 
	3.Years also evenly divisible by 400 are leap years. 
	*/
	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return Calendar.DOMonth[monthNo];
	
		return Calendar.lDOMonth[monthNo];
	} else
		return Calendar.DOMonth[monthNo];
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/* 
	Will return an 1-D array with 1st element being the calculated month 
	and second being the calculated year 
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();
	
	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}
	
	return ret_arr;
}

function Calendar_print() {
	ggWinCal.print();
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/* 
	Will return an 1-D array with 1st element being the calculated month 
	and second being the calculated year 
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();
	
	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}
	
	return ret_arr;
}

// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendar();

Calendar.prototype.getMonthlyCalendarCode = function() {
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";
	
	// Begin Table Drawing code here..
	vCode = vCode + "<TABLE BORDER=1 BGCOLOR=\"" + this.gBGColor + "\">";
	
	vHeader_Code = this.cal_header();
	vData_Code = this.cal_data();
	vCode = vCode + vHeader_Code + vData_Code;
	
	vCode = vCode + "</TABLE>";
	
	return vCode;
}

Calendar.prototype.show = function() {
	var vCode = "";
	
	this.gWinCal.document.open();

	// Setup the page...
	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("</head>");

	this.wwrite("<body " + 
		"link=\"" + this.gLinkColor + "\" " + 
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwriteA("<FONT FACE='" + fontface + "' SIZE=2><B>");
	this.wwriteA(this.gMonthName + " " + this.gYear);
	this.wwriteA("</B><BR>");

	// Show navigation buttons
	var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
	var prevMM = prevMMYYYY[0];
	var prevYYYY = prevMMYYYY[1];

	var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
	var nextMM = nextMMYYYY[0];
	var nextYYYY = nextMMYYYY[1];
	
	this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + 
		"');" +
		"\"><<<\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + 
		"');" +
		"\"><<\/A>]</TD><TD ALIGN=center>");
	this.wwrite("</TD><TD ALIGN=center>"); // [<A HREF=\"javascript:window.print();\">Print</A>]
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + 
		"');" +
		"\">><\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + 
		"');" +
		"\">>><\/A>]</TD></TR></TABLE><BR>");

	// Get the complete calendar code for the month..
	vCode = this.getMonthlyCalendarCode();
	this.wwrite(vCode);
	this.wwrite("</font></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.showY = function() {
	var vCode = "";
	var i;
	var vr, vc, vx, vy;		// Row, Column, X-coord, Y-coord
	var vxf = 285;			// X-Factor
	var vyf = 200;			// Y-Factor
	var vxm = 10;			// X-margin
	var vym;				// Y-margin
	if (isIE)	vym = 75;
	else if (isNav)	vym = 25;
	
	this.gWinCal.document.open();

	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("<style type='text/css'>\n<!--");
	for (i=0; i<12; i++) {
		vc = i % 3;
		if (i>=0 && i<= 2)	vr = 0;
		if (i>=3 && i<= 5)	vr = 1;
		if (i>=6 && i<= 8)	vr = 2;
		if (i>=9 && i<= 11)	vr = 3;
		
		vx = parseInt(vxf * vc) + vxm;
		vy = parseInt(vyf * vr) + vym;

		this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
	}
	this.wwrite("-->\n</style>");
	this.wwrite("</head>");

	this.wwrite("<body " + 
		"link=\"" + this.gLinkColor + "\" " + 
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>");
	this.wwrite("Year : " + this.gYear);
	this.wwrite("</B><BR>");

	// Show navigation buttons
	var prevYYYY = parseInt(this.gYear) - 1;
	var nextYYYY = parseInt(this.gYear) + 1;
	
	this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/A>]</TD></TR></TABLE><BR>");

	// Get the complete calendar code for each month..
	var j;
	for (i=11; i>=0; i--) {
		if (isIE)
			this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
		else if (isNav)
			this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");

		this.gMonth = i;
		this.gMonthName = Calendar.get_month(this.gMonth);
		vCode = this.getMonthlyCalendarCode();
		this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
		this.wwrite(vCode);

		if (isIE)
			this.wwrite("</DIV>");
		else if (isNav)
			this.wwrite("</LAYER>");
	}

	this.wwrite("</font><BR></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.wwrite = function(wtext) {
	this.gWinCal.document.writeln(wtext);
}

Calendar.prototype.wwriteA = function(wtext) {
	this.gWinCal.document.write(wtext);
}

Calendar.prototype.cal_header = function() {
	var vCode = "";
	
	vCode = vCode + "<TR>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sun</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Mon</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Tue</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Wed</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Thu</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Fri</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='16%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sat</B></FONT></TD>";
	vCode = vCode + "</TR>";
	
	return vCode;
}

Calendar.prototype.cal_data = function() {
	var vDate = new Date();
	vDate.setDate(1);
	vDate.setMonth(this.gMonth);
	vDate.setFullYear(this.gYear);

	var vFirstDay=vDate.getDay();
	var vDay=1;
	var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear);
	var vOnLastDay=0;
	var vCode = "";
	var vString;
	
	vString =  "" ;
    var strAutosave = "";
    var strSQJS = "";
    if(blnAutosave==true) {
        strAutosave = "window.opener.setAutosaveFlag();"
    }
    if(window.setSQJS) {
        strSQJS = "window.opener.setSQJS();"
    }
    /*
	Get day for the 1st of the requested month/year..
	Place as many blank cells before the 1st day of the month as necessary. 
	*/

if (p_qtype == 1 || p_qtype == 2)
{
	vCode = vCode + "<TR>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++) {
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
			"<A HREF='#' " + 
				//"onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
				"onClick=\"self.opener.document.getElementById('" + this.gReturnItem_New + "').value='" + 
				this.format_data(vDay) + 
				"';" + strAutosave + strSQJS + "window.close();\">" + 
				this.format_day(vDay) + 
			"</A>" + 
			"</FONT></TD>";
		vDay=vDay + 1;
	}
	vCode = vCode + "</TR>";

	// Write the rest of the weeks
	for (k=2; k<7; k++) {
		vCode = vCode + "<TR>";

		for (j=0; j<7; j++) {
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
				"<A HREF='#' " + 
					"onClick=\"self.opener.document.getElementById('" + this.gReturnItem_New + "').value='" + 
					this.format_data(vDay) + 
					"';" + strAutosave + strSQJS + "window.close();\">" + 
				this.format_day(vDay) + 
				"</A>" + 
				"</FONT></TD>";
			vDay=vDay + 1;

			if (vDay > vLastDay) {
				vOnLastDay = 1;
				break;
			}
		}

		if (j == 6)
			vCode = vCode + "</TR>";
		if (vOnLastDay == 1)
			break;
	}
	
	// Fill up the rest of last week with proper blanks, so that we get proper square blocks
	for (m=1; m<(7-j); m++) {
		if (this.gYearly)
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
		else
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
	}
}
else if(p_qtype == 3 || p_qtype == 4)
{
	vCode = vCode + "<TR>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
	}
	
//).selected
	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++) {
		this.format_data(vDay);
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
			"<A HREF='#' " + 
				//"onClick=\"self.opener.document." + this.gReturnItem + "dd.selectedIndex = " +(vDx-1) + ";self.opener.document." + this.gReturnItem + "yyyy.value ='" + vYx + "';self.opener.document." + this.gReturnItem + "mm.value = '" + vMx + "';" +
				"onClick=\"self.opener.document.getElementById('" + this.gReturnItem_New + "dd').selectedIndex = " +(vDx-1) + ";self.opener.document.getElementById('" + this.gReturnItem_New + "yyyy').value ='" + vYx + "';self.opener.document.getElementById('" + this.gReturnItem_New + "mm').value = '" + vMx + "';" +
				"" + strAutosave + strSQJS + " window.close();\">" + 
				this.format_day(vDay) + 
			"</A>" + 
			"</FONT></TD>";
		vDay=vDay + 1;
	}
	vCode = vCode + "</TR>";

	// Write the rest of the weeks
	for (k=2; k<7; k++) {
		vCode = vCode + "<TR>";

		for (j=0; j<7; j++) {
			this.format_data(vDay);
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
				"<A HREF='#' " + 
					//"onClick=\"self.opener.document." + this.gReturnItem + "mm.value = '" + vMx + "';self.opener.document." + this.gReturnItem + "yyyy.value ='" + vYx + "';self.opener.document." + this.gReturnItem + "dd.selectedIndex = " + (vDx-1) + 
					"onClick=\"self.opener.document.getElementById('" + this.gReturnItem_New + "mm').value = '" + vMx + "';self.opener.document.getElementById('" + this.gReturnItem_New + "yyyy').value ='" + vYx + "';self.opener.document.getElementById('" + this.gReturnItem_New + "dd').selectedIndex = " + (vDx-1) + 
					";" + strAutosave + strSQJS + "window.close();\">" + 
				this.format_day(vDay) + 
				"</A>" + 
				"</FONT></TD>";
			vDay=vDay + 1;

			if (vDay > vLastDay) {
				vOnLastDay = 1;
				break;
			}
		}

		if (j == 6)
			vCode = vCode + "</TR>";
		if (vOnLastDay == 1)
			break;
	}
	
	// Fill up the rest of last week with proper blanks, so that we get proper square blocks
	for (m=1; m<(7-j); m++) {
		if (this.gYearly)
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
		else
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
	}
}	
	return vCode;
}

Calendar.prototype.format_day = function(vday) {
	var vNowDay = gNow.getDate();
	var vNowMonth = gNow.getMonth();
	var vNowYear = gNow.getFullYear();

	if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
		return ("<FONT COLOR=\"RED\"><B>" + vday + "</B></FONT>");
	else
		return (vday);
}

Calendar.prototype.write_weekend_string = function(vday) {
	var i;

	// Return special formatting for the weekend day.
	for (i=0; i<weekend.length; i++) {
		if (vday == weekend[i])
			return (" BGCOLOR=\"" + weekendColor + "\"");
	}
	
	return "";
}

Calendar.prototype.format_data = function(p_day) {
	var vData;
	var vMonth = 1 + this.gMonth;
	vMonth = (vMonth.toString().length == 0) ? "0" + vMonth : vMonth;
	var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
	var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
	var vY4 = new String(this.gYear);
	var vY2 = new String(this.gYear.substr(2,2));
	var vDD = (p_day.toString().length == 0) ? "0" + p_day : p_day;
	
	vDx = vDD;
	vMx	= vMonth;
	vYx = vY4;
	switch (this.gFormat) {
		case "MM\/DD\/YYYY" :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
			break;
		case "MM\/DD\/YY" :
			vData = vMonth + "\/" + vDD + "\/" + vY2;
			break;
		case "MM-DD-YYYY" :
			vData = vMonth + "-" + vDD + "-" + vY4;
			break;
		case "MM-DD-YY" :
			vData = vMonth + "-" + vDD + "-" + vY2;
			break;

		case "DD\/MON\/YYYY" :
			vData = vDD + "\/" + vMon + "\/" + vY4;
			break;
		case "DD\/MON\/YY" :
			vData = vDD + "\/" + vMon + "\/" + vY2;
			break;
		case "DD-MON-YYYY" :
			vData = vDD + "-" + vMon + "-" + vY4;
			break;
		case "DD-MON-YY" :
			vData = vDD + "-" + vMon + "-" + vY2;
			break;

		case "DD\/MONTH\/YYYY" :
			vData = vDD + "\/" + vFMon + "\/" + vY4;
			break;
		case "DD\/MONTH\/YY" :
			vData = vDD + "\/" + vFMon + "\/" + vY2;
			break;
		case "DD-MONTH-YYYY" :
			vData = vDD + "-" + vFMon + "-" + vY4;
			break;
		case "DD-MONTH-YY" :
			vData = vDD + "-" + vFMon + "-" + vY2;
			break;

		case "DD\/MM\/YYYY" :
			vData = vDD + "\/" + vMonth + "\/" + vY4;
			break;
		case "DD\/MM\/YY" :
			vData = vDD + "\/" + vMonth + "\/" + vY2;
			break;
		case "DD-MM-YYYY" :
			vData = vDD + "-" + vMonth + "-" + vY4;
			break;
		case "DD-MM-YY" :
			vData = vDD + "-" + vMonth + "-" + vY2;
			break;

		default :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
	}
	return vData;
}

function Build(p_item, p_month, p_year, p_format) {
	var p_WinCal = ggWinCal;
	gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

	// Customize your Calendar here..
	gCal.gBGColor="white";
	gCal.gLinkColor="black";
	gCal.gTextColor="black";
	gCal.gHeaderColor="darkgreen";

	// Choose appropriate show function
	if (gCal.gYearly)	gCal.showY();
	else	gCal.show();
	
}

function show_calendar() {
	/* 
		p_month : 0-11 for Jan-Dec; 12 for All Months.
		p_year	: 4-digit year
		p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
		p_item	: Return Item.
	*/

	p_item = arguments[0];		
	if (arguments[1] == "" || arguments[1] == null)
		p_month = new String(gNow.getMonth());
	else
		p_month = arguments[1];
		
	if (arguments[2] == "" || arguments[2] == null)
		p_year = new String(gNow.getFullYear().toString());
	else
		p_year = arguments[2];
		
	if (arguments[3] == "" || arguments[3] == null)
		p_format = "MM/DD/YYYY";
	else
		p_format = "DD/MM/YYYY";
		
	if (arguments[4] == null)
		p_qtype = 0;
	else
		p_qtype = arguments[4];
		
	if (p_qtype == 1)
	{
		p_format = "MM/DD/YYYY";
	}
	else if (p_qtype == 2)
	{
		p_format = "DD/MM/YYYY";
	}
	else
	{	    	    	    
	    if(p_item.indexOf("ctl") == -1)
	    {
	    p_item=p_item.replace("_",":");
	    }
	}
	vWinCal = window.open("", "Calendar", 
		"width=250,height=245,status=no,resizable=no,top=200,left=200");
	vWinCal.opener = self;
	ggWinCal = vWinCal;
        
	Build(p_item, p_month, p_year, p_format);
}
/*
Yearly Calendar Code Starts here
*/
function show_yearly_calendar(p_item, p_year, p_format) {
	// Load the defaults..
	if (p_year == null || p_year == "")
		p_year = new String(gNow.getFullYear().toString());
	if (p_format == null || p_format == "")
		p_format = "MM/DD/YYYY";

	var vWinCal = window.open("", "Calendar", "scrollbars=yes");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, null, p_year, p_format);
}
//Radio Button Check / Uncheck Script
function toggleRadioCheck(theRadio, name){
    toggleAllRadioCheck(theRadio, name);
    if(theRadio.getAttribute("isChecked")=="true"){
        theRadio.checked = false;
        theRadio.setAttribute("isChecked","false");
    } 
    else {
        theRadio.setAttribute("isChecked","true");
    }
}

function toggleAllRadioCheck(theRadio, name) {
    var arrayID = document.getElementsByName(name);
    for (i=0;i<arrayID.length;i++)
        if(arrayID[i].id != theRadio.id) {
            arrayID[i].setAttribute("isChecked","false");
        }
}

function toggleRadioCheck_New(id, name){
    var theRadio = document.getElementById(id);
    toggleAllRadioCheck_New(theRadio, name);
    if(theRadio.getAttribute("isChecked")=="true"){
        theRadio.checked = false;
        theRadio.setAttribute("isChecked","false");
    } 
    else {
        theRadio.setAttribute("isChecked","true");
    }
}

function toggleAllRadioCheck_New(element, name) {
    var arrayID = document.getElementsByName(name);
    for (i=0;i<arrayID.length;i++)
        if(arrayID[i].id != element.id) {
            arrayID[i].setAttribute("isChecked","false");
        }
}
