
//Check option other with text
//If you select 'other' option,  the options except the 'other' should be unselected.
function optionother(chgobj, optobj, othobj)
{
   if((chgobj == optobj[optobj.length-1]) &&optobj[optobj.length-1].checked)
   {
        othobj.readOnly = false;
        for(i=0; i < optobj.length-1; i++)
        {
            optobj[i].checked = false;
        }       
    }
    else{
        othobj.value ="";
        othobj.readOnly=true;
        optobj[optobj.length-1].checked = false;
    }
}
//Check option other with text
//If you select 'other' option,  the text of other can be filled, or it can't.
function optionother2(chgobj, optobj, othobj)
{
   if((chgobj == optobj[optobj.length-1]) &&optobj[optobj.length-1].checked)
   {
        othobj.readOnly = false;      
    }
    else{
        othobj.value ="";
        othobj.readOnly=true;
    }
}
//Check option other with text
//If you select 'other' option,  the text of other can be filled, or it can't.
function optionother3(optobj, othobj)
{
  if(optobj[optobj.length-1].checked)
   {
        othobj.readOnly = false;    
    }
    else{
        othobj.value ="";
        othobj.readOnly=true;
    }
}
//Check option other without text
//If you select 'other' option,  the options except the 'other' should be unselected.
function optionother1(chgobj, optobj)
{
   if((chgobj == optobj[optobj.length-1]) &&optobj[optobj.length-1].checked)
   {
       
        for(i=0; i < optobj.length-1; i++)
        {
            optobj[i].checked = false;
        }       
    }
    else{
        optobj[optobj.length-1].checked = false;
    }
}


//Open window function to get the model of the car brand
function opennew(address)
{
    
    var op_tool  =  0;    
    var op_loc_box  =  0;    
    var op_dir  =  0;    
    var op_stat  =  0;    
    var op_menu  =  0;    
    var op_scroll  =  1;    
    var op_resize  =1 ;    
    var op_width  = 400;   
    var op_heigh = 400;    
    var option = "toolbar="+ op_tool +",location="+ op_loc_box +",directories=" 
        + op_dir +",status="+ op_stat +",menubar="+ op_menu +",scrollbars="  
        + op_scroll +",resizable="  + op_resize +",width=" + op_width +",height="+ op_heigh;
    window.open(address, "models", option);
}


function checkEmail1(input)
{
    email = input.value;
    if(!checkEmail(email))
    {
        alert("电子邮件不合法!");
    }
    else{
        alert("OK");
    }
}
function CheckDate1(CONTROL){ 
    var strFormat = "yyyy/mm/dd"; 
    if(!isDate(CONTROL.value)){ 
        return false; 
    }
    CONTROL.value = FormatDate(CONTROL.value,strFormat); 
    return true;
} 

function CheckDate2(CONTROL){ 
    var str = CONTROL.value;
    if(str == null || str==""){
        alert("请输入日期");
        return;
    }
    
    var strFormat = "yyyy/mm/dd"; 
    if(!isDate(CONTROL.value)){ 
        alert("Invalid Date") 
        return; 
    } 
    CONTROL.value = FormatDate(CONTROL.value,strFormat); 
} 


function CheckDate3(CONTROL){ 
    var strFormat = "yyyy/mm/dd"; 
    if(!isDate(CONTROL.value)){ 
        return false; 
    }
    CONTROL.value = FormatDate(CONTROL.value,strFormat); 
    return true;
} 

function checkListWithoutDefault(obj)
{
    for(i=1; i<obj.length; i++){
        if(obj[i].selected){
            return true;
        }        
    }
    return false;
}
function getList(obj)
{
    for(i=0; i<obj.length; i++){
        if(obj[i].selected){
            return obj[i].value;
        }        
    }
}
function checkOption(obj)
{
    for(i=0; i<obj.length; i++){
        if(obj[i].checked){
            return true;
        }        
    }
    return false;
}
function getOption(obj)
{
    if(obj[0]){
        for(i=0; i<obj.length; i++){
            if(obj[i].checked){
                return obj[i].value;
            }
        }
   }else{
        return obj.value;
    }
    return false;
}
function setOption(obj, str)
{
        for(i=0; i<obj.length; i++){
        if(obj[i].value==str){
            obj[i].selected = true;
        }        
    }
}
function setList(obj, str)
{
        for(i=0; i<obj.length; i++){
        if(obj[i].value==str){
            obj[i].selected = true;
        }        
    }
}



function checkEmail(email) {
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
    
    for(i=0; i < email.length ;i++){
        if(ok.indexOf(email.charAt(i))<0){ 
            return (false);
        }
    }
    if(!((email.indexOf(".") > 0) && (email.indexOf("@") > 0))) return false;
    return true;
}

function checkNum(s){
   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true; 
}


function checkString(str){
    var notAlow="\t\"";
    for(i=0; i < str.length ;i++){
        if(notAlow.indexOf(str.charAt(i))>0){ 
            return (false);
        }
        
    }
    return true;
}

function isDate(DateToCheck){
if(DateToCheck==""){return true;}
var m_strDate = FormatDate(DateToCheck);
if(m_strDate==""){
return false;
}
var m_arrDate = m_strDate.split("/");
var m_DAY = m_arrDate[0];
var m_MONTH = m_arrDate[1];
var m_YEAR = m_arrDate[2];
if(m_YEAR.length > 4){return false;}
m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
var testDate=new Date(m_strDate);
if(testDate.getMonth()+1==m_MONTH){
return true;
} 
else{
return false;
}
}//end function


function CheckDate(CONTROL){ 
var strFormat = "yyyy/mm/dd"; 
if(!isDate(CONTROL.value)){ 
alert("Invalid Date") 
return; 
} 
CONTROL.value = FormatDate(CONTROL.value,strFormat); 
} 


function FormatDate(DateToFormat,FormatAs){
if(DateToFormat==""){return"";}
if(!FormatAs){FormatAs="dd/mm/yyyy";}

var strReturnDate;
FormatAs = FormatAs.toLowerCase();
DateToFormat = DateToFormat.toLowerCase();
var arrDate
var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var strMONTH;
var Separator;

while(DateToFormat.indexOf("st")>-1){
DateToFormat = DateToFormat.replace("st","");
}

while(DateToFormat.indexOf("nd")>-1){
DateToFormat = DateToFormat.replace("nd","");
}

while(DateToFormat.indexOf("rd")>-1){
DateToFormat = DateToFormat.replace("rd","");
}

while(DateToFormat.indexOf("th")>-1){
DateToFormat = DateToFormat.replace("th","");
}

if(DateToFormat.indexOf(".")>-1){
Separator = ".";
}

if(DateToFormat.indexOf("-")>-1){
Separator = "-";
}


if(DateToFormat.indexOf("/")>-1){
Separator = "/";
}

if(DateToFormat.indexOf(" ")>-1){
Separator = " ";
}

arrDate = DateToFormat.split(Separator);
DateToFormat = "";
	for(var iSD = 0;iSD < arrDate.length;iSD++){
		if(arrDate[iSD]!=""){
		DateToFormat += arrDate[iSD] + Separator;
		}
	}
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
arrDate = DateToFormat.split(Separator);

if(arrDate.length < 3){
return "";
}

var DAY = arrDate[0];
var MONTH = arrDate[1];
var YEAR = arrDate[2];




if(parseFloat(arrDate[1]) > 12){
DAY = arrDate[1];
MONTH = arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
YEAR = arrDate[0];
DAY = arrDate[2];
MONTH = arrDate[1];
}


for(var iSD = 0;iSD < arrMonths.length;iSD++){
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
var MonthPosition = DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	MONTH = iSD + 1;
		if(MonthPosition == 0){
		DAY = arrDate[1];
		YEAR = arrDate[2];
		}
	break;
	}
}

var strTemp = YEAR.toString();
if(strTemp.length==2){

	if(parseFloat(YEAR)>40){
	YEAR = "19" + YEAR;
	}
	else{
	YEAR = "20" + YEAR;
	}

}


	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	MONTH = "0" + MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	DAY = "0" + DAY;
	}
	switch (FormatAs){
	case "dd/mm/yyyy":
	return DAY + "/" + MONTH + "/" + YEAR;
	case "mm/dd/yyyy":
	return MONTH + "/" + DAY + "/" + YEAR;
	case "dd/mmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
	case "mmm/dd/yyyy":
	return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
	case "dd/mmmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
	case "mmmm/dd/yyyy":
	return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	case "yyyy/mm/dd":
	return YEAR + "/" + MONTH + "/" + DAY;
	}

return DAY + "/" + strMONTH + "/" + YEAR;;

} //End Function
