var OKB = OKB || {};

function submit1() {
    document.form1.submit();
};

function resize_iframe() {
	
	var ie = (document.all)? true:false;
	if(ie) {
		var iframe = document.all.frame1;
		iframe.height = (document.frames("frame1").document.body.scrollHeight-24) + "px";
	} else {
		var f = $("#frame1");
		f.height($("body", f[0].contentDocument).height());
	};

};

function loadPage(page) {
    __doPostBack('PagingControl', page);
}

function videoloadPage(page) {
    __doPostBack('videoPagingControl', page);
}

function friendInvite() {
    var $valid = 'f';
    var Invite = document.getElementById("ctl00_ContentPlaceHolder1_uxFriendsInvite_btnFriendInvitation");
    for (i = 1; i <= 5; i++) {
        var email = document.getElementsByName("ctl00$ContentPlaceHolder1$uxFriendsInvite$friend_email" + i);
        if (email[0].value != '') {
            if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email[0].value) == false) {
                email[0].className = "notvalid";
                $valid = false;
            }
            else
            { email[0].className = ""; if ($valid != false) { $valid = true; } }
        }
    }
    if ($valid == true) { Invite.click(); }
    else { $('.novalid:hidden').fadeIn(); }
}

function blogPost() {
    var Blogs = document.getElementById("ctl00_ContentPlaceHolder1_uxBlogPost_btnSubmit");
    Blogs.click();
}

function professionalblogPost() {
    var Blogs = document.getElementById("ctl00_ContentPlaceHolder1_uxProfessionalBlogPost_btnSubmit");
    Blogs.click();
}

function addPhoto() {
    var Photo = document.getElementById("ctl00_ContentPlaceHolder1_btnSubmit");
    Photo.click();
}

function submitContact() {
    var email;
    email = document.getElementById("ctl00_ContentPlaceHolder1_uxContactUs_txtEmail");
    if (trim(email.value) != '') {
        if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.value) == false)
        { alert("Enter Valid Email address"); return fasle; }
    }
    else
    { alert("Enter Email address"); return fasle; }

    var comment;
    comment = document.getElementById("ctl00_ContentPlaceHolder1_uxContactUs_txtComments");
    if (trim(comment.value) == '')
    { alert("Enter Comments"); return fasle; }

    __doPostBack('ContactUs',''); 
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}

/*
	Table Pagination
	 - Add class="withPagination" to <table> to use
*/
(function($) {

	var
	
	config = {
		rows : 10
	},
	
	showPage = function(table, page) {
		if (page >= 0 && page < table.self.data('pages')) {
			table.rows.hide().each(function(i, el) {
				var row = $(el);
				if (row.data('page') === page) {
					row.show();
				}
			});
			table.self.data('currentPage', page);
			table.controls.find('.n').html(page + 1);
		}
	},
	
	initControls = function(table) {
		var
		prevCtrl = $('<span class="prev"></span>').appendTo(table.controls),
		nextCtrl = $('<span class="next"></span>').prependTo(table.controls);
		
		$('<span class="page">Page&nbsp;<span class="n"></span>&nbsp;of&nbsp;' + table.self.data('pages') + '</span>').insertAfter(nextCtrl);
		prevCtrl.bind('click', function(e) {
			showPage(table, table.self.data('currentPage') - 1);
		});
		nextCtrl.bind('click', function(e) {
			showPage(table, table.self.data('currentPage') + 1);
		});
	},
	
	mark = function(i, el) {
		var
		row = $(el),
		page = Math.floor(i / config.rows);
		
		row.data('page', page);
	},
	
	paginate = function(i, el) {
		var table = {};

		table.self = $(el);
		table.header = table.self.find('tr:first');
		table.rows = table.self.find('tr:not(:first)');
		table.pages = Math.ceil(table.rows.length / config.rows);
		table.controls = table.self.parents('.module:first').find('div.paginationControl:first');
		
	    if (table.controls.length > 0 && table.pages > 1) {
	        table.self.data('pages', table.pages);
	        table.rows.each(mark);
	        initControls(table);
	        table.header.show();
	        showPage(table, (table.self.find('.showFirst:first').data('page') || 0));
	    } else {
	        table.header.show();
	        table.rows.show();
	    }
	},
	
	init = function() {
		$('table.withPagination').each(paginate);
	};

	$(document).ready(function() {
		init();
	});

})(jQuery);

/*
	Get querystring members
*/
OKB.getQS = function(m) {
	var u = document.location.toString().split('?');
	if (u.length > 1) {
		var q = u[1].split('&'), p = {};
		for (var i = 0; i < q.length; i += 1) {
			var c = q[i].split('=');
			p[c[0].toLowerCase()] = c[1];
		}
		return p[m.toLowerCase()] || null;
	}
};



