﻿String.prototype.inc=function(k1,k2){return k2==null?this.indexOf(k1)>-1?true:false:(k2+this+k2).indexOf(k2+k1+k2)>-1?true:false}
String.prototype.trim=function(){return this.replace(/(^[\s]*)|([\s]*$)/g, "")}	

// changeImage function
function ChangeImage(ImageName, NewImage, Title, Directory)
{
	if (document.images)
	{
	// alert (ImageName + " - " + NewImage + " - " + Title + " - " + Directory);
	if (String (Directory) != "undefined")
	{
		var lastchar = Directory.substr(Directory.length-1);
		if (lastchar!="/" && lastchar!="\\")
		{
			document[ImageName].src = Directory + "/"+ NewImage;
		}
		else
		{
			document[ImageName].src = Directory + NewImage;
		}
	}
	else
		document[ImageName].src = "images/" + NewImage;
	}

	if (String (Title) != "undefined")
		window.status=Title;
	else
		window.status=' ';
}

function chgbk(id, newcolor)
{
	if(document.layers){ 	// browser="NN4"; 
		document.layers[id].bgColor = newcolor; 
	} 
	
	if(document.all){ 	// browser="IE"; 
		document.all[id].style.backgroundColor = newcolor; 
	} 
	
	if(!document.all && document.getElementById){ // browser="NN6+ or IE5+ if you're willing to dump the !document.all stuff"; 
		document.getElementById(id).style.backgroundColor = newcolor; 
	} 
}


// This function is a modified version of the above function that uses CSS classes rather than
// passing colors in directly.  The old version is left in for backward compatibility.
// Author: kdye@vignette.com, July 12, 2005
function chgBkgd(id, className)
{
	if(document.layers){ 	// browser="NN4"; 
		document.layers[id].className = className; 
	} 
	
	if(document.all){ 	// browser="IE";
		document.all[id].className = className;
	} 
	
	if(!document.all && document.getElementById){ // browser="NN6+ or IE5+ if you're willing to dump the !document.all stuff"; 
		document.getElementById(id).className = className; 
	} 
}



function redirectToExitPage(filename,exitPageUrl,newWindow,displayExitMsg,windowname)
//filename - destination Url
//exitPageUrl - Url for the global Exit Page(Path = Global/Global Exit Page)
//newwindow - boolean (if set to 'true' - opens up in a new window)
//displayExitMsg - if set to 0: redirects to the destination Url without displaing the exit message
//				- if set to 1: displays the exit Message
//windowname - name of the window
{
	//Support for bc in exit page
		var bc="";
		if (DCSext["mct_a"]!="") {
			bc=DCSext["mct_a"];			
			}
	//End Support for bc in exit page
 

	var redirectUrl = exitPageUrl + "&url=" + filename + "&Exit=" + displayExitMsg+ "&mct_a="+bc+"/affiliated_pages" ;
	if (String (newWindow) == "false" ) {
		document.location.href = redirectUrl;
	} else {
		popupWindowWithLocation(redirectUrl,windowname,"682","352"); 
	}
}
 
function popupWindow(filename,windowname,width,height)  
{
popup=window.open(filename,windowname,"width="+width+",height="+height+",resizable=yes,status=no,toolbar=yes,directories=no,menubar=yes,scrollbars=yes,location=no");
}

function popupWindowWithLocation(filename,windowname,width,height) 
{
popup=window.open(filename,windowname,"width="+width+",height="+height+",resizable=yes,status=yes,toolbar=yes,directories=no,menubar=yes,scrollbars=yes,location=yes");
}

function popupWindowNoToolbars(filename,windowname,width,height) 
{
popup=window.open(filename,windowname,"width="+width+",height="+height+",resizable=no,status=no,toolbar=no,directories=no,menubar=no,scrollbars=yes,location=no");
}

function popupWhyComerica(filename)
{
	// popupWindowWithLocation(filename, "why_com", "640", "480");
	popup=window.open(filename, "why_com", "width=630,height=470,resizable=yes,status=yes,toolbar=yes,directories=no,menubar=yes,scrollbars=no,location=yes,left=75,top=60");
}

function popupGlossary(filename)
{
	popupWindowNoToolbars(filename, 'glossary', '690', '470');
}

function popupFAQ(filename)
{
	popupWindowNoToolbars(filename, "faq", "690", "470");
}

function popupNewsletter(filename)
{
	popupWindowWithLocation(filename, "newsletter", "800", "575");
}

function popupCalculator(filename)
{
	popupWindowWithLocation(filename, "calculator", "540", "575");
}

function popupDemo(filename)
{
	if (filename.indexOf("eFX") > 0) {
		popupDemoNC(filename);
	} else {
		popupWindowWithLocation(filename, "demo", "800", "575");
	}
}

function popupTutorial(filename)
{
	popupWindowWithLocation(filename, "tutorial", "540", "575");
}

function popupBranchATM(filename)
{
	var windowHeight = 0.75 * screen.height;
	// alert("screen height = " + screen.height);
	// alert("window height = " + windowHeight);
	popupWindowWithLocation(filename, "branchATM", "575", windowHeight);
}
 
function popupForm(filename)
{
	//popupWindowWithLocation(filename, "form", "575", "575");
	popupWindowWithLocation(filename, "form", "710", "575");
}

function popupLogin(filename)
{
	popupWindowWithLocation(filename, "login", "800", "575");
}

function popupApply(filename)
{
	popupWindowWithLocation(filename, "apply", "800", "575");
}

function popupPrintable(filename)
{
	popupWindow(filename, "printable", "670", "575");
}

function popupPDF(filename)
{
	popupWindowWithLocation(filename, "pdf", "800", "575");
}

function popupDemoNC(filename) {
		
	var NewX = Math.max(0, Math.floor((screen.availWidth - (800)) / 2));
	var NewY = Math.max(0, Math.floor((screen.availHeight - (565)) / 2));
	
	var params = new Array();
	params.push('width=792');
	params.push('height=538');
	params.push('screenx=' + NewX);
	params.push('screeny=' + NewY);
	params.push('left=' + NewX);
	params.push('top=' + NewY);
	params.push('resizable="no"');
	params.push('scrollbars="no"');
	params.push('toolbar="no"');
	params.push('menubar="no"');
	params.push('status="no"');
	params.push('location="no"');
	params.push('directories="no"');	
		
	window.open(filename, '', params.join(','));

}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// -------------------------------------------------------------
// Start Render Masthead
// -------------------------------------------------------------
var loaded                      = new Array();
var onloadFired                 = false;

function addOnLoad( fn ) 
{
	if ( onloadFired ) 
	{
	    return;
	}
	if( window.onload ) 
	{
	    if( window.onload != safeLoad ) 
	    {
	        loaded[0] = window.onload;
	        window.onload = safeLoad;
	        loaded[ 1 ] = fn;
	    }
	    else
	    {
	        loaded[ loaded.length + 1 ] = fn;
	    }
    	}
	else
	{  
	    window.onload = fn; 
    	}
}
	
function safeLoad() 
{
    onloadFired = true;
    for( var i=0;i<loaded.length;i++ ) 
    {
        if( loaded[i] != undefined )
        {
	        loaded[i](); 
	    }
    }
}

function oo(obj)
{
	var o;
	if (typeof(obj)!="string")
		return obj;
	else
	{
		try
		{
			document.all
			try
			{
				o=document.all(obj);
			}
			catch(e)
			{
				return ;
			}
		}
		catch(ee)
		{
			try
			{
				o=document.getElementById(obj);
			}
			catch(e)
			{
				return ;
			}
		}
		return o;
	}
}

function fm_chk(fm)
{
	var a,i,l,name,rule;
	for(i=0;i<fm.length;i++)
	{
		name=fm[i].getAttribute("chkName");
		rule=fm[i].getAttribute("chkRule");
		if(name==null)
			continue;
		l="";
		if(rule.inc("cpwd","/")==true&&fm[i].value!=fm[i-1].value)
		{
			l=name+"不一致！";
		}
		if(rule.inc(">=4","/")==true&&fm[i].value.length<4)
		{
			l=name+"不得少于4个字符！";
		}
		if(rule.inc("<=16","/")==true&&fm[i].value.length>16)
		{
			l=name+"不得多于16个字符！";
		}
		if(rule.inc("<=255","/")==true&&fm[i].value.length>255)
		{
			l=name+"不得多于255个字符！";
		}
		if(rule.inc("中a1_","/")==true&&!new RegExp("^[_a-zA-Z0-9\\u4E00-\\u9FA5\\uF900-\\uFA2D]*$","g").test(fm[i].value))
		{
			l=name+"只能是汉字、英文、数字和下划线的组合！";
		}
		if(rule.inc("a1","/")==true&&!new RegExp("^[a-zA-Z0-9]*$","g").test(fm[i].value))
		{
			l=name+"只能为英文字母和数字的组合！";
		}
		if(rule.inc("mobile","/")==true&&!new RegExp("^1[3|5](\\d{9})+$").test(fm[i].value))
		{
			l="手机号码格式不正确！";
		}
		if(rule.inc("mobiles","/")==true&&fm[i].value.replace(/，/g,",").replace(/(,|^)1[3|5]\d{9}/g,"").replace(/\,/g,"")!="")
		{
			l="手机号码格式不正确！";
		}
		if(rule.inc("eml","/")==true&&!new RegExp("^[\\w._]+@\\w+\.(\\w+\.){0,3}\\w{2,4}$","g").test(fm[i].value.replace(/-|\//g,""))&&fm[i].value!="")
		{
			l=name+"的邮件格式不正确！";
		}
		if(rule.inc("emls","/")==true&&fm[i].value!="")
		{
			var value = fm[i].value.replace(/ |-|\//g,"").replace(/;|；|，/g,",").replace(/(,|^)(.|)+<([\w._]+@\w+\.(\w+\.){0,3}\w{2,4})>|(\,|^)([\w+._]+@\w+\.(\w+\.){0,3}\w{2,4})/g,"").replace(/\,/,"").trim();
			if(value!="")
			{
				l=name+"邮件格式不正确！";
			}
		}
		if(rule.inc("eml_nickname","/")==true&&new RegExp("[,|;|<|>]","g").test(fm[i].value))
		{
			l=name+"不能含有特殊字符！";
		}
		if(rule.inc("notnull","/")==true&&fm[i].value=="")
		{
			l=name+"不能为空！";
		}
		if(l!="")
		{
			alert(l);
			return false;
		}
	}
	return true;
}