//
//
// For fun / common functionality
//

//return  url query for country/market/language
function AWI_cml() {
	var pg = window.location.pathname;
	// /commfloor/Market/lang/cntry/page.foo
	//  \/(.+)\/(.+)\/.+\/(.+)\/.*
	var re = pg.match(/^\/.+\/(.+)\/(.+)\/(.+)\/.*/);
	return   "&market=" + re[1] + "&languageId=" + re[2] + "&countryId=" + re[3];
}

function AWI_goto(where) {
	//NOTE - escape ain't UNICODE happy!
	location.href=where + "?src=" + escape(AWI_thisPage()) ;
}

function AWI_thisPage() {
	var pg = document.URL;
	//now strip off http[s]://myhostname[.mydomain.com]
	return pg.replace(/^https{0,1}:\/\/[^\/]+/i, "");
}

function AWI_myProfile() {
	AWI_goto("goto_my_profile.service");
}

function AWI_myBasket() {
	location.href="my_cart_view.app";
}

function AWI_myBinder() {
	AWI_goto("goto_my_binder.service");
}



function AWI_showAssetSpec(lineId) {
	AWI_showAsset("goto_specntech.service?specificationFormat=S&lineId=" + lineId);
}

function AWI_showAssetTech(lineId) {
	AWI_showAsset("goto_specntech.service?specificationFormat=T&lineId=" + lineId);
}


function AWI_showAsset(asset) {
	//popup a window
	var props = "dependent=yes";
	props+= ",directories=no";
	props+= ",height=600";
	props+= ",location=no";
	props+= ",menubar=yes";
	props+= ",resizable=no";
	props+= ",scrollbars=yes";
	props+= ",status=no";
	props+= ",toolbar=no";
	props+= ",width=800";
	props+= ",screenX=1";
	props+= ",screenY=1";
	props+= ",left=1";
	props+= ",top=1";



	var w=window.open(asset, "_BLANK", props);
	w.focus();
	return  w;
}

function AWI_showChangeLanguage() {
	//popup a window
	var props = "dependent=yes";
	props+= ",directories=no";
	props+= ",height=275";
	props+= ",location=no";
	props+= ",menubar=no";
	props+= ",resizable=no";
	props+= ",scrollbars=yes";
	props+= ",status=no";
	props+= ",toolbar=no";
	props+= ",width=350";
	props+= ",screenX=150";
	props+= ",screenY=150";
	props+= ",left=150";
	props+= ",top=150";

	var w=window.open("switch_language.content", "switch_language", props);
	w.focus();
	return  w;
}

function AWI_switchLanguage(which) {
	var pg = window.location.pathname;
	// /commfloor/MARket/lang/cntry/page.foo
	//  \/(.+)\/(.+)\/.+\/(.+)\/.*
	var re = pg.match(/^\/(.+)\/(.+)\/.+\/(.+)\/.*/);
	pg = '/' + re[1] + '/' + re[2] + '/' + which + '/' + re[3] + '/';
	location.href=pg;
}

function AWI_enlarge(myPicture, widthOverride, heightOverride) {
	//popup a window
	var props = "dependent=yes";
	props+= ",directories=no";
	props+= ",location=no";
	props+= ",menubar=no";
	props+= ",resizable=no";
	props+= ",scrollbars=yes";
	props+= ",status=no";
	props+= ",toolbar=no";
	props+= ",screenX=100";
	props+= ",screenY=100";
	props+= ",left=100";
	props+= ",top=50";
	if (AWI_enlarge.arguments.length>=2) {
		props+= ",width=" + AWI_enlarge.arguments[1];
		if (AWI_enlarge.arguments.length>=3) {
			props+= ",height=" + AWI_enlarge.arguments[2];
		} else {
			props+= ",height=600";
		}
	} else {
		props+= ",width=540";
		props+= ",height=580";
	}


	var w=window.open("", "swatch", props);
	w.focus();

	w.document.close();
	w.document.open();
	w.document.writeln("<HTML><HEAD><TITLE>Enlarged Image</TITLE></HEAD>");
	w.document.writeln('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
	w.document.writeln("<P style='font-family : Verdana,Geneva,Arial,sans-serif;font-size : 11px;' ALIGN='CENTER'><IMG SRC='" + myPicture + "' ALT='enlarged picture' />");
	w.document.writeln("<BR />&copy; 2000-2007 AWI Licensing Company. All rights reserved. </P></BODY></HTML>");
	w.document.close();

	return  w;
}

function AWI_showIconKey() {
	var props = "dependent=yes";
	props+= ",directories=no";
	props+= ",location=no";
	props+= ",menubar=no";
	props+= ",resizable=yes";
	props+= ",scrollbars=yes";
	props+= ",status=yes";
	props+= ",toolbar=no";
	props+= ",screenX=50";
	props+= ",screenY=50";
	props+= ",left=50";
	props+= ",top=50";
	props+= ",width=470,height=425";


	var w=window.open("icon_key.content", "icon_help", props);
	w.focus();

	return  w;
}

