// JavaScript Document
var p;
var xmlHttp;
function createXMLHttpRequest(){
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}

function MM_findObj(n, d) { //v4.01
  	var p,i,x;  
  	if(!d) 
  		d = document; 
		
	if((p = n.indexOf("?")) > 0 && parent.frames.length){
		d = parent.frames[n.substring(p+1)].document;
		n = n.substring(0,p);
	}
	
	if(!(x=d[n]) && d.all) 
		x = d.all[n]; 
	
	for (i=0; !x && i<d.forms.length; i++) 
		x = d.forms[i][n];
		
	for(i=0; !x && d.layers && i < d.layers.length; i++) 
		x = MM_findObj(n,d.layers[i].document);
		
	if(!x && d.getElementById) 
		x = d.getElementById(n); 

	return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function RequireItem(Name,Msg) { 
	var obj=MM_findObj(Name);
	if (obj.value=='')
		return '<span class="error">' + Msg + '</span>';
	else
		return '';
}
function RequireEmail(Name, Msg){
	var obj=MM_findObj(Name);
	if(obj.value!=''){
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (filter.test(obj.value)) 
			return '';
		else
			return '<span class="error">' + Msg + '</span>';
	}
	return '';
}
function RequireFCK(Name, Msg){
	var oEditor = FCKeditorAPI.GetInstance(Name).GetXHTML( true ) ;
	if(oEditor == '')
		return '<span class="error">' + Msg + '</span>';
	else
		return '';
}
function CheckLength(Name,Len,Msg){
	var obj=MM_findObj(Name);
	if(obj.value!=''){
		if (obj.value.length<Len) 
			 return '<span class="error">' + Msg + '</span>';
		else
			return '';
	}
	return '';

}
function CheckMath(Name1,Name2,Msg){
	var obj1=MM_findObj(Name1);
	var obj2=MM_findObj(Name2);
	if(obj1.value != "" && obj2.value != ""){
		if (obj1.value != obj2.value) 
			 return '<span class="error">' + Msg + '</span>';
		else
			return '';
	}
	return '';
}

function __doPostBack(eventTarget, eventArgument, formName) {
	var theform = makeTheForm(formName);
	
	theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
	theform.__EVENTARGUMENT.value = eventArgument;
	theform.submit();
}

function makeTheForm(formName){
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
		theform = eval("document."+formName);
	else
		theform = document.forms[formName];
	return theform;
		
}

function __alert(alert_content){
	alert(alert_content);
}

function __CheckTogle(formName){
	len = document.forms[formName].elements.length;
	for(var i = 0 ; i < len ; i++) {
		if (document.forms[formName].elements[i].id == "chk_list" && document.forms[formName].elements[i].checked) {
			return true;
		}
	}
	return false;
}

function __CheckConfirm(formName, Code){
	var error = '';
	len = document.forms[formName].elements.length;
	for(var i = 0 ; i < len ; i++) {
		if (document.forms[formName].elements[i].id == "chk_list" && document.forms[formName].elements[i].checked) {
			//var Px = document.forms[FormName].elements[i].getAttribute("title").split(":");
			error += '\n - ' + document.forms[formName].elements[i].getAttribute("title");
			
		}
	}
	
	if( confirm('Do you want to delete ' + Code + '? ' + error + '\n\n Please click "OK" to delete Or click "Cancel" to cancel delete.') )
		return true;
	else
		return false;
}

function select_all(formName){
	var len = document.forms[formName].chk_list.length;
	if(document.forms[formName].chk_main.checked){
		for(var i=0; i<len; i++) 
			document.forms[formName].chk_list[i].checked = true;
			
		if(len = typeof('undefined')) 
			document.forms[formName].chk_list.checked = true; 
	}else{
		for(var i=0; i<len; i++) 
			document.forms[formName].chk_list[i].checked = false;
			
		if(len = typeof('undefined')) 
			document.forms[formName].chk_list.checked = false;	
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features, vWidth, vHeight) { //v2.0
  win = window.open(theURL,winName,features);
  var pageSize = getPageSize();
  var left = (pageSize[0] - vWidth) / 2;
  var top = (pageSize[1] - vHeight) / 2;
  win.moveTo(left, top);
}

function embledCSS(path, name){
	if(navigator.appVersion.indexOf("MSIE") > -1){
		document.write('<link href="../js/'+ path + 'Css/' + name +'IE.css" rel="stylesheet" type="text/css" />');
	}else{
		document.write('<link href="../js/'+ path + 'Css/' + name +'FireFox.css" rel="stylesheet" type="text/css" />');	
	}
}

function getValue(pForm) {
	var len = pForm.elements.length;
	var nParams = new Array();
	for(i=0; i<len; i++){
		if(pForm.elements[i].type == "checkbox" || pForm.elements[i].type == "radio"){
			if( pForm.elements[i].checked == true){
				var pParam = encodeURIComponent(pForm.elements[i].name);
				pParam += '=';
				pParam += encodeURIComponent(pForm.elements[i].value);
				nParams.push(pParam);	
			}			
		}else{
			var pParam = encodeURIComponent(pForm.elements[i].name);
			pParam += '=';
			pParam += encodeURIComponent(pForm.elements[i].value);
			nParams.push(pParam);
		}
	}
	return nParams.join('&');
}


/* SUBSCRIBE ZONE ONLY */
window.addEvent('domready', function(){
	if($('subscribe')){
		var Tips = new Prototips($('subscribe'), { fixed:true, closeBx:true});
		createXMLHttpRequest();
		$('submitSubscribe').addEvent('click', function(){
			Tips.hide();
			var val = $('subscribe').getProperty('value');
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
			if(val != ""){
				if( !filter.test(val) ){
					Tips.receive($('subscribe'), '<font color="#990000">Sorry, your email is not proper format.  Please enter again.</font>');
					$('subscribe').focus();
				}else{
					xmlHttp.open("GET","_ajax/subscribe.php?EMail=" + val,true);
					xmlHttp.onreadystatechange = function(){
						if(xmlHttp.readyState == 4){
							if(xmlHttp.status == 200){
								var c = xmlHttp.responseText.split('::');
								if(c[0] == 1){
									Tips.receive($('subscribe'), c[1]);
									$('subscribe').setProperty('value', '');
								}else{
									Tips.receive($('subscribe'), c[1]);
									$('subscribe').focus();
								}
							}
						}
					};
					xmlHttp.send(null);
				}
			}else{
				Tips.receive($('subscribe'), '<font color="#990000">Please enter you email address.</font>'); 
				$('subscribe').focus();	
			}
		});
	}
});
