// Main Javascript File

function swapCSS(id, css) {
		var obj = document.getElementById(id);
		obj.className = css;
}

function swapImage(id, path) {
    var obj;
    if (typeof id == "object")
        obj = id;
    else
        obj = document.getElementById(id);
	obj.src = path;
}

function show(id, type) {
    var element = document.getElementById(id);
    element.style.opacity = 1;
    if (type) {
        element.style.display = type;
    }else{
        element.style.display = "inline";
    }
}

function hide(id) {
    var element = document.getElementById(id);
    element.style.display = "none";
    element.style.opacity = 0;
}

function openWindow(url, id, params)
{
    var win = window.open(url, id, params);
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable)
		{
		  return pair[1];
		}
	} 
}
		
function animatePanel(id, opacity, height) {
    YAHOO.namespace('anim');
    var obj = document.getElementById(id);
    
	    var attributes = {
	      height: {to: height},
	      opacity: {to: opacity}
	    }
	    var myAnim = new YAHOO.util.Anim(id, attributes, .35, 
	                             YAHOO.util.Easing.easeOut);
		myAnim.animate();
	
}

function filterCardNumber(input)
{
    var output = "";
    var dash = '-';
    output = input.replace('-', '');
    return output;
}

function localize() {
	urls=new Array();
	oh=new Array();tsd=new Array();ohs=new Array();tsds=new Array();ohr=new Array();tsdr=new Array();
	tsh='espanol.dominos.com';
	ohs[0]=/www([0-9]{2})\.order\.dominos\.com/i;ohr[0]='www$1.order.dominos.com';
	tsds[0]=/\/enes\/sdwww([0-9]{2})\/sdorder\/ddominos\//i;tsdr[0]='/enes/sdwww$1/sdorder/ddominos/';
	oh[0]='order.dominos.com';tsd[0]='/enes/sdorder/ddominos/';
	oh[1]='sdc.dominos.com';tsd[1]='/enes/sdsdc/ddominos/'; 
	oh[2]='info.dominos.com';tsd[2]='/enes/sdinfo/ddominos/';
	oh[3]='public.dominos.com';tsd[3]='/enes/sdpublic/ddominos/';
	oh[4]='www.dominosbiz.com';tsd[4]='/enes/ddominosbiz/';
	oh[5]='dominos.optimumcard.com';tsd[5]='/enes/sdoptimumcard/';
    oh[6]='trkweb.dominos.com';tsd[6]='/enes/sdtrkweb/ddominos/';
    oh[7]='feedback.dominos.com';tsd[7]='/enes/sdfeedback/ddominos/';
    oh[8]='cache.dominos.com';tsd[8]='/enes/sdcache/ddominos/';
    oh[9]='tracker.dominos.com';tsd[9]='/enes/sdtracker/ddominos/';
    oh[10]='giftcard.dominos.com';tsd[10]='/enes/sdgiftcard/';
    oh[11]='dominos.com';tsd[11]='/enes/';
	urls[0]=new URLData(tsh,oh,tsd,ohs,tsds,ohr,tsdr);
	oh=new Array();tsd=new Array();ohs=null;tsds=null;ohr=null;tsdr=null;
	tsh='espanol-test.dominos.in.tellme.com';
	oh[0]='www-test.dominos.in.tellme.com';tsd[0]='/enes/sdwww-test/sddominos/sdin/dtellme/';
	oh[1]='order01.olo.pizza.hosting.sv2.tellme.com';tsd[1]='/enes/sdorder01/sdolo/sdpizza/sdhosting/sdsv2/dtellme/';
	oh[2]='order02.olo.pizza.hosting.sv2.tellme.com';tsd[2]='/enes/sdorder02/sdolo/sdpizza/sdhosting/sdsv2/dtellme/';
	oh[3]='biz-test.dominos.in.tellme.com';tsd[3]='/enes/sdbiz-test/sddominos/sdin/dtellme/';
	oh[4]='test.dominos.com';tsd[4]='/enes/sdtest/ddominos/';
	urls[1]=new URLData(tsh,oh,tsd,ohs,tsds,ohr,tsdr);
	var found=false;
	for (i=0;i<urls.length;i++){ 
		idx=location.href.indexOf(urls[i].tsh);
		rxmatch=false;
		if(idx==-1){
			if (urls[i].ohs != null) {
				for (j=0;j<urls[i].ohs.length;j++){
					match = location.href.match(urls[i].ohs[j])
					if (match!=null) {
						idx=location.href.indexOf(match[0]);
						rxmatch=true;
						break;
					}
				}
			}
			if (rxmatch) {
				idx=idx+match[0].length;hname=urls[i].tsh+match[0].replace(urls[i].ohs[j],urls[i].tsdr[j]);
				found=true;
			} else {
				for (j=0;j<urls[i].oh.length;j++){ 
					idx=location.href.indexOf(urls[i].oh[j]);
					if(idx>-1) {
						idx=idx+urls[i].oh[j].length;hname=urls[i].tsh+urls[i].tsd[j];
						found=true;
						break;
					}
				}
			}
		}else{
			if (urls[i].tsds != null) {
				for (j=0;j<urls[i].tsds.length;j++){
					match = location.href.match(urls[i].tsds[j])
					if (match!=null) {
						idx=location.href.indexOf(match[0]);
						rxmatch=true;
						break;
					}
				}
			}
			if (rxmatch) {
				idx=idx+match[0].length;hname=match[0].replace(urls[i].tsds[j],urls[i].ohr[j]);
				found=true;
			} else {
				for (j=0;j<urls[i].tsd.length;j++){ 
					idx=location.href.indexOf(urls[i].tsd[j]);
					if(idx>-1) {
						idx=idx+urls[i].tsd[j].length;hname=urls[i].oh[j];
						found=true;
						break;
					}
				}
			}
		}
		if (found) break;
	}
	path=location.href.substring(idx);
	hend=hname.charAt(hname.length-1);pstart=path.charAt(0);
	if(hend=='/' && pstart=='/')path=path.substring(path.indexOf('/')+1);
	if(hend!='/' && pstart!='/')path='/'+path;
	location.href=location.protocol+'//'+hname+path;
	return false;
}
function URLData(tsh, oh, tsd, ohs, tsds, ohr, tsdr) {
	this.tsh = tsh;
	this.oh = oh;
	this.tsd = tsd;
	this.ohs = ohs;
	this.tsds = tsds;
	this.ohr = ohr;
	this.tsdr = tsdr;
}

function init()
{
}

//Call the initialization

//YAHOO.util.Event.addListener(window, "load", init);