// JavaScript for dynamic text, button, etc.
//  define the action when mouse is over a object
function M_Over(src, cOvr) 
{if (!src.contains(event.fromElement)) {src.style.cursor = "default";src.bgColor = cOvr;}}

//  define the action when mouse is out of a object
function M_Out(src, cOut) 
{if (!src.contains(event.toElement)) {src.style.cursor = "default";src.bgColor = cOut;}}
//the functions above change table td color
//--> the functions below change the background of button
//  define the action when mouse is over a button
function Btn_Over(src, cOvr) 
{if (!src.contains(event.fromElement)) {src.style.background = cOvr;src.style.color="ff0000";src.style.fontStyle="italic";}}

function Btn_Out(src, cOut) 
{if (!src.contains(event.toElement)) {src.style.background = cOut; src.style.color="ffffff";src.style.fontStyle="normal";}}
function btn_over(src)
{
	src.style.cursor  = "hand";
	src.style.background = "CCFFCC";
	src.style.color="red";
}

function btn_out(src)
{
	src.style.cursor  = "";
	src.style.background = "cccccc";
	src.style.color="black";
}
function Text_OnFocus(src, cOvr) 
{   if (src.value=="Enter keyword here") src.value="";
    if (!src.contains(event.fromElement)) {src.style.background = cOvr; src.style.color="ff0000";}
}

//  define the action when the text got focused
function Text_OnBlur(src, cOvr) 
{   
    if (!src.contains(event.fromElement)) {src.style.background = cOvr;src.style.color="0000ff"}
}

function IsNumber(GivenStr)
{
    var str=GivenStr;
	var digit="1234567890.+- ";
	
	for (i=0; i<str.length; i++)
	{
	    if ( digit.indexOf(str.substring(i,i+1))<0 )  
		    return false;
	}
	return true;
}

function IsDate(str)
{
        var dateList;
		
		if (str.indexOf("/")>0 )  // date separate by "/"
		{  	dateList=str.split("/");
	 	    if ( parseInt(dateList[2])  < 1  ||   parseInt(dateList[2]) >3000 )   // year
				return false;
			if ( parseFloat(dateList[0])  < 1  ||   parseFloat(dateList[0]) >12 )   // month				 
		         return false;
			if ( parseFloat(dateList[1])  < 1  ||   parseFloat(dateList[1]) >31 )   // day
	 	         return false;
			if (  parseInt(dateList[0])  == 2 &&  parseInt(dateList[1]) >29 )   // February
		      return false;
		}
		else if (str.indexOf("-")>0 )
		{
			dateList=str.split("-");
			if (parseInt(dateList[0])<1000 || parseInt(dateList[0])>3000 )
			   return false;  // year is wrong!
			if (parseFloat(dateList[1])<1 || parseFloat(dateList[1])>12 )
			   return false; // month is wrong!
			if (parseFloat(dateList[2])<1 || parseFloat(dateList[2])>31 )
			   return false; // day is wrong!
			if ( parseInt(dateList[0])  == 2 && parseFloat(dateList[2])>29 )
			   return false; // check if February is wrong!
		}
		else
		   return false;
		return true;
}

function CreditCardDate(src)
{
    var datelist=src.value.split("/");
	var isDate = 0; 
	if (src.value.length != 5 ){
		isDate = 1;
	}

	if (parseFloat(datelist[0])>12 || parseFloat(datelist[0])<1 )   // month
	{
		isDate = 1;
	}
	if (parseFloat(datelist[1])<0 || parseFloat(datelist[1])>99 )  //year
	{
		isDate=1;
	}	
	if (isDate==1)
	{   alert("Please give a  valid expiry date! e.g. 09/03, format: month/year");
	    src.focus();
	}
}

function IsEmail(val)
{
   var i,j;
   if (val!=""){
		i=val.indexOf("@");
	    if (i>0){
		    j=val.lastIndexOf(".");
			if (j<i){
			   return false;
			}
		}
		else{
			  return false;
		}
	}
	return true;
}

function ucfirst(str){
	 var list, str1,str2;
	 var i;
	 list=str.split(" ");
	 for (i=0; i<list.length;  i++)
	 {
	    str1=list[i].substr(0,1);
		str2=list[i].substr(1,list[i].length -1);
        if (str1>="a" && str1<="z" )
     		str1 =str1.toUpperCase();
//		str2=str2.toLowerCase();
		list[i]=str1 + str2;   
	 }
	 str1="";
	 for (i=0; i<list.length;  i++)  
	 {  // loop to merge string 
	    if (i==0)
		    str1=list[i];
		else
			str1 =str1 +" "+ list[i];
	 }
	 return str1;
  }
  
function remove_dash(src)
{
    Text_OnBlur(src,'FFFFFF');
	src.value = src.value.replace("-","");
}