//
//Changes Email function as On 20/12/2009 by tanuj
//Changes valid Mobile function as On 20/12/2009 by tanuj
function NewWindow(mypage,myname,w,h,scroll, resize)
{
  var win = null;
  LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
  TopPosition = (screen.height) ? (screen.availHeight-h)/2 - 2 : 0;
  settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
  //settings = settings + 'fullscreen=yes,toolbar=no,location=no,directories=no,status=no,menubar=no';
  if (resize == 'yes') settings += ',resizable';
  win = window.open(mypage,myname,settings);
  
}

function CenteredWindow(mypage,myname,w,h,scroll, resize)
{
  var win = null;
  var ScreenWidth = 980;
  LeftPosition = (ScreenWidth) ? (ScreenWidth-w)/2 : 0;
  TopPosition = (screen.height) ? (screen.availHeight-h)/2 - 2 : 0;
  settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
  //settings = settings + 'fullscreen=yes,toolbar=no,location=no,directories=no,status=no,menubar=no';
  if (resize == 'yes') settings += ',resizable';
  win = window.open(mypage,myname,settings);
}

function CenteredWindowWithQueryString(mypage,mystring,myname,w,h,scroll, resize)
{
  var win = null;
  var ScreenWidth = 980;
  var queryString;
  LeftPosition = (ScreenWidth) ? (ScreenWidth-w)/2 : 0;
  TopPosition = (screen.height) ? (screen.availHeight-h)/2 - 2 : 0;
  settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
  //settings = settings + 'fullscreen=yes,toolbar=no,location=no,directories=no,status=no,menubar=no';
  if (resize == 'yes') settings += ',resizable';
  //alert("Page " + mypage);
  //alert("String " + mystring);
  //alert("Encode " + escape(mystring));
  //alert("Encode URi " + encodeURI(escape((mystring))));
  mypage = mypage + encodeURI(escape((mystring)));
  //alert(mypage);
  
  win = window.open(mypage,myname,settings);
}

//For Form, textboxes
function setControlDefaultButton(pstrDefaultButton)
{
if(event.which || event.keyCode)
  if ((event.which == 13) || (event.keyCode == 13)) 
  {
    if (pstrDefaultButton.length > 0) document.getElementById(pstrDefaultButton).click();
    return false;
  }
  return true;
}

function getValue(pstr)
{
  return document.getElementById(pstr).value;
}

function setValue(pstr, value)
{
  document.getElementById(pstr).value = value;
}

function setFocusAndSelect(pstr)
{
  var obj=document.getElementById(pstr);
  if (obj != null)
  {
    obj.focus();
    obj.select();
    
  }
}

function initialFocus(pstr)
{
  document.getElementById(pstr).focus();
}

function upperCase(pstrFieldName)
{
var str=document.getElementById(pstrFieldName).value;
document.getElementById(pstrFieldName).value=str.toUpperCase();
}

function emailold(pstrFieldName, pstrMessage) {
var email = document.getElementById(pstrFieldName);
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert(pstrMessage);
email.focus;
return false;
}
return true;
}

function email(pstrFieldName, pstrMessage) {
var email = document.getElementById(pstrFieldName);
var intIndex = -1;

intIndex = email.value.indexOf("..");
if (intIndex != -1) {
    alert("Two consecutive dots are not allowed.");
    email.focus();
	email.select();      
	return false;
}
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert(pstrMessage);
email.focus;
return false;
}
return true;
}



function selectedOptionButton(strRadioButton)
{
  var obj;
  obj=document.getElementById(strRadioButton); 
  for (var i=0;i < obj.length; i++) {
    if (obj.item(i).checked) {
      return obj.item(i).value;
    }
  }
  return ' ';
}

function selectedOptionButtonByGroupName(strRadioButtonGroupName)
{
  var objSelected = document.getElementsByName(strRadioButtonGroupName); 
  for (x = 0; x < objSelected.length; x++)
  { 
    if (objSelected[x].checked) {
      return objSelected[x].value; 
    }
  }
  return ' ';
}


function IsValidPassword(strFieldName, Message)
{
  var obj;
  strValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$^()-_+=?/|\<>[]{}";
  obj = document.getElementById(strFieldName);
  
  if (obj == null) return true;
  
  ReturnString = removeSpaces(obj.value);
  obj.value = ReturnString;
  
  str = obj.value;
  strInputWithUcase = str;
  
  if(ReturnString.length == 0)
    {
      alert(Message + ".");
      obj.focus();
      obj.select();      
      return false;
    }  

   //   checking for minlen
  
  if(ReturnString.length < 6)
    {
      alert(Message + " correctly. \n\n(Characters can not be less than 6)");
      obj.focus();
      obj.select();      
      return false;
    }  
      
               //   checking for maxlen
  if(obj.value.length > 15)
    {
      alert(Message + " correctly. \n\n(Characters can not be more than 15. Currently " + obj.value.length + " entered)");
      obj.focus();
      obj.select();      
      return false;
    }
 
              //  checking for invalid characters 

 for (i = 0; i < obj.value.length; i++) 
  {           // Searching through string

     var c = strInputWithUcase.charAt(i);
     if (strInputWithUcase.charCodeAt(i) != 13 && strInputWithUcase.charCodeAt(i) != 10) 
     {
       if (strValidChars.indexOf(c) == -1)
       {
          alert(Message + " correctly (Invalid Character: " + c + ").");
          obj.focus();
          obj.select();      
          return false;
        }  
      }
  }
  
  return true;  
}


function IsValidEntry(strFieldName, intMinLen, intMaxLen, strValidChars, blnCaseSensitive, Message)
{
  var obj;
  obj = document.getElementById(strFieldName);
  
  if (obj == null) return true;
  
  ReturnString = removeSpaces(obj.value);
  obj.value = ReturnString;
  
  str = obj.value;
  if (blnCaseSensitive) 
  {
     strInputWithUcase = str;
  }
  else
  {
     strInputWithUcase = str.toUpperCase();
  }
  
  if(ReturnString.length == 0 && intMinLen != 0)
    {
      alert(Message + ".");
      obj.focus();
      obj.select();      
      return false;
    }  

   //   checking for minlen
  if(ReturnString.length < intMinLen)
    {
      alert(Message + " correctly. \n\n(Characters can not be less than " + intMinLen + ")");
      obj.focus();
      obj.select();      
      return false;
    }  
      
               //   checking for maxlen
  if(obj.value.length > intMaxLen)
    {
      alert(Message + " correctly. \n\n(Characters can not be more than " + intMaxLen + ".  Currently " + obj.value.length + " entered)");
      obj.focus();
      obj.select();      
      return false;
    }
    
              // if ValidChars is Empty string than any input can be taken  
  if(strValidChars.length == 0) 
    {
      
      return true;
    }
   //alert(strFieldName + " " + strValidChars.length + " " + strValidChars);

              //  checking for unvalid characters 
 for (i = 0; i < obj.value.length; i++) 
  {           // Searching through string

     var c = strInputWithUcase.charAt(i);
     if (strInputWithUcase.charCodeAt(i) != 13 && strInputWithUcase.charCodeAt(i) != 10) 
     {
       if (strValidChars.indexOf(c) == -1)
       {
          alert(Message + " correctly (Invalid Character: " + c + ").");
          obj.focus();
          obj.select();      
          return false;
        }  
      }
  }
  return true;  
}

  // fn is required with IsValidEntry
function removeSpaces(string) 
{
  var temp;
  temp = string;
  while (!(temp.indexOf('  ') == -1))
  {
    temp = temp.replace('  ',' ');
  }
  
  if (temp.charAt(0)  == ' ')
   {
    temp = temp.substring(1, temp.length);
   }
  
  if (temp.charAt(temp.length - 1)  == ' ')
   {
    temp = temp.substring(0, temp.length - 1);
   }
  return temp;
}

function validMobile(pstrFieldName)
 {
   var character;
   character=document.getElementById(pstrFieldName).value;
   if (character.charAt(0) != "9" && character.charAt(0) != "8")
    {
      alert("Mobile # first character must be 8 or 9");
      document.getElementById(pstrFieldName).select();
      document.getElementById(pstrFieldName).focus();
      return false;
    }   
 
  return true; 
}



function initialFocus(pstr)
{
//  document.form1.item(pstr).focus();
  document.getElementById(pstr).focus();
}

function Trim (pstr)
{
return pstr.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function getURLParameters() 
{
	var sURL = window.document.URL.toString();
	
	if (sURL.indexOf("?") > 0)
	{
		var arrParams = sURL.split("?");
			
		var arrURLParams = arrParams[1].split("&");
		
		var arrParamNames = new Array(arrURLParams.length);
		var arrParamValues = new Array(arrURLParams.length);
		
		var i = 0;
		for (i=0;i<arrURLParams.length;i++)
		{
			var sParam =  arrURLParams[i].split("=");
			arrParamNames[i] = sParam[0];
			if (sParam[1] != "")
				arrParamValues[i] = unescape(sParam[1]);
			else
				arrParamValues[i] = "No Value";
		}
		
		for (i=0;i<arrURLParams.length;i++)
		{
			alert(arrParamNames[i]+" = "+ arrParamValues[i]);
		}
	}
	else
	{
		alert("No parameters.");
	}
}


function GetParamterValue ( ParameterName )
{
var url = window.document.URL.toString();
if ( url.indexOf ("?") > 0 )
{
var Parameters = url.split ("?") [ 1 ].split ("&");
for ( i = 0; i < Parameters.length; i++ )
{
if ( Parameters [ i ].indexOf ("=") > 0 )
{
var ParameterValue = Parameters [ i ].split ("=");
if ( ParameterValue [ 0 ] == ParameterName )
return ParameterValue [ 1 ];
}
}
}
return "";
}








