function popWindowMain(winURL,winName,winWidth,winHeight,winMenu,winResize,winScroll,winStatus,winToolbar,winOffset) {
	var popWinMain = null;

	//Always Centre Window
	var winPosX = (window.screen.width/2)-(winWidth/2);
	var winPosY = (window.screen.height/2)-(winHeight/2);
	
	if (winOffset) {
		//Offset window from centre
		winPosX = winPosX + 40;
		winPosY = winPosY + 40;
	}

	//Build Window Features
	var winFeatures = "height=" + winHeight
					+ ", width=" + winWidth
					+ ", innerHeight=" + winHeight
					+ ", innerWidth=" + winWidth
					+ ", channelmode=0"
					+ ", dependent=0"
					+ ", directories=0"
					+ ", fullscreen=0"
					+ ", location=0"
					+ ", menubar=" + winMenu
					+ ", resizable=" + winResize
					+ ", scrollbars=" + winScroll
					+ ", status=" + winStatus
					+ ", toolbar=" + winToolbar
					+ ", screenx=" + winPosX
					+ ", screeny=" + winPosY
					+ ", left=" + winPosX
					+ ", top=" + winPosY;
					//Only use the following attributes with a signed script:
					//-------------------------------
					//+ ", hotkeys=1"
					//+ ", alwaysLowered=0"
					//+ ", alwaysRaised=0"
					//+ ", titlebar=0"
					//+ ", z-lock=0"
					//-------------------------------

	var reWork = new RegExp('object','gi');
	try {
		//Pop the window
		popWinMain = window.open(winURL, winName, winFeatures);
		if (window.focus) { popWinMain.focus(); }
	} catch(e) { }
	if(!reWork.test(String(popWinMain))) {
		//Failed to open - killed by pop-up blocker
		alert("This window could not be opened because you have a 'Pop-Up Blocker' enabled.\n\nPlease Disable your 'Pop-Up Blocker' and try again.");
	}
}

function funcOpenNewWindow(filename,wWidth,wHeight) {
	popWindowMain(filename,'',wWidth,wHeight,0,1,1,0,0,0);
}

function funcDetail(username) {
	popWindowMain('detail.php?username='+username,'',424,460,0,1,1,0,0,0);
}

function funcProfile(username) {
	popWindowMain('shortprofile.php?username='+username,'',422,410,0,1,1,0,0,0);
}

function funcMessage(username) {
	popWindowMain('message.php?username='+username,'',424,320,0,1,1,0,0,0);
}

function funcViewPhoto(username) {
	popWindowMain('view_photo.php?id='+username,'',530,560,0,1,1,0,0,0);
}

function funcViewPhoto2(username,membertype) {
	if (membertype == '2') {
		popWindowMain('view_photo.php?id='+username,'',530,560,0,1,1,0,0,0);
	} else {
		alert('HANYA UNTUK GOLD MEMBER!\nGold Member dapat melihat foto ukuran sebenarnya / foto lainnya.');
	}
}

function funcViewPrivatePhoto(username) {
	popWindowMain('view_private_photo.php?id='+username,'',530,560,0,1,1,0,0,0);
}

function funcAdminViewProfile(username) {
	popWindowMain('user_profile.php?username='+username,'',380,520,0,1,1,0,0,0);
}

function funcAdminViewPhoto(username) {
	popWindowMain('user_photo.php?id='+username,'',560,560,0,1,1,0,0,0);
}

function funcAdminViewPhotoById(username,photoid) {
	popWindowMain('user_photo.php?id='+username+'&pid='+photoid,'',560,560,0,1,1,0,0,0);
}

function funcHotlist(hotuser) {
	popWindowMain('add_hotlist.php?hotuser='+hotuser,'',350,120,0,0,0,0,0,0);
}

function funcEmailPayment(payment_type) {
	popWindowMain('email_payment.php?t='+payment_type,'',350,120,0,0,0,0,0,0);
}

function funcPrintPayment(payment_type) {
	popWindowMain('print_payment.php?t='+payment_type,'',720,550,1,1,1,1,1,0);
}

function isEmail(emailAddress) {
	var result;
	var re = /^[\_\-\.0-9a-zA-Z]+\@([0-9a-zA-Z][0-9a-zA-Z]+\.)+[a-zA-Z]{2,4}$/;
	var r = emailAddress.match(re);
	result = ((r != null) ? true : false);
	return(result);
}

function isAlphanumeric(theString) {
	var result;
	var re1 = /[A-Za-z0-9_]{3,}/;
	var re2 = /[^A-Za-z0-9_]/;
	var r1 = theString.match(re1);
	var r2 = theString.match(re2);
	result = ((r1 == null) ? false : true) && ((r2 == null) ? true : false);
	return(result);
}

function isNumeric(theString) {
	var result;
	var re1 = /[0-9]{2,}/;
	var re2 = /[^0-9]/;
	var r1 = theString.match(re1);
	var r2 = theString.match(re2);
	result = ((r1 == null) ? false : true) && ((r2 == null) ? true : false);
	return(result);
}

function isNumeric2(theString) {
	var result;
	var re1 = /[0-9+-]{5,}/;
	var re2 = /[^0-9+-]/;
	var r1 = theString.match(re1);
	var r2 = theString.match(re2);
	result = ((r1 == null) ? false : true) && ((r2 == null) ? true : false);
	return(result);
}

function isNumeric3(theString) {
	var result;
	var re1 = /[0-9]{1,}/;
	var re2 = /[^0-9]/;
	var r1 = theString.match(re1);
	var r2 = theString.match(re2);
	result = ((r1 == null) ? false : true) && ((r2 == null) ? true : false);
	return(result);
}

function isNumeric4(theString) {
	var result;
	var re1 = /[0-9]{4,}/;
	var re2 = /[^0-9]/;
	var r1 = theString.match(re1);
	var r2 = theString.match(re2);
	result = ((r1 == null) ? false : true) && ((r2 == null) ? true : false);
	return(result);
}

function isNumeric5(theString) {
	var result;
	var re1 = /[0-9.]{1,}/;
	var re2 = /[^0-9.]/;
	var r1 = theString.match(re1);
	var r2 = theString.match(re2);
	result = ((r1 == null) ? false : true) && ((r2 == null) ? true : false);
	return(result);
}

function FineWordLength(theString,maxLength) {
	var nString = theString.length;
	var arraySentence = theString.split('\n');
	var nSentence = arraySentence.length;
	
	if (nSentence > 0) {
		for (i=0; i<=(nSentence-1); i++) {
			var arrayWord;
			var nWord;
			arrayWord = arraySentence[i].split(' ');
			nWord = arrayWord.length;
			for (j=0; j<=(nWord-1); j++) {
				if (arrayWord[j].length > maxLength) {
					return arrayWord[j];
				}
			}
		}
	}
	return "";
}

function howManyWords(theString) {
	var nString = theString.length;
	var arraySentence = theString.split('\n');
	var nSentence = arraySentence.length;
	var result = 0;
	
	if (nSentence > 0) {
		for (i=0; i<=(nSentence-1); i++) {
			if (arraySentence[i].length > 1) {
				result = result + arraySentence[i].split(' ').length;
			}
		}
	}
	return result;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g,'');
}

function BrowserName() {
	var nVer = navigator.appVersion;
	var nAgt = navigator.userAgent;
	var browserName  = navigator.appName;
	var fullVersion  = ''+parseFloat(navigator.appVersion); 
	var majorVersion = parseInt(navigator.appVersion,10);
	var nameOffset,verOffset,ix;
	
	// In MSIE, the true version is after "MSIE" in userAgent
	if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
		browserName = "Microsoft Internet Explorer";
		fullVersion = nAgt.substring(verOffset+5);
	}
	// In Opera, the true version is after "Opera" 
	else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
		browserName = "Opera";
		fullVersion = nAgt.substring(verOffset+6);
	}
	// In Chrome, the true version is after "Chrome" 
	else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
		browserName = "Chrome";
		fullVersion = nAgt.substring(verOffset+7);
	}
	// In Safari, the true version is after "Safari" 
	else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
		browserName = "Safari";
		fullVersion = nAgt.substring(verOffset+7);
	}
	// In Firefox, the true version is after "Firefox" 
	else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
		browserName = "Firefox";
		fullVersion = nAgt.substring(verOffset+8);
	}
	// In most other browsers, "name/version" is at the end of userAgent 
	else if ((nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/'))) {
		browserName = nAgt.substring(nameOffset,verOffset);
		fullVersion = nAgt.substring(verOffset+1);
		if (browserName.toLowerCase()==browserName.toUpperCase()) {
			browserName = navigator.appName;
		}
	}
	// trim the fullVersion string at semicolon/space if present
	if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
	if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);
	
	majorVersion = parseInt(''+fullVersion,10);
	if (isNaN(majorVersion)) {
		fullVersion  = ''+parseFloat(navigator.appVersion); 
		majorVersion = parseInt(navigator.appVersion,10);
	}
	return browserName;
}

function ResizeWindow(width,height) {
	var browserName = BrowserName();
	var newWidth, newHeight;
	if (browserName == "Microsoft Internet Explorer") {
		newWidth = width;
		newHeight = height;
	} else if (browserName == "Firefox") {
		newWidth = width - 21;
		newHeight = height - 11;
	} else if (browserName == "Opera") {
		newWidth = width - 20;
		newHeight = height - 45;
	} else if (browserName == "Safari") {
		newWidth = width - 33;
		newHeight = height - 69;
	} else if (browserName == "Chrome") {
		newWidth = width - 21;
		newHeight = height - 33;
	} else {
		newWidth = width - 21;
		newHeight = height - 11;
	}
	window.resizeTo(newWidth,newHeight);
}

function KeyDownHandler(e,buttonID) {
	var keyCode;
	if (e && e.which) {
		e = e;
		keyCode = e.which;
	} else {
		e = event;
		keyCode = e.keyCode;
	}
	if ((keyCode == 13) && (document.getElementById(buttonID) != null)) {
		document.getElementById(buttonID).click();
	}
}

function firstFocus(elemenID) {
	var myField = document.getElementById(elemenID); 
	if (myField != null) {
		myField.focus();
		myField.selectionStart = '0';
		myField.selectionEnd = '0';
		myField.scrollTop = '0';
	}
}

function funcCloseWindow() {
	window.close();
}

function funcBack() {
	window.history.back();
}

function funcGoHomepage() {
	window.location.href = "index.php";
}

function funcGoWebboard(relURL) {
	window.location.href = relURL;
}

function funcGo2URL(relURL) {
	window.location.href = relURL;
}

function edInsertContent(elementID, myValue) {
    myField = document.getElementById(elementID);
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
		myField.focus();
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		var scrollTop = myField.scrollTop;
		myField.value = myField.value.substring(0, startPos) + myValue  + myField.value.substring(endPos, myField.value.length);
		myField.focus();
		myField.selectionStart = startPos + myValue.length;
		myField.selectionEnd = startPos + myValue.length;
		myField.scrollTop = scrollTop;
	} else {
		myField.value += myValue;
		myField.focus();
	}
}

function funcInsertEmoticon(code) {
	edInsertContent('txtMailBody', code);
}

function funcLoading() {
    document.getElementById("loadingText").style.visibility = "visible";  
}

function funcReLoading() { 
    window.setTimeout("funcLoading()", 500); 
}

function funcLoadingBar() {
    document.getElementById("loadingbar").style.display = "inline";  
}

function funcReLoadingBar() { 
    window.setTimeout("funcLoadingBar()", 500); 
}

function CreateXMLHttpRequest() {
	var xhttp;
   		try {
      		xhttp = new ActiveXObject("Msxml2.XMLHTTP");
    	} catch (e) {
      		try {
        		xhttp = new ActiveXObject("Microsoft.XMLHTTP");
      		} catch (e2) {
			    try {
	      			xhttp = new XMLHttpRequest();
	    		} catch (e3) {
	      			xhttp = false;
	    		}
      		}
    	}
  	return xhttp;
}

function ArrayContainWord(myArray,myWord) {
	for (var i = 0; i < myArray.length; i++) {
		if (myArray[i] == myWord) return true;
	}
	return false;
}

function AddWord2StringExclusive(myString,myWord) {
	var myArray = new Array();
	myArray = myString.split(', ');
	if (!ArrayContainWord(myArray,myWord)) {
		myArray.push(myWord);
		return myArray.join(', ');
	} else {
		return myString;
	}
}

function GetXMLHttpRequest(url,method,post_data,return_data_type,callback_function,param_array) {
	var http_request,response;
	try {  
		http_request = new XMLHttpRequest();  
	} catch (e) {  
		try {  
			http_request = new ActiveXObject('MSXML2.XMLHTTP');  
		} catch (e) {  
			try {  
				 http_request = new ActiveXObject('Microsoft.XMLHTTP');  
			} catch (e) {  
				alert("Your browser doesn't support this feature.");
				return false;
			}  
		}  
	}
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				switch (return_data_type) {  
					case 'text':  
						response = http_request.responseText; 
						break;  
					case 'xml':  
						response = http_request.responseXML;
						break;  
					case 'object':  
						response = http_request;
						break;  
				}
				callback_function(response,param_array);
			} else {
				alert('There was a problem with the request.(Code: ' + http_request.status + ')');
				return false;
			}
		}
	};
	http_request.open(method,url,true);
	http_request.setRequestHeader('If-Modified-Since', 'Wed, 15 Jan 1995 01:00:00 GMT');
	http_request.setRequestHeader('Cache-Control','no-cache');
	http_request.setRequestHeader('Cache-Control', 'must-revalidate');
	http_request.setRequestHeader('Cache-Control','no-store');
	http_request.setRequestHeader('Pragma','no-cache');
	http_request.setRequestHeader('Expires','0');
	if (method == 'GET') {
		http_request.send(null);
	} else if (method == 'POST') {
		http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http_request.send(post_data);
	}
}

function searchNumberInString(myString) {
	var regForNumber = /\d+/;
	return myString.match(regForNumber);	
}
