//This function validates float
// This function is written on 18/10/2004 
// by- Vinod V Patil
function isValidFloat(field) 
{
	var valid="0123456789."

		for (var i=0; i<field.value.length; i++) {
			if (valid.indexOf(field.value.charAt(i)) < 0)
			 {
				return false
			}
		}
		return true
}
//End of fnValidTelephoneNumber
//This function validates Integer
// This function is written on 18/10/2004 
// by- Vinod V Patil
function isValidInteger(field) 
{
	var valid="0123456789"

		for (var i=0; i<field.value.length; i++) {
			if (valid.indexOf(field.value.charAt(i)) < 0)
			 {
				return false
			}
		}
		return true
}//End of fnValidTelephoneNumber
//This function checks Email ID
// This function is written on 04/10/2004 Monday
// by-Vinod V Patil
function isValidEmail(fieldValue)
{
     var strEmail = fieldValue;
     var bolValid = true;
     if( strEmail.length < 7)
     {
          bolValid = false;
     }
     if(strEmail.lastIndexOf(" ") >0)
     {
          bolValid = false;
     }
     var intLastDot = strEmail.lastIndexOf(".")
     if(intLastDot == -1 ||  strEmail.length - intLastDot >4)
     {
          bolValid = false;
     }
     var intAt = strEmail.lastIndexOf("@")
     if(intAt == -1 ||  strEmail.length - intAt < 5)
     {
          bolValid = false;
     }
     if(!bolValid)
     {
          alert("Please enter a valid email address !");
     }
     return bolValid;
}//end-->

function isValidDate(day,month,year)
{
	var msg="Only integer values and / is allowed in date field in MM/DD/YYYY format"
	var numberexp=/[^0-9]/
	if(numberexp.test(day) || numberexp.test(month) || numberexp.test(year))
	{
		alert(msg)
		return false
	}

	if(day < 1 || day >31    )
	{
		alert("Invalid day! Please enter valid date in MM/DD/YYYY format")
		return false
	}
	if( month < 1 || month >12 )
	{
		alert("Invalid month! Please enter valid date in MM/DD/YYYY format")
		return false
	}
	if( year  < 1 || year.length!=4)
	{
		alert("Invalid year! Please enter valid date in MM/DD/YYYY format")
		return false
	}

	return true
}

//This function validates whether the TextBox is Empty
// This function is written on 04/10/2004 
// by- Vinod V Patil
function isTextBoxNull(field,msg)
{
	if(field.value.length==0)
	{
		alert(msg);
		return false;
	}
	return true;
}//End of isTextBoxNull


//This function validates the Employee Name
// This function is written on 04/10/2004  
// by- Vinod V Patil

function isValidAlphabet(field,msg)
{   
	field.value=field.value.replace(/\s/g,'')
	var Alphabetexp=/[^a-z]/i
	if(Alphabetexp.test(field.value))
	{    
		alert(msg)
		return false
	}
	return true
}//End of fnValidAlphabet



//This function validates the Employee Name
// This function is written on 04/10/2004  
// by- Vinod V Patil
function isValidAlphaNumerics(field)
{
	var wordexp=/[^a-z0-9]/i 
	if(wordexp.test(field.value))
	{
		return false
	}
	return true

}//End of fnValidAlphaNumerics



//This function validates the combo box
// This function is written on 04/10/2004 
// by- Vinod V Patil

function isValidCombo(field,msg)
{
	if(field.value=="")
	{
	 	alert(msg)
		return false
	}
	return true
}//end of fnValidCombo



//This function validates the UserID
// This function is written on 04/10/2004 
// by- Vinod V Patil

function fnValidUserID(field) 
{
	var valid="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"

		for (var i=0; i<field.value.length; i++) {
			if (valid.indexOf(field.value.charAt(i)) < 0) {
				return false
			}
		}
		return true
} //End of fnValidUserID



//This function validates the Telephone Numbers
// This function is written on 04/10/2004 
// by- Vinod V Patil
function isValidTelephoneNumber(field) 
{
	var valid=" 0123456789-/+"

		for (var i=0; i<field.value.length; i++) {
			if (valid.indexOf(field.value.charAt(i)) < 0)
			 {
				 alert("Enter Valid Telephone Number.");
				return false
			}
		}
		return true
}//End of fnValidTelephoneNumber


function TrimField(field)
{
	field.value=field.value.replace(/\r\n/g,' ')	
	while(field.value.charAt(0)==' ')
	{
		field.value= field.value.substring(1)
	}
	while(field.value.charAt(field.value.length-1) == ' ')
	{
		field.value = field.value.substring(0, (field.value.length-1))
	}
}




// Checks if time is in HHH:MM:SS format.
// The seconds and AM/PM are optional.
// This function is written on 25/7/2004 sunday
// by-Vinod V Patil


function IsValidTime(hour,minute,second) 
{
	
	if (hour < 0  || hour > 837) 
	{
		alert("Hour must be between 0 and 838");
		return false;
	}
	
	if (minute < 0 || minute > 59) 
	{
		alert ("Minute must be between 0 and 59.");
		return false;
	}

	if (second < 0 || second > 59) 
	{
		alert ("Second must be between 0 and 59.");
		return false;
	}
	return true;
}
//  End -->



function fnTrimText(field)
{
	field.value=field.value.replace(/\r\n/g,' ')	
	while(field.value.charAt(0)==' ')
	{
		field.value= field.value.substring(1)
	}
	while(field.value.charAt(field.value.length-1) == ' ')
	{
		field.value = field.value.substring(0, (field.value.length-1))
	}
}

function fnValidTextArea(field, name, maxlength)
{
	if(field.value.length > maxlength)
	{	
		alert("Contents in " + name + "should not exceed " + maxlength +" characters")
		field.focus()
		return false
	}
	else
		return true
}

function fnValidInteger(field, msg)
{  
	field.value=field.value.replace(/\s/g,'')	
	var numberexp=/[^0-9]/
	if(numberexp.test(field.value))
	{
		alert(msg)
		field.focus()
		return false
	}
	if(parseInt(field.value, 10)<=0 )
	{
		alert("only zeros are not allowed")
		field.focus()
		return false
	}
	return true
}
function RoundDecimal(fieldval, n)
{
	if (n<0) return;
	temp=1;
	for(i=0;i<n;i++)
	temp*=10;
	var fieldval=parseFloat(fieldval, 10)
	fieldval = (Math.round(fieldval*temp)) / temp;
	fieldval = (fieldval==Math.floor(fieldval))?fieldval.toString()+".00":fieldval.toString();

	return fieldval;
}

function fnValidDecimal(field, maxvalue, msg)
{
	field.value=field.value.replace(/\s/g,'')
	var deciexp=/^([0-9]*)(\.[0-9]*)?$/
	if(field.value.length!=0)
	{
		if(field.value=='.')
		{
			alert("Only decimal point is not a valid entry")
			field.focus()
			return false
		}
		if(!(deciexp.test(field.value)))
		{
			alert("Only numbers and one decimal point is allowed")
			field.focus()
			return false
		}
		if(field.value.indexOf(".")!=-1)
			field.value=RoundDecimal(field.value, 2)
		if(parseFloat(field.value, 10)<=0.00 || parseFloat(field.value, 10)>=parseInt(maxvalue, 10) )
		{
			alert(msg)
			field.focus()
			return false
		}
	}
	return true
}


// allow ONLY alphanumeric keys, no symbols or punctuation

function fnValidAlphaNumeric(field, msg)
{
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
	var checkStr = field.Alias.value
	var allValid = true
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break
			if (j == checkOK.length)
			{
				allValid = false
				break
			}
	}
	if (!allValid)
	{
		alert(msg)
		field.Alias.focus()
		return (false)
	}
}


function fnToDate(field, serverdate)
{
	field.value=serverdate
}


function fnValidDateNoMsg(field)
{
	field.value=field.value.replace(/\s/g,'')
	var idDay=field.value.indexOf('/')
	var day=field.value.substr(0, idDay)
	var strTemp=field.value.substr(idDay+1)
	var idMonth=strTemp.indexOf('/')
	var month=strTemp.substr(0, idMonth)
	var year=strTemp.substr(idMonth+1, 4)
	var numberexp=/[^0-9]/
	if(numberexp.test(day) || numberexp.test(month) || numberexp.test(year))
	{
		return false
	}

	if(day < 1 || day >31   )
	{
		return false
	}
	if( month < 1 || month >12   )
	{
		return false
	}
	if( year  < 1 || year.length!=4)
	{
		return false
	}
	return true
}

function fnValidIntegerNoMsg(field)
{  
	field.value=field.value.replace(/\s/g,'')	
	var numberexp=/[^0-9]/
	if(numberexp.test(field.value))
	{
		return false
	}
	if(parseInt(field.value, 10)<=0 )
	{
		return false
	}
	return true
}

function fnValidDecimalNoMsg(field, maxvalue)
{
	field.value=field.value.replace(/\s/g,'')
	var deciexp=/^([0-9]*)(\.[0-9]*)?$/
	if(field.value.length!=0)
	{
		if(field.value=='.')
		{
			return false
		}
		if(!(deciexp.test(field.value)))
		{
			return false
		}
		if(field.value.indexOf(".")!=-1)
			field.value=RoundDecimal(field.value, 2)
		if(parseFloat(field.value, 10)<=0.00 || parseFloat(field.value, 10)>=parseInt(maxvalue, 10) )
		{
			return false
		}
	}
	return true
}

function fnTimeCheck(Fld)
{
	var a=Fld.value;
	var reg=/^([0-9]{2,2})[:]([0-9]{2,2})$/
	if(!reg.test(a))
	{
		alert("The time should be entered in HH:MM format");
		return false;
	}
	var x=parseInt(a.substr(0,a.indexOf(":")),10);
	var y=parseInt(a.substr(a.indexOf(":")+1),10);
	if(x >12 || x<0)
	{
		alert("Invalid Hour is Entered.Please Check");
		return false;
	}
	else if(y<0 || y>59)
	{
		alert("Invalid Minute is Entered.Please Check");
		return false;
	}
	return true;
}

function trim(s) {

  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

 function day(dt){
   return dt.substring(dt.indexOf('/')+1 , dt.lastIndexOf('/'));
   }
   
   function month(dt){
   return dt.substring(0 , dt.indexOf('/'));
   }
      
	function year(dt){
	return dt.substring(dt.lastIndexOf('/')+1,dt.length);
	}

function isValidMultipleIds(emails)
{	
	var mail=""
    emails= emails.substring(0,emails.length-1);
	 
     if( emails.indexOf(',')>=0)
	{ 
	    emails=emails+",";
		for(i=0;i<emails.length;i++)
		{ 
		   	if(emails.substring(i,i+1)!=",")
	    	  	mail=mail+emails.substring(i,i+1);
		  	else
			{
				  if(!isValidEmail(mail)) 
				  {
	//				document.NewServiceAds.Email.focus();
		      		 return false;
     			  }
			 		mail="";
		  	}
		
		}
	}
	else
	{
		  if(!isValidEmail(emails)) {
		//	document.NewServiceAds.Email.focus();
		   		 return false;
     	 }
	 }
	
	return true;
	}

	
	
// Checks single mailid
// The seconds and AM/PM are optional.
// This function is written on 25/7/2004 sunday
// by-Parameshwara	
	
	function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Please Enter the Email Id/ User Id")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//AdsStation – Designing communication that works. Communication that works is intuitive, stimulating and connects with target audience
/**************************************************************/
function scrollingStatus(seed)
{
  var m1  = "Designing communication that works.";
  var m2  = "";
  var m3  = " Communication that works is intuitive,";
  var m4  = " stimulating and connects with target audience   ";
  var msg=m1+m2+m3+m2+m4;
  var out = "AdsStation – ";
  var c   = 1;
  if (seed > 100) {
    seed--;
    var cmd="scrollingStatus(" + seed + ")";
    timerTwo=window.setTimeout(cmd,100);
  }
  else if (seed <= 100 && seed > 0) {
    for (c=0 ; c < seed ; c++) {
      out+=" ";
    }
    out+=msg;
    seed--;
    var cmd="scrollingStatus(" + seed + ")";
    window.status=out;
    timerTwo=window.setTimeout(cmd,100);
  }
  else if (seed <= 0) {
    if (-seed < msg.length) {
      out+=msg.substring(-seed,msg.length);
      seed--;
      var cmd="scrollingStatus(" + seed + ")";
      window.status=out;
      timerTwo=window.setTimeout(cmd,100);
    }
    else {
      window.status=" ";
      timerTwo=window.setTimeout("scrollingStatus(100)",75);
    }
  }
}
/*******************************************************/

/****************************************************/
function myWindowOpen(url)
{
	var horPos = (screen.width-610);
	var verPos = 0;
	var features = "width=601,height=451,left="+ horPos +",top="+ verPos +",screenX="+ horPos +",screenY="+ verPos+",z-lock=off";
	var windowHandle = window.open(url,'AdsStation',features);
	var ua = navigator.userAgent;
	var netScapeFlag = (ua.indexOf('Netscape/7') != -1) || (ua.indexOf('Netscape/7.1') != -1);
	if(ua.indexOf('Gecko') != -1 && !netScapeFlag)
	{
		windowHandle.moveTo((screen.width-610),0);
		windowHandle.focus();
	}
	else
	{
		windowHandle.moveTo((screen.width-610),0);
		windowHandle.focus();
	}
}
/****************************************************/

var currecntselectedlinkelem="";
function changelinkelem(elem)
{
	if(currecntselectedlinkelem)currecntselectedlinkelem.style.color="#047716";
	elem.style.color="#2eb135";
	currecntselectedlinkelem=elem;
}


/****************************************************/
function searchsite()
{
	window.location.href='http://www.adsstation.biz/html/sitesearch.htm?srchkey='+document.getElementById('searchString').value;
}
