// JavaScript Document
var xmlHttp = null;

function $(id) {
	return document.getElementById(id);
}

var tab_id_last = 0;
function nextstep() {
	if(tab_id_last >= 5) {
		//对所有classname为required的进行验证
		//submit form
		//return;
		document.itsail_form_1.submit(); 
	}
	
	form_tabs(tab_id_last + 1);
}
function form_tabs(tab_id) {
	$('form_tabs_' + tab_id).className = "on";
	$('form_confidential_' + tab_id).className = "on";
	
	if(tab_id_last > 0) {
		$('form_tabs_' + tab_id_last).className = "";
		$('form_confidential_' + tab_id_last).className = "";
	}
	
	tab_id_last = tab_id;
	window.location.href="#";
}

//viewFLV(382,360,"Salon_Camera_360_Flash","SalonCamera1");
function showlightbox(ShowUrl) {
	$('lightbox_content').style.display = 'block';
	$('lightbox_content').style.top = (document.documentElement.scrollTop + 300) + "px";
	$('lightbox_bg').style.display = 'block';

	if(xmlHttp == null) {
		creatXMLHttpRequest();
		if(xmlHttp == null) {
			$('lightbox_area').innerHTML = "Can't creat XMLHttpRequest Object, loading files failed!";
			return false;
		}
	}

	$('lightbox_area').innerHTML = '<img src="image/loading.gif" width="100" height="100" style="margin-top:120px;margin-left:260px;" />';

	ShowUrl = ShowUrl + "&itemid=85&inajax=1";
	xmlHttp.open("POST", "index.php", true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				$('lightbox_area').innerHTML = xmlHttp.responseText;
				SalonCamera(1);
			}
		}
	};
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-Length", ShowUrl.length);
	xmlHttp.send(ShowUrl);
}

function closelightbox() {
	$('lightbox_content').style.display = 'none';
	$('lightbox_bg').style.display = 'none';
}


function creatXMLHttpRequest() {
	if(window.ActiveXObject) {
		xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	} else if(window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}

function viewFLV(width, height, id, name) {
	var so = new SWFObject('player.swf',name,width,height,'9');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	so.addParam("wmode", "transparent");
	so.addParam('flashvars','file=upload/flash/' + name + '.flv&autostart=false&fullscreen=true');
	so.write(id);
}

function viewFLV2(width, height, id, name) {
	var so = new SWFObject('player.swf',name,width,height,'9');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	so.addParam("wmode", "transparent");
	so.addParam('flashvars','file=upload/flash/' + name + '.flv&autostart=false&fullscreen=true');
	so.write(id);
}

function SalonCamera(v) {
	for(i=1;i<4;i++) {
		if(i==v) {
			$('SalonCamera_li_' + i).className = "on";
		} else {
			$('SalonCamera_li_' + i).className = "";
		}
	}
	
	viewFLV(420,350,"Salon_Camera_360_Flash","SalonCamera" + v);
}


var oNav = menuId = itemId = lastId = null;
var oImg = new Array();
var navSub = new Array();
var timerID = new Array();
var navSubWidth = new Array(124,124,0,0,0,90,0);
function itsNav(dMenuId) {
	oNav = $('header_nav');
	oImg = oNav.getElementsByTagName("IMG");

	if(dMenuId >= 0) {
		itsNavOver(oImg[dMenuId], 1);
		menuId = dMenuId;
	}

	for(i = 0; i < oImg.length; i++) {
		oImg[i].id = "nav_item_" + i;
		oImg[i].onmouseover = function(){itsNavOver(this);};
		oImg[i].onmouseout = function(){itsNavOut(this);};

		oSub = $("nav_sub_" + i);
		if(oSub != null) {
			oSub.onmouseover = function(){itsNavSubOver(this);};
			oSub.onmouseout = function(){itsNavSubOut(this);};
		}
		navSub[i] = oSub;
	}

	window.document.onclick = function (){
		itsNavSubClose(lastId);
	}
}

function itsNavSubOver(o) {
	subId = o.id.replace("nav_sub_", "");
	if(timerID[subId] != null) clearTimeout(timerID[subId]);
}

function itsNavSubOut(o) {
	subId = o.id.replace("nav_sub_", "");
	timerID[subId] = setTimeout("itsNavSubClose(" + subId + ")", 500);
}

function itsNavSubClose(subId) {
	if(navSub[subId] != null) navSub[subId].style.display = "none";
	//if(oImg[subId] != null && subId != menuId) oImg[subId].src = oImg[subId].src.replace("_on.jpg", ".jpg");
	if(oImg[subId] != null && subId != menuId && oImg[subId].src.indexOf("_on.jpg") > 0) oImg[subId].src = oImg[subId].src.replace("_on.jpg", ".jpg");
}

function itsNavOver(o, c) {
	itemId = o.id.replace("nav_item_", "");

	//Show Sub Item
	if(c == 1) {
		o.src = o.src.replace(".jpg", "_on.jpg");
	} else if(navSub[itemId] != null) {
		clearTimeout(timerID[itemId]);

		iPos = itsObjPosition(oImg[itemId]);
		navSub[itemId].style.top = (iPos[0] + oImg[itemId].height + 18) + "px";
		navSub[itemId].style.left = (iPos[1] + oImg[itemId].width - navSubWidth[itemId]) + "px";
		//alert(navSubWidth[itemId]);

		if(lastId != itemId) itsNavSubClose(lastId);
		if(itemId != menuId && o.src.indexOf("_on.jpg") == -1) o.src = o.src.replace(".jpg", "_on.jpg");
		navSub[itemId].style.display = "block";
	}

	lastId = itemId;
}

function itsNavOut(o) {
	itemId = o.id.replace("nav_item_", "");
	if(navSub[itemId] != null) itsNavSubOut(navSub[itemId]);
}

function itsObjPosition(obj) {
	var top = 0, left = 0;
	do {
		top += obj.offsetTop;
		left += obj.offsetLeft;
	} while (obj = obj.offsetParent);

	var arr = new Array();
	arr[0] = top;
	arr[1] = left;

	return arr;
}
