
function setDivContent(in_divid, in_str)
{
	if(document.getElementById)  // W3 dom
	{
		document.getElementById(in_divid).innerHTML = in_str;
	}
	else if(document.all) // IE4
	{
		window.document.all[in_divid].innerHTML = in_str;
	}
	else if (document.layers) //NS4
	{
		window.document.layers[in_divid].innerHTML = in_str;
    }
}

function setParentDivContent(in_divid, in_str)
{
	if(document.getElementById)  // W3 dom
	{
		self.opener.document.getElementById(in_divid).innerHTML = in_str;
	}
	else if(document.all) // IE4
	{
		self.opener.window.document.all[in_divid].innerHTML = in_str;
	}
	else if (document.layers) //NS4
	{
		self.opener.window.document.layers[in_divid].innerHTML = in_str;
    }
}

function showDiv(in_divId)	{
	if (document.getElementById) { //NS6
		document.getElementById(in_divId).style.visibility = "visible" ;
	}
	else if (document.all) { //IE4
		window.document.all[in_divId].style.visibility = "visible";
	}
	else if (document.layers) { //NS4
		window.document.layers[in_divId].visibility = "show";
	}
}

function hideDiv(in_divId)
{
	if (document.getElementById) { //NS6
		 document.getElementById(in_divId).style.visibility = "hidden" ;
	}
	else if (document.all) { //IE4
		window.document.all[in_divId].style.visibility = "hidden";
	}
	else if (document.layers) { //NS4
		window.document.layers[in_divId].visibility = "hide";
	}
}

function divBlock( in_divId ) {
	if (document.getElementById) { //NS6
		 document.getElementById(in_divId).style.display = "block";
	}
	else if (document.all) { //IE4
		window.document.all[in_divId].style.display = "block";
	}
	else if (document.layers) { //NS4
		window.document.layers[in_divId].display = "block";
	}
}

function divNone( in_divId ) {
	if (document.getElementById) { //NS6
		 document.getElementById(in_divId).style.display = "none" ;
	}
	else if (document.all) { //IE4
		window.document.all[in_divId].style.display = "none";
	}
	else if (document.layers) { //NS4
		window.document.layers[in_divId].display = "none";
	}
}

function divContent(in_divId,in_contentDiv)	{
	if (document.getElementById) { //NS6
		document.getElementById(in_divId).innerHTML  = document.getElementById(in_contentDiv).innerHTML ;
	}
	else if (document.all) { //IE4
		window.document.all[in_divId].innerHTML  = window.document.all[in_contentDiv].innerHTML;
	}
	else if (document.layers) { //NS4
		window.document.layers[in_divId].innerHTML  = window.document.layers[in_contentDiv].innerHTML;
	}
}

function showOffset(object,x,y) {
    if (document.layers && document.layers[object]) {
        document.layers[object].left += x;
        document.layers[object].top += y;
        document.layers[object].visibility = 'visible';
    }
    else if (document.all) {
        document.all[object].style.posLeft = document.all[object].offsetLeft + x;
        document.all[object].style.posTop = document.all[object].offsetTop + y;
        document.all[object].style.visibility = 'visible';
    }
}

function hideOffset(object,x,y) {
    if (document.layers && document.layers[object]) {
        document.layers[object].visibility = 'hidden';
        document.layers[object].left -= x;
        document.layers[object].top -= y;
    }
    else if (document.all) {
        document.all[object].style.visibility = 'hidden';
        document.all[object].style.posLeft -= x;
        document.all[object].style.posTop -= y;
    }
}

function setSelect( form, field, value )
{
    for( i=0; i < form.elements[field].length; i++ )
    {
        // alert(form.elements[field].options[i].value);
        if( form.elements[field].options[i].value == value )
        {
            form.elements[field].options[i].selected = true;
        }
    }
    return false;
}

function setRemember( form )
{
	if( getCookie('user') != 'null' && getCookie('user') != '' && getCookie('user') ) { form.elements['USER'].value = getCookie('user'); }
	if( getCookie('password') != 'null' && getCookie('password') != '' && getCookie('password') ) { form.elements['PASSWORD'].value = getCookie('password'); }
	if( getCookie('save') == 'true' && getCookie('save') && form.elements['REMEMBER'] ) { form.elements['REMEMBER'].checked = true; }
	document.forms['LOGIN'].elements['USER'].focus();
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
	return null;
}

function checkImages( num )
{
	for( i = 0; i < num; i++ )
	{
		img = eval("document.forms['post'].elements['image" + i + "']" );
		if( img.value != '' )
			return false;
	}
	return true;
}

function getRandom( upper )
{
    var ranNum= Math.round(Math.random()*upper);
    ranNum = ( ranNum.toString().length < 2 ) ? '00' + ranNum : ranNum;
    ranNum = ( ranNum.toString().length < 3 ) ? '0' + ranNum : ranNum;
    return ranNum;
}

function confirmAction( url, msg)
{
    if( msg == null || msg == '')
    {
        msg = 'Are you sure?';
    }
    if( confirm( msg))
    {
        window.location = url;
    }
    else
    {
    	return false;
    }
}

function basicConfirm( msg )
{
    if( !confirm( msg ) )
    { return false; }
    else
    { return true; }
}

function swapImage( on, off, current )
{
	if( current == on ) {
		this.src = off;
	} else {
		this.src = on;
	}
}

function trim(in_string)
{
	return in_string.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

function download( file, redirect )
{
	window.open(file,'awcdownload','toolbar=0,location=no,directories=0,status=0,scrollbars=no,resizable=0,width=1,height=1,top=0,left=0');
	window.focus();
	if( redirect )
	{
		if( redirect.length > 0 )
		{
			location.href = redirect;
			return true;
		}
	}
	return true;
}
function setAffiliate(name, value)
{
	var expires = new Date();
	expires.setTime(expires.getTime() + 60*60*24*90);
	setCookie(name, value, expires);

}

function setCookie(name, value, expires) {
  	var curCookie = name + "=" + escape(value) +
    	((expires) ? "; expires=" + expires.toGMTString() : "") ;
    curCookie = curCookie + "; path=/; domain=.anywebcam.com";
	document.cookie = curCookie;
}

function getCookie(name)
{  if (document.cookie.length > 0) 
{     begin = document.cookie.indexOf(name+"="); 
    if (begin != -1)   
     begin += name.length+1; 
      end = document.cookie.indexOf(";", begin);
      if (end == -1) end = document.cookie.length;
      if(begin == -1)
      	return null;
      	
      return unescape(document.cookie.substring(begin, end));       
  }

}

function billingCharacterCheck( userStr, passStr, message ) {
    if( ( userStr.length > 12 ) || ( passStr > 12 ) )
    {
        alert( message );
    }
    re = /^[A-Za-z][A-Za-z0-9]+$/i;
    if(!userStr.match(re) || !passStr.match(re))
    {
        alert( message );
    }
}

function ageCheck( date )
{
    var now= new Date( );
    var date = new Date( parseInt( date ) );
    
    difference = now - date;
    years = difference / (1000*60*60*24*365);
    if( years > 18 ) {
        return true;
    } else {
        return false;
    }
}

function checkDomain(str)
{
    if( email.toLowerCase().indexOf("anywebcam") == -1) { 
        return true; 
    } else { 
        return false; 
    }
}

function LooksLikeEmail(str, check) {
	re = /^[-\w_\.]+(\.[-\w_]+)?@[-\w]+\.[-\w\.]+$/i;
	return str.match(re) ? true : false;
}

function LooksLikeUsername(str) {
	if(str.toLowerCase().indexOf("admin") != -1)
		return false;

	if(str.toLowerCase().indexOf("fuck") != -1)
		return false;
		
	if(str.toLowerCase().indexOf("cunt") != -1)
		return false;

	if(str.toLowerCase().indexOf("awc") != -1)
		return false;

	if(str.toLowerCase().indexOf("anywebcam") != -1)
		return false;
		
	if(str.toLowerCase().indexOf("jmeeting") != -1)
		return false;

	re = /^[A-Za-z][\-A-Za-z0-9]+$/i;
	return str.match(re)?true:false; 
}

function validatePassword(str) {
	re = /^[^\s\/\-?]{6,}$/i;
	

	return str.match(re) ? true : false;
	// return true;
}

function validateStr( str, minlength, maxlength )
{
	if( ( str.length > minlength ) && ( str.length < maxlength ) )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function validateNum( num, min, max )
{
	num = parseInt( num );
	if( ( num > min ) && ( num < max ) )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function refresh( url )
{
    window.location.href = url;
}

function addError( error )
{
	return '* ' + error + '\n';
}

function checkForError( intro, errorStr )
{
	if( errorStr.length > 0 ) {
		alert( intro + '\n' + errorStr );
		return false;
	} else {
		return true;
	}
}

function checkGoodTags( text )
{
	// paragraph, italics, bold, break, anchor
	re = /<(\/?(?!p\W|i\W|b\W|P\W|I\W|B\W|BR\W|br\W|Br\W|a\W|A\W)\w+)/g;

	if( text.match( re ) ) {
		return false;
	} else {
		return true;
	}
}

function checkVideo(value) {
	if(value.toLowerCase().match(/(\.mpg|\.avi|\.asf|\.wmv|\.qt|\.rm|\.ra|\.ram|\.wmf|\.wmx|\.wm|\.mov|\.mpeg)$/i))
		return true;
	else
		return false;
}

function checkImage(value) {
	if(value.toLowerCase().match(/(\.gif|\.jpg|\.jpeg|\.png|\.bmp)$/i))
		return true;
	else
		return false;
}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  }
}


