/*--------------------------------------
	Core UI Library
	Author: (Ran.Baron 1/2009)
	Copyright (c) 2009
	baron.ran at gmail dot com
  --------------------------------------*/

var core, coreClass = Class.create({
	options: {},
	msgs: {
		defBusyMsg : 'Processing, Please Wait...',
		busyMsg    : ''
	},

	initialize: function(options) {	
		this.options = Object.extend(this.options, options || {});
	},
	
	Goto: function (Url, win) { if (win) { newWin = top.window.open(Url,'_blank'); } else { self.location.href = Url; } },
	topGoto: function (Url) { if (top) {  if (top.coreWin.winMngr.activeWindow()) { setTimeout(core.cancel,10); } top.location.href = Url; } else { self.location.href = Url; } },
	
	cancel : function (Obj) {
		var activeWin = (coreWin && coreWin.winMngr.activeWindow()) ? coreWin : (parent.coreWin && parent.coreWin.winMngr.activeWindow()) ? parent.coreWin : (top.coreWin) ? top.coreWin : null;
		if (activeWin) {
			if (activeWin.winMngr.activeWindow()) {
				activeWin = activeWin.winMngr.stack.windows.last();
				activeWin.options.reload = (Obj && Obj.reload===true) ? true : false;
				activeWin.close(null, Obj);
			}
		}
		if (Obj && Obj.msg) {
			var cancelWin = new activeWin.Window({
			title:(Obj.title || 'Please Note!'),
			content:Obj.msg,
			style:'padding:10px',
			width:250,height:null,
			shaded:false,
			timer:Obj.timer||2000
		});
		}
	},
	
	alert: function(Obj) {
		var activeWin = (top.coreWin) ? top.coreWin : coreWin;
		var alertWin = new activeWin.Window({ 
			title:(Obj.title || 'Please Note!'),
			html:Obj.msg,
			width:Obj.width || 250,
			height:Obj.height || null,
			close:Obj.close || true,
			style:Obj.style || 'padding:20px;',
			shaded:Obj.shaded || false,
			timer:Obj.timer || null
		});
	},
	
	vEmail:function(str) {
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		return filter.test(str);
	},
    
    contactUs:function(){
		if ($F('fullname').empty()) {
			$('fullname').addClassName('frmError');
			alert("The 'Name' field is required, please try again!");
			$('fullname').focus();
			return;
		}

		if ($F('email').empty()) {
			$('email').addClassName('frmError');
			alert("The 'Email' field is required, please try again!");
			$('email').focus();
			return;
		}
		
		if (!this.vEmail($F('email'))) {
        	$('email').addClassName('frmError');
            alert('This email address is invalid, please try again!');
            $('email').focus();
            return;
        }
    	
        var setAjax = new Ajax.Request('/js/ajax/', {
    		parameters: Object.toQueryString({ 
	            'fields' : Form.serialize('mainForm'),
	            'func'   : 'contactForm'
        	}),
            onComplete: function (req) {
                stateRes = req.responseText;
                if (stateRes==1) {
                    $('contactForm').hide();
                    $('contactThankU').show();
                } else {
                    alert('An error occured, Please try again!');
                }
            }
        });
	}
});

core = new coreClass();

try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}