/*
 * Converts the first character into upper case
 */

function makeFirstCapital(text)
{
	text.value=text.value.substring(0, 1).toUpperCase()+text.value.substring(1, text.value.length);
	return true;
}

/*
 * Checks the field is empty or not 
 */
 
 function LTrim( value ) {
   	
    	var re = /\s*((\S+\s*)*)/;
     	return value.replace(re, "$1");
     	
     }
     
   // Removes ending whitespaces
   function RTrim( value ) {
    	
    	var re = /((\s*\S+)*)\s*/;
    	return value.replace(re, "$1");
    	
    }
    
    // Removes leading and ending whitespaces
   function trim( value ) {
    	
    	return LTrim(RTrim(value));
    	
    }
	
function isBlank(text,message)
{
	with(text)
	{
		trim_value=trim(value);
		if (trim_value==null||trim_value=="")
		{
			document.getElementById("javscripterrors").innerHTML = message+" is mandatory.";			
			text.focus();
			return false;
		}	
		return true;
	}
}
function isBlankHomePage2(text,message)
{
	with(text)
	{
		trim_value=trim(value);
		if (trim_value==null||trim_value=="")
		{
			document.getElementById("javscripterrors2").innerHTML = message;			
			text.focus();
			return false;
		}	
		return true;
	}
}
function isBlankHomePage(text,message)
{
	with(text)
	{
		trim_value=trim(value);
		if (trim_value==null||trim_value=="")
		{
			document.getElementById("javscripterrors").innerHTML = message;			
			text.focus();
			return false;
		}	
		return true;
	}
}
function contatinsSpclChars(text,message)
{
	if (!(/^[A-Z\a-z\d\@\.\_\-]*$/i.test(text.value))) {
		document.getElementById("javscripterrors").innerHTML = message+" should not contain special characters and spaces.";		
		text.focus();
		return false;
	}
	return true;
}

function checkSelect(text,message)
{	
	if(text.value=="")
	{
		document.getElementById("javscripterrors").innerHTML = "Please select "+message+".";		
		text.focus();
		return false;
	}
	return true;	
}

function checkLength(text,message,low,high)
 {
	 if(text.value.length<low||text.value.length>high)
	 {
	 	document.getElementById("javscripterrors").innerHTML = message+" length must be greater than "+low+" and less than "+high+" characters.";
		text.focus();
		return false;
	 }
	 return true;	 
}



function isContact(text,message)
 {
 	 if(isNaN(text.value))
 	 {
 	 	document.getElementById("javscripterrors").innerHTML = message+" number should contain digits only.";
		text.focus();
		return false;
 	 }
	 if(text.value.length!=10)
	 {
		document.getElementById("javscripterrors").innerHTML = message+" number should be 10 digits only.";
		text.focus();
		return false;
	 }
	 return true;	 
 }
 
 function isEmailCheck(text,message) 
 {
		var str=text.value;
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var lldot = str.lastIndexOf(dot);
		if (str==""){
		   return true;
		}
		if (str.indexOf(at)==-1){
		   document.getElementById("javscripterrors").innerHTML = "Please enter a valid "+message;
		   text.focus();
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		  document.getElementById("javscripterrors").innerHTML = "Please enter a valid "+message;
		   text.focus();
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   document.getElementById("javscripterrors").innerHTML = "Please enter a valid "+message;
		   text.focus();
		   return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		     document.getElementById("javscripterrors").innerHTML = "Please enter a valid "+message;
		   text.focus();
		   return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		     document.getElementById("javscripterrors").innerHTML = "Please enter a valid "+message;
		   text.focus();
		   return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		      document.getElementById("javscripterrors").innerHTML = "Please enter a valid "+message;
		   text.focus();
		   return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		      document.getElementById("javscripterrors").innerHTML = "Please enter a valid "+message;
		   text.focus();
		   return false;
		 }
		 
		 if(lldot == (lstr-1) )
		 {
		 	document.getElementById("javscripterrors").innerHTML = "Please enter a valid "+message;
		   text.focus();
		   return false;
		 }
		
 		 return true;					
	}
	
function isSame(text1,text2)
{
	if(text1.value!=text2.value)
	{
		document.getElementById("javscripterrors").innerHTML = "Confirmed password does not match with the new password.";
		text2.value="";
		text2.select();
		return false;
	}
	return true;
}
var fieldObj;
var imagefield2;
function setup(url,field,imagefield)
{
	imagefield2 = imagefield;
	fieldObj = field;
	
			if (window.XMLHttpRequest) 
			{ 
				// Non-IE browsers
					req = new XMLHttpRequest();       
					req.onreadystatechange = processStateChange;
					try 
					{
						 req.open("GET", url, true);
					}
					catch (e) 
					{
						 alert(e);
					}
					req.send(null);
			} 
			else if (window.ActiveXObject) 
			{ // IE
			
				 req = new ActiveXObject("Microsoft.XMLHTTP");
				if (req) 
				{
					 req.onreadystatechange = processStateChange;
					 req.open("GET", url, true);
					 req.send();
				}
			}
//		alert("ajax code worked properly");
}

function processStateChange() 
{
	if (req.readyState == 4) 
	{ // Complete
		if (req.status == 200) 
		{ // OK response				
			if(trim(req.responseText) != "")
			{						
				document.getElementById(fieldObj).innerHTML = req.responseText;					
			}
			else
			imagefield2.style.cursor = "default";					
		} 			
		else
		{
			 alert("Problem: " + req.statusText);
		}
	}
}
	  
function date_check(field1,field2,message)
{
	
	
	var effective_array=field1.value.split("/");
	var eff_mm=parseInt(effective_array[0]);
	var eff_dd=parseInt(effective_array[1]);
	var eff_yy=parseInt(effective_array[2]);
	
	var expiry_array=field2.value.split("/");
	var ex_mm=parseInt(expiry_array[0]);
	var ex_dd=parseInt(expiry_array[1]);
	var ex_yy=parseInt(expiry_array[2]);
	if(ex_yy<eff_yy)
	{
	document.getElementById("javscripterrors").innerHTML = message;
	field1.focus();
	return false;
	}
	else if(ex_yy==eff_yy)
	{
		if(ex_mm<eff_mm)
		{
		document.getElementById("javscripterrors").innerHTML = message;
		   field1.focus();
		   return false;
		}
		else if(ex_mm==eff_mm)
		{
			if(ex_dd<eff_dd)
			{
			document.getElementById("javscripterrors").innerHTML = message;
		   field1.focus();
		   return false;
			}
			
		}
		
	}
	return true;

}

function validDate(field,fielddate){
	with(field)
	{
	  var endDate = new Date(value); 
	  var currentdate=new Date();
	  
	  if(endDate>currentdate)
	  {
	  alert( "Birth Date should not be greater than the current date") ;
	  field.focus();
	  return false;
	  }
	  else 
	  return true;
	}
}
function showthemes()
{
	document.getElementById("homelink").style.display = "none";
	document.getElementById("logintablink").style.visibility = "visible";
	document.getElementById("themes").style.visibility = "visible";	
}
function checkSize(size,field)
{
	var data = field.value;
	if(data.length >=size)
	data = data.substring(0,size);
	field.value = data;
}

function voteStar(wishid,field,imagefield)
{
	var url = "blesswishaction?wishid="+wishid+"&type=star";	
	setup(url,field,imagefield);
}
function voteThumb(wishid,field,imagefield)
{
	var url = "blesswishaction?wishid="+wishid+"&type=thumbs";	
	setup(url,field,imagefield);
}
function voteRoses(wishid,field,imagefield)
{
	var url = "blesswishaction?wishid="+wishid+"&type=roses";	
	setup(url,field,imagefield);
}

function song(field,srcfile)
{
	//alert(srcfile);
	if(trim(document.getElementById(field).innerHTML) != "Click play to listen this Wish.")
	{
		document.getElementById(field).innerHTML="Click play to listen this Wish.";	
		document.getElementById("play"+field).style.backgroundImage = "url(../images/voxx_corp/play.png)";
	}
	else
	{
		document.getElementById(field).innerHTML="<img src='../images/voxx_corp/loader.gif'/><object type='application/x-mplayer2' id='music1' pluginspage='../application/wmpfirefoxplugin.exe' src='"+srcfile+"' width='0' height='0' controltype='false' showcontrols='0' showstatusbar='0' AutoStart='true' align='baseline' ></object>";
	//	document.getElementById(field).innerHTML="<img src='../images/loader.gif'/><OBJECT ID='MediaPlayer' WIDTH='0' HEIGHT='0' CLASSID='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' TYPE='application/x-oleobject' pluginspage='../application/wmpfirefoxplugin.exe'><EMBED TYPE='application/x-mplayer2' SRC='"+srcfile+"' NAME='MediaPlayer' ShowStatusBar='0' ShowDisplay='0' autostart='1'> </EMBED></OBJECT>";
		document.getElementById("play"+field).style.backgroundImage = "url(../images/voxx_corp/stop.png)";
	}
}