//created by pradip ku dash on 24-oct-08
function rLblank(obj,val)
{
	if(val == 1)
	{
  		if(obj.id == 'vEmail'){
        if(obj.value != ''){
          if(obj.value=='Email'){
    		  obj.value='';
          }else if(obj.value !='Email'){
            obj.value=obj.value;
          }
        }else{
          obj.value ='Email';
        }
        
      }else if(obj.id == 'vPassword'){
        if(obj.value != ''){
          if(obj.value=='Password'){
      		  obj.value='';
          }else if(obj.value !='Password'){
            obj.value=obj.value;
          }
        }else{
          obj.value ='Password';
        } 
      }
  }
	//oldObject = document.getElementById('vPassword');
  //changeInputType1(oldObject);
}
function checkemail(obj)
{
  if(obj.id == 'vEmail')
  {
    obj.value ='Email';
  }else if(obj.id == 'vPassword')
  {
    obj.value ='Password';
  }
}
function getFocused(obj,func){
  if(func == '0'){
    changeInputType(obj);
  }else{
    changeInputType1(obj);
  }
} 
function changeInputType(oldObject){
if(oldObject.type == 'text'){
    if(oldObject.value == 'Password' || oldObject.value == ''){
      var newObject = document.createElement('input');
      newObject.type = "password";
      if(oldObject.size) newObject.size = oldObject.size;
      newObject.value = "";
      if(oldObject.name) newObject.name = oldObject.name;
      if(oldObject.id) newObject.id = oldObject.id;
      if(oldObject.className) newObject.className = oldObject.className;
      newObject.style.width= "147px";
      if(oldObject.tabIndex) newObject.tabIndex = oldObject.tabIndex;
      if(oldObject.onblur) newObject.onblur= oldObject.onblur;
      if(oldObject.onfocus) newObject.onfocus= oldObject.onfocus;
      if(oldObject.onkeypress) newObject.onkeypress= oldObject.onkeypress;
      
      oldObject.parentNode.replaceChild(newObject,oldObject);
    }
  }
    
}
function changeInputType1(oldObject){

  if(oldObject.type != 'text'){
    if(oldObject.value == ''){
      var newObject = document.createElement('input');
      newObject.type = "text";
      if(oldObject.size) newObject.size = oldObject.size;
      newObject.value = "Password";
      if(oldObject.name) newObject.name = oldObject.name;
      if(oldObject.id) newObject.id = oldObject.id;
      if(oldObject.className) newObject.className = oldObject.className;
      newObject.style.width= "147px";
      if(oldObject.tabIndex) newObject.tabIndex = oldObject.tabIndex;
      if(oldObject.onblur) newObject.onblur= oldObject.onblur;
      if(oldObject.onfocus) newObject.onfocus= oldObject.onfocus;
      if(oldObject.onkeypress) newObject.onkeypress= oldObject.onkeypress;
      oldObject.parentNode.replaceChild(newObject,oldObject);
      $('btnLogin').focus();
    }
  }
}
function displayImg(obj){
 var ext= obj.value.split("."); 
 if((ext[1].toLowerCase() != 'jpg') && (ext[1].toLowerCase() != 'gif')){  
    alert("Supported Files Types .jpg and .gif");
    return false;
 }else{
    if(obj.files){
		  var data = obj.files.item(0).getAsDataURL();		   	
	  }else{	
		  var data = obj.value;
	  }	
	  $('imgb').src = data;
 }	
}

function getTabbed(events){
  var unicodes=events.charCode? events.charCode :events.keyCode;
  
  if(unicodes == 9){
    $('btnLogin').focus();
  }  
}
function chkValidPhone(events) 
{
var unicodes=events.charCode? events.charCode :events.keyCode;
//alert(unicodes);
/*return false;*/
	if (unicodes!=8)
	{ //backspace
	        if( (unicodes>47 && unicodes<58) || unicodes == 46 || unicodes == 45 || unicodes == 40 || unicodes == 41 || unicodes == 43 || unicodes == 32 || unicodes == 9 || unicodes == 91 || unicodes == 93)
	            return true;
			else
				return false; 
	}
	
}
//check only digit
function chkDigit(events) 
{
var unicodes=events.charCode? events.charCode :events.keyCode;
	if (unicodes!=8)
	{ //backspace
	        if( (unicodes>47 && unicodes<58 || unicodes == 46 || unicodes == 39 || unicodes == 9))
	            return true;
			else
				return false; 
	}
}

//checked limit of words in a text field
function limitText(limitField,limitNum) 
{
	if (limitField.value.length > limitNum)
     {
		limitField.value = limitField.value.substring(0, limitNum);
		return false;
	}
}

function fillState(control, statcode, val)
{
	
	control.options.length = 0;
	control.options[0] = new Option("---- Select state -----");
	control.options[0].value = "";
	for(i=0,j=1; i<stateArr.length; i++)
	{
		if(stateArr[i][0] == val)
		{
			if(statcode == stateArr[i][3])
			{
				control.options[j] = new Option( stateArr[i][2]);
				control.options[j].value = stateArr[i][3];
				control.options[j].selected = true;
			}
			else
			{
				control.options[j] = new Option( stateArr[i][2]);
				control.options[j].value = stateArr[i][3];
			}				
			j++;
		}
	}	
	control.options[j] = new Option("Other");
	control.options[j].value = "Other";
	if(statcode == "Other")
	{
		control.options[j].selected = true;
		
	}
}

//Added by pradip
function chkValidChar(events) 
{
var unicodes=events.charCode? events.charCode :events.keyCode;
//alert(unicodes);
	if (unicodes!=8)
	{ 
	     if((unicodes > 96 && unicodes < 123) ||(unicodes > 64 && unicodes < 91) || unicodes == 32){
		 	return true; 
		 }else{
			if(events.charCode == 0)
					return true;
				else	
					return false; 
		}			
	}
}
function chkValidPassword(events) 
{
var unicodes=events.charCode? events.charCode :events.keyCode;
//alert(unicodes);
/*return false;*/
	if (unicodes!=8)
	{ //backspace
	        if((unicodes >31 && unicodes<34) || unicodes == 94 || unicodes == 61 || unicodes == 95 ||  unicodes == 96 )
	            return false;
			else
				return true; 
	}
}

function chkCharUser(events) 
{
var unicodes=events.charCode? events.charCode :events.keyCode;
/*return false;*/
	if (unicodes!=8)
	{ //backspace
	        if((unicodes>31 && unicodes<46) || unicodes == 94 || unicodes == 61 || unicodes == 95 || unicodes == 64 || unicodes == 96)
	            return false;
			else
				return true; 
	}
}

//zip code validation
function chkZip(events) 
{
var codes=events.charCode? events.charCode :events.keyCode;

/*return false;*/
	if (codes!=8)
	{ //backspace
	        if( (codes>47 && codes<58) || (codes>64 && codes<91) || (codes>96 && codes<122) )
	            return true;
			else
				return false; 
	}
}
function chkSpace(events)
{
	var unicodes=events.charCode? events.charCode :events.keyCode;
	//alert(unicodes);
	if (unicodes!=8)
	{ //backspace			
	        if(unicodes!=32)
	            return true;
			else{
				if(events.charCode == 0)
					return true;
				else	
					return false; 
			}
	}
}
function noCTRL(e)
{
	var forbiddenKeys = new Array('c','x','v');
	var keyCode = (e.keyCode) ? e.keyCode : e.which;	
	if(e.ctrlKey) {		
		for(i = 0; i < forbiddenKeys.length; i++) {			
			if(forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {			
			return false;
			}
		}
	}
}
//devloped by pradip
function ChkFormat(events,val,type,id)
{	
	//alert(navigator.appName);
	if(navigator.appName == 'Microsoft Internet Explorer'){
		var chkdigit = '3';
	}else{
		var chkdigit = '2';
	}
	var chktype = type;
	var chkid =id;
	var unicodes=events.charCode? events.charCode :events.keyCode;
	//alert(unicodes);
	var firstlength = val.length;
	if(unicodes!=8){ 
		if( (unicodes>47 && unicodes<58 || unicodes == 39 || unicodes == 9 )){
			if(firstlength >= chkdigit && chktype == 'phone'){
				if(unicodes>47 && unicodes<58){
					if(chkid == 'vPhone1'){
						$('vPhone2').focus();
					}
					else if(chkid == 'vPhone2'){
						$('vPhone3').focus();
					}
					else if(chkid == 'vPhone3'){
						
					}
				}
			}else if (firstlength >= chkdigit && chktype == 'mobile'){
				if(unicodes>47 && unicodes<58){
					if(chkid == 'vMobile1'){
						$('vMobile2').focus();
					}
					else if(chkid == 'vMobile2'){
						$('vMobile3').focus();
					}else if(chkid == 'vMobile3'){
						
					}
				}
			}else if (firstlength >= chkdigit && chktype == 'fax'){
				if(unicodes>47 && unicodes<58){
					if(chkid == 'vFax1'){
						$('vFax2').focus();
					}else if(chkid == 'vFax2'){
						$('vFax3').focus();
					}else if(chkid == 'vFax3'){
						
					}
				}
			}
			return true;		
		}else{
			if(events.charCode == 0)
					return true;
			else	
				return false; 
		}
	}
}
function resChkAll(chk,totno){
	for(i=0;i<totno;i++)
	{
		if(chk == true)
		$("ch"+i).checked = "true";
		else
		$("ch"+i).checked = false;
	}
	
}
function focuses(id)
{
	document.getElementById(id).focus();
}
/* To get relative Combo */
function getRelativeCombo(id,selectedCat,combId,comboText,genArr){
	//alert(id);
	var val =id;
	var control	=	$(""+combId+"");
	control.options.length = 0;
	control.options[0] = new Option("---"+comboText+"---");
	control.options[0].value = "";

	for(i=0,j=0; i< genArr.length; i++)
	{	
		//alert(genArr[i][2]+"===>"+val);
		if(genArr[i][2] == val)
		{
			
			if(selectedCat == genArr[i][0])
			{
				control.options[j+1] = new Option(genArr[i][1]);
				control.options[j+1].value = genArr[i][0];
				control.options[j+1].selected = true;
			}else
			{
				control.options[j+1] = new Option(genArr[i][1]);
				control.options[j+1].value = genArr[i][0];
			}
			j++;
		}
	}	
}
function trim(s)
{
 	return s.replace(/^\s+|\s+$/g, ''); 
}
function noCTRL(e)
{
	var forbiddenKeys = new Array('c','x','v');
	var keyCode = (e.keyCode) ? e.keyCode : e.which;	
	if(e.ctrlKey) {		
		for(i = 0; i < forbiddenKeys.length; i++) {			
			if(forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {			
			return false;
			}
		}
	}
}
function getclearAddvance(obj){
	var msg = $(obj.id).value;	

	if(msg == '')
		msg = 'ZIP Code or City, State';
	$('msg').value = msg;	
	if(obj.value == msg){
		obj.value='';
	}
}
function getDefaultValue(obj){
  	
   if(obj.value == ""){
      if(obj.id == 'vEmail'){
         //obj.value = $('msg').value;
         obj.value = "Email";
      }else if(obj.id == 'vPassword'){
         obj.value = "Password";
      }else{  
         obj.value = $('msg').value;
      }		
	}
	$('msg').value = '';
}
/* To get relative Combo Temporarily*/ 
function getRelativeCombo1(id,selectedCat,combId,comboText,genArr,ext){	
	alert(genArr);
	var val = id;
	if(ext && ext !='')
		var extval = $(ext).value;
	var control	=$(""+combId+"");
	//alert(control.options.length);
	control.options.length = 0;
	control.options[0] = new Option(comboText);
	control.options[0].value = "";
//	alert(genArr.length);
//	alert(genArr[0][2]+"===>"+val);
	for(i=0,j=0; i< genArr.length; i++)
	{	
		if(ext && ext !=''){
			if(genArr[i][2] == val && extval == genArr[i][3])
			{
				
				if(selectedCat == genArr[i][0])
				{
					control.options[j+1] = new Option(genArr[i][1]);
					control.options[j+1].value = genArr[i][0];
					control.options[j+1].selected = true;
				}else
				{
					control.options[j+1] = new Option(genArr[i][1]);
					control.options[j+1].value = genArr[i][0];
					//alert(control.options[j+1].value);
				}
				j++;
			}
		}else{
			if(genArr[i][2] == val)
			{
				
				if(selectedCat == genArr[i][0])
				{
					control.options[j+1] = new Option(genArr[i][1]);
					control.options[j+1].value = genArr[i][0];
					control.options[j+1].selected = true;
				}else
				{
					control.options[j+1] = new Option(genArr[i][1]);
					control.options[j+1].value = genArr[i][0];
					//alert(control.options[j+1].value);
				}
				j++;
			}
		}
	}	
}
