function navigatePage(f, page) {
  f.current_page.value = page;
  f.submit();
}

// Browser / OS Check
var getNavigator =
{
  init: function()
  {
    this.Browser  = this.searchBrowser(navigator.userAgent);
    this.OS     = this.searchOS(navigator.platform);
  },

  searchBrowser: function(data)
  {
    if(data.indexOf("MSIE") != -1)          return "MSIE";
    else if(data.indexOf("Firefox") != -1)  return "Firefox"
    else if(data.indexOf("Netscape") != -1) return "Netscape";
    else if(data.indexOf("Mozilla") != -1)  return "Netscape";
    else if(data.indexOf("Gecko") != -1)    return "Mozilla";
    else if(data.indexOf("OmniWeb") != -1)  return "OmniWeb";
  },

  searchOS: function(data)
  {
    if(data.indexOf("Win") != -1)         return "Windows";
    else if(data.indexOf("Mac") != -1)    return "Mac";
    else if(data.indexOf("Linux") != -1)  return "Linux";
    else                                  return "unknown";
  }
}
getNavigator.init();

// Login
function login(){
	document.getElementById("light").style.display = "block";
	CoverLayerShow();
	
	document.sendForm1.username_or_email.focus();
}
function login_close(){
	document.getElementById("loginarea").style.display = "none";
	CoverLayerHide();
}
function loginCheck(f){
	if(f.username_or_email.value==""){
		alert("Please input user name or email.");
		f.username_or_email.focus();
		return false;
	}
	if(f.user_pwd.value==""){
		alert("Please input user password.");
		f.user_pwd.focus();
		return false;
	}
	
	var username_or_email = f.username_or_email.value;
	var user_pwd = f.user_pwd.value;
	var user_mode = f.user_mode.value;
	var forwardingUrl = f.forwardingUrl.value;

	var result = GetAjaxResponseText("/login.php?username_or_email="+username_or_email+"&user_pwd="+user_pwd+"&user_mode="+user_mode);
	var tmp = result.split("||");
	var resultCode = tmp[0];
	var resultMsg = tmp[1];
	
	if(resultCode=="Success"){
		if(forwardingUrl==""){
			f.action = "/"+resultMsg;
			window.location.href = "/"+resultMsg;
		}
		else{
			window.location.href = forwardingUrl;
		}
	}
	else if(resultCode=="Fail"){
		alert(resultMsg);
		window.location.href="/"+tmp[2];
	}
	else{
		alert(result);
	}
	
	return false;
}

// Register
function signup(){
	document.getElementById("signuparea").style.display = "block";
	CoverLayerShow();
	//document.getElementById("all_cover_login").style.display = "block";
}
function signup_close(){
	document.getElementById("signuparea").style.display = "none";
	CoverLayerHide();
	//document.getElementById("all_cover_login").style.display = "none";
}

/* Cover Layer Start */
var SetStyleSheet = {
	Display : function ( mode ) {
		if ( mode == 'show' )
			return "block";		
		else
			return "none";
	}
};

var GetLayer = { CoverLayer : function () { return document.getElementById( "CoverLayer" ); } } 
function SetCoverLayerStyle( mode ) {	
	with ( GetLayer.CoverLayer() ) {
		style.position				= "absolute";
		style.top						= "0px";
		style.left						= "0px";
		style.width						= "" + document.body.scrollWidth + "px";
		style.height					= "" + document.body.scrollHeight + "px";
		style.backgroundColor			= "#333333";
		style.filter					= "Alpha(Opacity=50)";
		style.opacity					= "0.5";
		style.zIndex					= "1000";
		style.display					= SetStyleSheet.Display( mode );														
	}	
}

function CoverLayerShow() {	SetCoverLayerStyle( "show" );}

function CoverLayerHide() {	SetCoverLayerStyle( "hide" );}
/* Cover Layer End */


function checkWidget(store_name, idx){
	setCookie("store",store_name,3);
	setCookie("idx",idx,3);
	
	try{
		if(NotifierFinder.IsInstallNotifier("")==true){ // Add Store
			location.href = "widget://vcwg&store="+escape(store_name)+"&rss=http://www.vercoop.com/rss.php?idx="+idx;
		}
		else{ // Setup
			notifier.location.href = "/download/Notifier/download.php";
		}
	}
	catch (e){
		// Setup
		notifier.location.href = "/download/Notifier/download.php";
		//notifier.location.reload();
	}
}

function setCookie(name, value, expiredays){
	var todayDate = new Date(); 
	todayDate.setDate( todayDate.getDate() + expiredays ); 
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";";
}

function goUrl(store_name, idx){
	setCookie("store",store_name,3);
	setCookie("idx",idx,3); 
	
	window.location.href="http://www.vercoop.com/download/vcwg_Setup.exe";
}

function S4(){
	//return (((1+Math.random())*0��10000)|0).toString(16).substring(1);
}

function aaa(){
	//return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()).toUpperCase();
}


function getInfo(c_type, i_type, idx){
	document.getElementById("embedwidget").style.display = "block";
	CoverLayerShow();
	
	result = GetAjaxResponseText("/include/getcode.html?c_type="+c_type+"&i_type="+i_type+"&idx="+idx);
	document.getElementById("embedwidget").innerHTML = result;
}
function getInfo_close(){
	document.getElementById("embedwidget").style.display = "none";
	CoverLayerHide();
}

function add_Notifier(user_email, store_idx, mode){
	result = GetAjaxResponseText("/include/add_notifier.php?user_email="+user_email+"&store_idx="+store_idx+"&mode="+mode);

	var subscribe = document.getElementById("subscribe_id");
	
	if(result=="Y")
	{
		subscribe.innerHTML = "Unsubscribe";
		subscribe.style.background = "url(/img/unsubscribe.gif)";
	}
	else{
		subscribe.innerHTML = "Subscribe";
		subscribe.style.background = "url(/img/add_subscribe.gif)";
	}
	subscribe.style.backgroundRepeat = "no-repeat";
}

// Login
function login_layer(){
	document.getElementById('light').style.display='block';
	document.getElementById('fade').style.display='block';
	
	document.sendForm1.username_or_email.focus();
}

function popupForgotPwd(){
	document.getElementById('light').style.display = 'none';
	document.getElementById('fade').style.display = 'block';

	document.getElementById('forgotPassword').style.display = 'block';
	document.forgotPwdForm.username_or_email.focus();
}

function pwdCheck(f){
	if(f.username_or_email.value==""){
		alert("Please input user name or email.");
		f.username_or_email.focus();
		return false;
	}
	
	result = GetAjaxResponseText("/include/checkPwd.php?username_or_email="+f.username_or_email.value);
	var tmp = result.split("||");
	
	if(tmp[0]=="Success"){
		alert(tmp[1]);
		
		document.getElementById('light').style.display = 'block';
		document.getElementById('forgotPassword').style.display = 'none';
		return false;
	}
	else if(tmp[0]=="Fail"){
		alert(tmp[1]);
		return false;
	}
}

function addSubscribe(my_st_idx,st_idx,ch_idx,cmode){
	var result;
	result = GetAjaxResponseText("/include/addSubscribe.php?my_st_idx="+my_st_idx+"&st_idx="+st_idx+"&ch_idx="+ch_idx+"&mode="+cmode);
	
	var subscribe = document.getElementById("subscribe_id");
	//alert(result);
	
	if(subscribe != null && subscribe != ""){
	
		if(result=="Y")
		{
			subscribe.innerHTML = "Unsubscribe";
			subscribe.style.background = "url(/img/unsubscribe.png)";
			//document.getElementById("subscribe_id").className = "unsubscribe_out";
		}
		else{
			subscribe.innerHTML = "Subscribe";
			subscribe.style.background = "url(/img/add_subscribe_nor.png)";
		}
		subscribe.style.backgroundRepeat = "no-repeat";
	}
}

function addSubscribeMulti(my_st_idx,st_idx,ch_idx,cmode,obj){
	var result;
	result = GetAjaxResponseText("/include/addSubscribe.php?my_st_idx="+my_st_idx+"&st_idx="+st_idx+"&ch_idx="+ch_idx+"&mode="+cmode);

	if(result=="Y"){
		document.getElementById(obj.id).innerHTML = "Unsubscribe";
		document.getElementById(obj.id).style.background = "url(/img/unsubscribe.png)";
		//document.getElementById(obj.id).onmouseout = setBackground(obj,'unsubscribe');
	}
	else{
		document.getElementById(obj.id).innerHTML = "Subscribe";
		document.getElementById(obj.id).style.background = "url(/img/add_subscribe_nor.png)";
		//document.getElementById(obj.id).onmouseout = setBackground(obj,'add_subscribe_nor');
	}
	document.getElementById(obj.id).style.backgroundRepeat = "no-repeat";
}

function setBackground(obj,bgImg){
	document.getElementById(obj.id).style.background = "url(/img/"+bgImg+".png)";
	document.getElementById(obj.id).style.backgroundRepeat = "no-repeat";
}

function subscribeButton(my_st_idx,st_idx,ch_idx,mouseMode){
	var result;
	result = GetAjaxResponseText("/include/addSubscribe.php?my_st_idx="+my_st_idx+"&st_idx="+st_idx+"&ch_idx="+ch_idx+"&mode=query");

	if(mouseMode=="over"){
		document.getElementById("subscribe_id").style.background = "url(/img/add_subscribe_over.png)";
	}
	else{
		if(result=="Y"){
			document.getElementById("subscribe_id").style.background = "url(/img/unsubscribe.png)";
		}
		else{
			document.getElementById("subscribe_id").style.background = "url(/img/add_subscribe_nor.png)";
		}
	}

	document.getElementById("subscribe_id").style.backgroundRepeat = "no-repeat";
}

function addFriends(my_st_idx,st_idx,mode){
	result = GetAjaxResponseText("/include/addFriends.php?my_st_idx="+my_st_idx+"&st_idx="+st_idx+"&mode="+mode);

	var friends = document.getElementById("friends_id");
	
	if(result=="Y"){
		friends.innerHTML = "Remove Friend";
		friends.style.background = "url(/img/unsubscribe.gif)";
	}
	else{
		friends.innerHTML = "Add Friend";
		friends.style.background = "url(/img/add_subscribe.gif)";
	}
	friends.style.backgroundRepeat = "no-repeat";
}

function addFriendsOnly(my_st_idx,st_idx,mode){
	result = GetAjaxResponseText("/include/addFriends.php?my_st_idx="+my_st_idx+"&st_idx="+st_idx+"&mode="+mode);
}

function addFriendsAgain(my_st_idx,st_idx,mode){
	result = GetAjaxResponseText("/include/addFriendsAgain.php?my_st_idx="+my_st_idx+"&st_idx="+st_idx);
}

function joinGroup(st_idx,group_idx,mode){
	result = GetAjaxResponseText("/group/joinGroup.php?st_idx="+st_idx+"&group_idx="+group_idx+"&mode="+mode);

	var friends = document.getElementById("friends_id");
	
	if(result=="Y")
	{
		friends.innerHTML = "Leave Group";
		friends.style.background = "url(/img/unsubscribe.gif)";
	}
	else{
		friends.innerHTML = "Join Group";
		friends.style.background = "url(/img/add_subscribe.gif)";
	}
	friends.style.backgroundRepeat = "no-repeat";
}

function joinGroupOnly(st_idx,group_idx,mode){
	result = GetAjaxResponseText("/group/joinGroup.php?st_idx="+st_idx+"&group_idx="+group_idx+"&mode="+mode);
}

String.prototype.ltrim = function() {
	var re = /\s*((\S+\s*)*)/;
	return this.replace(re, "$1");
}

String.prototype.rtrim = function() {
	var re = /((\s*\S+)*)\s*/;
	return this.replace(re, "$1");
}

String.prototype.trim = function() {
	return this.ltrim().rtrim();
}


function clearText(thefield) {
  if (thefield.defaultValue==thefield.value) {
    thefield.value="";
  }
} 
function defaultText(thefield) {
  if (thefield.value=="") {
    thefield.value=thefield.defaultValue;
  }
}

function blink_text(elId) {
	
  var html = '';
  if (document.all){
    html += 'var el = document.all.' + elId + ';';
  }else if (document.getElementById){
    html += 'var el = document.getElementById("' + elId + '");';
  }
	  
  html += "if(el != null && el != 'undefined'){" +	  
             'el.style.visibility = ' + 
	         'el.style.visibility == "hidden" ? "visible" : "hidden"; }';
  
  if (document.all || document.getElementById) setInterval(html, 1200)
}

function wait(msecs)
{
	var start = new Date().getTime();	
	var cur = start;
	
	while(cur - start < msecs)	
	{	
		cur = new Date().getTime();	
	}
	
}



function getObject(idName) 
{ 
	if (window.document[idName]) 
	{ 
		return window.document[idName]; 
	} 
	
	if (navigator.appName.indexOf("Microsoft Internet")==-1) 
	{ 
		if (document.embeds && document.embeds[idName]) 
		return document.embeds[idName]; 
	} 
	else 
	{ 
		return document.getElementById(idName); 
	} 
} 

var lastMusicControl = null;
var lastMusicInfo = null;

function playMusic(obj) {

	if (lastMusicControl != null)
	{
		lastMusicControl.innerHTML = "";
		lastMusicControl.style.display = "none";
	}
	if (lastMusicInfo != null)
	{
		lastMusicInfo.style.display = "block";
	}

	var idx;
	var title;
	var url;
	var control;
	var st_guid;
	
	for(var i=0; i<obj.attributes.length; i++){
		switch (obj.attributes[i].name){
			case "idx":
			idx = obj.attributes[i].value;
			break;
			case "title":
			title = obj.attributes[i].value;
			break;
			case "url":
			url = obj.attributes[i].value;
			break;
			case "control":
			control = obj.attributes[i].value;
			break;
			case "st_guid":
			st_guid = obj.attributes[i].value;
			break;
		}
	}
	
	var isItLive = GetAjaxResponseText("/include/isItLive.php?cts_idx="+idx);

	lastMusicControl = document.getElementById(control);

	if (lastMusicControl != null)
	{
		lastMusicInfo = obj;
		obj.style.display = "none";

		var html = '<object width="355" height="30" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' ;
		html += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
		html += '<param name="allowFullScreen" value="true">';
		html += '<param name="play" value="true">';
		html += '<param name="wmode" value="transparent">';
		html += '<param name="allowscriptaccess" value="always">';
		html += '<param name="movie" value="/webwidget/podcast/mp3_index.swf?st_guid='+st_guid+'&isItLive='+isItLive+'&idx='+idx+'&media_url='+url+'&title='+title+'">';
		html += '<embed allowFullScreen="true" width="355" height="30" align="middle" allowScriptAccess="always" ';
		html += 'src="/webwidget/podcast/mp3_index.swf?st_guid='+st_guid+'&isItLive='+isItLive+'&idx='+idx+'&media_url='+url+'&title='+title+'"';
		html += ' quality="high" wmode="transparent" type="application/x-shockwave-flash"/>';
		html += '</object>';
		lastMusicControl.innerHTML = html;
		lastMusicControl.style.display = "block";
		lastMusicControl.style.marginTop = "0px";
		lastMusicControl.style.marginLeft = "0px";
		lastMusicControl.style.height = "30px";
		lastMusicControl.style.background = "#FFFFFF";
	}
}


