var Blind = new Object();

Blind.Display = function (oTab, isHideSlt) {

	Blind.ZIndex = 1982;
	Blind.Alpha = 0;
	

	Blind.BoxDiv = document.createElement("div");
	Blind.PopDiv = document.createElement("div");
	Blind.BgDiv = document.createElement("div");

	Blind.BoxDiv.appendChild(Blind.PopDiv);
	Blind.BoxDiv.appendChild(Blind.BgDiv);
	Blind.BoxDiv.style.display = "block";
	document.body.appendChild(Blind.BoxDiv);
	var flashDiv = document.getElementById("flashDiv");
	//alert(flashDiv);
	flashDiv.style.visibility="hidden";
	
	Blind.OpTab = oTab || document.getElementById("BlindTab");
	Blind.IsHideSlt = (isHideSlt==null) ? true : isHideSlt;

	with (Blind.PopDiv){
		if (hasChildNodes()&&(childNodes[0]!=Blind.OpTab))
			removeChild(childNodes[0]);
		appendChild(Blind.OpTab);
		Blind.OpTab.style.display = "block";
		with (style) {
			position = "absolute";
			top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-document.getElementById("middle").offsetHeight)/2)+"px";
			left=window.screen.availWidth/2-Blind.PopDiv.clientWidth/2 + "px";
			zIndex = Blind.ZIndex;
		}
	}

	if (!Blind.IsHideSlt) {
		Blind.Frame = document.createElement("iframe");
		with (Blind.Frame) {
			src = "";
			scrolling = "no";
			frameBorder = "0";
			with (style){
				position = "absolute";
				top = Blind.PopDiv.offsetTop;
				left = Blind.PopDiv.offsetLeft;
				width = Blind.PopDiv.offsetWidth;
				height = Blind.PopDiv.offsetHeight;
			}
		}
		Blind.BoxDiv.appendChild(Blind.Frame);
	}
	Blind.Gradual();
	if (Blind.IsHideSlt)
		Blind.CtrlSlt(true, true);
	else
		Blind.CtrlSlt(true, false);
	Blind.Move();

}

Blind.Close = function(){

	Blind.BoxDiv.style.display = "none";
	if (Blind.IsHideSlt)
		Blind.CtrlSlt(false, true);
	else
		Blind.CtrlSlt(false, false);
	Blind.Alpha = 0;
	var flashDiv = document.getElementById("flashDiv");
	flashDiv.style.visibility="visible";
	
	//document.getElementById("idselect2").options[0].selected=true;
}

Blind.Gradual = function() {
	if (Blind.Alpha > 50) return;
	Blind.Alpha += 10;
	with (Blind.BgDiv.style) {
		position = "absolute";
		top = "0px";
		left = "0px";
		zIndex = Blind.ZIndex - 1;
		background = "#000";
		cursor = "not-allowed";
		if (document.all) {	//For IE
			height = document.body.clientHeight;
			width = document.body.clientWidth;
			filter = "Alpha(Opacity=" + Blind.Alpha + ")";
		}
		else {
			height = "180%";
			width = "100%";
			MozOpacity = Blind.Alpha / 100;
		}
	}
	setTimeout("Blind.Gradual()", 100);
}

Blind.Move = function (){
	var o = document.getElementById("alphaMove") || Blind.OpTab.getElementsByTagName("h2")[0];
	
}

Blind.CtrlSlt = function(isOn, isHide) {
	//var slt = document.getElementsByTagName("select");
	//if (isHide)
	//	for (var i=0; i<slt.length; i++)
		//	slt[i].style.visibility = isOn ? "hidden" : "visible";
	//else
		//for (var i=0; i<slt.length; i++)
		//	slt[i].disabled= isOn ? true : false;
}


function sendSMS(){

		var sendSMSResultDIV = document.getElementById("sendSMSResult");
		sendSMSResultDIV.style.visibility="visible";  
		var sendHintDIV = document.getElementById("sendHint");
		var dive = document.getElementById("SMSButton")
		var leftp = dive.offsetLeft;
		var topp = dive.offsetTop;
		while (dive = dive.offsetParent)   {
			leftp += dive.offsetLeft;		
			topp += dive.offsetTop;  
		}
		
	    sendSMSResultDIV.style.top = (topp+20) + "px";
		sendSMSResultDIV.style.left =leftp + "px";
		sendSMSResultDIV.style.display="block";
			var val = validate();
			//alert(val);
	if(!val){
		return;
	} 
		sendHintDIV.innerHTML="The SMS is being sent......";
		var cellPhone = document.getElementById('textfield4').value+document.getElementById('textfield22').value+document.getElementById('textfield32').value;
		//alert(cellPhone);
			var v = document.getElementById("sendSMS");
			if(v!=null){
				document.body.removeChild(v);
			}
			var now = new Date();
			var content = "http://wap.webex.com"
			var url = "/LabsSite/sendSMSAction.do?cellPhone=" + cellPhone+"&content="+content+"&currentTime=" + now;
			url = encodeURI(url);
			//alert(url);
			var js_obj = document.createElement("script");
			js_obj.type = "text/javascript";
			js_obj.setAttribute("src", url);
			js_obj.setAttribute("id", "sendSMS");
			document.body.appendChild(js_obj);
			// Add by Arthur
			setTimeout("directBack()",1000);
	}
	

	// Add by Arthur
	function directBack(){
		var sendSMSHintDIV = document.getElementById("sendHint");
		var cellPhone = document.getElementById('textfield4').value+"-"+document.getElementById('textfield22').value+"-"+document.getElementById('textfield32').value;
		sendSMSHintDIV.innerHTML="SMS was sent out.";
		setTimeout("closeDiv()",2000);
		//clearInterval(clearIn);
	}

	function callbackSendSMS(success){
		// Modify by Arthur
		/*
		var sendSMSHintDIV = document.getElementById("sendHint");
		var cellPhone = document.getElementById('textfield4').value+"-"+document.getElementById('textfield22').value+"-"+document.getElementById('textfield32').value;
		if(success =='true'){
		sendSMSHintDIV.innerHTML="<font color='#009900'>Has been sent to your phone.</font>";
		}else{
		sendSMSHintDIV.innerHTML="<font color='#FF0000'>Sending SMS failed.</font>";
		}
		setTimeout("closeDiv()",1000);
		//clearInterval(clearIn);
		*/
	}

	function closeDiv(){
		var sendSMSResultDIV = document.getElementById("sendSMSResult");
		sendSMSResultDIV.style.display="none"; 
		
	}

	function checkNumber(e)
	{
		var key = window.event ? e.keyCode : e.which;
		var keychar = String.fromCharCode(key);
		reg = /\d/; 
		if(key==8){
			return true;
		}
		var target = window.event?document.activeElement:e.explicitOriginalTarget;
		//alert(document.getElementById('textfield4').value.length);
		if(target.id=='textfield4'&&document.getElementById('textfield4').value.length>2){
			return false;
		}
		if(target.id=='textfield22'&&document.getElementById('textfield22').value.length>2){
			return false;
		}
		if(target.id=='textfield32'&&document.getElementById('textfield32').value.length>3){
			return false;
		}
		var result = reg.test(keychar);
		if(!result)    
		{ 
			return false;   
		}   
		else    
		{  
			return true;   
		}    
	} 
	
	function validate(){
		var sendSMSResultDIV = document.getElementById("sendSMSResult");
		var sendHintDIV = document.getElementById("sendHint");
		if(document.getElementById('textfield4').value.length<3){
			var left = sendSMSResultDIV.offsetLeft-230;
			sendSMSResultDIV.style.left = (left)+"px";
			//alert(sendSMSResultDIV.style.left);
			sendHintDIV.innerHTML="<font color='#FF0000'>No less than 3 digits.</font>";
			document.getElementById('textfield4').focus();
			var clearIn = setTimeout("closeDiv()",4000);		
			return false;
		}
		if(document.getElementById('textfield22').value.length<3){
			var left = sendSMSResultDIV.offsetLeft-170;
			sendSMSResultDIV.style.left = (left)+"px";
			sendHintDIV.innerHTML="<font color='#FF0000'>No less than 3 digits.</font>";
			document.getElementById('textfield22').focus();
			setTimeout("closeDiv()",4000);		
			return false;
		}
		if(document.getElementById('textfield32').value.length<4){
			var left = sendSMSResultDIV.offsetLeft-120;
			sendSMSResultDIV.style.left = (left)+"px";
			document.getElementById('textfield32').focus();
			sendHintDIV.innerHTML="<font color='#FF0000'>No less than 4 digits.</font>";
			clearIn = setTimeout("closeDiv()",4000);		
			return false;
		}
		return true;
	}
	
	function showHint(){
	  var hintDiv = document.getElementById("hint");
	  var dive = document.getElementById("textfield4")
		var leftp = dive.offsetLeft;
		var topp = dive.offsetTop;
		while (dive = dive.offsetParent)   {
			leftp += dive.offsetLeft;		
			topp += dive.offsetTop;  
		}
		
	    hintDiv.style.top = (topp-20) + "px";
		hintDiv.style.left =(leftp-165) + "px";
		hintDiv.style.display="block";
	}
	
		function closeHintDiv(){
		var hintDiv = document.getElementById("hint");
		hintDiv.style.display="none"; 
	}