
function replaceChar(entry){
	
	var	out = ":"; // replace this
	var add = "."; // with this
	var temp = "" + entry; // temporary holder

	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add +
	temp.substring((pos + out.length), temp.length));
	return temp;
}
}

function numeralsOnly(evt) {
	
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 32 && (charCode < 48 || charCode > 57)) {
		if(charCode==46 ){
		return true;
		}
		return false;
    }
	
    return true;
}

// @ kaustubh 
function charactersOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode >31 && (charCode < 33 || charCode > 64)) {
		if(charCode==43 || charCode==45 ){
		return false;
		
		}
		return true;
	
    }
	alert("Numbers And Special Characters Are Not Allowed");
    return false;
}
// kaustubh @
function trimAll(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;

}

//  @ kaustubh
function checkCountry(val,country)
{
	//For mandotory check

	if(val=="no" || val=="None")
		return false;
	if(val=="" && country=="")
		return false;
	else 
		return true;
	
}
//  kaustubh @

function RegisterCompanyForm_verifyCountry()
	{
		
		    if(document.RegisterCompanyForm.tscomCountry.value!="")
			{
				
				document.RegisterCompanyForm.tscomOtherCountry.disabled=true;
				document.RegisterCompanyForm.tscomOtherCountry.value="";
				if(document.RegisterCompanyForm.tscomCountry.value=="no"){
					document.RegisterCompanyForm.tscomOtherCountry.disabled=true;
					document.RegisterCompanyForm.tscomCountryCode.value="";	
					document.RegisterCompanyForm.tscomPhoneno.focus();
				}else
				{
					document.RegisterCompanyForm.tscomCountryCode.value=document.RegisterCompanyForm.tscomCountry.value;
				}
				
				document.RegisterCompanyForm.tscomPhoneno.focus();
			}else{
				
			    document.RegisterCompanyForm.tscomOtherCountry.disabled=false;
				document.RegisterCompanyForm.tscomCountryCode.value="";
				document.RegisterCompanyForm.tscomOtherCountry.focus();
				
			}
	}

function RegisterCustomer_checkCountry()
{
 
//	if(document.RegisterClientForm.tsclientCountry.value !="")
//	{
		
		if(checkCountry(document.RegisterClientForm.tsclientCountry.value, document.RegisterClientForm.tsclientOtherCountry.value) == false)
		{
			alert("Country Is Not Selcted");
			
			 return false;
		}
		else
		{
			return true;
		}
	//}
	

}

	// @ kaustubh 11-03-08

function UpdateCompanyForm_checkCountry()
{
	
	//if(document.RegisterCompanyForm.tscomCountry.value !="")
	//{
		
		if(checkCountry(document.RegisterCompanyForm.tscomCountry.value,document.RegisterCompanyForm.tscomOtherCountry.value) ==false)
		{
			//alert("Website Format is invalid");
			//alert("Valid Example : www.###.com");
			alert("Country Is Not Selected");
			 return false;
		}
		else
		{
			return true;
		}
	//}
	//else
	//	return true

		 	
}

function RegisterCompanyForm_checkWebsite(val)
{
	 
	var flag=true;
	web= new String(val);
	temp=new String();
	temp= web.substring(0,4).toUpperCase();
	
	var count;
	count=0;
	var dotindex;

	numArray=new Array("1","2","3","4","5","6","7","8","9");
	

	if(web.length<4)
	{
		flag=false;
	//	alert(" Less than 4");
	}
	else if(temp != "WWW.")
	{
		flag=false;
			
	}
	else
	{
		for(i=6;i<web.length;i++)
		{
			if(web.charAt(i)==".")
			{
				count=count+1;
				dotindex=i;
				var a;
				 a=web.length - (dotindex+1);
				 if(a>4)
					 count=2;
				 
			}
			if(web.charAt(i)==" ")
				flag=false;
		}

		if(web.charAt(5)==".")
			count=2;

		if(count==1)
		{
			
			for(j=dotindex+1;j<dotindex+3;j++)
			{
				
				if(web.charAt(j)=="")
					count=2;
				for(k=0;k<numArray.length;k++)
					if(web.charAt(j)==numArray[k])
					{
				//	    alert("Numeric proble");
						flag=false;
					}
			}
		}


	}
	
	 if(count != 1)
	{
	//	 alert("Problem with dort");
		 flag=false;
	}
	 
	
		
	 
	 if(flag==true)
		return true;
	 if(flag==false)
	{
	//	 alert("Url is invalid'");
		return false;	
	}
		 
}

// @ kaustubh 11-03-08 

function ChangePasswordForm_confirmPassword()
{
	if(document.ChangePasswordForm.tsUserPassword.value!=document.ChangePasswordForm.tsUserconfirmPass.value)
	{
		alert("Password doesn't match");
		return false;
	}
}

function RegisterCompanyForm_confirmPassword()
{ 
		if(document.RegisterCompanyForm.tsKeyContactPassword.value!=document.RegisterCompanyForm.tsKeyConfirmPassword.value)
		{
			alert("Password doesn't match");
			//document.RegisterCompanyForm.tsKeyContactPassword.value="";
			//document.RegisterCompanyForm.tsKeyConfirmPassword.value="";
			return false;			
		}

		else
		{
			if(document.RegisterCompanyForm.tscomWebsite.value != "")
			{
				/*if(RegisterCompanyForm_checkWebsite(document.RegisterCompanyForm.tscomWebsite.value) == false)
				{
					alert("Website Format is invalid");
					alert("Valid Example : www.###.com");
					 return false;
				}
				else
				{
					return true;
				}*/	
				return true;
			}
			else if(checkCountry(document.RegisterCompanyForm.tscomCountry.value,document.RegisterCompanyForm.tscomOtherCountry.value)==false)
			{
				alert("Country Is Not Selected");
				return false;
			}
			else
				return true;
		}
			
}

function RegisterCompanyForm_confirmHintAnswer()
{
	if(RegisterCompanyForm_confirmPassword()){
		
	if(document.RegisterCompanyForm.tsKeyContactHintQue.value!="" && document.RegisterCompanyForm.tsKeyContactHintAns.value=="")
	{
		alert("Please Enter hint answer.");
		document.RegisterCompanyForm.tsKeyContactHintAns.focus();
		return false;
	}
	else
	{    	 
		 return true;		
	}
	}
	else
	{    
		document.RegisterCompanyForm.tsKeyContactPassword.focus();
		 return false;		
	}
}

function RegisterCompanyForm_confirmHintQuestion()
{
	if(document.RegisterCompanyForm.tsKeyContactHintQue.value=="")
	{
		document.RegisterCompanyForm.tsKeyContactHintAns.enable=false;
		//document.RegisterCompanyForm.adminCheck.focus()
	}
}
function RegisterCompanyForm_setCountryCode()
{
 document.RegisterCompanyForm.tscomCountryCode.value=document.RegisterCompanyForm.tscomCountry.value;
}

function RegisterClientForm_setCountryCode()
{
 document.RegisterClientForm.tsclientCountryCode.value=document.RegisterClientForm.tsclientCountry.value;
}


function RegisterClientForm_verifyCountry()
{
		
		    if(document.RegisterClientForm.tsclientCountry.value!="" )
			{ //alert("Here")
				document.RegisterClientForm.tsclientOtherCountry.value="";
				document.RegisterClientForm.tsclientOtherCountry.enable=false;				
				document.RegisterClientForm.tsclientPhoneno.focus();
				return true
			}else{
				document.RegisterClientForm.tsclientCountryCode.value="";
				return true
			}
}

function RegisterClientForm_changeFocus()
{
	document.RegisterClientForm.tsclientFax.focus();
	
}

function RegisterProjectForm_setFocusEdate()
{
	//alert("!");
	document.RegisterProjectForm.tsProjectEndDate.focus();
}
function RegisterProjectForm_setFocusHrs()
{
	//alert("2");
	document.RegisterProjectForm.tsProjectHrsWeek.focus();
}

function RegisterAdminForm_confirmPassword()
{
	if(document.AdminForm.tsAdminPassword.value!=document.AdminForm.tsAdminConfirmPassword.value)
	{
		alert("Password doesn't match");
		document.AdminForm.tsAdminPassword.value="";
		document.AdminForm.tsAdminConfirmPassword.value="";
		document.AdminForm.tsAdminPassword.focus();
		return false;
		
	}
}

function RegisterAccForm_confirmPassword()
{
	if(document.AccountantForm.tsaccPassword.value=="")
	{
		alert("Password is required");
		document.AccountantForm.tsaccPassword.focus();
		return false;
	}
	else if(document.AccountantForm.tsaccPassword.value!=document.AccountantForm.tsaccconfirmPass.value)
	{
		
		alert("Password doesn't match");
		document.AccountantForm.tsaccPassword.value="";
		document.AccountantForm.tsaccconfirmPass.value="";
		document.AccountantForm.tsaccPassword.focus();
		return false;		
	}
	else{
		return true;
	}
}

function RegisterRepForm_confirmPassword()
{
	if(document.RepActionForm.tsRepPassword.value!=document.RepActionForm.tsRepconfirmPass.value)
	{
		alert("Password doesn't match");
		document.RepActionForm.tsRepPassword.value="";
		document.RepActionForm.tsRepconfirmPass.value="";
		document.RepActionForm.tsRepPassword.focus();
		return false;
		
	}
}

function RegisterSupervisorForm_confirmPassword()
{
	if(document.supform.tsSuperviosrPassword.value!=document.supform.tsSuperviosrconfirmPass.value)
	{
		alert("Password doesn't match");
		document.supform.tsSuperviosrPassword.value="";
		document.supform.tsSuperviosrconfirmPass.value="";
		document.supform.tsSuperviosrPassword.focus();
		return false;
		
	}
}

// validation for BuildTeam

function teamform_confirmPassword()
{
	if(document.teamform.teamMemberPass.value != document.teamform.teamMemberConfirmPass.value)
	{
		alert("Password doesn't match");
		document.teamform.teamMemberPass.value="";
		document.teamform.teamMemberConfirmPass.value="";
		document.teamform.teamMemberConfirmPass.focus();
	}
}



function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
alert("trim");	
return LTrim(RTrim(value));
	
}



//*****************************************************************************
// Global variables
var container = new Array();
var onResizeHandler;

function scrollbarWidth(){
    var w;

    if (! document.body.currentStyle)   document.body.currentStyle = document.body.style;

    if (document.body.currentStyle.overflowY == 'visible' || document.body.currentStyle.overflowY == 'scroll'){
        w = document.body.offsetWidth - document.body.clientLeft - document.body.clientWidth;
    }else{
        win = window.open("about:blank", "_blank", "top=0,left=0,width=100,height=40,scrollbars=yes");
        win.document.writeln('scrollbar');
        w = win.document.body.offsetWidth - win.document.body.clientLeft - win.document.body.clientWidth;
        win.close();
    }

    return w;
}

function getActualWidth(e){
    if (! e.currentStyle)   e.currentStyle = e.style;

    return  e.clientWidth - parseInt(e.currentStyle.paddingLeft) - parseInt(e.currentStyle.paddingRight);
}

function findRowWidth(r){
    for (var i=0; i < r.length; i++){
        r[i].actualWidth = getActualWidth(r[i]);
    }
}

function setRowWidth(r){
    for (var i=0; i < r.length; i++){
        r[i].width = r[i].actualWidth;
        r[i].innerHTML = '<span style="width:' + r[i].actualWidth + ';">' + r[i].innerHTML + '</span>';
    }
}

function fixTableWidth(tbl){
    for (var i=0; i < tbl.tHead.rows.length; i++)   findRowWidth(tbl.tHead.rows[i].cells);
    findRowWidth(tbl.tBodies[0].rows[0].cells);
    if (tbl.tFoot)  for (var i=0; i < tbl.tFoot.rows.length; i++)   findRowWidth(tbl.tFoot.rows[i].cells);

    //tbl.width = '';

    for (var i=0; i < tbl.tHead.rows.length; i++)   setRowWidth(tbl.tHead.rows[i].cells);
    setRowWidth(tbl.tBodies[0].rows[0].cells);
    if (tbl.tFoot)  for (var i=0; i < tbl.tFoot.rows.length; i++)   setRowWidth(tbl.tFoot.rows[i].cells);
}

function makeScrollableTable(tbl,scrollFooter,height){
    var c, pNode, hdr, ftr, wrapper, rect;

    if (typeof tbl == 'string') tbl = document.getElementById(tbl);

    pNode = tbl.parentNode;
    fixTableWidth(tbl);

    c = container.length;
    container[c] = document.createElement('<SPAN style="height: 100; overflow: auto;">');
    container[c].id = tbl.id + "Container";
    pNode.insertBefore(container[c], tbl);
    container[c].appendChild(tbl);
    container[c].style.width = tbl.clientWidth + 2 * tbl.clientLeft + scrollbarWidth();

    hdr = tbl.cloneNode(false);
    hdr.id += 'Header';
    hdr.appendChild(tbl.tHead.cloneNode(true));
    tbl.tHead.style.display = 'none';

    if (!scrollFooter || !tbl.tFoot){
        ftr = document.createElement('<SPAN style="width:1;height:1;clip: rect(0 1 1 0);background-color:transparent;">');
        ftr.id = tbl.id + 'Footer';
        ftr.style.border = tbl.style.border;
        ftr.style.width = getActualWidth(tbl) + 2 * tbl.clientLeft;
        ftr.style.borderBottom = ftr.style.borderLeft = ftr.style.borderRight = 'none';
    }else{
        ftr = tbl.cloneNode(false);
        ftr.id += 'Footer';
        ftr.appendChild(tbl.tFoot.cloneNode(true));
        ftr.style.borderTop = 'none';
        tbl.tFoot.style.display = 'none';
    }

    wrapper = document.createElement('<table border=0 cellspacing=0 cellpadding=0>');
    wrapper.id = tbl.id + 'Wrapper';
    pNode.insertBefore(wrapper, container[c]);

    wrapper.insertRow(0).insertCell(0).appendChild(hdr);
    wrapper.insertRow(1).insertCell(0).appendChild(container[c]);
    wrapper.insertRow(2).insertCell(0).appendChild(ftr);

    wrapper.align = tbl.align;
    tbl.align = hdr.align = ftr.align = 'left';
    hdr.style.borderBottom = 'none';
    tbl.style.borderTop = tbl.style.borderBottom = 'none';

    // adjust page size
    if (c == 0 && height == 'auto'){
        onResizeAdjustTable();
        onResizeHandler = window.onresize;
        window.onresize = onResizeAdjustTable;
    }else{
        container[c].style.height = height;
    }
}

function onResizeAdjustTable(){
    if (onResizeHandler) onResizeHandler();

    var rect = container[0].getClientRects()(0);
    var h = document.body.clientHeight - (rect.top + (document.body.scrollHeight - rect.bottom));
    container[0].style.height = (h > 0) ? h : 1;
}

function printPage(){
    var tbs = document.getElementsByTagName('TABLE');
    var e;

    for (var i=0; i < container.length; i++)    container[i].style.overflow = '';

    window.print();

    for (var i=0; i < container.length; i++)    container[i].style.overflow = 'auto';
}

 function limitText(limitField, limitNum) 
{
		if (limitField.value.length > limitNum) 
		{
				limitField.value = limitField.value.substring(0, limitNum);
				alert("You can enter only upto 1000 characters")
			
		}
		else 
		{
				document.timesheetForm.countdown.value = limitNum - limitField.value.length;
		} 
}		

