
// Simple Pop out DIV
var viewport = {
    o: function() {
        if (self.innerHeight) {
			this.pageYOffset = self.pageYOffset;
			this.pageXOffset = self.pageXOffset;
			this.innerHeight = self.innerHeight;
			this.innerWidth = self.innerWidth;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			this.pageYOffset = document.documentElement.scrollTop;
			this.pageXOffset = document.documentElement.scrollLeft;
			this.innerHeight = document.documentElement.clientHeight;
			this.innerWidth = document.documentElement.clientWidth;
		} else if (document.body) {
			this.pageYOffset = document.body.scrollTop;
			this.pageXOffset = document.body.scrollLeft;
			this.innerHeight = document.body.clientHeight;
			this.innerWidth = document.body.clientWidth;
		}
		return this;
    },
    init: function(el) {
    	jQuery(el).css("display","");
        jQuery(el).css("left",Math.round(viewport.o().innerWidth/2) + viewport.o().pageXOffset - Math.round(jQuery(el).width()/2));
        jQuery(el).css("top",Math.round(viewport.o().innerHeight/2) + viewport.o().pageYOffset - Math.round(jQuery(el).height()/2)-20);
    }
};// End Simple Pop out DIV
//Get X and Y position of an element
var elementPos = {
	init: function(el)
	{
		xPos = document.getElementById(el).offsetLeft;
		tempEl = document.getElementById(el).offsetParent;
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
			tempEl = tempEl.offsetParent;
		}
		
		yPos = document.getElementById(el).offsetTop;
		tempEl = document.getElementById(el).offsetParent;
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		yPos = yPos - 250;
		window.scroll(xPos,yPos); 
  }
};//End Get X and Y position of an element    

//Pop up Newsletter
function popNewsletter(){
	var newscontent = "<form id=\"newsletter\" name=\"newsletter\" action=\"\" method=\"post\"><input type=\"hidden\" id=\"pageaction\" name=\"pageaction\" value=\"subscribenews\"><p class=\"news_field\"><span id=\"error\" class=\"redspan\">&nbsp;</span></p><p class=\"news_field\">Nama&nbsp;&nbsp;</p><p class=\"news_field\"><input type=\"text\" id=\"name\" name=\"name\" style=\"width:150px\" value=\"\"></p><p class=\"news_field\">Telefon Bimbit&nbsp;&nbsp;</p><p class=\"news_field\"><input type=\"text\" id=\"phone\" name=\"phone\" style=\"width:150px\" value=\"\"></p><p class=\"news_field\">Emel&nbsp;&nbsp;</p><p class=\"news_field\"><input type=\"text\" id=\"email\" name=\"email\" style=\"width:150px\" value=\"\"></p><a href=\"#\"><div id=\"popup_submit\" class=\"popup_submit\" ></div></a></form>";
	   
    jQuery("#opaque").show();
    windowDiv = "<div class='popup_inner'><a href=\"#\"><div style='float:right;' class='popup_close'></div></a><div class='popup_content'>"+newscontent+"</div></div>";  
	jQuery("#popupdiv").append(windowDiv);
	viewport.init("#popupdiv");           
	jQuery('.popup_inner').fadeIn();
    jQuery(".popup_close").click(function(){
        jQuery(".popup_inner").remove(); 	                
		jQuery("#popupdiv").css("display","none");  
    	jQuery("#opaque").hide();               
        return false;
    });           
    jQuery("#popup_submit").click(function(e){ // Register Newsletter 
		e.preventDefault();
 		var pageaction = jQuery("#pageaction").val();
 		var yourname = jQuery("input#name").val();
		if (yourname == "") {
	      	jQuery('#error').html("Sila Masukan Nama Anda!");
	      	jQuery("input#name").focus();
	      	return false;
	    }
 		var yourphone = jQuery("input#phone").val();
		if (yourphone == "") {
	      	jQuery('#error').html("Sila Masukan Telefon Bimbit!");
	      	jQuery("input#phone").focus();
	      	return false;
	    }
 		var youremail = jQuery("input#email").val();	
		if(validateEmail(youremail)){			
	 		jQuery('#error').html("Sila Masukan Emel Yang Sah.");
	  		jQuery("input#email").focus();
	  		return false;
		}
		var dataString = 'pageaction=' + pageaction + '&yourname=' + yourname + '&yourphone=' + yourphone + '&youremail='+ youremail;
		jQuery.ajax({
	    	type: "POST",
	    	url: "newsletter.php",
	    	data: dataString,
	    	success: function(responseText, responseStatus) {
        		jQuery(".popup_content").html(responseText);
	        }
	     });
	});// End Register Newsletter  
}//End Pop Up Newsletter

//function Validate Email contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
function validateEmail(email){
	if(! /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(email)){
	      	return true;
		}
}//End Validate Email

$(function() {
});
