// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// email
function IsNumeric(sText)
{
   var ValidChars = "0123456789-";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         	IsNumber = false;
         }
      }
   return IsNumber;

}


function WindowPopup(url, width_in, height_in)
	{//alert(url);
		new_window = window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,top=50,left=100,scrollbars=yes,width=' + width_in + ',height=' + height_in);		
		new_window.focus();
	}

function action_new(option,id,frmname)
{
  //alert(option)
	if(option=='delete' || option=='draft_delete')
	{
		if(confirm('Are you sure to delete the record?'))
		{
			document.search.option.value=option;
			document.search.appid.value=id;
			document.search.submit();
		}
	}
	else if(option=='edit' || option=='draft_edit' || option=='reply_postages'|| option == 'view_issues')
	{

		document.search.option.value=option;
		document.search.appid.value=id;
		document.search.submit();
	}
}




function checkEmail (strng) {
var error="";
//alert(strng);
if (strng == "") {
   error = "You didn't enter an email address.\n";
}
else
	{
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) {
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
	}
return error;
}




// phone number - strip out delimiters and check for 10 digits

function CheckPhoneNumber(PhoneNo,TagStr){

	// get rid of non-numerics
	var checkOK = new String("0123456789");
	var strNo = new String(PhoneNo.value);

	var checkStr = PhoneNo.value;
	var allValid = "y";
	var decPoints = 0;
	var ch="";
	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 = "N";
			break;
		}
	}
	if (allValid=="N")
	{
		alert("Please enter only digits in [ \"" + TagStr + " ]\".");
		PhoneNo.focus();
		return ("N");
	}

	if ( checkStr.length == 12 )
	{
		if ( checkStr.charAt(0) < '2' )
		{
			alert("The first digit of the area code in [ \"" + TagStr + " ]\" cannot be a '1' or '0'");
			PhoneNo.focus();
			return ("N");
		}

		if ( checkStr.charAt(3) < '2' )
		{
			alert("The first digit of the prefix in [ \"" + TagStr + " ]\" cannot be a '1' or '0'");
			PhoneNo.focus();
			return ("N");
		}

		if ( checkStr.substring(0,3) == "900" )
		{
			alert("The area code in [ \"" + TagStr + " ]\" cannot be '900'");
			PhoneNo.focus();
			return ("N");
		}
	}


	else
		return ("Y");


}

//min number of calls

function CheckNumber(number1,TagStr1)
{

	var checkStr1 = number1.value;
	var checkOK1 = new String("0123456789");
	var allValid1 = "Y";
	var decPoints1 = 0;
	var ch="";
	for (i = 0;  i < checkStr1.length;  i++)
	{
		ch1 = checkStr1.charAt(i);
		for (j = 0;  j < checkOK1.length;  j++)
		if (ch1 == checkOK1.charAt(j))
		break;
		if (j == checkOK1.length)
		{
			allValid1 = "N";
			break;
		}
	}
	if (allValid1=="N")
	{
		alert("Please enter only digits in [ \"" + TagStr1 + " ]\".");
		number1.focus();
		return ("N");
	}
	else
		return ("Y");


}


// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers

    if ((strng.length < 6) || (strng.length > 8)) {
       error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    }
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }
return error;
}


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a username.\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 1)) {
       error = "The username is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    }
return error;
}


// non-empty textbox

/*function isEmpty(strng)
{
var error = "";
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in.\n"
  }
return error;
} */

function isEmpty(fname)
	{
		invalid = " ";

		flag = 1;
		for(ttt=0;ttt<fname.value.length;ttt++)
		{
			if(fname.value.charAt(ttt)!=invalid)
			{
				//alert('sdf');
				break;
			}
		}
		if(ttt==fname.value.length) flag = 0;
		if(flag==0) return true;
		if((fname.value=="") ||(fname.value==invalid))
			return true;
		else
			return false;
	}

// was textbox altered

function isDifferent(strng) {
var error = "";
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }
return error;
}


//function to count the characters

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}

//function checkSpace not allow spaces

function checkSpace(obj)
{
	var val=obj.keyCode?obj.keyCode:obj.charCode;
	//alert(val);
	if(val==32)
		return false;
	else 
		return true;
}

//for Online Portfolio 
	function redirect()
	{
		var width=window.screen.width;
		var height=window.screen.height-75;		
		//var userName='<?=$_SESSION[username]?>';
		//var password='<?=$_SESSION[password]?>';		
		
		var uname='';
		var pwd='';
		for(var i=0; i<userName.length; i++ )
		{
			uname+=userName.charCodeAt(i)+'~';
		}
		for(var j=0; j<password.length; j++ )
		{
			pwd+=password.charCodeAt(j)+'~';
		}
		url="http://investwell.in:8080/jsp/beforeLogin.jsp?who=c&lgn="+uname+"&pswd="+pwd+"&brokerId=10059";
		
		var win=window.open('',"investwell","toolbar=no,top=0,left=,width="+width+",height="+height+"location=no,status=0,menubar=no,scrollbars=yes,resizable=yes");
		win.status="";
		win.location=url;			
	}
	
	//for Online Portfolio 
	function redirect1(userName,password)
	{
		var width=window.screen.width;
		var height=window.screen.height-75;
		var uname='';
		var pwd='';	
		for(var i=0; i<userName.length; i++ )
		{
			uname+=userName.charCodeAt(i)+'~';
		}
		for(var j=0; j<password.length; j++ )
		{
			pwd+=password.charCodeAt(j)+'~';
		}
		url="http://investwell.in/jsp/beforeLogin.jsp?who=c&lgn="+uname+"&pswd="+pwd+"&brokerId=10059";
		var win=window.open('',"investwell","toolbar=no,top=0,left=,width="+width+",height="+height+"location=no,status=0,menubar=no,scrollbars=yes,resizable=yes");
		win.status="";
		win.location=url;			
	}
	
	
	
	//for removing spaces
function trim(str)
{
    if(!str || typeof str != 'string')
        return "";
    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function WindowPopupImage(url) 
	{
		new_window = window.open(url,'imgwin','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,top=50,left=100,scrolling=yes');    		
		new_window.focus();
	}

