function ValidateForm(form)
{
	var x = form.elements;
	for (var i=0;i<x.length;i++)
	{
		EleObj=x[i].id;
		LastIndex = EleObj.substring(EleObj.length-2,EleObj.length)
		switch(LastIndex)
		{
			case "_R":
				if(ValidateForm_Required(x[i],x[i].title)==false)
					return false;
			break;
			case "_P":
				if(ValidateForm_Password(x[i],x[i].title,4)==false)
					return false;
			break;
			case "_V":
				if(ValidateForm_Password(x[i],x[i].title,16)==false)
					return false;
			break;
			case "_E":
				if(ValidateForm_Email(x[i],x[i].title)==false)
					return false;
			break;
			case "_C":
				if(ValidateForm_Confirm(x[i-1],x[i],x[i].title)==false)
					return false;
			break;
			case "_I":
				if(ValidateForm_Required(x[i],x[i].title)==false)
					return false;
				if(ValidateForm_Numeric(x[i],'0123456789',x[i].title)==false)
					return false;
			break;
			case "_N":
				if(ValidateForm_Numeric(x[i],'0123456789',x[i].title)==false)
					return false;
			break;
			case "_A":
			FieldArray = form.elements[x[i].name];
			if(ValidateForm_CheckArray(x[i],FieldArray,x[i].title)==false)			
				return false;
			break;
		}		
	}
return true;
}
function ValidateForm_Required(Ctrl,msg)
{
	ElementType = Ctrl.type;
	ElementTypeString = ElementType.toUpperCase();
	switch(ElementTypeString)
	{
		case "CHECKBOX":
			if(Ctrl.checked == false)
			{
				alert(msg);
				Ctrl.focus();
				return false;
			}
		break;
		default :
			if(trimString(Ctrl.value) == "")
			{
				alert(msg);
				Ctrl.focus();
				return false;
			}
		break;		
		
	}
	return true;
}

function ValidateForm_Password(Ctrl,msg,Minlen)
{
	var charpos = Ctrl.value.search("[^A-Za-z*0-9]"); 
	if(trimString(Ctrl.value).length < Minlen ||  charpos >= 0) 
      { 
      	alert(msg);
		Ctrl.focus();
		return false;
      } 
		
	return true;
}
function ValidateForm_CheckArray(Ctrl,FieldArray,msg)
{
	MyCheck = true;
	for (var j=0;j<FieldArray.length;j++)
	{
		if(FieldArray[j].checked)
			MyCheck = false;
		
	}
	if(MyCheck)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}	
	return true;
}
function ValidateForm_Checked(Ctrl,msg)
{
	if(Ctrl.checked == false)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}
	return true;
}
function ValidateForm_Numeric(Ctrl,valid_chars,msg)
{
	if(chkNumericValidate(Ctrl.value,valid_chars) == false)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}
	return true;
}
function chkNumericValidate(strString,strValidChars)
{
   var strChar;
   var blnResult = true; 
  	for (i = 0; i < strString.length && blnResult == true; i++)
   {
	  strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
    	   blnResult = false;
      }
   }
   return blnResult;
}
function ValidateForm_Email(Ctrl,msg)
{
	if(chkEmailValidate(Ctrl.value) == false)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}
	return true;
}

function ValidateForm_Confirm(Ctrl1,Ctrl2,msg)
{
	if(Ctrl1.value != Ctrl2.value)
	{
		alert(msg);
		Ctrl2.focus();
		return false;
	}
	return true;
}

function chkEmailValidate(str)
{
	return(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str));
}
function trimString (str)
{
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
 function getObject(nameStr) 
 {
    var ie  = (document.all);
    var ns4 = document.layers? true : false;
    var dom = document.getElementById && !document.all ? true : false;

    if (dom) {
        return document.getElementById(nameStr);
    } else if (ie) {
        return document.all[nameStr];
    } else if (ns4) {
        return document.layers[nameStr];
    }
}
function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) 
{
  var countedTextBox = opt_countedTextBox ?
    opt_countedTextBox : "countedTextBox";
  var countBody = opt_countBody ? opt_countBody : "countBody";
  var maxSize = opt_maxSize ? opt_maxSize : 1024;
    
  var field = document.getElementById(countedTextBox);
  if (field && field.value.length >= maxSize) 
  {
    field.value = field.value.substring(0, maxSize);
  }
  var txtField = document.getElementById(countBody);
  if (txtField) 
  {  
    txtField.innerHTML = field.value.length;
  }
}
function AddressSame(Obj)
{
	if(Obj.checked==true)
	{
		
		//alert(document.getElementById('sfaddress_R').value);
		//alert("value of s="+document.getElementById('sfaddress_R').value);
		
		
		document.getElementById('sfname_R').value = document.getElementById('bfname_R').value;
		document.getElementById('slname_R').value = document.getElementById('blname_R').value;
		document.getElementById('sfaddress_R').value = document.getElementById('bfaddress_R').value;
		document.getElementById('ssaddress_R').value = document.getElementById('bsaddress_R').value;
		document.getElementById('scity_R').value = document.getElementById('city_R').value;
		document.getElementById('spincode_R').value = document.getElementById('pincode_R').value;
		document.getElementById('scountry').value = document.getElementById('country').value;		
		document.getElementById('sphone_R').value = document.getElementById('phone_R').value;		
		document.getElementById('shipfax_R').value = document.getElementById('fax_R').value;		
		document.getElementById('shipemail_R').value = document.getElementById('email_R').value;		
		
	}
	
}
// Set the horizontal and vertical position for the popup
		
		PositionX = 20;
		PositionY = 20;
		
		// Set these value approximately 20 pixels greater than the
		// size of the largest image to be used (needed for Netscape)
		
		defaultWidth  = 500;
		defaultHeight = 500;
		
		// Set autoclose true to have the window close automatically
		// Set autoclose false to allow multiple popup windows
		
		var AutoClose = true;
		
		// Do not edit below this line...
		// ================================
		if (parseInt(navigator.appVersion.charAt(0))>=4){
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
		var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
		var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
		function popImage(imageURL,imageTitle)
		{
					if (isNN){imgWin=window.open('about:blank','',optNN);}
					if (isIE){imgWin=window.open('about:blank','',optIE);}
					with (imgWin.document){
					writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
					writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
					writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
					writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
					writeln('width=250-(document.body.clientWidth-document.images[0].width);');
					writeln('height=100-(document.body.clientHeight-document.images[0].height);');
					writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
					writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
					writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
					if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
					else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
					writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
					close();		
					}
		}
function mypopup(url,wwidth,wheight,iid)
 {
   mywindow = window.open (url,"mywindow","location=1,status=1,scrollbars=1,menubar=0,resizable=0,width="+wwidth+",height="+wheight+"");
   
   mywindow.moveTo(0,0);
   
 //  width=document.getElementById(iid).width;
 //  height=document.getElementById(iid).height;
   
   //window.resizeTo(width,height)
	  return false;
 } 
 function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}





