/*
********************************************************************************
Author	Name	:	Xyfosys Technologies
Script Name		:	scripts.js
Starting Date	:	17-September-2007
Last Modified	:	07-January-2008
********************************************************************************
*/


var _xPos = 'm';
var moveX = 0;
var moveY = 0;
var _gwidth = 0;


document.write('<div style="position:absolute;" id="_tp"></div>');


// If IE
var ie = document.all;
// If NetScape
var ns6 = document.getElementById && !document.all;


// Is true body
function ieTrueBody()
{
	return (document.compatMode && document.compatMode != 'BackCompat')?document.documentElement:document.body;
}

// Returns an object reference to one or more strings (www.conio.net).
// The method checks the actual # of arguments -- returns a single object or an array.
function $()
{
	var elements = new Array();
	
	for(var i=0; i<arguments.length; i++)
	{
		var element = arguments[i];
		
		if(typeof element == 'string')
			element = document.getElementById(element);
		
		if(arguments.length == 1)
			return element;
		
		elements.push(element);
    }
    
    return elements;
}


// Function open new window
function popBox(_url, _size, _scrolls, _resize)
{
	if(typeof _scrolls == 'undefined')
		_scrolls = 'no';
	if(typeof _resize == 'undefined')
		_resize = 'no';
	
	var _splits = _size.split('x');
	var _w = _splits[0];
	var _h = _splits[1];
	window.open(_url, 'popWin', 'width='+_w+', height='+_h+', resizable='+_resize+', alwaysRaised=yes, scrollbars='+_scrolls);
}

// Function open new window
function flashBox(_url)
{
	var w = window.open(_url, 'flaWin', 'width='+screen.width+', height='+screen.height+', resizable=yes, alwaysRaised=yes, scrollbars=yes');
	w.moveTo(0, 0);
}

// Prompt comfirm
function confirms(_msg, _url, _isGo)
{
	var _go = _isGo?_isGo:false;
	var isOk = confirm(_msg, _url);
	if(isOk)
	{
		if(_go)
		{
			window.location.href = _url;
		}
		else
		{
			document.forms[0].action = _url;
			document.forms[0].submit();
			return true;
		}
	}
	else
	{
		return false;
	}
}


function wclose(_bool)
{
	var _bools = _bool?_bool:false;
	if(_bools)
	{
		window.opener.location = window.opener.location;
		window.close();
	}
	else
	{
		window.close();
	}
}


// Function to show tool tips
function showTips(_str, _width, _img)
{
	if(ie || ns6)
	{
		var tipObj = $('_tp');
		_gwidth = _width?_width-(-14):500
		
		var _tipDivs = '\
			<div id="did" style="position:absolute;width:'+_gwidth+'px;border:4px solid #005984;">\
				<div style="width:auto;background-color:#FFFFFF;padding:2px;">\
					<div style="padding:2px 6px 2px 0px;background-color:#DFFFDF;"><img onclick="hideTips(\'_tp\')" style="cursor:pointer;cursor:hand;" align="right" src="js/close_button.gif" border="0" /></div>\
					<div style="padding:6px;background-color:#DFFFDF;"></div>\
					<div align="center" style="padding:2px;"><img align="center" src="uploads/big_image/'+_str+'" border="0" /></div>\
				</div>\
			</div>';
		
		tipObj.innerHTML = _tipDivs;
		
		//tipObj.style.left = mX + 'px';
		//tipObj.style.top = mY + 'px';
		
		// Move tool tip
		_img.onmousemove = mMove;
	}
}


// Function to show tool tips
function showMores(_str, _width)
{
	if(ie || ns6)
	{
		var tipObj = $('_tp');
		_gwidth = _width?_width-(-14):500
		
		var _tipDivs = '\
			<div id="did" style="position:absolute;width:'+_gwidth+'px;border:4px solid #005984;">\
				<div style="width:auto;background-color:#FFFFFF;padding:2px;">\
					<div style="padding:2px 6px 2px 0px;background-color:#DFFFDF;"><img onclick="hideTips(\'_tp\')" style="cursor:pointer;cursor:hand;" align="right" src="js/close_button.gif" border="0" /></div>\
					<div style="padding:6px;background-color:#DFFFDF;"></div>\
					<div id="_more" style="padding:2px;">'+_str+'</div>\
				</div>\
			</div>';
		
		tipObj.innerHTML = _tipDivs;
		
		_xPos = 'r';
		ajaxpage(_str, '_more');
		
		// Move tool tip
		$('_cntid').onmousemove = mMove;
	}
}


// Move tool tip follow by pointer / cursor
function mMove(e)
{
	if (!e)
		var e = window.event||window.Event;
	
	if('undefined' != typeof e.pageX){
		mX = e.pageX;
		mY = e.pageY;
	}
	else{
		mX = e.clientX + ieTrueBody().scrollLeft;
		mY = e.clientY + ieTrueBody().scrollTop;
	}
	
	if(_xPos == 'l')
	{
		$('_tp').style.left = mX + 'px';
	}
	else if(_xPos == 'r')
	{
		$('_tp').style.left = mX-parseInt(_gwidth) + 'px';
	}
	else
	{
		$('_tp').style.left = mX-parseInt(_gwidth/2) + 'px';
	}
	$('_tp').style.top = mY + 'px';
}


// Function to show tool tips
function addEditVideo(_id, _ids, _width)
{
	if(ie || ns6)
	{
		var tipObj = $(_id);
		_width = _width?_width:500
		
		var _tipDivs = '\
			<div id="_idid0" style="position:absolute;width:'+_width+'px;background-color:#FFFFFF;border:4px solid #005984;">\
				<div id="_idid" style="width:auto;background-color:#FFFFFF;padding:2px;"></div>\
			</div>';
		tipObj.innerHTML = _tipDivs;
		
		tipObj.style.left = moveX + 'px';
		tipObj.style.top = moveY + 'px';
		
		if(_ids >= 0)
			ajaxpage('edit/edit_left_menu.php?ids='+_ids, '_idid');
		else if(_ids.search(/demo/g) != '-1')
		{
			tipObj.style.left = (moveX-parseInt(_width)) + 'px';
			ajaxpage('edit/ldemo.php?ids='+_ids, '_idid');
		}
		else
			ajaxpage('edit/add_left_menu.php?ids='+_ids, '_idid');
	}
}
// Move tool tip
document.onmousemove = _mMove;


// Move tool tip follow by pointer / cursor
function _mMove(e)
{
	if (!e)
		var e = window.event||window.Event;
	
	if('undefined' != typeof e.pageX){
		moveX = e.pageX;
		moveY = e.pageY;
	}
	else{
		moveX = e.clientX + ieTrueBody().scrollLeft;
		moveY = e.clientY + ieTrueBody().scrollTop;
	}
}



// Function to hide tips
function hideTips(_id)
{
	if(ie || ns6)
	{
		var tipObj = $(_id);
		if(tipObj.style.display == 'block')
			tipObj.style.display = 'none';
		
		tipObj.innerHTML = '';
	}
}

//
function editText(_id, _width)
{
	if(ie || ns6)
	{
		var tipObj = $('_docid');
		_width = _width?_width:500
		
		var _tipDivs = '\
			<div id="_idid0" style="position:absolute;width:'+_width+'px;background-color:#FFFFFF;border:4px solid #005984;">\
				<div id="_idid" style="width:auto;background-color:#FFFFFF;padding:2px;"></div>\
			</div>';
		tipObj.innerHTML = _tipDivs;
		
		ajaxpage('edit/docedit.php?id='+_id, '_idid');
	}
}


//_upldimg
function popAjaxBox(_container, _query, _width, _pg)
{
	if(ie || ns6)
	{
		var tipObj = $(_container);
		_width = _width?_width:500;
		if(tipObj.style.display == 'none')
			tipObj.style.display = 'block';
		
		var _tipDivs = '\
			<div id="_idid0" style="position:absolute;width:'+_width+'px;background-color:#FFFFFF;border:4px solid #005984;">\
				<div id="_idid" style="width:auto;background-color:#FFFFFF;padding:2px;"></div>\
			</div>';
		
		tipObj.innerHTML = _tipDivs;
		
		//alert(_width);
		//alert(moveX);
		
		if(moveX < _width)
			tipObj.style.left = '60px';
		else
			tipObj.style.left = (moveX-parseInt(_width)) + 'px';
		tipObj.style.top = moveY + 'px';
		
		if(_pg == 'vdo1')
		{
			tipObj.style.left = moveX-100 + 'px';
			tipObj.style.top = moveY-60 + 'px';
			
			ajaxpage('edit/vdo.php?ids='+_query, '_idid');
		}
		else if(_pg == 'vdo')
			ajaxpage('edit/vdo.php?ids='+_query, '_idid');
		else if(_pg == 'misnte')
			ajaxpage('instant_buy_nows/edit_instance'+_query+'.html', '_idid');
		else if(_pg == 'misntnewse')
			ajaxpage('news_headings/edit_news'+_query+'.html', '_idid');
		else if(_pg == 'misntn')
			ajaxpage('instant_buy_nows/new_instance.html', '_idid');
		else if(_pg == 'misntnews')
			ajaxpage('news_headings/new_news.html', '_idid');
		else if(_pg == 'imgupn')
			ajaxpage('edit/add_image.php?ids='+_query, '_idid');
		else if(_pg == 'playvideo')
			ajaxpage('inner_page/playvideo.php?ids='+_query, '_idid');
		else if(_pg == 'tim')
		{
			//tipObj.style.left = moveX-(-400) + 'px';
			//tipObj.style.top = moveY-60 + 'px';
			ajaxpage('tips.php?ids='+_query+'&ti='+_container, '_idid');
		}
		else
		{
			// Nithing
		}
	}
}



// SITE SEARCH
var searchRS = function(event, obj){
	var kcode = event.keyCode?event.keyCode:event.charCode;
	validChar(event);
	
	if(kcode == 13)
	{
		var skeys = obj.value.replace(/,& /g, '+');
		//var skeys = escape(keys.replace(/ /g, '+'));
		////alert(skeys);
		//ajaxpage('search/'+skeys+'.html', 'rightcolumn');
		//alert(key);
	}
}


var validChar = function(event){
	//var sk = ~/[a-z0-9]/;
	//alert(event.keyValue);
	//if(sk.match(event.keyValue))
	//	alert('OK');
	/*
	var kcode = event.keyCode?event.keyCode:event.charCode;
	alert(event.keyChar);
	// Check if valid entries
	if((kcode>=48 && kcode<=57) || (kcode>=65 && kcode<=90) || (kcode>=97 && kcode<=122) || (kcode==32 || kcode==43 || kcode==44))
	{alert(kcode);
		event.returnValue = true;
	}
	else
	{
		if(event.keyCode)
			event.returnValue = false;
		else if(event.which)
			event.preventDefault();
	}
	*/
}


// Check fileds
function checkFields(obj)
{
	alert(obj);
	alert(obj.imgtitle.value);
}


function showhide(id, bool)
{
	if(bool)
		$(id).style.display = 'block';
	else
		$(id).style.display = 'none';
}

function _check()
{
	var _str = '';
	if(document.projFrm._text2.value == '')
		_str += 'Enter your name.'+"\n";
	if(document.projFrm._text3.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)== -1)
		_str += 'Enter your valid email.'+"\n";
	if(document.projFrm._text4.value == '')
		_str += 'Enter payable amount.'+"\n";
	if(document.projFrm._text5.value == '')
		_str += 'Enter payment note.'+"\n";
	
	if(_str == '')
		document.projFrm.submit();
	else
		alert(_str);
}