//Javascript Trim Function
//Developed by Noothan Krishnan

//Usage:str=trim(value); 
//This will trim the left and right side space and return the string.

function trim(txt){                  //javascript trim function 
max=txt.length;                      //total length of the text
strlen=max;
trimmedText="";

cue=0;
while(txt.charCodeAt(cue)==32){     //skip the left side space
cue++;}

for (i=cue;i<max;i++){
trimmedText+=txt.substr(i,1)        //from the Ist char concat to the end of the text to perform ltrim
}

ltrimTxtLen=trimmedText.length;
ltrimTxtLen--;                      //find the lenght of the ltrimmed text     

while(trimmedText.charCodeAt(ltrimTxtLen)==32) {   //skip the right side space - reverse sweep
ltrimTxtLen--;
}

ltrimTxtLen++;
trimmedText=trimmedText.substr(0,ltrimTxtLen);

return (trimmedText);               //return the trimmed text
}

var testresults;

function validEmail(emailValue){
str=emailValue;

if (str.indexOf("@")==-1 || str.indexOf(".")==-1)
testresults=false;
else
testresults=true;

/*
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66}).([a-z]{2,6}(?:[a-z]{2})?)$/i
if (filter.test(str)){
testresults=true;
}
else {
testresults=false;
}
*/
return (testresults);
}

success=true;
function validAlpha(theString,theField) {
success=true;
                        for (i=0;i<theString.length;i++)
                                {
                                        if (!(isNaN(parseInt(theString.substr(i,1)))))
                                        {
                                        validationMsg+="<br>><b>" + theField + "</b> should be alphabetic!";
                                        success=false;
                                        break;
                                        }
                                }
                                return (success);
        }
        

var localMsg="";
function validDate(day,month,year){
localMsg="";
success=true;
cmonths=new Array("","January", "February", "March", "April", "May", "June", "July","August", "September", "October", "November", "December");

if (day=="nil" || month=="nil" || year=="nil"){
localMsg+= "<b>Date </b> Not Entered Properly";
success=false;
return success;
}

if (month==1 ||month==3 || month==5||month==7||month==8||month==10||month==12){
                if (day>31){
                        localMsg+= "The month <b>" + cmonths[month]  + "</b> contains only 31 days!";
                        success=false;
                }

}

else

if (month==4 ||month==6 || month==9||month==11){
                if (day>30){
                        localMsg+= "The month <b>" + cmonths[month]  + "</b> contains only 30 days!";
                        success=false;
                }

}
else

if (month==2)
        {
        if (!isleap(year))
        {
                if (day>28)
                {
                localMsg+="<b>February " + year + "</b>  contains only 28 days!";
                success=false;
                }
        }
else
{
        if (day>29){
                        success=false;
                        localMsg+="<b>February " +year + "</b> contains only 29 days!";
                   }

}

}
 return (success);
}

function isleap(yy){
res=false;
if (yy%4==0 && yy%100!=0 || yy%400==0)
res=true;
return res;
}

function inColor(obj,theColor){
obj.style.backgroundColor=theColor;
}

function outColor(obj,theColor){
obj.style.backgroundColor=theColor;
}

function inColorLink(obj,theColor){
obj.style.color=theColor;
}

function outColorLink(obj,theColor){
obj.style.color=theColor;
}

function domainCopy(obj){
dotPos=obj.value.indexOf(".")+1;
document.getElementById("coemail").value="@"+obj.value.substr(dotPos);
}

function validCheck(){
theFeedback=document.getElementById("feedback").value;
if ((theFeedback.indexOf("http")!=-1)||(theFeedback.indexOf("www")!=-1)||(theFeedback.indexOf("//")!=-1) || (theFeedback.indexOf("url")!=-1)){
location.href="about:blank";
return (false);
}
else {
return (true);
}

}

